Targets and runtimes¶
A Target* lowers a Module to a backend. TargetNumpy returns the
matching native-Python runtime view; TargetCpp emits an Eigen C++
library; TargetWasm emits a browser bundle (WASM + JS); TargetJax
emits a jitted rollout.
Targets¶
manta.TargetNumpy ¶
TargetNumpy(x, *, compile=False, optimization=None, compile_timeout_s=DEFAULT_COMPILATION_TIMEOUT_S, max_instructions=DEFAULT_MAX_INSTRUCTIONS)
Lower a typed Module — or any transform exposing .module()
(Sim, EKF, LQR, a recurrence block) — to the matching
native-Python view (sim / filter / recurrence / regulator), or the
bare kernel engine when no view matches.
compile=True builds the kernel's CasADi functions with optimized native
code (O1 by default for full-simulation graphs, -O3 -march=native for
other runtime models). Each artifact caller may explicitly select a
startup/balanced/runtime profile or O0/O1/O2 according to its own
compile/runtime tradeoff and cold-build ceiling. It
calls them as externals instead of interpreting the MX graph. Results are
cached on disk; the default cold-build deadline is five minutes, and the
artifact caller may replace or disable that deadline. It raises
CompilationError if an external cannot be produced; explicit native
execution never silently becomes interpretation. Pair with NumpySim's
step_n to fold substeps for a further amortization.
max_instructions is the cost-benefit size gate, counted in CasADi
instructions over every kernel (default DEFAULT_MAX_INSTRUCTIONS).
Above it compilation is refused with an error naming this parameter. A
deliberately large full-truth simulation whose owner has declared a
finite cold-build ceiling raises it, or passes None to disable the
gate entirely.
Source code in manta/codegen/numpy/__init__.py
manta.TargetFilterReplay ¶
TargetFilterReplay(value, *, max_operations, max_checkpoints, max_execution_bytes=_DEFAULT_EXECUTION_BYTE_CAP, optimization='runtime')
Generate a bounded exact-sequential EKF/UKF replay target.
Source code in manta/codegen/numpy/_filter_replay.py
manta.TargetCpp ¶
C++ codegen target.
Args:
x — a Module, or a transform with .module().
out_dir — destination directory (created if missing).
class_name — C++ class name. Conventionally PascalCase.
basename — filename stem; defaults to class_name.lower().
namespace — C++ namespace enclosing the emitted class.
Returns:
EmitResult with paths to every emitted file plus a small funcs
summary (world_name / dims).
Source code in manta/codegen/cpp/__init__.py
manta.TargetWasm ¶
WASM codegen target.
Args:
x — a Module, or a transform with .module().
out_dir — destination directory (created if missing).
class_name — public name for the bundle. Conventionally PascalCase.
basename — filename stem; defaults to class_name.lower().
Returns:
WasmEmitResult with paths to every emitted file plus the descriptor.
Source code in manta/codegen/wasm/__init__.py
manta.TargetJax ¶
Lower a Module (or any transform exposing .module()) to jitted
JAX kernels by name + a lax.scan rollout builder — the functional
artifacts a training loop wants (see manta.codegen.jax.JaxModule).
jax is imported only when this is called, so manta itself never
requires it.
Source code in manta/codegen/__init__.py
manta.NoiseDriver ¶
Draws the per-step samples that make an oracle Module's noise live.
Binds to the NOISE port's fields (name, dim, σ); each sample() is an
independent N(0, σ²) draw per active channel. Deliberately thin and
swappable — kept out of the pure kernels — and simply omitted on a
deploy target.
Source code in manta/codegen/numpy/_noise.py
sample ¶
Draw only active channels, or every channel when unspecified.
Dependency-scheduled simulation uses this boundary so measurement white noise advances on acquisition, not on unrelated plant ticks. Channel order remains the bound NOISE-port order for deterministic replay.
Source code in manta/codegen/numpy/_noise.py
Numpy runtime views¶
The view TargetNumpy(x) returns is determined by the Module's shape.
manta.codegen.NumpyRuntime ¶
The generic engine over a typed Module: state storage + the
typed-arg gather → kernel call → scatter. Views subclass it.
Source code in manta/codegen/numpy/_runtime.py
state_revision
property
¶
Monotonic revision for consumers caching state projections.
compile_functions ¶
compile_functions(function_names, *, optimization='balanced', timeout_s=DEFAULT_COMPILATION_TIMEOUT_S, max_instructions=DEFAULT_MAX_INSTRUCTIONS)
Compile a selected hot subset of this runtime's kernels.
Large transforms need not make native execution all-or-nothing. A
rate loop can compile its dominant kernel while retaining interpreted
entry points that execute rarely. Selection is by stable Module
function identity, and a failure leaves the runtime unchanged.
max_instructions raises or disables (None) the size gate.
Source code in manta/codegen/numpy/_runtime.py
call ¶
Run one entry point. values/kwargs are keyed by port or state
name (use the dict for dotted names); TIME ports default to 0.
The Hosting contract: a THREADED module's state is the caller's —
supply state fields by name in values (unsupplied ones fall back
to the engine's last-written copy) and read the fresh writes from
the returned dict alongside the entry's returns. A HELD module's
state lives in the runtime and is read/written in place; only the
entry's returns come back.
Source code in manta/codegen/numpy/_runtime.py
build_u ¶
Resolve a {name: value} dict (full or suffix names) to the
flat control vector over the Module's declared defaults.
Source code in manta/codegen/numpy/_runtime.py
set_parameters ¶
Override promoted-parameter values (full or suffix names); every subsequent kernel call uses them. Values not overridden stay at the Module's declared defaults.
Source code in manta/codegen/numpy/_runtime.py
param_vector ¶
The flat promoted-parameter vector: declared defaults merged
with set_parameters overrides, in port-field order.
manta.codegen.NumpySim ¶
Bases: NumpyRuntime
The simulation oracle. The runtime holds the nested state dict
(sim.state); step(dt, u={...}) applies the commands and advances it,
realizing that step's sensor readings. Rate-limited measurement kernels
are called only when due and their last values are held between samples.
Read sensors with outputs() (raw nested) or reading(name) (one, by
name).
Source code in manta/codegen/numpy/_sim.py
state
property
writable
¶
The held nested state (lazy-seeded; mutate in place to set commands or override slots).
Aliasing rule: the OWNER DICTS stay live across steps (holding
st = sim.state['craft'] keeps working), but the slot VALUES are
replaced each step — a reference to sim.state['c']['position']
goes stale after step(); read through the dict, don't cache the
array. Unknown keys are rejected at the next step() (a typo'd
slot would otherwise be a silent no-op).
initial_state ¶
Fresh nested initial state: the manifold slots' defaults plus
input/noise placeholder entries (commands you may set; noise seeds
that stay at zero — a NoiseDriver draw never enters the dict).
Source code in manta/codegen/numpy/_sim.py
model_state ¶
Only manifold state slots, excluding commands/noise placeholders.
step ¶
Advance the held state by dt. u is {input: value} (full or
suffix names) applied this step over the held sim.state inputs.
Runs the oracle kernel (one noise draw) and returns the new state
dict. Downstream code owns any actuator intake hold policy.
Source code in manta/codegen/numpy/_sim.py
attach_model ¶
Attach physical non-spatial state to this simulation clock.
A coupled model contributes pre-step Manta inputs and advances once after the corresponding physics tick. Checkpoint/restore and failures are atomic across the spatial model, noise driver, and every attached model.
Source code in manta/codegen/numpy/_sim.py
step_n ¶
Advance n substeps of dt in ONE folded call — u commands held
(ZOH) for the block, state chained through a mapaccum of the step
kernel. Output readings + state are bit-identical to n sequential
step(dt, u=u) calls; compiled (_enable_compile) it runs the whole
inner loop in C.
Falls back to sequential stepping when a NoiseDriver is attached (a
fresh stochastic draw per substep cannot be folded).
Source code in manta/codegen/numpy/_sim.py
outputs ¶
Sensor readings from the most recent step (nested, realized with that step's noise draw).
attach_driver ¶
Attach a stochastic NoiseDriver: every active (σ>0) channel of
the Module's NOISE port is sampled each step, so truth is noisy
with the very σ the EKF reads for R/Q. Without one the sim is a
noiseless oracle.
Source code in manta/codegen/numpy/_sim.py
reading ¶
The latest raw reading for a sensor (full or suffix name) from the most recent acquisition. A rate-limited reading is held between acquisitions; an unrated reading is realized every plant step.
Source code in manta/codegen/numpy/_sim.py
manta.codegen.NumpyFilter ¶
Bases: NumpyRuntime
A predict/update filter over a held x/P, with baked per-sensor
update kernels — the same surface every backend emits.
You own the loop, identically in numpy and C++: fold each fresh measurement at the pre-predict state, then predict.
for nm in sensors:
if gate[nm].due(t):
ekf.update(nm, sim.reading(nm), u=u) # update-then-...
ekf.predict(dt, u=u) # ...-predict
The update-then-predict order is yours to keep: a reading sampled at the interval start belongs against the current (pre-predict) state.
Clock: same convention as NumpySim — the runtime tracks t,
predict(dt) advances it, and an explicit t= overrides it for that
call. (The kernels stay pure; this is caller-side bookkeeping the two
runtimes must agree on: a filter that silently pinned t=0 while the
sim advanced left every time-dependent world linearized at t=0.)
Source code in manta/codegen/numpy/_filter.py
Q
property
writable
¶
Default process noise for predict (overridden per-call by
predict(dt, Q=...); None uses the model's baked L Σ Lᵀ).
state_dict ¶
reset ¶
Reset state, covariance, and clock from the Module defaults.
state is merged over the declared initial state and P may
replace the declared initial covariance. To move only the nominal
state while deliberately preserving covariance, use
:meth:set_state_keep_covariance.
Source code in manta/codegen/numpy/_filter.py
reset_from_model_record ¶
Reset from a broader authoring record containing inputs/noise.
This explicit projection is for Craft.initial_state()-style
records. Ordinary :meth:reset remains strict so typoed state keys
cannot disappear among unrelated model fields.
Source code in manta/codegen/numpy/_filter.py
checkpoint ¶
Capture nominal state, covariance, and logical time atomically.
Source code in manta/codegen/numpy/_filter.py
restore ¶
Restore a checkpoint after strict shape/finite validation.
Restore never partially mutates the live filter: all values are validated and copied before any runtime field changes.
Source code in manta/codegen/numpy/_filter.py
set_state_keep_covariance ¶
Replace the nominal state while preserving covariance and clock.
This is intentionally separate from :meth:reset: retaining a
covariance after moving its linearization point is an advanced,
explicit operation.
Source code in manta/codegen/numpy/_filter.py
preintegrated_inputs ¶
Merge an IMUPreintegrator readout into INS inputs.
This is a naming/validation convenience for the NumPy runtime. The
generated C++ filter exposes the same fields directly on Inputs.
packet is the dict returned by the recurrence's step or
readouts method.
Source code in manta/codegen/numpy/_filter.py
predict_preintegrated ¶
Advance a preintegrated INS by the packet's accumulated duration.
Source code in manta/codegen/numpy/_filter.py
predict ¶
Advance the estimate by dt. Process noise: an explicit Q, else
self.Q, else the model's baked L Σ Lᵀ. u is {input: value}
(unset inputs fall to the Module's declared defaults); pass the same
held u truth ran on. t=None uses (and advances) the runtime's
clock, matching NumpySim.step; an explicit t overrides and
resynchronizes it.
Source code in manta/codegen/numpy/_filter.py
update ¶
Fold one measurement at the current state.
update("gps.position", z)— by sensor name (full or suffix), through the baked covariance and gate.update("gps.position", z, R=sample_R)— typed per-sample device covariance through the deployable Module entry point; non-overrideable white model covariance remains additive, while static calibration uncertainty remains in the Schmidt recursion.update(h_sym, z, R=R)— a caller-suppliedh(x)callable + measurement covariance (custom measurements; numpy-only).
t=None reads the runtime's clock (which predict advances); a
measurement is dt-independent, so update never advances it.
Source code in manta/codegen/numpy/_filter.py
compile_sensor_updates ¶
compile_sensor_updates(sensor_names, *, covariance='model', optimization='balanced', timeout_s=DEFAULT_COMPILATION_TIMEOUT_S, max_instructions=DEFAULT_MAX_INSTRUCTIONS)
Compile selected sensor-fold kernels through the public filter API.
covariance="model" selects the ordinary diagnostic update whose
covariance is baked into the estimator. "per_sample" selects the
update entry accepting an R= override. Sensor names use the same
full-name/unambiguous-suffix rules as :meth:update; callers never
need to construct or depend on generated Module entry names.
Source code in manta/codegen/numpy/_filter.py
manta.FilterCheckpoint
dataclass
¶
Complete restart point for a filter runtime.
Arrays are owned snapshots rather than views into the live runtime.
time is the filter's logical model time, not a wall clock.
manta.UpdateResult
dataclass
¶
Diagnostics and disposition of one measurement fold.
manta.FilterReplayProgram
dataclass
¶
FilterReplayProgram(kernel_identity, initial, operation_count, checkpoint_count, _kinds, _sensors, _times, _dts, _controls, _measurements, _measurement_covariances, _process_covariances, _use_measurement_covariance, _use_process_covariance, _checkpoint_flags)
Validated, bounded native input owned by one kernel identity.
manta.FilterReplayResult
dataclass
¶
Final state plus ordered per-update diagnostics and checkpoints.
manta.codegen.NumpyRegulator ¶
Bases: NumpyRuntime
A stateless control law: map a state estimate to commands via
control(estimate) -> {input: value}.
Holds the live operating point the law flies about — the reference
x_ref plus every MATRIX-role coefficient the Module declares (an
LQR's gain K and feed-forward u_ff), each seeded from its
declared default. retarget() moves the reference alone;
reprogram() installs a whole re-solved operating point.
Source code in manta/codegen/numpy/_regulator.py
retarget ¶
Move the reference point the law regulates to (nested or flat
dict, merged over the CURRENT reference). The gain is NOT
re-solved: exact wherever the dynamics are invariant along the
moved direction (e.g. translating a hover setpoint), but NOT for
a heading change — there the world-frame feedback rotates with
the reference. Use reprogram(lqr.resolve_at(...)) for those.
Source code in manta/codegen/numpy/_regulator.py
reprogram ¶
Install a re-solved operating point — gain, feed-forward, and reference at once (a gain is only valid about the point it was solved at, so they move together).
solution is anything carrying K, u_ff and x_ref — an
LQRSolution from LQR.resolve_at, or a plain object/namespace
rebuilt from JSON on the far side of a retarget service.
Source code in manta/codegen/numpy/_regulator.py
u ¶
Control vector for a flat ambient state (full-spec layout).
Source code in manta/codegen/numpy/_regulator.py
control ¶
Map a state estimate (nested or flat dict) → {input: value},
merged over the live reference point (unsupplied slots sit at
the reference, i.e. zero error).
Source code in manta/codegen/numpy/_regulator.py
manta.codegen.NumpyRecurrence ¶
Bases: NumpyRuntime
A stateful dataflow block (PID, Madgwick, …): step(dt, **inputs)
advances the held state and computes the readouts.