kipe 0.2.0__tar.gz → 0.3.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.3.0/.github/workflows/docs.yml +47 -0
- {kipe-0.2.0 → kipe-0.3.0}/.gitignore +2 -1
- {kipe-0.2.0 → kipe-0.3.0}/.pre-commit-config.yaml +13 -0
- {kipe-0.2.0 → kipe-0.3.0}/CITATION.cff +2 -2
- {kipe-0.2.0 → kipe-0.3.0}/PKG-INFO +6 -1
- kipe-0.3.0/docs/README.md +21 -0
- kipe-0.3.0/docs/source/_static/mermaid.css +4 -0
- kipe-0.3.0/docs/source/api.rst +8 -0
- kipe-0.3.0/docs/source/conf.py +51 -0
- kipe-0.3.0/docs/source/design.rst +177 -0
- kipe-0.3.0/docs/source/index.rst +11 -0
- {kipe-0.2.0 → kipe-0.3.0}/pyproject.toml +6 -0
- {kipe-0.2.0 → kipe-0.3.0}/src/kipe/cli.py +9 -2
- {kipe-0.2.0 → kipe-0.3.0}/src/kipe/forward_solver.py +31 -0
- {kipe-0.2.0 → kipe-0.3.0}/src/kipe/options.py +26 -2
- {kipe-0.2.0 → kipe-0.3.0}/src/kipe/synthesis.py +136 -23
- kipe-0.3.0/tests/conftest.py +36 -0
- {kipe-0.2.0 → kipe-0.3.0}/tests/test_estimation.py +31 -11
- {kipe-0.2.0 → kipe-0.3.0}/tests/test_measurement_options.py +9 -0
- kipe-0.3.0/tests/test_synthesis.py +291 -0
- kipe-0.2.0/DESIGN_OVERVIEW.md +0 -164
- kipe-0.2.0/tests/test_synthesis.py +0 -165
- {kipe-0.2.0 → kipe-0.3.0}/.github/ISSUE_TEMPLATE/bug.md +0 -0
- {kipe-0.2.0 → kipe-0.3.0}/.github/ISSUE_TEMPLATE/chore.md +0 -0
- {kipe-0.2.0 → kipe-0.3.0}/.github/ISSUE_TEMPLATE/documentation.md +0 -0
- {kipe-0.2.0 → kipe-0.3.0}/.github/ISSUE_TEMPLATE/feature.md +0 -0
- {kipe-0.2.0 → kipe-0.3.0}/.github/ISSUE_TEMPLATE/performance.md +0 -0
- {kipe-0.2.0 → kipe-0.3.0}/.github/workflows/ci.yml +0 -0
- {kipe-0.2.0 → kipe-0.3.0}/.github/workflows/release.yml +0 -0
- {kipe-0.2.0 → kipe-0.3.0}/AUTHORS +0 -0
- {kipe-0.2.0 → kipe-0.3.0}/LICENSE +0 -0
- {kipe-0.2.0 → kipe-0.3.0}/README.md +0 -0
- {kipe-0.2.0 → kipe-0.3.0}/examples/fitzhugh_nagumo/study.yaml +0 -0
- {kipe-0.2.0 → kipe-0.3.0}/examples/heat/measurement_mesh.py +0 -0
- {kipe-0.2.0 → kipe-0.3.0}/examples/heat/study.yaml +0 -0
- {kipe-0.2.0 → kipe-0.3.0}/src/kipe/__init__.py +0 -0
- {kipe-0.2.0 → kipe-0.3.0}/src/kipe/_formatting.py +0 -0
- {kipe-0.2.0 → kipe-0.3.0}/src/kipe/_types.py +0 -0
- {kipe-0.2.0 → kipe-0.3.0}/src/kipe/_yaml.py +0 -0
- {kipe-0.2.0 → kipe-0.3.0}/src/kipe/estimation.py +0 -0
- {kipe-0.2.0 → kipe-0.3.0}/src/kipe/examples/__init__.py +0 -0
- {kipe-0.2.0 → kipe-0.3.0}/src/kipe/examples/fitzhugh_nagumo.py +0 -0
- {kipe-0.2.0 → kipe-0.3.0}/src/kipe/fenicsx/__init__.py +0 -0
- {kipe-0.2.0 → kipe-0.3.0}/src/kipe/fenicsx/examples/__init__.py +0 -0
- {kipe-0.2.0 → kipe-0.3.0}/src/kipe/fenicsx/examples/heat.py +0 -0
- {kipe-0.2.0 → kipe-0.3.0}/src/kipe/fenicsx/forward_solver.py +0 -0
- {kipe-0.2.0 → kipe-0.3.0}/src/kipe/fenicsx/sampling.py +0 -0
- {kipe-0.2.0 → kipe-0.3.0}/src/kipe/measurements.py +0 -0
- {kipe-0.2.0 → kipe-0.3.0}/src/kipe/parameters.py +0 -0
- {kipe-0.2.0 → kipe-0.3.0}/src/kipe/plot.py +0 -0
- {kipe-0.2.0 → kipe-0.3.0}/src/kipe/provenance.py +0 -0
- {kipe-0.2.0 → kipe-0.3.0}/src/kipe/py.typed +0 -0
- {kipe-0.2.0 → kipe-0.3.0}/src/kipe/roukf.py +0 -0
- {kipe-0.2.0 → kipe-0.3.0}/src/kipe/sampling.py +0 -0
- {kipe-0.2.0 → kipe-0.3.0}/tests/examples/test_fitzhugh_nagumo.py +0 -0
- {kipe-0.2.0 → kipe-0.3.0}/tests/examples/test_fitzhugh_nagumo_protocol.py +0 -0
- {kipe-0.2.0 → kipe-0.3.0}/tests/fenicsx/conftest.py +0 -0
- {kipe-0.2.0 → kipe-0.3.0}/tests/fenicsx/test_heat.py +0 -0
- {kipe-0.2.0 → kipe-0.3.0}/tests/fenicsx/test_heat_example.py +0 -0
- {kipe-0.2.0 → kipe-0.3.0}/tests/fenicsx/test_mesh_sampler.py +0 -0
- {kipe-0.2.0 → kipe-0.3.0}/tests/test_measurements.py +0 -0
- {kipe-0.2.0 → kipe-0.3.0}/tests/test_parameters.py +0 -0
- {kipe-0.2.0 → kipe-0.3.0}/tests/test_plot.py +0 -0
- {kipe-0.2.0 → kipe-0.3.0}/tests/test_provenance.py +0 -0
- {kipe-0.2.0 → kipe-0.3.0}/tests/test_roukf.py +0 -0
- {kipe-0.2.0 → kipe-0.3.0}/tests/test_roukf_kalman.py +0 -0
- {kipe-0.2.0 → kipe-0.3.0}/tests/test_study_file.py +0 -0
|
@@ -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
|
|
@@ -24,6 +24,19 @@ repos:
|
|
|
24
24
|
pass_filenames: false
|
|
25
25
|
additional_dependencies: [matplotlib, mpi4py, numpy, pytest, pydantic, ruamel.yaml]
|
|
26
26
|
|
|
27
|
+
# Needs the docs extra in the active environment: pip install -e ".[docs]"
|
|
28
|
+
# Manual stage: skipped on commit; run with: pre-commit run sphinx-build --all-files --hook-stage manual
|
|
29
|
+
# (the --hook-stage manual flag is required, otherwise: "No hook with id `sphinx-build` in stage `pre-commit`")
|
|
30
|
+
- repo: local
|
|
31
|
+
hooks:
|
|
32
|
+
- id: sphinx-build
|
|
33
|
+
name: sphinx docs build
|
|
34
|
+
stages: [manual]
|
|
35
|
+
entry: bash -c 'python -m sphinx -q -W --keep-going -b html docs/source docs/build/html && python -m webbrowser -t "file://$(pwd)/docs/build/html/index.html"'
|
|
36
|
+
language: system
|
|
37
|
+
files: ^(docs/|src/.*\.py$|pyproject\.toml$)
|
|
38
|
+
pass_filenames: false
|
|
39
|
+
|
|
27
40
|
# The scope is optional: the module a commit is about, or the area for non-code changes,
|
|
28
41
|
# e.g., "feat(plot): ...", "fix(estimation,roukf): ..."; no scope for broader commits.
|
|
29
42
|
- repo: https://github.com/compilerla/conventional-pre-commit
|
|
@@ -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.
|
|
32
|
-
date-released: 2026-10-
|
|
31
|
+
version: 0.3.0 # update on each release
|
|
32
|
+
date-released: 2026-10-14
|
|
33
33
|
# doi: added by Zenodo, if connected
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: kipe
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Parameter estimation with reduced-order unscented Kalman filtering, and identifiability analysis, for PDE models
|
|
5
5
|
Project-URL: Homepage, https://github.com/cardiomath/kipe
|
|
6
6
|
Project-URL: Issues, https://github.com/cardiomath/kipe/issues
|
|
@@ -28,6 +28,11 @@ Requires-Dist: pre-commit; extra == 'dev'
|
|
|
28
28
|
Requires-Dist: pytest>=8; extra == 'dev'
|
|
29
29
|
Requires-Dist: ruff==0.16.9; extra == 'dev'
|
|
30
30
|
Requires-Dist: scipy>=1.12; extra == 'dev'
|
|
31
|
+
Provides-Extra: docs
|
|
32
|
+
Requires-Dist: myst-parser<6,>=4; extra == 'docs'
|
|
33
|
+
Requires-Dist: sphinx-rtd-theme<4,>=3; extra == 'docs'
|
|
34
|
+
Requires-Dist: sphinx<10,>=8; extra == 'docs'
|
|
35
|
+
Requires-Dist: sphinxcontrib-mermaid<3,>=1; extra == 'docs'
|
|
31
36
|
Description-Content-Type: text/markdown
|
|
32
37
|
|
|
33
38
|
# kipe
|
|
@@ -0,0 +1,21 @@
|
|
|
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 `sphinx-build` pre-commit hook runs this same build on commits touching `docs/` or `src/`.
|
|
14
|
+
|
|
15
|
+
Open `docs/build/html/index.html` (or `python -m http.server -d docs/build/html`).
|
|
16
|
+
|
|
17
|
+
## GitHub Pages
|
|
18
|
+
|
|
19
|
+
The workflow `.github/workflows/docs.yml` builds and deploys on every push to `main`
|
|
20
|
+
(or manually via *Run workflow*). One-time setup: **Settings → Pages → Build and deployment →
|
|
21
|
+
Source: GitHub Actions**. The site is then at `https://cardiomath.github.io/kipe/`.
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"""Sphinx configuration for the kipe documentation."""
|
|
2
|
+
|
|
3
|
+
from importlib.metadata import PackageNotFoundError
|
|
4
|
+
from importlib.metadata import version as _version
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
from sphinx.ext.apidoc import main as apidoc_main
|
|
8
|
+
|
|
9
|
+
ROOT = Path(__file__).resolve().parents[2]
|
|
10
|
+
|
|
11
|
+
project = "kipe"
|
|
12
|
+
author = "kipe contributors"
|
|
13
|
+
try:
|
|
14
|
+
release = _version("kipe")
|
|
15
|
+
except PackageNotFoundError:
|
|
16
|
+
release = "0.0.0"
|
|
17
|
+
|
|
18
|
+
extensions = [
|
|
19
|
+
"sphinx.ext.autodoc",
|
|
20
|
+
"sphinx.ext.napoleon",
|
|
21
|
+
"sphinx.ext.viewcode",
|
|
22
|
+
"myst_parser",
|
|
23
|
+
"sphinxcontrib.mermaid",
|
|
24
|
+
]
|
|
25
|
+
source_suffix = {".rst": "restructuredtext", ".md": "markdown"}
|
|
26
|
+
exclude_patterns = ["_apidoc/modules.rst"]
|
|
27
|
+
html_theme = "sphinx_rtd_theme"
|
|
28
|
+
html_static_path = ["_static"]
|
|
29
|
+
html_css_files = ["mermaid.css"]
|
|
30
|
+
mermaid_height = "auto" # in proportion to the width, not a fixed box; see mermaid.css
|
|
31
|
+
autodoc_member_order = "bysource"
|
|
32
|
+
# compiled dependencies (MPI, FEniCSx) are not needed to render the API
|
|
33
|
+
autodoc_mock_imports = ["mpi4py", "dolfinx", "ufl", "petsc4py", "basix"]
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _generate_api(app):
|
|
37
|
+
"""Generate the API pages from the package, so none are maintained by hand."""
|
|
38
|
+
out = Path(app.srcdir) / "_apidoc"
|
|
39
|
+
apidoc_main([
|
|
40
|
+
"--force",
|
|
41
|
+
"--separate",
|
|
42
|
+
"--module-first",
|
|
43
|
+
"-o",
|
|
44
|
+
str(out),
|
|
45
|
+
str(ROOT / "src" / "kipe"),
|
|
46
|
+
])
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def setup(app):
|
|
50
|
+
"""Register the API generation hook."""
|
|
51
|
+
app.connect("builder-inited", _generate_api)
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
Design
|
|
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** sets ``size`` and ``global_indices`` and implements
|
|
159
|
+
:meth:`~kipe.sampling.SpatialSampler.sample`, which takes the observed fields (rank-local
|
|
160
|
+
arrays) and returns this rank's sampled entries. It may take what it needs from the solver at
|
|
161
|
+
construction, e.g., function spaces, through a backend capability.
|
|
162
|
+
|
|
163
|
+
**A measurement model** implements :meth:`~kipe.measurements.MeasurementModel.predict` and
|
|
164
|
+
:meth:`~kipe.measurements.MeasurementModel.innovation`. It sees this rank's entries as arrays.
|
|
165
|
+
A model that needs all entries at once (e.g., a Fourier transform) will also need the
|
|
166
|
+
communicator; none does so far.
|
|
167
|
+
|
|
168
|
+
**A data format** is read where the data are read
|
|
169
|
+
(:func:`kipe.estimation.estimate` and :func:`kipe.synthesis.synthesize`, through
|
|
170
|
+
:func:`~kipe.measurements.read_numpy` and :func:`~kipe.measurements.write_numpy`). kipe has
|
|
171
|
+
one format so far, ``numpy``; the second one will add a build function for readers, following
|
|
172
|
+
the pattern above.
|
|
173
|
+
|
|
174
|
+
**A forward solver** lives outside kipe. It implements
|
|
175
|
+
:class:`~kipe.forward_solver.ForwardSolver`, plus the capabilities of the backend it uses.
|
|
176
|
+
:mod:`kipe.examples.fitzhugh_nagumo` is the reference for a solver without a backend,
|
|
177
|
+
:mod:`kipe.fenicsx.examples.heat` for a FEniCSx solver; both are tested against the protocol.
|
|
@@ -269,6 +269,9 @@ def _setup_logging(level: str, log_file: Path) -> None:
|
|
|
269
269
|
logged. Rank 0 also writes all messages, from the debug level on and with their location, to
|
|
270
270
|
``log_file`` (overwritten).
|
|
271
271
|
|
|
272
|
+
The messages don't propagate to the root logger: an imported library may have given it a
|
|
273
|
+
handler on stderr (UFL does, with ``logging.debug``), which would show them at all levels.
|
|
274
|
+
|
|
272
275
|
Args:
|
|
273
276
|
level: minimum level of the messages on stderr of rank 0, e.g., ``"info"``
|
|
274
277
|
log_file: path of the log file
|
|
@@ -279,10 +282,12 @@ def _setup_logging(level: str, log_file: Path) -> None:
|
|
|
279
282
|
|
|
280
283
|
logger = logging.getLogger("kipe")
|
|
281
284
|
for handler in list(logger.handlers): # main() may run several times in one process
|
|
282
|
-
|
|
283
|
-
|
|
285
|
+
if handler.name in ("kipe.console", "kipe.file"):
|
|
286
|
+
logger.removeHandler(handler)
|
|
287
|
+
handler.close()
|
|
284
288
|
|
|
285
289
|
console = logging.StreamHandler()
|
|
290
|
+
console.name = "kipe.console"
|
|
286
291
|
console.setFormatter(
|
|
287
292
|
logging.Formatter(f"{prefix}: {location if level == 'debug' else ''}%(message)s")
|
|
288
293
|
)
|
|
@@ -292,12 +297,14 @@ def _setup_logging(level: str, log_file: Path) -> None:
|
|
|
292
297
|
if rank == 0:
|
|
293
298
|
log_file.parent.mkdir(parents=True, exist_ok=True)
|
|
294
299
|
file = logging.FileHandler(log_file, mode="w", encoding="utf-8")
|
|
300
|
+
file.name = "kipe.file"
|
|
295
301
|
file.setFormatter(
|
|
296
302
|
logging.Formatter(f"%(asctime)s %(levelname)-7s {location}%(message)s")
|
|
297
303
|
)
|
|
298
304
|
logger.addHandler(file)
|
|
299
305
|
|
|
300
306
|
logger.setLevel(logging.DEBUG if rank == 0 else logging.WARNING)
|
|
307
|
+
logger.propagate = False
|
|
301
308
|
|
|
302
309
|
|
|
303
310
|
if __name__ == "__main__":
|
|
@@ -120,6 +120,37 @@ class ForwardSolver(Protocol):
|
|
|
120
120
|
...
|
|
121
121
|
|
|
122
122
|
|
|
123
|
+
@runtime_checkable
|
|
124
|
+
class SupportsCheckpoints(Protocol):
|
|
125
|
+
"""A forward solver that reads states from the checkpoints of an earlier run.
|
|
126
|
+
|
|
127
|
+
Synthesis uses it (``synthesis.truth: {type: checkpoints, path: ...}``) to generate data
|
|
128
|
+
from an existing run instead of running the solver. The run may differ from the solver's
|
|
129
|
+
own configuration (e.g., in its time step), as long as its checkpoints can be read into
|
|
130
|
+
the solver's state layout.
|
|
131
|
+
"""
|
|
132
|
+
|
|
133
|
+
def read_checkpoint(self, path: str, t: float) -> State:
|
|
134
|
+
"""Return the state at time ``t`` from the checkpoints at ``path``.
|
|
135
|
+
|
|
136
|
+
The checkpoint need not hold the full state: the fields it has, in the layout of
|
|
137
|
+
:attr:`ForwardSolver.state_spec`. Synthesis checks that the fields a measurement
|
|
138
|
+
observes are among them.
|
|
139
|
+
|
|
140
|
+
Args:
|
|
141
|
+
path: location of the checkpoints, as the solver understands it (e.g., the output
|
|
142
|
+
directory of the run)
|
|
143
|
+
t: time of the checkpoint
|
|
144
|
+
|
|
145
|
+
Returns:
|
|
146
|
+
the fields of the checkpoint at ``t``, valid until the next call
|
|
147
|
+
|
|
148
|
+
Raises:
|
|
149
|
+
ValueError: if there is no checkpoint at ``t``, or none can be read at ``path``
|
|
150
|
+
"""
|
|
151
|
+
...
|
|
152
|
+
|
|
153
|
+
|
|
123
154
|
# --- construction ------------------------------------------------------------------------------
|
|
124
155
|
|
|
125
156
|
|
|
@@ -306,6 +306,29 @@ class RunTruthOptions:
|
|
|
306
306
|
"""Source of the true state."""
|
|
307
307
|
|
|
308
308
|
|
|
309
|
+
@dataclass(frozen=True, config=_CONFIG)
|
|
310
|
+
class CheckpointsTruthOptions:
|
|
311
|
+
"""Generate the data from the checkpoints of an earlier run of the forward solver.
|
|
312
|
+
|
|
313
|
+
The solver reads the true states at the measurement times from the checkpoints at
|
|
314
|
+
``path``; it needs :class:`kipe.forward_solver.SupportsCheckpoints`. The run may differ
|
|
315
|
+
from the model of the ``forward_solver`` section (e.g., in its time step or parameters), as
|
|
316
|
+
long as the solver can read its checkpoints into the model's state.
|
|
317
|
+
"""
|
|
318
|
+
|
|
319
|
+
type: Literal["checkpoints"]
|
|
320
|
+
"""Source of the true state."""
|
|
321
|
+
|
|
322
|
+
path: str
|
|
323
|
+
"""Location of the checkpoints, as the solver understands it (e.g., the output directory of
|
|
324
|
+
the run)."""
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
type TruthOptions = Annotated[
|
|
328
|
+
RunTruthOptions | CheckpointsTruthOptions, Field(discriminator="type")
|
|
329
|
+
]
|
|
330
|
+
|
|
331
|
+
|
|
309
332
|
@dataclass(frozen=True, config=_CONFIG)
|
|
310
333
|
class SynthesisNoiseOptions:
|
|
311
334
|
"""Noise that synthesis adds to the data of a measurement."""
|
|
@@ -318,8 +341,9 @@ class SynthesisNoiseOptions:
|
|
|
318
341
|
class SynthesisOptions:
|
|
319
342
|
"""Generation of synthetic measurement data."""
|
|
320
343
|
|
|
321
|
-
truth:
|
|
322
|
-
"""Source of the true state the data are generated from
|
|
344
|
+
truth: TruthOptions = field(default_factory=RunTruthOptions)
|
|
345
|
+
"""Source of the true state the data are generated from: a run of the forward solver, or
|
|
346
|
+
its checkpoints."""
|
|
323
347
|
|
|
324
348
|
noise: dict[str, SynthesisNoiseOptions] = field(default_factory=dict)
|
|
325
349
|
"""Noise synthesis adds to the data of the listed measurements (measurement name ->
|