kipe 0.2.0__tar.gz → 0.4.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.
Files changed (87) hide show
  1. kipe-0.4.0/.github/CODEOWNERS +1 -0
  2. {kipe-0.2.0 → kipe-0.4.0}/.github/workflows/ci.yml +3 -0
  3. kipe-0.4.0/.github/workflows/docs.yml +47 -0
  4. {kipe-0.2.0 → kipe-0.4.0}/.gitignore +3 -1
  5. kipe-0.4.0/.markdownlint.yaml +5 -0
  6. {kipe-0.2.0 → kipe-0.4.0}/.pre-commit-config.yaml +29 -1
  7. kipe-0.4.0/.yamllint.yaml +9 -0
  8. {kipe-0.2.0 → kipe-0.4.0}/CITATION.cff +2 -2
  9. kipe-0.4.0/PKG-INFO +119 -0
  10. kipe-0.4.0/README.md +81 -0
  11. kipe-0.4.0/docs/README.md +22 -0
  12. kipe-0.4.0/docs/source/_static/mermaid.css +4 -0
  13. kipe-0.4.0/docs/source/_static/tables.css +14 -0
  14. kipe-0.4.0/docs/source/api.rst +8 -0
  15. kipe-0.4.0/docs/source/architecture.rst +178 -0
  16. kipe-0.4.0/docs/source/conf.py +95 -0
  17. kipe-0.4.0/docs/source/development.rst +67 -0
  18. kipe-0.4.0/docs/source/getting_started.rst +89 -0
  19. kipe-0.4.0/docs/source/index.md +31 -0
  20. kipe-0.4.0/docs/source/measurements.rst +139 -0
  21. kipe-0.4.0/docs/source/running.rst +200 -0
  22. kipe-0.4.0/docs/source/study_file.rst +12 -0
  23. kipe-0.4.0/docs/source/study_reference.py +510 -0
  24. kipe-0.4.0/docs/source/theory.rst +331 -0
  25. kipe-0.4.0/docs/source/write_a_sampler.rst +147 -0
  26. {kipe-0.2.0 → kipe-0.4.0}/examples/fitzhugh_nagumo/study.yaml +1 -0
  27. {kipe-0.2.0 → kipe-0.4.0}/examples/heat/study.yaml +1 -0
  28. kipe-0.4.0/examples/study.schema.json +622 -0
  29. {kipe-0.2.0 → kipe-0.4.0}/pyproject.toml +8 -1
  30. {kipe-0.2.0 → kipe-0.4.0}/src/kipe/cli.py +114 -10
  31. {kipe-0.2.0 → kipe-0.4.0}/src/kipe/estimation.py +26 -10
  32. kipe-0.4.0/src/kipe/fenicsx/forward_solver.py +72 -0
  33. kipe-0.4.0/src/kipe/fenicsx/points.py +126 -0
  34. {kipe-0.2.0 → kipe-0.4.0}/src/kipe/fenicsx/sampling.py +102 -17
  35. {kipe-0.2.0 → kipe-0.4.0}/src/kipe/forward_solver.py +31 -0
  36. {kipe-0.2.0 → kipe-0.4.0}/src/kipe/options.py +187 -22
  37. {kipe-0.2.0 → kipe-0.4.0}/src/kipe/roukf.py +12 -4
  38. {kipe-0.2.0 → kipe-0.4.0}/src/kipe/sampling.py +13 -2
  39. kipe-0.4.0/src/kipe/synthesis.py +440 -0
  40. kipe-0.4.0/tests/conftest.py +36 -0
  41. kipe-0.4.0/tests/fenicsx/test_list_fields.py +60 -0
  42. {kipe-0.2.0 → kipe-0.4.0}/tests/fenicsx/test_mesh_sampler.py +59 -8
  43. kipe-0.4.0/tests/fenicsx/test_point_sampler.py +106 -0
  44. {kipe-0.2.0 → kipe-0.4.0}/tests/test_estimation.py +62 -12
  45. {kipe-0.2.0 → kipe-0.4.0}/tests/test_measurement_options.py +61 -0
  46. {kipe-0.2.0 → kipe-0.4.0}/tests/test_study_file.py +53 -1
  47. kipe-0.4.0/tests/test_synthesis.py +313 -0
  48. kipe-0.2.0/DESIGN_OVERVIEW.md +0 -164
  49. kipe-0.2.0/PKG-INFO +0 -166
  50. kipe-0.2.0/README.md +0 -134
  51. kipe-0.2.0/src/kipe/fenicsx/forward_solver.py +0 -30
  52. kipe-0.2.0/src/kipe/synthesis.py +0 -252
  53. kipe-0.2.0/tests/test_synthesis.py +0 -165
  54. {kipe-0.2.0 → kipe-0.4.0}/.github/ISSUE_TEMPLATE/bug.md +0 -0
  55. {kipe-0.2.0 → kipe-0.4.0}/.github/ISSUE_TEMPLATE/chore.md +0 -0
  56. {kipe-0.2.0 → kipe-0.4.0}/.github/ISSUE_TEMPLATE/documentation.md +0 -0
  57. {kipe-0.2.0 → kipe-0.4.0}/.github/ISSUE_TEMPLATE/feature.md +0 -0
  58. {kipe-0.2.0 → kipe-0.4.0}/.github/ISSUE_TEMPLATE/performance.md +0 -0
  59. {kipe-0.2.0 → kipe-0.4.0}/.github/workflows/release.yml +0 -0
  60. {kipe-0.2.0 → kipe-0.4.0}/AUTHORS +0 -0
  61. {kipe-0.2.0 → kipe-0.4.0}/LICENSE +0 -0
  62. {kipe-0.2.0 → kipe-0.4.0}/examples/heat/measurement_mesh.py +0 -0
  63. {kipe-0.2.0 → kipe-0.4.0}/src/kipe/__init__.py +0 -0
  64. {kipe-0.2.0 → kipe-0.4.0}/src/kipe/_formatting.py +0 -0
  65. {kipe-0.2.0 → kipe-0.4.0}/src/kipe/_types.py +0 -0
  66. {kipe-0.2.0 → kipe-0.4.0}/src/kipe/_yaml.py +0 -0
  67. {kipe-0.2.0 → kipe-0.4.0}/src/kipe/examples/__init__.py +0 -0
  68. {kipe-0.2.0 → kipe-0.4.0}/src/kipe/examples/fitzhugh_nagumo.py +0 -0
  69. {kipe-0.2.0 → kipe-0.4.0}/src/kipe/fenicsx/__init__.py +0 -0
  70. {kipe-0.2.0 → kipe-0.4.0}/src/kipe/fenicsx/examples/__init__.py +0 -0
  71. {kipe-0.2.0 → kipe-0.4.0}/src/kipe/fenicsx/examples/heat.py +0 -0
  72. {kipe-0.2.0 → kipe-0.4.0}/src/kipe/measurements.py +0 -0
  73. {kipe-0.2.0 → kipe-0.4.0}/src/kipe/parameters.py +0 -0
  74. {kipe-0.2.0 → kipe-0.4.0}/src/kipe/plot.py +0 -0
  75. {kipe-0.2.0 → kipe-0.4.0}/src/kipe/provenance.py +0 -0
  76. {kipe-0.2.0 → kipe-0.4.0}/src/kipe/py.typed +0 -0
  77. {kipe-0.2.0 → kipe-0.4.0}/tests/examples/test_fitzhugh_nagumo.py +0 -0
  78. {kipe-0.2.0 → kipe-0.4.0}/tests/examples/test_fitzhugh_nagumo_protocol.py +0 -0
  79. {kipe-0.2.0 → kipe-0.4.0}/tests/fenicsx/conftest.py +0 -0
  80. {kipe-0.2.0 → kipe-0.4.0}/tests/fenicsx/test_heat.py +0 -0
  81. {kipe-0.2.0 → kipe-0.4.0}/tests/fenicsx/test_heat_example.py +0 -0
  82. {kipe-0.2.0 → kipe-0.4.0}/tests/test_measurements.py +0 -0
  83. {kipe-0.2.0 → kipe-0.4.0}/tests/test_parameters.py +0 -0
  84. {kipe-0.2.0 → kipe-0.4.0}/tests/test_plot.py +0 -0
  85. {kipe-0.2.0 → kipe-0.4.0}/tests/test_provenance.py +0 -0
  86. {kipe-0.2.0 → kipe-0.4.0}/tests/test_roukf.py +0 -0
  87. {kipe-0.2.0 → kipe-0.4.0}/tests/test_roukf_kalman.py +0 -0
