kipe 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- kipe-0.1.0/.github/workflows/ci.yml +43 -0
- kipe-0.1.0/.github/workflows/release.yml +58 -0
- kipe-0.1.0/.gitignore +36 -0
- kipe-0.1.0/.pre-commit-config.yaml +35 -0
- kipe-0.1.0/AUTHORS +24 -0
- kipe-0.1.0/CITATION.cff +34 -0
- kipe-0.1.0/DESIGN_OVERVIEW.md +164 -0
- kipe-0.1.0/LICENSE +22 -0
- kipe-0.1.0/PKG-INFO +124 -0
- kipe-0.1.0/README.md +90 -0
- kipe-0.1.0/examples/fitzhugh_nagumo/study.yaml +37 -0
- kipe-0.1.0/pyproject.toml +136 -0
- kipe-0.1.0/src/kipe/__init__.py +5 -0
- kipe-0.1.0/src/kipe/_formatting.py +27 -0
- kipe-0.1.0/src/kipe/_types.py +6 -0
- kipe-0.1.0/src/kipe/_yaml.py +24 -0
- kipe-0.1.0/src/kipe/cli.py +307 -0
- kipe-0.1.0/src/kipe/estimation.py +646 -0
- kipe-0.1.0/src/kipe/examples/__init__.py +1 -0
- kipe-0.1.0/src/kipe/examples/fitzhugh_nagumo.py +158 -0
- kipe-0.1.0/src/kipe/forward_solver.py +226 -0
- kipe-0.1.0/src/kipe/measurements.py +248 -0
- kipe-0.1.0/src/kipe/options.py +357 -0
- kipe-0.1.0/src/kipe/parameters.py +226 -0
- kipe-0.1.0/src/kipe/plot.py +405 -0
- kipe-0.1.0/src/kipe/provenance.py +333 -0
- kipe-0.1.0/src/kipe/py.typed +0 -0
- kipe-0.1.0/src/kipe/roukf.py +374 -0
- kipe-0.1.0/src/kipe/sampling.py +79 -0
- kipe-0.1.0/src/kipe/synthesis.py +188 -0
- kipe-0.1.0/tests/examples/test_fitzhugh_nagumo.py +61 -0
- kipe-0.1.0/tests/examples/test_fitzhugh_nagumo_protocol.py +71 -0
- kipe-0.1.0/tests/test_estimation.py +324 -0
- kipe-0.1.0/tests/test_measurement_options.py +84 -0
- kipe-0.1.0/tests/test_measurements.py +124 -0
- kipe-0.1.0/tests/test_parameters.py +153 -0
- kipe-0.1.0/tests/test_plot.py +222 -0
- kipe-0.1.0/tests/test_provenance.py +153 -0
- kipe-0.1.0/tests/test_roukf.py +76 -0
- kipe-0.1.0/tests/test_roukf_kalman.py +183 -0
- kipe-0.1.0/tests/test_study_file.py +201 -0
- kipe-0.1.0/tests/test_synthesis.py +130 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
concurrency:
|
|
9
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
10
|
+
cancel-in-progress: true
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
lint:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
with:
|
|
18
|
+
fetch-depth: 0 # all tags, for the version (hatch-vcs)
|
|
19
|
+
- uses: actions/setup-python@v5
|
|
20
|
+
with:
|
|
21
|
+
python-version: "3.12"
|
|
22
|
+
- run: pip install ".[check,test,plot]"
|
|
23
|
+
- run: ruff check .
|
|
24
|
+
- run: ruff format --check .
|
|
25
|
+
- run: mypy
|
|
26
|
+
|
|
27
|
+
test:
|
|
28
|
+
runs-on: ubuntu-latest
|
|
29
|
+
strategy:
|
|
30
|
+
fail-fast: false
|
|
31
|
+
matrix:
|
|
32
|
+
python-version: ["3.12", "3.13"]
|
|
33
|
+
steps:
|
|
34
|
+
- uses: actions/checkout@v4
|
|
35
|
+
with:
|
|
36
|
+
fetch-depth: 0 # all tags, for the version (hatch-vcs)
|
|
37
|
+
- uses: actions/setup-python@v5
|
|
38
|
+
with:
|
|
39
|
+
python-version: ${{ matrix.python-version }}
|
|
40
|
+
# non-editable install: with the src layout, tests run against the installed package
|
|
41
|
+
# mpi4py loads an MPI library at runtime; the runner has none, so install MPICH from PyPI
|
|
42
|
+
- run: pip install ".[test,plot]" mpich
|
|
43
|
+
- run: pytest -q
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
# Publishing a GitHub release builds the package from its tag and uploads it:
|
|
4
|
+
# a pre-release (e.g., tag 0.1.0rc1) to TestPyPI, a release (e.g., tag 0.1.0) to PyPI.
|
|
5
|
+
# Uploads use trusted publishing: no token; the projects on (Test)PyPI name this workflow
|
|
6
|
+
# and its environment as their publisher.
|
|
7
|
+
|
|
8
|
+
on:
|
|
9
|
+
release:
|
|
10
|
+
types: [published]
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
build:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
with:
|
|
18
|
+
fetch-depth: 0 # all tags, for the version (hatch-vcs)
|
|
19
|
+
- uses: actions/setup-python@v5
|
|
20
|
+
with:
|
|
21
|
+
python-version: "3.12"
|
|
22
|
+
- run: pip install build twine
|
|
23
|
+
- run: python -m build
|
|
24
|
+
- run: twine check --strict dist/*
|
|
25
|
+
- uses: actions/upload-artifact@v4
|
|
26
|
+
with:
|
|
27
|
+
name: dist
|
|
28
|
+
path: dist/
|
|
29
|
+
|
|
30
|
+
testpypi:
|
|
31
|
+
if: github.event.release.prerelease
|
|
32
|
+
needs: build
|
|
33
|
+
runs-on: ubuntu-latest
|
|
34
|
+
environment: testpypi
|
|
35
|
+
permissions:
|
|
36
|
+
id-token: write # trusted publishing, only in the upload job
|
|
37
|
+
steps:
|
|
38
|
+
- uses: actions/download-artifact@v4
|
|
39
|
+
with:
|
|
40
|
+
name: dist
|
|
41
|
+
path: dist/
|
|
42
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
43
|
+
with:
|
|
44
|
+
repository-url: https://test.pypi.org/legacy/
|
|
45
|
+
|
|
46
|
+
pypi:
|
|
47
|
+
if: ${{ !github.event.release.prerelease }}
|
|
48
|
+
needs: build
|
|
49
|
+
runs-on: ubuntu-latest
|
|
50
|
+
environment: pypi
|
|
51
|
+
permissions:
|
|
52
|
+
id-token: write # trusted publishing, only in the upload job
|
|
53
|
+
steps:
|
|
54
|
+
- uses: actions/download-artifact@v4
|
|
55
|
+
with:
|
|
56
|
+
name: dist
|
|
57
|
+
path: dist/
|
|
58
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
kipe-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Byte-compiled / cached files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
|
|
5
|
+
# Packaging / build
|
|
6
|
+
build/
|
|
7
|
+
dist/
|
|
8
|
+
*.egg-info/
|
|
9
|
+
.eggs/
|
|
10
|
+
src/kipe/_version.py
|
|
11
|
+
|
|
12
|
+
# Virtual environments
|
|
13
|
+
.venv/
|
|
14
|
+
venv/
|
|
15
|
+
env/
|
|
16
|
+
|
|
17
|
+
# Tool caches
|
|
18
|
+
.mypy_cache/
|
|
19
|
+
.ruff_cache/
|
|
20
|
+
.pytest_cache/
|
|
21
|
+
.coverage
|
|
22
|
+
.coverage.*
|
|
23
|
+
htmlcov/
|
|
24
|
+
|
|
25
|
+
# Output of running the examples
|
|
26
|
+
examples/**/data/
|
|
27
|
+
examples/**/results/
|
|
28
|
+
|
|
29
|
+
# Docs build
|
|
30
|
+
doc/build/
|
|
31
|
+
docs/_build/
|
|
32
|
+
|
|
33
|
+
# Editors / OS
|
|
34
|
+
.idea/
|
|
35
|
+
*.swp
|
|
36
|
+
.DS_Store
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Install: pip install ".[check]" && pre-commit install --hook-type pre-commit --hook-type commit-msg
|
|
2
|
+
repos:
|
|
3
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
4
|
+
rev: v6.0.0
|
|
5
|
+
hooks:
|
|
6
|
+
- id: check-yaml
|
|
7
|
+
- id: check-toml
|
|
8
|
+
- id: end-of-file-fixer
|
|
9
|
+
- id: trailing-whitespace
|
|
10
|
+
- id: check-added-large-files
|
|
11
|
+
|
|
12
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
13
|
+
rev: v0.16.9 # keep in sync with the ruff pin in pyproject.toml [check]
|
|
14
|
+
hooks:
|
|
15
|
+
- id: ruff-check
|
|
16
|
+
args: [--fix]
|
|
17
|
+
- id: ruff-format
|
|
18
|
+
|
|
19
|
+
- repo: https://github.com/pre-commit/mirrors-mypy
|
|
20
|
+
rev: v2.3.1 # keep in sync with the mypy pin in pyproject.toml [check]
|
|
21
|
+
hooks:
|
|
22
|
+
- id: mypy
|
|
23
|
+
files: ^(src|tests)/
|
|
24
|
+
pass_filenames: false
|
|
25
|
+
additional_dependencies: [matplotlib, mpi4py, numpy, pytest, pydantic, ruamel.yaml]
|
|
26
|
+
|
|
27
|
+
# The scope is optional: the module a commit is about, or the area for non-code changes,
|
|
28
|
+
# e.g., "feat(plot): ...", "fix(estimation,roukf): ..."; no scope for broader commits.
|
|
29
|
+
- repo: https://github.com/compilerla/conventional-pre-commit
|
|
30
|
+
rev: v4.4.0
|
|
31
|
+
hooks:
|
|
32
|
+
- id: conventional-pre-commit
|
|
33
|
+
stages: [commit-msg]
|
|
34
|
+
args:
|
|
35
|
+
- --scopes=cli,options,forward-solver,parameters,measurements,sampling,synthesis,estimation,roukf,plot,provenance,fenicsx,examples,docs,ci,pre-commit
|
kipe-0.1.0/AUTHORS
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
kipe authors
|
|
2
|
+
============
|
|
3
|
+
|
|
4
|
+
The copyright notice "The kipe authors" in LICENSE refers to the people listed
|
|
5
|
+
here. See CITATION.cff for how to cite kipe.
|
|
6
|
+
|
|
7
|
+
Authors
|
|
8
|
+
-------
|
|
9
|
+
|
|
10
|
+
- David Nolte
|
|
11
|
+
- Cristóbal Bertoglio
|
|
12
|
+
|
|
13
|
+
roukf contributors
|
|
14
|
+
------------------
|
|
15
|
+
|
|
16
|
+
kipe contains code derived from roukf (MIT License, "Copyright (c) 2018-2026 The
|
|
17
|
+
roukf authors"). Contributors to roukf, in alphabetical order:
|
|
18
|
+
|
|
19
|
+
- Reidmen Arostica Barrera
|
|
20
|
+
- Cristóbal Bertoglio
|
|
21
|
+
- Jeremías Garay Labra
|
|
22
|
+
- Miriam Löcke
|
|
23
|
+
- David Nolte
|
|
24
|
+
- Giorgia Pase
|
kipe-0.1.0/CITATION.cff
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Citation metadata, used by GitHub ("Cite this repository") and Zenodo.
|
|
2
|
+
# Format: https://citation-file-format.github.io — validate with `cffconvert --validate`.
|
|
3
|
+
cff-version: 1.2.0
|
|
4
|
+
message: "If you use kipe, please cite it using the metadata below."
|
|
5
|
+
title: "kipe: Kalman-based identifiability and parameter estimation"
|
|
6
|
+
type: software
|
|
7
|
+
abstract: >-
|
|
8
|
+
Identifiability and parameter estimation for PDE models: reduced-order unscented
|
|
9
|
+
Kalman filtering (ROUKF), Fisher-information sensitivity analysis and synthetic
|
|
10
|
+
observations, with an optional FEniCSx backend.
|
|
11
|
+
license: MIT
|
|
12
|
+
repository-code: "https://github.com/cardiomath/kipe" # TODO: update if moved to an organization
|
|
13
|
+
keywords:
|
|
14
|
+
- ROUKF
|
|
15
|
+
- unscented Kalman filter
|
|
16
|
+
- data assimilation
|
|
17
|
+
- parameter estimation
|
|
18
|
+
- identifiability
|
|
19
|
+
- Fisher information
|
|
20
|
+
- inverse problems
|
|
21
|
+
- FEniCS
|
|
22
|
+
authors:
|
|
23
|
+
- family-names: Nolte
|
|
24
|
+
given-names: David
|
|
25
|
+
affiliation: "University of Groningen"
|
|
26
|
+
orcid: "https://orcid.org/0000-0002-3535-8075"
|
|
27
|
+
- family-names: Bertoglio
|
|
28
|
+
given-names: Cristóbal
|
|
29
|
+
affiliation: "University of Groningen"
|
|
30
|
+
orcid: "https://orcid.org/0000-0001-5049-1707"
|
|
31
|
+
# Add on release (or let Zenodo add the DOI):
|
|
32
|
+
# version: 0.1.0
|
|
33
|
+
# date-released: YYYY-MM-DD
|
|
34
|
+
# doi: 10.5281/zenodo.TODO
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# kipe: design overview
|
|
2
|
+
|
|
3
|
+
**Goal:** one open-source package (GitHub, MIT) for Kalman-based parameter estimation (ROUKF),
|
|
4
|
+
Fisher-information sensitivity analysis and synthetic measurements. It should work with *any*
|
|
5
|
+
forward solver, not only fsix. kipe is the successor of roukf: a fresh repo with ported code,
|
|
6
|
+
while roukf stays in use until kipe reaches parity.
|
|
7
|
+
|
|
8
|
+
## Principles
|
|
9
|
+
|
|
10
|
+
1. **Solver-agnostic core.** The core is pure numpy, with no FEniCS dependency. FEniCSx is an
|
|
11
|
+
optional backend (`pip install kipe[fenicsx]`).
|
|
12
|
+
2. **kipe never changes solver settings.** The solver owns `dt`, `T`, output paths. kipe only
|
|
13
|
+
passes state, parameters and time. This removes today's conflicting settings, such as the
|
|
14
|
+
timestep defined in both input files.
|
|
15
|
+
3. **Configuration lives in input files, not command-line arguments.** One archived YAML file
|
|
16
|
+
fully reproduces an HPC run.
|
|
17
|
+
4. **Small, explicit extension points.** Adding a new solver, data format, spatial sampler or
|
|
18
|
+
measurement type means writing one small class.
|
|
19
|
+
|
|
20
|
+
## Forward solver interface
|
|
21
|
+
|
|
22
|
+
- **Stateless calls:** `initial_state()`, `propagate(t0, t1, state, θ)`.
|
|
23
|
+
- **State:** named numpy fields, local to each MPI rank. Measurements refer to fields by name
|
|
24
|
+
(`velocity`), not by index.
|
|
25
|
+
- **Parameters:** the solver lists what can be estimated, with nominal values
|
|
26
|
+
(e.g., `fluid.bc4.R_d`). The kipe config selects parameters and sets the prior (std next to
|
|
27
|
+
the reparameterization; optionally the initial guess). Today the prior is split across two
|
|
28
|
+
files.
|
|
29
|
+
- **Construction:** the input file names a `factory` (a class, or a function returning the
|
|
30
|
+
solver) plus its arguments. Using kipe directly from Python works just as well.
|
|
31
|
+
- **Time:** `propagate` guarantees that all particles reach the same time. Solvers with a
|
|
32
|
+
fixed step are checked against the measurement times at startup, before anything is
|
|
33
|
+
computed.
|
|
34
|
+
|
|
35
|
+
## Measurements, sampling, innovations
|
|
36
|
+
|
|
37
|
+
- **Measurement:** data (read by a pluggable Reader) + times + noise σ. One generic class.
|
|
38
|
+
- **SpatialSampler:** samples the solver's fields at the measurement locations; depends on
|
|
39
|
+
the solver: interpolation, voxelization, point evaluation, projections (component, surface
|
|
40
|
+
normal). ("Spatial" as opposed to the temporal sampling given by the measurement times.)
|
|
41
|
+
- **MeasurementModel:** the acquisition physics. `predict` is the signal model (e.g., MRI
|
|
42
|
+
phase, FFT, mask); `innovation` is the comparison formula (plain difference, phase-based,
|
|
43
|
+
complex).
|
|
44
|
+
- **Observation operator** H = M ∘ S: measurement model after spatial sampling,
|
|
45
|
+
h(x) = `predict(sample(x))`. It's shared by estimation, synthetic data and sensitivity
|
|
46
|
+
analysis, so the same model that generates the data also inverts it. ("Observation" is
|
|
47
|
+
reserved for this composite, as in the data-assimilation literature.)
|
|
48
|
+
- **Extension cost:** a new data format is one reader; a new sampling method is one
|
|
49
|
+
spatial sampler; a new innovation rule is one model. Costs add up (N + M), instead of one class
|
|
50
|
+
per combination (N × M).
|
|
51
|
+
|
|
52
|
+
## Parallelism
|
|
53
|
+
|
|
54
|
+
- **Particles in parallel:** within a step, particles are independent; they only synchronize at
|
|
55
|
+
the correction. Ranks are split into groups, each running its own solver instance on n
|
|
56
|
+
ranks; the filter combines particles across groups with elementwise MPI reductions (the
|
|
57
|
+
state is rank-local numpy). Up to q·n tasks for q particles in one job; serial solvers
|
|
58
|
+
(numpy/scipy) are the case n = 1 (`mpirun -n q`).
|
|
59
|
+
- **After 0.1, prepared for now:** 0.1 runs particles sequentially. The core takes its MPI
|
|
60
|
+
communicator as an argument from day one (no hardcoded global communicator), and solvers
|
|
61
|
+
receive theirs at construction, so particle groups can be added later without re-plumbing:
|
|
62
|
+
first serial solvers (n = 1), then groups of several ranks (partition check, fsix
|
|
63
|
+
sub-communicator support).
|
|
64
|
+
- **Sensitivity analysis (FIM):** the 2n+1 finite-difference runs are independent, so they
|
|
65
|
+
map onto a job array: `kipe sensitivity plan / run --index i / assemble`, or a local loop.
|
|
66
|
+
|
|
67
|
+
## Problems fixed along the way
|
|
68
|
+
|
|
69
|
+
- **Measurement data at other MPI rank counts:** PETScBinaryIO only reads back with the same
|
|
70
|
+
number of ranks. io4dolfinx reads with any number.
|
|
71
|
+
- **MPI-safe innovations:** each entry is owned by exactly one rank.
|
|
72
|
+
- **Generic resume** of interrupted runs.
|
|
73
|
+
- **Parameter names instead of `theta_0..n`** in the outputs.
|
|
74
|
+
|
|
75
|
+
## Input file and CLI
|
|
76
|
+
|
|
77
|
+
**One CLI with subcommands** (`kipe estimation / synthesis / sensitivity`, with verb aliases
|
|
78
|
+
`kipe estimate` / `kipe synthesize`) and **one input file per study**, with optional sections:
|
|
79
|
+
each subcommand uses its subset. A twin experiment is `kipe synthesis study.yaml` followed by
|
|
80
|
+
`kipe estimation study.yaml` on the same file.
|
|
81
|
+
|
|
82
|
+
```yaml
|
|
83
|
+
output:
|
|
84
|
+
path: results/aorta_freq
|
|
85
|
+
|
|
86
|
+
forward_solver:
|
|
87
|
+
factory: "fsix.fluid.inverse:init"
|
|
88
|
+
arguments: {input_file: input/forward_aorta.yaml}
|
|
89
|
+
|
|
90
|
+
parameters:
|
|
91
|
+
reparameterization: exponential
|
|
92
|
+
select:
|
|
93
|
+
fluid.bc4.R_d: {stddev: 1.0, initial: 8000}
|
|
94
|
+
|
|
95
|
+
measurements:
|
|
96
|
+
mri_velocity:
|
|
97
|
+
fields: [velocity]
|
|
98
|
+
times: {start: 0.0, stop: 0.4, step: 0.02}
|
|
99
|
+
data: {type: numpy, path: data/mri_velocity}
|
|
100
|
+
spatial_sampling: {type: fenicsx.voxel, resolution: [0.2, 0.2, 0.2]}
|
|
101
|
+
model: {type: pcmri_frequency, venc: 351.05}
|
|
102
|
+
noise: {stddev: 10.0}
|
|
103
|
+
|
|
104
|
+
estimation:
|
|
105
|
+
particles: simplex
|
|
106
|
+
iterations: 1
|
|
107
|
+
write: [sensitivities, gramian] # optional filter products
|
|
108
|
+
|
|
109
|
+
synthesis:
|
|
110
|
+
truth: {type: run, cache: results/aorta/truth}
|
|
111
|
+
noise_seeds: [0, 1, 2]
|
|
112
|
+
|
|
113
|
+
# future
|
|
114
|
+
sensitivity:
|
|
115
|
+
method: finite_differences
|
|
116
|
+
step: 1.0e-3
|
|
117
|
+
write: [sensitivities, fim, eigen]
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
- **Shared sections:** `forward_solver`, `parameters` and `measurements` are used by all
|
|
121
|
+
subcommands. The prior and its reparameterization live together in `parameters`.
|
|
122
|
+
- **One measurement section serves both directions:** `synthesis` writes what `estimation`
|
|
123
|
+
reads, so a twin experiment can't mismatch.
|
|
124
|
+
- **Per measurement,** not global: data format, spatial sampling and measurement model. Different
|
|
125
|
+
kinds of measurements can be combined in one study.
|
|
126
|
+
- **Named entries** (measurements, parameters) appear in logs, outputs and error messages.
|
|
127
|
+
- **Explicit backend in type names** where one is involved (`fenicsx.voxel`,
|
|
128
|
+
`fenicsx.io4dolfinx`); backend-free components have plain names (`numpy`, `array`,
|
|
129
|
+
`pcmri_frequency`).
|
|
130
|
+
- **Times:** the data says which times exist; `times` selects from them. `synthesis`
|
|
131
|
+
requires `times` and writes them into the generated data.
|
|
132
|
+
- **No `time:` section:** the timestep belongs to the solver; the end time follows from the
|
|
133
|
+
last measurement.
|
|
134
|
+
- **Truth for `synthesis`:** kipe runs the solver with its nominal (true) parameters and
|
|
135
|
+
generates measurements with the same sampling and model as estimation — works for any
|
|
136
|
+
solver. Optionally it caches the true states, so measurements with other noise or
|
|
137
|
+
sampling cost no further forward solve. Existing solver checkpoints (as used today) can
|
|
138
|
+
be read instead.
|
|
139
|
+
|
|
140
|
+
## Validation
|
|
141
|
+
|
|
142
|
+
- **FitzHugh–Nagumo** (no FEniCS at all; a standard ODE parameter-estimation benchmark with an
|
|
143
|
+
attracting limit cycle) proves the interface is really solver-agnostic. Later: a 1D heat
|
|
144
|
+
equation in plain numpy with an MPI-distributed field, to test distributed fields without
|
|
145
|
+
FEniCS.
|
|
146
|
+
- **Parallel equivalence** (after 0.1): FitzHugh–Nagumo with particles in parallel
|
|
147
|
+
(`mpirun -n 4`) must give results identical to the serial run.
|
|
148
|
+
- **Parity:** results must match roukf on the fsix fluid example, serial and on 2 ranks.
|
|
149
|
+
- **Design check:** two CMR feature-tracking scenarios (tracked points; contours via signed
|
|
150
|
+
surface distance) must be expressible without changing the interfaces.
|
|
151
|
+
|
|
152
|
+
## 4-week plan
|
|
153
|
+
|
|
154
|
+
| Week | Focus |
|
|
155
|
+
|---|---|
|
|
156
|
+
| 1 | Scaffold; interfaces; numpy core; FitzHugh–Nagumo twin experiment (synthesis → estimation), without FEniCS |
|
|
157
|
+
| 2 | FEniCSx backend; fsix adapters (fluid, solid, FSI); parity with roukf |
|
|
158
|
+
| 3 | MRI measurement models; `kipe synthesis` (replaces synthmeas); resume; validation |
|
|
159
|
+
| 4 | Docs, CI, release 0.1.0; buffer |
|
|
160
|
+
|
|
161
|
+
**If time runs short, cut in this order:** sensitivity analysis (FIM), the adaptive FitzHugh–Nagumo
|
|
162
|
+
variant, mid-iteration resume, the output hook, `pcmri_frequency`. Particle parallelism is
|
|
163
|
+
postponed to after 0.1. **Kept regardless:** FitzHugh–Nagumo, fsix parity, all three
|
|
164
|
+
adapters, `synthesis`, docs, the release.
|
kipe-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 The kipe authors (see AUTHORS and CITATION.cff)
|
|
4
|
+
Portions derived from roukf, Copyright (c) 2018-2026 The roukf authors (see AUTHORS)
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
kipe-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: kipe
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Parameter estimation with reduced-order unscented Kalman filtering, and identifiability analysis, for PDE models
|
|
5
|
+
Project-URL: Homepage, https://github.com/cardiomath/kipe
|
|
6
|
+
Project-URL: Issues, https://github.com/cardiomath/kipe/issues
|
|
7
|
+
Author-email: David Nolte <dajuno@users.noreply.github.com>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: AUTHORS
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: FEniCS,ROUKF,data-assimilation,fisher-information,identifiability,inverse-problems,parameter-estimation,unscented-kalman-filter
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
18
|
+
Requires-Python: >=3.12
|
|
19
|
+
Requires-Dist: mpi4py>=4
|
|
20
|
+
Requires-Dist: numpy>=1.26
|
|
21
|
+
Requires-Dist: pydantic>=2.7
|
|
22
|
+
Requires-Dist: ruamel-yaml>=0.18
|
|
23
|
+
Provides-Extra: check
|
|
24
|
+
Requires-Dist: mypy==2.3.1; extra == 'check'
|
|
25
|
+
Requires-Dist: pre-commit; extra == 'check'
|
|
26
|
+
Requires-Dist: ruff==0.16.9; extra == 'check'
|
|
27
|
+
Provides-Extra: plot
|
|
28
|
+
Requires-Dist: matplotlib>=3.8; extra == 'plot'
|
|
29
|
+
Requires-Dist: plotext<7,>=6.1; extra == 'plot'
|
|
30
|
+
Provides-Extra: test
|
|
31
|
+
Requires-Dist: pytest>=8; extra == 'test'
|
|
32
|
+
Requires-Dist: scipy>=1.12; extra == 'test'
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
|
|
35
|
+
# kipe
|
|
36
|
+
|
|
37
|
+
***K**alman-based **i**dentifiability and **p**arameter **e**stimation*
|
|
38
|
+
|
|
39
|
+
kipe estimates parameters of dynamical models, e.g., PDE models, from time series of
|
|
40
|
+
measurements, with the reduced-order unscented Kalman filter (ROUKF). The filter needs only
|
|
41
|
+
forward runs of your model, no derivatives and no changes to the solver. kipe also generates
|
|
42
|
+
synthetic measurement data from a model run, for twin experiments.
|
|
43
|
+
|
|
44
|
+
> **Status: early development.** The core works (ROUKF estimation, synthetic data, plotting,
|
|
45
|
+
> run provenance), but the study file format and the Python API may still change. Feedback is
|
|
46
|
+
> very welcome: please open an [issue](https://github.com/cardiomath/kipe/issues).
|
|
47
|
+
> Coming next: a FEniCSx backend for observations of finite element fields.
|
|
48
|
+
|
|
49
|
+
## Installation
|
|
50
|
+
|
|
51
|
+
kipe needs Python ≥ 3.12 and an MPI library (for `mpi4py`). Use your system's MPI, or install one
|
|
52
|
+
with pip:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
pip install "kipe[plot]"
|
|
56
|
+
pip install mpich # only if there is no MPI library on your system
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
The `plot` extra adds matplotlib and plotext for `kipe plot`. The latest development version
|
|
60
|
+
installs from GitHub:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
pip install "kipe[plot] @ git+https://github.com/cardiomath/kipe"
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## First run: the FitzHugh–Nagumo example
|
|
67
|
+
|
|
68
|
+
The example estimates the three parameters of the FitzHugh–Nagumo model from noisy measurements
|
|
69
|
+
that kipe generated itself with the true parameters (a twin experiment):
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
git clone https://github.com/cardiomath/kipe
|
|
73
|
+
cd kipe/examples/fitzhugh_nagumo
|
|
74
|
+
kipe synthesis study.yaml # generate the measurement data
|
|
75
|
+
kipe estimation study.yaml # estimate a, b, c from a wrong initial guess
|
|
76
|
+
kipe plot study.yaml --truth # estimates with their 1σ range; --terminal without a display
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Everything is configured in the study file,
|
|
80
|
+
[`study.yaml`](https://github.com/cardiomath/kipe/blob/main/examples/fitzhugh_nagumo/study.yaml):
|
|
81
|
+
the forward solver, the estimated parameters with their initial guess and uncertainty, the
|
|
82
|
+
measurements and the filter. Results, a log and the provenance of the run (versions, git state,
|
|
83
|
+
environment) go to the `output.path` it names.
|
|
84
|
+
|
|
85
|
+
Other subcommands: `kipe list-parameters study.yaml` shows the parameters a solver accepts;
|
|
86
|
+
`kipe <subcommand> --help` shows the options.
|
|
87
|
+
|
|
88
|
+
## Your own model
|
|
89
|
+
|
|
90
|
+
kipe calls your model through a small interface, the `ForwardSolver` protocol in
|
|
91
|
+
[`kipe/forward_solver.py`](https://github.com/cardiomath/kipe/blob/main/src/kipe/forward_solver.py):
|
|
92
|
+
the initial state, the nominal parameters, and a `propagate` that advances a state from one time
|
|
93
|
+
to the next with given parameters. The study file names a factory that builds your solver:
|
|
94
|
+
|
|
95
|
+
```yaml
|
|
96
|
+
forward_solver:
|
|
97
|
+
factory: "my_package.my_module:MySolver" # module:name, imported by kipe
|
|
98
|
+
arguments: {dt: 0.01} # arguments passed to MySolver
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
The `arguments` are those passed to the factory, i.e., `MySolver(dt=0.01)`.
|
|
102
|
+
|
|
103
|
+
The FitzHugh–Nagumo solver in [`kipe/examples/fitzhugh_nagumo.py`](https://github.com/cardiomath/kipe/blob/main/src/kipe/examples/fitzhugh_nagumo.py)
|
|
104
|
+
is a complete example in about 150 lines, docstrings included.
|
|
105
|
+
|
|
106
|
+
## Development
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
git clone https://github.com/cardiomath/kipe
|
|
110
|
+
cd kipe
|
|
111
|
+
pip install -e ".[test,plot,check]"
|
|
112
|
+
pre-commit install --hook-type pre-commit --hook-type commit-msg
|
|
113
|
+
pytest
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
The pre-commit hooks run ruff, mypy and a check of the commit message, which follows
|
|
117
|
+
[Conventional Commits](https://www.conventionalcommits.org), e.g., `fix(roukf): ...`; the
|
|
118
|
+
allowed scopes are listed in `.pre-commit-config.yaml`.
|
|
119
|
+
|
|
120
|
+
## License
|
|
121
|
+
|
|
122
|
+
MIT, see [LICENSE](https://github.com/cardiomath/kipe/blob/main/LICENSE). If you use kipe, please
|
|
123
|
+
cite it as described in
|
|
124
|
+
[CITATION.cff](https://github.com/cardiomath/kipe/blob/main/CITATION.cff).
|
kipe-0.1.0/README.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# kipe
|
|
2
|
+
|
|
3
|
+
***K**alman-based **i**dentifiability and **p**arameter **e**stimation*
|
|
4
|
+
|
|
5
|
+
kipe estimates parameters of dynamical models, e.g., PDE models, from time series of
|
|
6
|
+
measurements, with the reduced-order unscented Kalman filter (ROUKF). The filter needs only
|
|
7
|
+
forward runs of your model, no derivatives and no changes to the solver. kipe also generates
|
|
8
|
+
synthetic measurement data from a model run, for twin experiments.
|
|
9
|
+
|
|
10
|
+
> **Status: early development.** The core works (ROUKF estimation, synthetic data, plotting,
|
|
11
|
+
> run provenance), but the study file format and the Python API may still change. Feedback is
|
|
12
|
+
> very welcome: please open an [issue](https://github.com/cardiomath/kipe/issues).
|
|
13
|
+
> Coming next: a FEniCSx backend for observations of finite element fields.
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
kipe needs Python ≥ 3.12 and an MPI library (for `mpi4py`). Use your system's MPI, or install one
|
|
18
|
+
with pip:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pip install "kipe[plot]"
|
|
22
|
+
pip install mpich # only if there is no MPI library on your system
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The `plot` extra adds matplotlib and plotext for `kipe plot`. The latest development version
|
|
26
|
+
installs from GitHub:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pip install "kipe[plot] @ git+https://github.com/cardiomath/kipe"
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## First run: the FitzHugh–Nagumo example
|
|
33
|
+
|
|
34
|
+
The example estimates the three parameters of the FitzHugh–Nagumo model from noisy measurements
|
|
35
|
+
that kipe generated itself with the true parameters (a twin experiment):
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
git clone https://github.com/cardiomath/kipe
|
|
39
|
+
cd kipe/examples/fitzhugh_nagumo
|
|
40
|
+
kipe synthesis study.yaml # generate the measurement data
|
|
41
|
+
kipe estimation study.yaml # estimate a, b, c from a wrong initial guess
|
|
42
|
+
kipe plot study.yaml --truth # estimates with their 1σ range; --terminal without a display
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Everything is configured in the study file,
|
|
46
|
+
[`study.yaml`](https://github.com/cardiomath/kipe/blob/main/examples/fitzhugh_nagumo/study.yaml):
|
|
47
|
+
the forward solver, the estimated parameters with their initial guess and uncertainty, the
|
|
48
|
+
measurements and the filter. Results, a log and the provenance of the run (versions, git state,
|
|
49
|
+
environment) go to the `output.path` it names.
|
|
50
|
+
|
|
51
|
+
Other subcommands: `kipe list-parameters study.yaml` shows the parameters a solver accepts;
|
|
52
|
+
`kipe <subcommand> --help` shows the options.
|
|
53
|
+
|
|
54
|
+
## Your own model
|
|
55
|
+
|
|
56
|
+
kipe calls your model through a small interface, the `ForwardSolver` protocol in
|
|
57
|
+
[`kipe/forward_solver.py`](https://github.com/cardiomath/kipe/blob/main/src/kipe/forward_solver.py):
|
|
58
|
+
the initial state, the nominal parameters, and a `propagate` that advances a state from one time
|
|
59
|
+
to the next with given parameters. The study file names a factory that builds your solver:
|
|
60
|
+
|
|
61
|
+
```yaml
|
|
62
|
+
forward_solver:
|
|
63
|
+
factory: "my_package.my_module:MySolver" # module:name, imported by kipe
|
|
64
|
+
arguments: {dt: 0.01} # arguments passed to MySolver
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
The `arguments` are those passed to the factory, i.e., `MySolver(dt=0.01)`.
|
|
68
|
+
|
|
69
|
+
The FitzHugh–Nagumo solver in [`kipe/examples/fitzhugh_nagumo.py`](https://github.com/cardiomath/kipe/blob/main/src/kipe/examples/fitzhugh_nagumo.py)
|
|
70
|
+
is a complete example in about 150 lines, docstrings included.
|
|
71
|
+
|
|
72
|
+
## Development
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
git clone https://github.com/cardiomath/kipe
|
|
76
|
+
cd kipe
|
|
77
|
+
pip install -e ".[test,plot,check]"
|
|
78
|
+
pre-commit install --hook-type pre-commit --hook-type commit-msg
|
|
79
|
+
pytest
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
The pre-commit hooks run ruff, mypy and a check of the commit message, which follows
|
|
83
|
+
[Conventional Commits](https://www.conventionalcommits.org), e.g., `fix(roukf): ...`; the
|
|
84
|
+
allowed scopes are listed in `.pre-commit-config.yaml`.
|
|
85
|
+
|
|
86
|
+
## License
|
|
87
|
+
|
|
88
|
+
MIT, see [LICENSE](https://github.com/cardiomath/kipe/blob/main/LICENSE). If you use kipe, please
|
|
89
|
+
cite it as described in
|
|
90
|
+
[CITATION.cff](https://github.com/cardiomath/kipe/blob/main/CITATION.cff).
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# FitzHugh-Nagumo twin experiment. Run from this directory:
|
|
2
|
+
# kipe synthesis study.yaml # generates data/v.npz, data/w.npz with the nominal parameters
|
|
3
|
+
# kipe estimation study.yaml # estimates a, b, c from them, starting from a wrong guess
|
|
4
|
+
|
|
5
|
+
output:
|
|
6
|
+
path: results
|
|
7
|
+
log_level: info
|
|
8
|
+
|
|
9
|
+
forward_solver:
|
|
10
|
+
factory: "kipe.examples.fitzhugh_nagumo:Solver"
|
|
11
|
+
arguments: {dt: 0.05} # nominal (true) parameters: a = 0.2, b = 0.2, c = 3
|
|
12
|
+
|
|
13
|
+
parameters:
|
|
14
|
+
reparameterization: log
|
|
15
|
+
select:
|
|
16
|
+
a: {initial: 0.3, relative_stddev: 0.1}
|
|
17
|
+
b: {initial: 0.3, relative_stddev: 0.1}
|
|
18
|
+
c: {initial: 2.0, relative_stddev: 0.1}
|
|
19
|
+
|
|
20
|
+
measurements:
|
|
21
|
+
v:
|
|
22
|
+
fields: [v]
|
|
23
|
+
times: {start: 0.5, stop: 20.0, step: 0.5}
|
|
24
|
+
data: {type: numpy, path: data/v.npz}
|
|
25
|
+
noise: {stddev: 0.01, seed: 0}
|
|
26
|
+
w:
|
|
27
|
+
fields: [w]
|
|
28
|
+
times: {start: 0.5, stop: 20.0, step: 0.5}
|
|
29
|
+
data: {type: numpy, path: data/w.npz}
|
|
30
|
+
noise: {stddev: 0.01, seed: 1}
|
|
31
|
+
|
|
32
|
+
synthesis:
|
|
33
|
+
truth: {type: run} # run the solver with its nominal parameters (the default)
|
|
34
|
+
|
|
35
|
+
estimation:
|
|
36
|
+
sigma_points: simplex
|
|
37
|
+
iterations: 5 # outer iterations: restart from the previous estimate
|