Forward solver requirements

kipe runs the model through a small interface, the ForwardSolver protocol. A solver conforms structurally: it has the members below, and neither imports nor subclasses anything from kipe. This page lists what kipe expects from a solver; the protocol’s API documentation gives the exact signatures. The FitzHugh–Nagumo solver (kipe.examples.fitzhugh_nagumo) is a small, complete example.

Construction

The forward_solver section of the study file names a factory, a class or a function, and the keyword arguments kipe calls it with. The factory returns the solver: an object with the members listed under The interface.

forward_solver:
  factory: "my_package.my_module:MySolver"  # module:name, imported by kipe
  arguments: {dt: 0.01}                     # MySolver(dt=0.01)

An existing code with its own input file is typically built by a small factory function, which reads the file:

def build(config: str) -> MySolver:
    """Build the solver from its own input file."""
    return MySolver(read_my_config(config))
forward_solver:
  factory: "my_package.kipe_interface:build"
  arguments: {config: input/model.yaml}  # build(config="input/model.yaml")

kipe passes the arguments as keywords, as they are in the study file, and does not interpret them: a path stays a string. kipe does not change the working directory either, so relative paths are relative to the directory kipe runs in, like every path in the study file. That includes the paths in the solver’s own input file, e.g., to a mesh, unless the solver resolves them otherwise, e.g., relative to its input file.

Before anything expensive runs, kipe checks the arguments against the factory’s signature, and the object the factory returns against the protocol, so that a misspelled argument or a missing method is reported right away. Each command builds its own solver, on every MPI rank of the run.

The interface

member

what kipe uses it for

state_spec

the names of the state fields and their layout on this rank

initial_state()

the start time and the initial state

nominal_parameters()

the parameters a study can estimate, with their nominal values

propagate()

the state at time t1 from the state at t0, with the given parameters

What kipe relies on

  • The filter calls propagate() once for each sigma point (a candidate state and parameter set) at each measurement time. Calls may therefore arrive with different states and parameters; each result must depend only on that call’s arguments. Put everything needed to continue from a state, such as multistep history or boundary-model state, in the state itself. See the method’s API documentation for details.

  • propagate receives physical parameter values and must return the state exactly at t1. Parameters it does not receive retain their nominal values.

  • initial_state must return the same state each time, at a time before the first measurement.

  • On each rank, state fields must match the names, layout and local sizes in state_spec (FieldSpec).

If propagate raises an exception, the estimation stops, and the log shows the step, the times and the parameters of the sigma point that failed.

Optional capabilities

Some features need more from the solver, again as structural protocols:

  • SupportsCheckpoints: read_checkpoint(path, t) reads the state at time t from the checkpoints of an earlier run. Synthesis then generates data from them instead of running the solver (Synthetic data).

  • SupportsFunctionSpaces: function_space(field) returns the function space of a distributed field. The FEniCSx samplers need it to interpolate a field onto a measurement mesh or to evaluate it at points (Measurements).

  • SupportsFacetTags: facet_tags(field) returns the mesh’s facet tags. When the forward solver contains multiple meshes, the field identifies which mesh’s tags to return. The displaced vertex sampler uses them to select the vertices of tagged surfaces.

Checking a solver

  • kipe list-parameters study.yaml builds the solver, checks it against the protocol, and lists its parameters with their nominal values; kipe list-fields study.yaml lists its state fields.

  • Statelessness is easy to test directly: two calls of propagate from the same state (passed as copies, since propagate may modify it) and with the same parameters, with another call in between, return the same state.

  • A twin experiment (Synthetic data, Estimation) tests the whole setup: with little noise, the estimates should approach the parameters the data were generated with.

The heat equation example (kipe.fenicsx.examples.heat) is a FEniCSx solver with function spaces, which runs on several MPI ranks.