@@ -0,0 +1 @@
1
+ * @dajuno @cabertog
@@ -23,6 +23,9 @@ jobs:
23
23
  - run: ruff check .
24
24
  - run: ruff format --check .
25
25
  - run: mypy
26
+ # with the versions in .pre-commit-config.yaml
27
+ - run: pre-commit run yamllint --all-files
28
+ - run: pre-commit run markdownlint-cli2 --all-files
26
29
 
27
30
  test:
28
31
  runs-on: ubuntu-latest
@@ -0,0 +1,47 @@
1
+ name: docs
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ workflow_dispatch:
8
+
9
+ permissions:
10
+ contents: read
11
+
12
+ concurrency:
13
+ group: pages
14
+ cancel-in-progress: false
15
+
16
+ jobs:
17
+ build:
18
+ runs-on: ubuntu-latest
19
+ steps:
20
+ - uses: actions/checkout@v4
21
+ with:
22
+ fetch-depth: 0 # version from git tags
23
+ - uses: actions/setup-python@v5
24
+ with:
25
+ python-version: "3.12"
26
+ cache: pip
27
+ - name: Install project and docs dependencies
28
+ run: pip install -e ".[docs]"
29
+ - name: Build HTML (warnings are errors; API pages are generated by conf.py)
30
+ run: python -m sphinx -W --keep-going -b html docs/source docs/build/html
31
+ - uses: actions/upload-pages-artifact@v3
32
+ with:
33
+ path: docs/build/html
34
+
35
+ deploy:
36
+ needs: build
37
+ if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
38
+ runs-on: ubuntu-latest
39
+ permissions:
40
+ pages: write
41
+ id-token: write
42
+ environment:
43
+ name: github-pages
44
+ url: ${{ steps.deployment.outputs.page_url }}
45
+ steps:
46
+ - id: deployment
47
+ uses: actions/deploy-pages@v4
@@ -27,7 +27,9 @@ examples/**/data/
27
27
  examples/**/results/
