kipe.options module
Options of the kipe study file.
A study file is a YAML file with one section per concern: output, forward_solver,
parameters, measurements, synthesis and estimation (StudyOptions).
Each command reads the sections it needs. Relative paths are relative to the working directory
kipe is run from.
The dataclasses of this module are the only definition of the study file: pydantic validates study files against them, unknown keys are an error, and the documentation’s study file reference is generated from them, with their attribute docstrings as the descriptions.
See examples/fitzhugh_nagumo/study.yaml for a complete study file.
- exception kipe.options.StudyFileError[source]
Bases:
ExceptionThe study file cannot be read, or is not a YAML mapping of sections.
- class kipe.options.OutputOptions(path: str, log_level: Literal['debug', 'info', 'warning', 'error'] = 'info')[source]
Bases:
objectWhere and how kipe writes its results.
- path: str
Directory for all results. Subcommands write into subdirectories.
- log_level: Literal['debug', 'info', 'warning', 'error'] = 'info'
Minimum level of the log messages kipe writes.
- class kipe.options.ForwardSolverOptions(factory: str, arguments: dict[str, ~typing.Any]=<factory>)[source]
Bases:
objectHow to construct the forward solver.
kipe imports
factoryand calls it withargumentsas keyword arguments. The factory can be a class or a function; it must return an object that conforms tokipe.forward_solver.ForwardSolver.- factory: str
Import path of the factory,
"module:name", e.g.,"kipe.examples.fitzhugh_nagumo:Solver".
- arguments: dict[str, Any]
Keyword arguments passed to the factory, as given (no path resolution).
- type kipe.options.Reparameterization = Literal['log', 'multiplicative', 'additive']
- class kipe.options.ParameterPrior(mean: float, relative_stddev: float | None = None, stddev: float | None = None, reparameterization: Reparameterization | None = None)[source]
Bases:
objectPrior of one estimated parameter: its mean and standard deviation.
The prior is Gaussian in the estimated parameter \(\theta\), and the filter starts from it: at the mean, with the standard deviation as the initial size of the sigma-point stencil used for the derivative-free linearization, and as the initial weight against the measurement noise.
logandmultiplicativetake arelative_stddev,additivean absolutestddev.- mean: float
where the estimation starts.
- Type:
Prior mean, as physical value
- relative_stddev: float | None = None
Standard deviation relative to the
mean, e.g.,0.3for 30%. Forlogandmultiplicative.The standard deviation of \(\theta\) is \(\sigma_\theta\) =
relative_stddev, i.e., that of \(\ln \phi\) forlogand that of \(\phi / \phi_0\) formultiplicative. To first order, both are the standard deviation of \(\phi\) relative to themean, so both give about the same prior as long asrelative_stddevis small. For large values they differ:logkeeps the sign of the parameter, at the price of an asymmetric distribution.kipe list-parametersshows the resulting 1σ range.
- stddev: float | None = None
Absolute standard deviation, in the parameter’s physical unit. For
additive.
- reparameterization: Reparameterization | None = None
Gaussian in \(\theta\), i.e., log-normal in the parameter for
log, normal formultiplicativeandadditive. Overrides the section’sreparameterizationfor this parameter.- Type:
The distribution of this prior
- class kipe.options.ParametersOptions(reparameterization: Reparameterization, priors: dict[str, ParameterPrior])[source]
Bases:
objectPriors and reparameterization of the estimated parameters.
kipe list-parametersshows the names the forward solver accepts.- reparameterization: Reparameterization
How the estimated parameter \(\theta\) relates to the physical value \(\phi\), relative to the prior mean \(\phi_0\). Default for all parameters in
priors, each can override it.Available reparameterizations:
log: \(\phi = \phi_0 e^\theta\), starting at \(\theta = 0\), with arelative_stddev. Keeps the sign of \(\phi_0\); the prior mean may be positive or negative, but not zero.multiplicative: \(\phi = \phi_0 \theta\), starting at \(\theta = 1\), with arelative_stddev. The prior mean must not be zero; \(\phi\) can change sign.additive: \(\phi = \phi_0 + \theta\), starting at \(\theta = 0\), with an absolutestddev. \(\theta\) is the deviation from the prior mean, in the parameter’s physical unit. Accepts any prior mean, including zero.
- priors: dict[str, ParameterPrior]
parameter name -> prior (mean and standard deviation). All other parameters keep their nominal values.
- Type:
Estimated parameters
- class kipe.options.TimeRange(start: float, stop: float, step: float)[source]
Bases:
objectEquidistant times from
starttostop, both included.- start: float
First time.
- stop: float
Last time, included (up to round-off).
- step: float
Distance between successive times.
- class kipe.options.NumpyDataOptions(type: Literal['numpy'], path: str)[source]
Bases:
objectMeasurement data in a numpy
.npzfile.The file holds the arrays
times, shape(n,), andvalues, shape(n, m): m values at each of the n times.- type: Literal['numpy']
Data format.
- path: str
Path to the
.npzfile. With several noise realizations (synthesis.realizations), it contains the placeholder{realization}, e.g.,"data/r{realization}/u.npz"or"data/u_{realization:02d}.npz": each realization has its own file. In quotes, since YAML reads braces in{type: ..., path: ...}as a mapping.
- class kipe.options.ArraySamplingOptions(type: Literal['array'] = 'array')[source]
Bases:
objectSample all entries of the observed fields, concatenated in the order of
fields.- type: Literal['array'] = 'array'
Kind of spatial sampling.
- class kipe.options.DifferenceModelOptions(type: Literal['difference'] = 'difference')[source]
Bases:
objectMeasured data are the sampled fields; innovation = measured - predicted.
- type: Literal['difference'] = 'difference'
Kind of measurement model.
- class kipe.options.PlaneModelOptions(type: Literal['plane'] = 'plane', normal_toward: tuple[float, float, float] | None = None)[source]
Bases:
objectFit
z = a*x + b*y + cto sampled 3D vertices by orthogonal least squares.The sampler must return flattened vertex coordinates, with x, y and z together for each vertex. Predicted and measured data are the three coefficients, ordered
[a, b, c]. The innovation is measured minus predicted coefficients.- type: Literal['plane'] = 'plane'
Kind of measurement model.
- normal_toward: tuple[float, float, float] | None = None
Optional reference point toward which the first fitted normal is oriented.
Coordinates use the mesh’s coordinate system and units. The point must lie off the first plane. Later normals align with the first normal, whether or not a point was provided. This affects the exposed normal, not the predicted
[a, b, c].
- type kipe.options.MeasurementModelOptions = DifferenceModelOptions | PlaneModelOptions
- class kipe.options.NoiseOptions(stddev: float | list[float], seed: int | None = None)[source]
Bases:
objectMeasurement noise: assumed by
estimation, added bysynthesis.synthesis.noisecan set another noise for synthesis to add, e.g., none.- stddev: float | list[float]
one scalar for all data entries, or a list with one positive value per entry, in the data’s global order and units.
- Type:
Independent noise standard deviations
- seed: int | None = None
Seed of the noise added by
synthesis(required there, unless it adds none, seesynthesis.noise). The noise of the k-th time of the measurement is drawn fromnumpy.random.default_rng([seed, k]), so it does not depend on the other times. Measurements must have different seeds.
- class kipe.options.MeshSamplingOptions(type: Literal['fenicsx.mesh'], mesh: str, mesh_name: str = 'mesh', element: Literal['P1', 'DG0'] = 'P1', projection: list[float] | Literal['surface_normal'] | None = None, padding: float = 0.0)[source]
Bases:
objectInterpolate the observed field onto a measurement mesh (FEniCSx backend).
The field must be a distributed field whose function space the forward solver provides (
kipe.fenicsx.forward_solver.SupportsFunctionSpaces). The measurement mesh need not match the solver’s mesh. The data are in the order of the mesh file: by vertex forP1, by cell forDG0, independent of the number of ranks; for a vector field without projection, the components of each vertex or cell one after another.- type: Literal['fenicsx.mesh']
Kind of spatial sampling.
- mesh: str
Path to the measurement mesh, an XDMF file.
- mesh_name: str = 'mesh'
meshas dolfinx writes it; meshio writesGrid.- Type:
Name of the mesh in the XDMF file (its grid)
- element: Literal['P1', 'DG0'] = 'P1'
vertex values (
P1) or cell values (DG0).- Type:
Finite element on the measurement mesh
- projection: list[float] | Literal['surface_normal'] | None = None
What is measured of a vector field; all components if not given. A direction, e.g.,
[0, 0, 1]for the z component (normalized by kipe), orsurface_normal: the component along the cell normal of a surface mesh (needselement: DG0, one normal per cell). The normal’s orientation follows the order of each cell’s vertices in the mesh file, asufl.CellNormal: the right-hand rule for triangles in 3D, the tangent rotated by +90° for lines in 2D; it is outward only if the mesh’s cells are oriented that way.
- padding: float = 0.0
Distance, in mesh units, by which a measurement point may lie outside the solver’s mesh, e.g., where a surface mesh cuts slightly across the solver’s boundary. Such a point takes the value of the field in the nearest cell, extrapolated; a point farther out is an error.
- class kipe.options.PointSamplingOptions(type: Literal['fenicsx.points'], points: list[list[float]])[source]
Bases:
objectEvaluate the observed field at given points (FEniCSx backend).
The field must be a distributed field whose function space the forward solver provides (
kipe.fenicsx.forward_solver.SupportsFunctionSpaces). The data are in the order ofpoints; for a vector field, the components of each point one after another.- type: Literal['fenicsx.points']
Kind of spatial sampling.
- points: list[list[float]]
Coordinates of the measurement points, one list per point, e.g.,
[[0.5, 0.5], [0.2, 0.8]]in 2D. Each point must lie in the solver’s mesh.
- class kipe.options.DisplacedVertexSamplingOptions(type: Literal['fenicsx.displaced_vertices'], tags: list[int], combine: Literal['union', 'intersection'])[source]
Bases:
objectReturn displaced vertices of tagged mesh facets (FEniCSx backend).
The observed field is a displacement vector with one component per spatial dimension. The mesh and facet tags are provided by the forward solver for the observed field. Vertices are ordered by their original geometry input indices.
- type: Literal['fenicsx.displaced_vertices']
Kind of spatial sampling.
- tags: list[int]
Tag IDs of the mesh facets whose vertices are selected. Cell tags are not supported.
- combine: Literal['union', 'intersection']
select vertices of facets with any listed tag;
intersection: select vertices shared by the facet sets of all listed tags. Must be specified explicitly.- Type:
union
- type kipe.options.SpatialSamplingOptions = ArraySamplingOptions | MeshSamplingOptions | PointSamplingOptions | DisplacedVertexSamplingOptions
- class kipe.options.MeasurementOptions(fields: list[str], data: ~kipe.options.NumpyDataOptions, noise: ~kipe.options.NoiseOptions, times: list[float] | ~kipe.options.TimeRange | None = None, spatial_sampling: ~kipe.options.SpatialSamplingOptions = <factory>, model: ~kipe.options.MeasurementModelOptions = <factory>)[source]
Bases:
objectOne measurement: which fields it observes, its data, and how to compare them.
- fields: list[str]
State fields the measurement observes.
- data: NumpyDataOptions
read by
estimation, written bysynthesis.- Type:
Where the measured data are
- noise: NoiseOptions
Measurement noise.
- times: list[float] | TimeRange | None = None
a list or a range. Required by
synthesis(the times to generate); forestimationa selection from the times in the data, all if not given.- Type:
Measurement times
- spatial_sampling: SpatialSamplingOptions
How the observed fields are brought to the measurement locations; the kind is selected by
type,arrayby default.
- model: MeasurementModelOptions
How predicted data are computed from the sampled fields and compared with the data.
- class kipe.options.RunTruthOptions(type: Literal['run'] = 'run')[source]
Bases:
objectGenerate the data by running the forward solver with its nominal parameters.
- type: Literal['run'] = 'run'
Source of the true state.
- class kipe.options.CheckpointsTruthOptions(type: Literal['checkpoints'], path: str)[source]
Bases:
objectGenerate the data from the checkpoints of an earlier run of the forward solver.
The solver reads the true states at the measurement times from the checkpoints at
path; it needskipe.forward_solver.SupportsCheckpoints. The run may differ from the model of theforward_solversection (e.g., in its time step or parameters), as long as the solver can read its checkpoints into the model’s state.- type: Literal['checkpoints']
Source of the true state.
- path: str
Location of the checkpoints, as the solver understands it (e.g., the output directory of the run).
- class kipe.options.DataTruthOptions(type: Literal['data'], path: str)[source]
Bases:
objectGenerate the data from given true data, read from files, with noise added.
E.g., the noise-free data of an earlier synthesis (in
<output.path>/synthesis/ noise_free/), for other noise levels, seeds or realizations without running the solver again; or measured data, to test the estimation with more noise. A measurement’stimesselect from the file’s times; withouttimes, all of them are used. The forward solver is built, for the layout of the measurements, but not run.- type: Literal['data']
Source of the true state.
- path: str
Path to the true data of each measurement, an
.npzfile in the format of the data files, with the placeholder{measurement}for the measurement’s name, e.g.,"results/synthesis/noise_free/{measurement}.npz". In quotes, since YAML reads braces as a mapping. Without the placeholder, all measurements read the same file, so a study with several measurements needs it.
- type kipe.options.TruthOptions = RunTruthOptions | CheckpointsTruthOptions | DataTruthOptions
- class kipe.options.SynthesisNoiseOptions(stddev: float | list[float])[source]
Bases:
objectNoise that synthesis adds to the data of a measurement.
- stddev: float | list[float]
a scalar or one value per data entry; 0 means noise-free.
- Type:
Added independent noise
- class kipe.options.SynthesisOptions(truth: TruthOptions = <factory>, noise: dict[str, ~kipe.options.SynthesisNoiseOptions]=<factory>, realizations: int = 1)[source]
Bases:
objectGeneration of synthetic measurement data.
- truth: TruthOptions
a run of the forward solver, its checkpoints, or given data. From a run or checkpoints, synthesis also writes the noise-free data, to
<output.path>/synthesis/noise_free/<measurement>.npz.- Type:
Source of the true state the data are generated from
- noise: dict[str, SynthesisNoiseOptions]
Noise synthesis adds to the data of the listed measurements (measurement name -> noise), instead of their
noise.stddev, which estimation assumes: for noise-free data (stddev: 0) or studies with misspecified noise. Measurements not listed get theirnoise.stddev.
- realizations: int = 1
Number of noise realizations, e.g., for the statistics of the estimates over the noise. Synthesis computes the true state once and writes the data of realizations \(r = 0, \dots, n - 1\), each to the
data.pathof the measurements with{realization}replaced by \(r\);kipe estimation --realization restimates from one of them. Realization 0 has the noise of a study without realizations.
- type kipe.options.SigmaPoints = Literal['simplex', 'canonical', 'unique']
- class kipe.options.EstimationOptions(sigma_points: SigmaPoints = 'simplex', iterations: int = 1)[source]
Bases:
objectParameter estimation with the reduced-order unscented Kalman filter (ROUKF).
- sigma_points: SigmaPoints = 'simplex'
Sigma-point stencil, the pattern along which the estimates are perturbed. Each sigma point costs one forward run per measurement time:
simplex: \(p + 1\) sigma points, the cheapest.canonical: \(2p\) sigma points, \(\pm\) along each parameter.unique: one sigma point at the estimate, no spread: no correction. A sanity check of the whole pipeline (with the true parameters, the innovations are pure noise).
- iterations: int = 1
Number of passes over the measurements. Each pass after the first starts from the previous estimate, with the prior’s uncertainty: relative to that estimate for
log, the same physical spread formultiplicativeandadditive.
- class kipe.options.SensitivityOptions(step: float = 0.01)[source]
Bases:
objectSensitivity analysis with the Fisher information (
kipe sensitivity).It computes the sensitivities of the measurements to the estimated parameters, and from them the Fisher information the measurements carry about the parameters. The sensitivities are evaluated at the nominal parameters, i.e., the truth of a twin experiment, in \(\theta\) of the
parameterssection, by centered finite differences with two forward runs per parameter. The measurements are those of the study, their predicted data noise-free, and weighted with the measurements’noise.stddev, the noise that estimation assumes.- step: float = 0.01
for
logparameters, the relative change of each, e.g., 0.01 for 1 %; formultiplicativeparameters, a change by that fraction of their priormean; foradditiveparameters, a fraction of their priorstddev, which gives the step its unit.- Type:
Step of the finite differences
- class kipe.options.StudyOptions(output: OutputOptions, forward_solver: ForwardSolverOptions, parameters: ParametersOptions | None = None, measurements: dict[str, ~kipe.options.MeasurementOptions] | None=None, synthesis: SynthesisOptions = <factory>, estimation: EstimationOptions = <factory>, sensitivity: SensitivityOptions = <factory>)[source]
Bases:
objectAll sections of a study file.
- output: OutputOptions
Output location and logging.
- forward_solver: ForwardSolverOptions
Construction of the forward solver.
- parameters: ParametersOptions | None = None
Estimated parameters.
- measurements: dict[str, MeasurementOptions] | None = None
name -> measurement. The names appear in logs, output and errors.
- Type:
Measurements
- synthesis: SynthesisOptions
Generation of synthetic measurement data.
- estimation: EstimationOptions
Parameter estimation.
- sensitivity: SensitivityOptions
Sensitivity analysis with the Fisher information (
kipe sensitivity).
- kipe.options.truth_path(truth: DataTruthOptions, measurement: str) str[source]
Return the path to the true data of a measurement,
synthesis.truth: {type: data}.- Parameters:
truth – the truth options
measurement – name of the measurement
- Returns:
truth.path, with{measurement}replaced
- kipe.options.data_path(measurement: MeasurementOptions, realization: int = 0) str[source]
Return the path to a measurement’s data of one noise realization.
- Parameters:
measurement – the measurement options
realization – number of the noise realization
- Returns:
data.path, with{realization}replaced
- kipe.options.estimation_directory(study: StudyOptions, realization: int = 0) Path[source]
Return the output directory of an estimation.
- Parameters:
study – the study options
realization – number of the noise realization the estimation uses
- Returns:
<output.path>/estimation; with several realizations, its subdirectory of the realization, e.g.,r07, numbered with as many digits as the largest number- Raises:
StudyFileError – if the study has no such realization
- kipe.options.load_study(path: str | Path) StudyOptions[source]
Read and validate a study file.
- Parameters:
path – path to the YAML study file
- Returns:
validated study options
- Raises:
StudyFileError – if the file cannot be read, is not valid YAML or is not a mapping
pydantic.ValidationError – if the options are invalid
- kipe.options.study_schema() dict[str, Any][source]
Return the JSON schema of the study file, e.g., for editors (
kipe schema).It is pydantic’s schema of
StudyOptions, in JSON Schema draft 2020-12, with the options’ docstrings as descriptions.- Returns:
the JSON schema, as a mapping that
json.dumps()writes
- kipe.options.dump_study(study: StudyOptions, path: str | Path) None[source]
Write study options as a study file, which
load_study()reads back.All options are written, defaults included,
nullfor those not set. Useful to generate study files from Python, e.g., for a sweep over noise seeds.- Parameters:
study – the study options
path – where to write the study file