28
28
 
29
29
  # Docs build
30
- doc/build/
30
+ docs/build/
31
+ docs/source/_apidoc/
32
+ docs/source/_generated/
31
33
  docs/_build/
32
34
 
33
35
  # Editors / OS
@@ -0,0 +1,5 @@
1
+ # markdownlint: https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md
2
+ default: true
3
+
4
+ MD013:
5
+ line_length: 97 # as for ruff
@@ -1,4 +1,5 @@
1
- # Install: pip install ".[dev]" && pre-commit install --hook-type pre-commit --hook-type commit-msg
1
+ # Install: pip install ".[dev]"
2
+ # pre-commit install --hook-type pre-commit --hook-type commit-msg
2
3
  repos:
3
4
  - repo: https://github.com/pre-commit/pre-commit-hooks
4
5
  rev: v6.0.0
@@ -24,6 +25,33 @@ repos:
24
25
  pass_filenames: false
25
26
  additional_dependencies: [matplotlib, mpi4py, numpy, pytest, pydantic, ruamel.yaml]
26
27
 
28
+ - repo: https://github.com/adrienverge/yamllint
29
+ rev: v1.38.0
30
+ hooks:
31
+ - id: yamllint
32
+ args: [--strict] # warnings fail too, e.g., one space before a comment
33
+
34
+ - repo: https://github.com/DavidAnson/markdownlint-cli2
35
+ rev: v0.23.3
36
+ hooks:
37
+ - id: markdownlint-cli2
38
+
39
+ # Needs the docs extra in the active environment: pip install -e ".[docs]"
40
+ # Manual stage, skipped on commit; run it with
41
+ # pre-commit run sphinx-build --all-files --hook-stage manual
42
+ # (without --hook-stage manual: "No hook with id `sphinx-build` in stage `pre-commit`")
43
+ - repo: local
44
+ hooks:
45
+ - id: sphinx-build
46
+ name: sphinx docs build
47
+ stages: [manual]
48
+ entry: >-
49
+ bash -c 'python -m sphinx -q -W --keep-going -b html docs/source docs/build/html
50
+ && python -m webbrowser -t "file://$(pwd)/docs/build/html/index.html"'
51
+ language: system
52
+ files: ^(docs/|src/.*\.py$|pyproject\.toml$)
53
+ pass_filenames: false
54
+
27
55
  # The scope is optional: the module a commit is about, or the area for non-code changes,
28
56
  # e.g., "feat(plot): ...", "fix(estimation,roukf): ..."; no scope for broader commits.
29
57
  - repo: https://github.com/compilerla/conventional-pre-commit
@@ -0,0 +1,9 @@
1
+ # yamllint: https://yamllint.readthedocs.io/en/stable/rules.html
2
+ extends: default
3
+
4
+ rules:
5
+ line-length:
6
+ max: 97 # as for ruff
7
+ document-start: disable # no "---" at the top of each file
8
+ truthy:
9
+ check-keys: false # GitHub Actions' "on:" key
@@ -28,6 +28,6 @@ authors:
28
28
  given-names: Cristóbal
29
29
  affiliation: "University of Groningen"
30
30
  orcid: "https://orcid.org/0000-0001-5049-1707"
31
- version: 0.2.0 # update on each release
32
- date-released: 2026-10-13
31
+ version: 0.4.0 # update on each release
32
+ date-released: 2026-10-15
33
33
  # doi: added by Zenodo, if connected
kipe-0.4.0/PKG-INFO ADDED
@@ -0,0 +1,119 @@
1
+ Metadata-Version: 2.5
2
+ Name: kipe
3
+ Version: 0.4.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: matplotlib>=3.8
20
+ Requires-Dist: mpi4py>=4
21
+ Requires-Dist: numpy>=1.26
22
+ Requires-Dist: plotext<7,>=6.1
23
+ Requires-Dist: pydantic>=2.7
24
+ Requires-Dist: ruamel-yaml>=0.18
25
+ Provides-Extra: dev
26
+ Requires-Dist: jsonschema>=4; extra == 'dev'
27
+ Requires-Dist: mypy==2.3.1; extra == 'dev'
28
+ Requires-Dist: pre-commit; extra == 'dev'
29
+ Requires-Dist: pytest>=8; extra == 'dev'
30
+ Requires-Dist: ruff==0.16.9; extra == 'dev'
31
+ Requires-Dist: scipy>=1.12; extra == 'dev'
32
+ Provides-Extra: docs
33
+ Requires-Dist: myst-parser<6,>=5; extra == 'docs'
34
+ Requires-Dist: sphinx-rtd-theme<4,>=3.1; extra == 'docs'
35
+ Requires-Dist: sphinx<10,>=9; extra == 'docs'
36
+ Requires-Dist: sphinxcontrib-mermaid<3,>=1; extra == 'docs'
37
+ Description-Content-Type: text/markdown
38
+
39
+ # kipe
40
+
41
+ [![CI](https://github.com/cardiomath/kipe/actions/workflows/ci.yml/badge.svg)](https://github.com/cardiomath/kipe/actions/workflows/ci.yml)
42
+ [![Documentation](https://img.shields.io/badge/docs-cardiomath.github.io%2Fkipe-blue)](https://cardiomath.github.io/kipe/)
43
+ ![Python 3.12+](https://img.shields.io/badge/python-3.12%2B-blue)
44
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
45
+
46
+ <!-- docs: start of the introduction (index.md) -->
47
+
48
+ ***K**alman-based **i**dentifiability and **p**arameter **e**stimation*
49
+
50
+ kipe estimates the parameters of dynamical models, e.g., PDE models, from time series of
51
+ measurements, with the reduced-order unscented Kalman filter (ROUKF). The filter needs only
52
+ forward runs of your model, no derivatives, through a lean interface. Around the estimation,
53
+ kipe generates synthetic measurement data for twin experiments, from a run of the model or from
54
+ the checkpoints of an earlier run, and will analyze the identifiability of the parameters with
55
+ the Fisher information (planned).
56
+
57
+ ## Key features
58
+
59
+ + **Solver-agnostic**: Connect your model through a small forward-solver interface
60
+ + **Derivative-free**: Optimizer is based on the reduced-order
61
+ unscented Kalman filter (ROUKF) and hence it needs only forward runs.
62
+ + **Modular observation operators**: New observation operators can be implemented easily by
63
+ extending the library.
64
+ + **Twin experiments**: Generate synthetic measurements from a model run.
65
+ + **Reproducible runs**: Keep results, logs, and run provenance together.
66
+
67
+ > **Status: early development.** The core works (ROUKF estimation, synthetic data, plotting, run
68
+ > provenance), as does a first FEniCSx backend for measurements on finite element meshes, but the
69
+ > study file format and the Python API may still change. Feedback is very welcome: please open an
70
+ > [issue](https://github.com/cardiomath/kipe/issues).
71
+
72
+ <!-- docs: end of the introduction -->
73
+
74
+ ## Installation
75
+
76
+ `kipe` needs Python ≥ 3.12 and an MPI library (for `mpi4py`):
77
+
78
+ ```bash
79
+ pip install kipe
80
+ pip install mpich # only if there is no MPI library on your system
81
+ ```
82
+
83
+ For FEniCSx models, install kipe into your FEniCSx (dolfinx 0.9) environment.
84
+
85
+ ## Quick start
86
+
87
+ A twin experiment with the FitzHugh–Nagumo model: synthetic data from the true parameters, then
88
+ the estimation from a wrong initial guess.
89
+
90
+ ```bash
91
+ git clone https://github.com/cardiomath/kipe
92
+ cd kipe/examples/fitzhugh_nagumo
93
+ kipe synthesis study.yaml
94
+ kipe estimation study.yaml
95
+ kipe plot study.yaml --truth # --terminal without a display
96
+ ```
97
+
98
+ ## Documentation
99
+
100
+ **[cardiomath.github.io/kipe](https://cardiomath.github.io/kipe/)**: getting started, running a
101
+ study, measurements, the study file reference, the theory, and how to extend kipe.
102
+
103
+ ## Development
104
+
105
+ ```bash
106
+ git clone https://github.com/cardiomath/kipe
107
+ cd kipe
108
+ pip install -e ".[dev]"
109
+ pre-commit install --hook-type pre-commit --hook-type commit-msg
110
+ pytest
111
+ ```
112
+
113
+ See [Development](https://cardiomath.github.io/kipe/development.html) in the documentation.
114
+
115
+ ## License
116
+
117
+ MIT, see [LICENSE](https://github.com/cardiomath/kipe/blob/main/LICENSE). If you use kipe, please
118
+ cite it as described in
119
+ [CITATION.cff](https://github.com/cardiomath/kipe/blob/main/CITATION.cff).
kipe-0.4.0/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # kipe
2
+
3
+ [![CI](https://github.com/cardiomath/kipe/actions/workflows/ci.yml/badge.svg)](https://github.com/cardiomath/kipe/actions/workflows/ci.yml)
4
+ [![Documentation](https://img.shields.io/badge/docs-cardiomath.github.io%2Fkipe-blue)](https://cardiomath.github.io/kipe/)
5
+ ![Python 3.12+](https://img.shields.io/badge/python-3.12%2B-blue)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
7
+
8
+ <!-- docs: start of the introduction (index.md) -->
9
+
10
+ ***K**alman-based **i**dentifiability and **p**arameter **e**stimation*
11
+
12
+ kipe estimates the parameters of dynamical models, e.g., PDE models, from time series of
13
+ measurements, with the reduced-order unscented Kalman filter (ROUKF). The filter needs only
14
+ forward runs of your model, no derivatives, through a lean interface. Around the estimation,
15
+ kipe generates synthetic measurement data for twin experiments, from a run of the model or from
16
+ the checkpoints of an earlier run, and will analyze the identifiability of the parameters with
17
+ the Fisher information (planned).
18
+
19
+ ## Key features
20
+
21
+ + **Solver-agnostic**: Connect your model through a small forward-solver interface
22
+ + **Derivative-free**: Optimizer is based on the reduced-order
23
+ unscented Kalman filter (ROUKF) and hence it needs only forward runs.
24
+ + **Modular observation operators**: New observation operators can be implemented easily by
25
+ extending the library.
26
+ + **Twin experiments**: Generate synthetic measurements from a model run.
27
+ + **Reproducible runs**: Keep results, logs, and run provenance together.
28
+
29
+ > **Status: early development.** The core works (ROUKF estimation, synthetic data, plotting, run
30
+ > provenance), as does a first FEniCSx backend for measurements on finite element meshes, but the
31
+ > study file format and the Python API may still change. Feedback is very welcome: please open an
32
+ > [issue](https://github.com/cardiomath/kipe/issues).
33
+
34
+ <!-- docs: end of the introduction -->
35
+
36
+ ## Installation
37
+
38
+ `kipe` needs Python ≥ 3.12 and an MPI library (for `mpi4py`):
39
+
40
+ ```bash
41
+ pip install kipe
42
+ pip install mpich # only if there is no MPI library on your system
43
+ ```
44
+
45
+ For FEniCSx models, install kipe into your FEniCSx (dolfinx 0.9) environment.
46
+
47
+ ## Quick start
48
+
49
+ A twin experiment with the FitzHugh–Nagumo model: synthetic data from the true parameters, then
50
+ the estimation from a wrong initial guess.
51
+
52
+ ```bash
53
+ git clone https://github.com/cardiomath/kipe
54
+ cd kipe/examples/fitzhugh_nagumo
55
+ kipe synthesis study.yaml
56
+ kipe estimation study.yaml
57
+ kipe plot study.yaml --truth # --terminal without a display
58
+ ```
59
+
60
+ ## Documentation
61
+
62
+ **[cardiomath.github.io/kipe](https://cardiomath.github.io/kipe/)**: getting started, running a
63
+ study, measurements, the study file reference, the theory, and how to extend kipe.
64
+
65
+ ## Development
66
+
67
+ ```bash
68
+ git clone https://github.com/cardiomath/kipe
69
+ cd kipe
70
+ pip install -e ".[dev]"
71
+ pre-commit install --hook-type pre-commit --hook-type commit-msg
72
+ pytest
73
+ ```
74
+
75
+ See [Development](https://cardiomath.github.io/kipe/development.html) in the documentation.
76
+
77
+ ## License
78
+
79
+ MIT, see [LICENSE](https://github.com/cardiomath/kipe/blob/main/LICENSE). If you use kipe, please
80
+ cite it as described in
81
+ [CITATION.cff](https://github.com/cardiomath/kipe/blob/main/CITATION.cff).
@@ -0,0 +1,22 @@
1
+ # Documentation
2
+
3
+ Built with Sphinx (reStructuredText and Markdown via MyST). API pages are generated
4
+ automatically from the package docstrings at build time (`sphinx.ext.apidoc` in `conf.py`).
5
+
6
+ ## Build locally
7
+
8
+ ```bash
9
+ pip install -e ".[docs]"
10
+ python -m sphinx -W --keep-going -b html docs/source docs/build/html
11
+ ```
12
+
13
+ The same build is a manual pre-commit hook, which also opens the result:
14
+ `pre-commit run sphinx-build --all-files --hook-stage manual`.
15
+
16
+ Open `docs/build/html/index.html` (or `python -m http.server -d docs/build/html`).
17
+
18
+ ## GitHub Pages
19
+
20
+ The workflow `.github/workflows/docs.yml` builds and deploys on every push to `main`
21
+ (or manually via *Run workflow*). One-time setup: **Settings → Pages → Build and deployment →
22
+ Source: GitHub Actions**. The site is then at `https://cardiomath.github.io/kipe/`.
@@ -0,0 +1,4 @@
1
+ /* Diagrams fill the column width, but tall ones no more than this height. */
2
+ pre.mermaid > svg {
3
+ max-height: 30em;
4
+ }
@@ -0,0 +1,14 @@
1
+ /* The Read the Docs theme keeps table cells on one line; wrap them, e.g., long descriptions. */
2
+ .wy-table-responsive table td,
3
+ .wy-table-responsive table th {
4
+ white-space: normal;
5
+ }
6
+
7
+ /* Code in tables: monospace only, without the theme's colored boxes. */
8
+ .wy-table-responsive table code.literal {
9
+ color: inherit;
10
+ background: none;
11
+ border: none;
12
+ padding: 0;
13
+ font-size: 90%; /* the theme's 75% is small without the box */
14
+ }
@@ -0,0 +1,8 @@
1
+ API reference
2
+ =============
3
+
4
+ .. toctree::
5
+ :maxdepth: 1
6
+ :glob:
7
+
8
+ _apidoc/kipe
@@ -0,0 +1,178 @@
1
+ Architecture
2
+ ============
3
+
4
+ This page is for those who want to extend kipe: use it with a new kind of measurement (e.g.,
5
+ MRI phase images instead of velocities on a mesh), compare model and data differently, read
6
+ another data format, or connect their own forward solver. It explains how kipe is put together
7
+ and where each of these extensions goes. The API pages document each part in detail.
8
+
9
+ Principles
10
+ ----------
11
+
12
+ **The core is solver-agnostic.** The core (``kipe``) uses numpy and MPI only. Everything that
13
+ needs a discretization library lives in a backend subpackage (``kipe.fenicsx``), imported only
14
+ when a study uses it. The FitzHugh–Nagumo example (:mod:`kipe.examples.fitzhugh_nagumo`)
15
+ runs without any backend and keeps it that way.
16
+
17
+ **The solver owns its settings.** Time step, end time, output paths and solver tolerances
18
+ belong to the forward solver. kipe passes only state, parameters and time, so no setting is
19
+ defined twice.
20
+
21
+ **A study is one file.** The study file (:mod:`kipe.options`) holds everything a run needs. An
22
+ archived study file reproduces an HPC run; command-line options only change what is printed.
23
+ The same file serves synthesis and estimation, so a twin experiment cannot mismatch.
24
+
25
+ **Extensions are small and explicit.** A new component is a class, its options and one
26
+ ``case`` in a build function, all in kipe. There are no plugin registries or entry points:
27
+ reading the build function shows every choice there is.
28
+
29
+ Overview
30
+ --------
31
+
32
+ The study file is read into options dataclasses. Build functions turn the options into the
33
+ objects that do the work: the forward solver, the parameterization and, for each measurement,
34
+ its observation operator. Synthesis runs the solver with its nominal parameters, or reads the
35
+ states from the solver's checkpoints, and writes the measurement data. The data can also come
36
+ from an acquisition, converted to kipe's format outside kipe. Estimation reads the data and
37
+ runs the filter.
38
+
39
+ .. mermaid::
40
+
41
+ flowchart TD
42
+ study[/"study file"/] --> options["options<br/>kipe.options"]
43
+ options --> solver["forward solver<br/>(external)"]
44
+ options --> operators["observation operators<br/>H = M ∘ S<br/>kipe.measurements"]
45
+ options --> parameterization["parameterization<br/>kipe.parameters"]
46
+ solver -- "run, or read checkpoints" --> synthesis["kipe synthesis<br/>kipe.synthesis"]
47
+ operators --> synthesis
48
+ synthesis --> data[/"measurement data"/]
49
+ acquired[/"acquired data<br/>(e.g., MRI)"/] -. "converted" .-> data
50
+ solver --> estimation["kipe estimation<br/>kipe.estimation"]
51
+ operators --> estimation
52
+ parameterization --> estimation
53
+ data --> estimation
54
+ estimation --> history[/"estimation history"/]
55
+
56
+ The forward solver
57
+ ------------------
58
+
59
+ kipe sees the forward model through :class:`kipe.forward_solver.ForwardSolver`, a protocol:
60
+ a solver conforms structurally and does not import kipe. It is constructed by the
61
+ ``factory`` named in the study file, with the ``arguments`` given there; from Python, the
62
+ arguments can be any objects, e.g., the solver's own options.
63
+
64
+ - **Stateless calls.** :meth:`~kipe.forward_solver.ForwardSolver.initial_state` and
65
+ :meth:`~kipe.forward_solver.ForwardSolver.propagate` take and return the state; a call's
66
+ result must not depend on earlier calls. The filter propagates every sigma point, each from
67
+ its own state, one after another, with the same solver instance.
68
+ - **Named state fields.** The state is a mapping from field names to numpy arrays, local to
69
+ the MPI rank. A field is ``distributed`` (each entry owned by one rank, e.g., the owned
70
+ degrees of freedom of a finite element function) or ``replicated`` (every rank holds all
71
+ of it, e.g., the state of a lumped-parameter model). Measurements refer to fields by name.
72
+ - **Named parameters.** The solver lists what can be estimated, with nominal values. The study
73
+ selects parameters by name and sets their prior; parameters it does not select keep their
74
+ nominal values.
75
+ - **Backend capabilities.** A backend may need more from the solver: FEniCSx samplers need the
76
+ function space of a field (:class:`kipe.fenicsx.forward_solver.SupportsFunctionSpaces`).
77
+ Such a capability is a separate protocol, so a solver without it still works with the core
78
+ samplers.
79
+
80
+ Measurements
81
+ ------------
82
+
83
+ A :class:`~kipe.measurements.Measurement` is data at measurement times, with a noise level,
84
+ and the observation operator that predicts those data from a model state. The observation
85
+ operator :math:`\mathcal{H} = M \circ S` has two parts:
86
+
87
+ - the **spatial sampler** :math:`S` (:mod:`kipe.sampling`) evaluates the observed fields at
88
+ the measurement locations: interpolation onto a measurement mesh, a projection onto a
89
+ direction or the surface normal, all entries of a field;
90
+ - the **measurement model** :math:`M` (:mod:`kipe.measurements`) predicts the data from the
91
+ sampled values and compares the prediction with the measured data, giving the innovation.
92
+
93
+ The diagram shows one observation operator of the overview, with its two parts, and how its
94
+ result enters the filter.
95
+
96
+ .. mermaid::
97
+
98
+ flowchart LR
99
+ state["model state χ"] --> sampler["SpatialSampler S<br/>.sample"]
100
+ sampler -- "sampled values y" --> predict["MeasurementModel M<br/>.predict"]
101
+ predict -- "predicted data ẑ" --> innovation["MeasurementModel M<br/>.innovation"]
102
+ data[/"measured data z"/] --> innovation
103
+ innovation -- "innovation Γ(z, ẑ)" --> filter["ROUKF correction<br/>kipe.roukf"]
104
+
105
+ Synthesis and estimation use the same operator, so the model that generates synthetic data
106
+ is the one that inverts them; a sensitivity analysis would use it too.
107
+
108
+ **Why two parts.** Samplers depend on the discretization, models on the acquisition physics
109
+ (e.g., the phase of an MRI signal, a Fourier transform, a mask). Models act on arrays only,
110
+ so they work with every backend. Split this way, N samplers and M models give N × M
111
+ combinations from N + M classes.
112
+
113
+ **Why "observation".** In the data-assimilation literature, the observation operator is the
114
+ map from the model state to predicted data. kipe keeps the word for that composition and
115
+ calls its parts by what they do.
116
+
117
+ Parallel layout
118
+ ---------------
119
+
120
+ Everything in kipe that communicates takes the MPI communicator as an argument (``comm``,
121
+ ``MPI.COMM_WORLD`` by default); only the command line uses ``MPI.COMM_WORLD`` directly. The
122
+ same code runs serially and in parallel, and sigma points can later run in parallel in groups
123
+ of ranks, each group with its own communicator.
124
+
125
+ **Each entry on one rank.** A sampler knows the size of the sampled vector over all ranks
126
+ and, on each rank, the ``global_indices`` of the entries that rank returns. Every entry is
127
+ returned by exactly one rank. The filter's reductions (sums over entries) are then plain
128
+ ``allreduce`` operations, with nothing counted twice.
129
+
130
+ **Data independent of the rank count.** Measurement data are stored in the order of the
131
+ global indices, which the sampler defines independently of the partition (e.g.,
132
+ :class:`~kipe.fenicsx.sampling.MeshSampler` uses the row of each vertex or cell in the mesh
133
+ file). Synthetic noise depends only on an entry's position. So data synthesized on 1 rank are
134
+ the same as on 8, and either can be used with any number of ranks.
135
+
136
+ Extending kipe
137
+ --------------
138
+
139
+ Each kind of component follows the same pattern:
140
+
141
+ 1. **The class**, in the module of its kind: a subclass of the abstract base class.
142
+ 2. **Its options**, a frozen dataclass in :mod:`kipe.options` with a literal ``type`` field,
143
+ added to the union of its kind. The ``type`` selects it in the study file. Backend
144
+ components carry the backend in the name (``fenicsx.mesh``); core components have plain
145
+ names (``array``, ``difference``).
146
+ 3. **One case** in the build function of its kind, which constructs the class from its
147
+ options. A backend case imports the backend inside the case, so the core never imports it.
148
+ 4. **Tests**, with the FitzHugh–Nagumo example for core components, with the heat example
149
+ (:mod:`kipe.fenicsx.examples.heat`) for FEniCSx components.
150
+
151
+ ========================= ================================================ =====================================================
152
+ component base class build function
153
+ ========================= ================================================ =====================================================
154
+ spatial sampler :class:`kipe.sampling.SpatialSampler` :func:`kipe.sampling.build_sampler`
155
+ measurement model :class:`kipe.measurements.MeasurementModel` :func:`kipe.measurements.build_model`
156
+ ========================= ================================================ =====================================================
157
+
158
+ **A spatial sampler**: :doc:`write_a_sampler` walks through a complete one. It sets ``size``
159
+ and ``global_indices`` and implements
160
+ :meth:`~kipe.sampling.SpatialSampler.sample`, which takes the observed fields (rank-local
161
+ arrays) and returns this rank's sampled entries. It may take what it needs from the solver at
162
+ construction, e.g., function spaces, through a backend capability.
163
+
164
+ **A measurement model** implements :meth:`~kipe.measurements.MeasurementModel.predict` and
165
+ :meth:`~kipe.measurements.MeasurementModel.innovation`. It sees this rank's entries as arrays.
166
+ A model that needs all entries at once (e.g., a Fourier transform) will also need the
167
+ communicator; none does so far.
168
+
169
+ **A data format** is read where the data are read
170
+ (:func:`kipe.estimation.estimate` and :func:`kipe.synthesis.synthesize`, through
171
+ :func:`~kipe.measurements.read_numpy` and :func:`~kipe.measurements.write_numpy`). kipe has
172
+ one format so far, ``numpy``; the second one will add a build function for readers, following
173
+ the pattern above.
174
+
175
+ **A forward solver** lives outside kipe. It implements
176
+ :class:`~kipe.forward_solver.ForwardSolver`, plus the capabilities of the backend it uses.
177
+ :mod:`kipe.examples.fitzhugh_nagumo` is the reference for a solver without a backend,
178
+ :mod:`kipe.fenicsx.examples.heat` for a FEniCSx solver; both are tested against the protocol.
@@ -0,0 +1,95 @@
1
+ """Sphinx configuration for the kipe documentation."""
2
+
3
+ import sys
4
+ import typing
5
+ from importlib.metadata import PackageNotFoundError
6
+ from importlib.metadata import version as _version
7
+ from pathlib import Path
8
+
9
+ from sphinx.ext.apidoc import main as apidoc_main
10
+
11
+ ROOT = Path(__file__).resolve().parents[2]
12
+
13
+ project = "kipe"
14
+ author = "kipe contributors"
15
+ try:
16
+ release = _version("kipe")
17
+ except PackageNotFoundError:
18
+ release = "0.0.0"
19
+
20
+ extensions = [
21
+ "sphinx.ext.autodoc",
22
+ "sphinx.ext.napoleon",
23
+ "sphinx.ext.viewcode",
24
+ "myst_parser",
25
+ "sphinxcontrib.mermaid",
26
+ ]
27
+ source_suffix = {".rst": "restructuredtext", ".md": "markdown"}
28
+ exclude_patterns = ["_apidoc/modules.rst", "_generated/*"] # _generated: included by pages
29
+ html_theme = "sphinx_rtd_theme"
30
+ # \bs{x}: bold symbols, as in the article the theory page follows
31
+ mathjax3_config = {"tex": {"macros": {"bs": [r"\boldsymbol{#1}", 1]}}}
32
+ html_static_path = ["_static"]
33
+ html_css_files = ["mermaid.css", "tables.css"]
34
+ mermaid_height = "auto" # in proportion to the width, not a fixed box; see mermaid.css
35
+ autodoc_member_order = "bysource"
36
+ # compiled dependencies (MPI, FEniCSx) are not needed to render the API
37
+ autodoc_mock_imports = ["mpi4py", "dolfinx", "ufl", "petsc4py", "basix"]
38
+
39
+
40
+ def _generate_api(app):
41
+ """Generate the API pages from the package, so none are maintained by hand."""
42
+ out = Path(app.srcdir) / "_apidoc"
43
+ apidoc_main([
44
+ "--force",
45
+ "--separate",
46
+ "--module-first",
47
+ "-o",
48
+ str(out),
49
+ str(ROOT / "src" / "kipe"),
50
+ ])
51
+
52
+
53
+ def _generate_study_reference(app):
54
+ """Generate the study file reference from the options, so none is maintained by hand."""
55
+ sys.path.insert(0, str(Path(__file__).parent)) # study_reference.py, next to this file
56
+ from study_reference import write_reference
57
+
58
+ write_reference(Path(app.srcdir) / "_generated" / "study_file.rst")
59
+
60
+
61
+ def _show_annotated_as_its_type(app):
62
+ """Show ``Annotated[X, ...]`` as ``X`` in the API pages.
63
+
64
+ The options use ``Annotated`` for pydantic's constraints, e.g., ``Field(ge=0)``, which
65
+ autodoc would show as ``Annotated[float, FieldInfo(..., required=True, ...)]``, misleading
66
+ for optional fields. The study file reference shows the constraints readably. Sphinx has no
67
+ setting for this, so this wraps its ``stringify_annotation`` wherever a Sphinx module holds
68
+ it; if none does (a renamed function), the build fails here.
69
+ """
70
+ import sphinx.util.typing
71
+
72
+ original = sphinx.util.typing.stringify_annotation
73
+
74
+ def stringify_annotation(annotation, *args, **kwargs):
75
+ if typing.get_origin(annotation) is typing.Annotated:
76
+ annotation = typing.get_args(annotation)[0]
77
+ return original(annotation, *args, **kwargs)
78
+
79
+ modules = [
80
+ module
81
+ for name, module in list(sys.modules.items())
82
+ if name.startswith("sphinx")
83
+ and getattr(module, "stringify_annotation", None) is original
84
+ ]
85
+ if not modules:
86
+ raise RuntimeError("sphinx.util.typing.stringify_annotation not found: update conf.py")
87
+ for module in modules:
88
+ module.stringify_annotation = stringify_annotation
89
+
90
+
91
+ def setup(app):
92
+ """Register the API generation hook."""
93
+ app.connect("builder-inited", _generate_api)
94
+ app.connect("builder-inited", _generate_study_reference)
95
+ app.connect("builder-inited", _show_annotated_as_its_type)