OP System¶
op_system
¶
op_system.
Domain-agnostic RHS specification + compilation utilities.
Public API (v1)¶
Primary user entrypoints:
- compile_spec: Validate, normalize, and compile a RHS specification in one step.
- normalize_rhs: Validate and normalize a YAML-friendly RHS specification.
- compile_rhs: Compile a NormalizedRhs into an efficient callable RHS.
Core data structures:
- NormalizedRhs
- CompiledRhs
- OperatorDescriptor
Design guarantees: - No dependency on provider/adapters (eg flepimop2). - Stable interface for downstream engines. - Forward-compatible with multiphysics extensions.
IdentifierString = Annotated[str, AfterValidator(_validate_identifier_string)]
module-attribute
¶
Custom pydantic type for validated identifier strings used in op_system.
Identifier strings are used for state names, dimension names, and other keys in the system. They must be non-empty, contain only alphanumeric characters, and start with a letter. Leading and trailing whitespace is stripped before validation.
Examples:
>>> from pydantic import BaseModel
>>> from op_system import IdentifierString
>>> class ExampleModel(BaseModel):
... identifier: IdentifierString
...
>>> ExampleModel(identifier="S")
ExampleModel(identifier='S')
>>> ExampleModel(identifier=" Foobar ")
ExampleModel(identifier='Foobar')
>>> ExampleModel(identifier="123abc")
Traceback (most recent call last):
...
pydantic_core._pydantic_core.ValidationError: 1 validation error for ExampleModel
identifier
Value error, IdentifierString must contain only alphanumerical characters and start with a letter. [...]
For further information visit ...
>>> ExampleModel(identifier="")
Traceback (most recent call last):
...
pydantic_core._pydantic_core.ValidationError: 1 validation error for ExampleModel
identifier
Value error, IdentifierString must not be empty. [...]
For further information visit ...
Array
¶
Bases: Protocol
Structural Array-API protocol.
Any object whose runtime type implements shape, dtype,
__array_namespace__ and item satisfies this protocol. NumPy
= 2.0 ndarrays and JAX arrays (concrete and traced) qualify directly.
Runtime evaluation is deliberately broader: it discovers namespaces via
:func:array_api_compat.array_namespace, so native arrays such as
torch.Tensor are accepted even though they do not structurally satisfy
this protocol. No compile-time backend selector is needed.
BlockAxisInfo(name, size, state_axis_pos, param_axis_pos)
dataclass
¶
Metadata for one block-diagonal (factorizable) axis.
A BlockAxisInfo is attached to
:class:~op_system.compile.CompiledRhs for each axis declared in
spec["factorize_axes"] that passes the IR separability check in
:func:analyze_block_axes. Engines (e.g. the diffrax plugin) consume
this to partition ODE solves with jax.vmap over the block axis.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Axis name string (e.g. |
size |
int
|
Number of elements along the axis. |
state_axis_pos |
dict[str, int]
|
Maps each state-template base name to the integer position of this axis within that template's shape tuple. Only templates that carry this axis appear in the dict. |
param_axis_pos |
dict[str, int | None]
|
Maps each shaped parameter name to the integer
position of this axis within the actual runtime array that the
engine passes to the eval function, or |
Note
BlockAxisInfo uses dict fields and therefore cannot be used
as a hash key. It is stored on
:class:~op_system.compile.CompiledRhs with hash=False and is
fully pickle-stable.
Examples:
>>> info = BlockAxisInfo(
... name="loc",
... size=3,
... state_axis_pos={"S": 1, "I": 1, "R": 1},
... param_axis_pos={"rho": 0, "beta": None},
... )
>>> info.name
'loc'
>>> info.size
3
>>> info.state_axis_pos["S"]
1
>>> info.param_axis_pos["rho"]
0
>>> info.param_axis_pos["beta"] is None
True
BodyEvalFn
¶
Bases: Protocol
Callable that evaluates history signal bodies at (t, y, **params).
Returns a mapping from signal_id to the evaluated body array/value.
CompiledReactant(state_base, state_axes, full_axes, pinned, order)
dataclass
¶
Molecular reactant metadata aligned to an expanded reaction channel.
The record is numerical-array neutral. Providers combine state_axes
with the enclosing reaction's channel coordinates and pinned indices
to locate a state cell, then place order in their reactant-order
matrix. Catalysts appear here even when their net stoichiometric change is
zero.
CompiledReaction(name, from_base, from_axes, full_axes, to_base, to_axes, sum_axes, pinned, from_pinned, propensity_fn, reactants=(), reactants_complete=False)
dataclass
¶
Compiled propensity + axis bookkeeping for one named transition.
Produced from :class:op_system._reactions.ReactionArtifactIR at
compile time. A firing event at from-cell index i (in the natural
N-D shape given by from_axes) depletes 1 from from_base at that
cell and adds 1 to to_base at the cell obtained by: keeping every
axis in to_axes at i's value for that axis, and using the fixed
coordinate index from pinned for every axis in pinned (this
includes both axes that are wildcard on from_axes and pinned on
to -- a "collapse to a fixed target" transition, where multiple
source cells share one destination and the axis also appears in
sum_axes -- and axes pinned on BOTH from and to, a
"point-to-point" shift between two specific coordinates on the same
axis, e.g. a vaccination-dose-progression transition, which do NOT
appear in sum_axes since there's only ever one source value on
that axis). Consumers that need a single combined scatter/reduce
target (e.g. an engine applying many simultaneous firings) sum over
sum_axes when depositing into to_base -- op_system does not do
that summation itself, since whether/how to combine simultaneous
firings across a summed axis is an execution-semantics decision for
the consumer, not a compile-time one.
from_base is None for a SOURCE-ONLY (from: null) reaction
-- an exogenous hazard with no compartment to deplete (e.g.
cross-district case importation). A consumer must special-case this:
skip every from-side depletion/clamp step and apply only the
to_base scatter, using from_axes/full_axes (which are the
to-side template's own axes in this case, not a nonexistent
from-side one -- see ReactionArtifactIR).
CompiledRhs(state_names, param_names, eval_fn, meta=(lambda: MappingProxyType({}))(), operators=tuple(), factorize_axes=tuple(), block_axes=tuple(), pytree_eval_fn=None, template_shapes=None, block_pytree_eval_fn=None, block_template_shapes=None, history_requirements=tuple(), history_eval_fn=None, body_eval_fn=None, block_history_eval_fn=None, block_body_eval_fn=None, reactions=tuple(), _rhs=None)
dataclass
¶
Container for a compiled RHS evaluation function.
Instances produced by :func:compile_rhs retain a private reference to
their source :class:NormalizedRhs so the container can be pickled and
re-hydrated by re-running the compile pipeline on load. eval_fn
itself is a closure (and on the vectorized path captures compiled code
objects), so it is dropped from the pickle and rebuilt by
:func:compile_rhs in :meth:__setstate__. Round-tripping a
CompiledRhs therefore costs one compile on load and yields a
functionally equivalent instance whose eval_fn produces identical
outputs for identical inputs.
__getstate__()
¶
Return picklable state.
The compiled eval_fn is a closure (and on the vectorized path
captures compiled :class:types.CodeType objects), which is not
portably picklable. Instead we serialize just the source
:class:NormalizedRhs and let :meth:__setstate__ recompile.
Raises:
| Type | Description |
|---|---|
TypeError
|
If the source |
Source code in src/op_system/compile.py
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 | |
__setstate__(state)
¶
Restore by recompiling from the pickled :class:NormalizedRhs.
Source code in src/op_system/compile.py
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 | |
bind(params)
¶
Bind parameter values and return a 2-arg RHS: rhs(t, y) -> dydt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
Mapping[str, object]
|
Mapping of parameter names to values. |
required |
Returns:
| Type | Description |
|---|---|
Callable[[object, object], Float64Array]
|
A callable |
Source code in src/op_system/compile.py
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 | |
EvalFn
¶
Bases: Protocol
Callable RHS evaluator supporting runtime parameter kwargs.
Accepts a flat (n_state,) state array and returns a flat
(n_state,) derivative array in the same array namespace.
ExprRhs(state_names, equations, aliases, param_names, all_symbols, meta, state_templates=(), shaped_params=(), time_varying_params=(), aliases_ir=dict(), equations_ir=(), aliases_ir_reduce=dict(), equations_ir_reduce=(), alias_templates=())
dataclass
¶
Bases: _RhsBase
Normalized RHS for kind="expr" specs (explicit d(state)/dt equations).
Produced by :func:normalize_expr_rhs. Use :data:NormalizedRhs as the
union type when you need to accept both kinds.
ExpressionString(source)
dataclass
¶
Validated expression wrapper with cached AST and symbol names.
as_ir()
¶
Return the typed IR representation for this expression.
Returns:
| Type | Description |
|---|---|
Expr
|
Parsed typed IR tree. |
Source code in src/op_system/_symbols.py
43 44 45 46 47 48 49 | |
as_lowered_ir()
¶
Return helper-lowered typed IR for this expression.
Returns:
| Type | Description |
|---|---|
Expr
|
Typed IR tree with helper calls lowered to |
Source code in src/op_system/_symbols.py
51 52 53 54 55 56 57 | |
OperatorDescriptor(axis, kind=None, bc=None, velocity=None, rate=None, kernel=None, name=None, apply_to=None, direction=None)
dataclass
¶
Typed description of a spatial operator declared in an op_system RHS spec.
Captures the model-level description of an operator that is known at compile time: which axis it acts on, its kind (advection, diffusion, etc.), optional boundary condition, and the names of any runtime parameters (velocity, rate) it consumes. Grid geometry, CN matrix construction, and solver staging remain downstream concerns handled by the engine.
Attributes:
| Name | Type | Description |
|---|---|---|
axis |
str
|
Name of the axis the operator acts on (e.g. |
kind |
str | None
|
Operator type string, e.g. |
bc |
str | None
|
Boundary condition, e.g. |
velocity |
str | float | None
|
Parameter name or numeric constant for an advection velocity,
or |
rate |
str | float | None
|
Parameter name or numeric constant for a rate/coefficient, or
|
kernel |
Mapping[str, Any] | None
|
Mixing-kernel sub-specification, or |
name |
str | None
|
Optional operator name from the specification. |
apply_to |
tuple[str, ...] | None
|
Concrete state names selected by the operator, or |
direction |
str | None
|
Optional normalized direction. For advection and transport,
|
Examples:
>>> od = OperatorDescriptor(axis="loc")
>>> od.axis
'loc'
>>> od.kind is None
True
>>> od.bc is None
True
>>> od.velocity is None
True
>>> od2 = OperatorDescriptor(
... axis="loc",
... kind="advection",
... bc="absorbing",
... velocity=0.25,
... name="drift",
... apply_to=("S",),
... )
>>> od2.kind
'advection'
>>> od2.bc
'absorbing'
>>> od2.velocity
0.25
>>> od2.name
'drift'
>>> od2.apply_to
('S',)
PytreeEvalFn
¶
Bases: Protocol
Callable RHS evaluator operating on shaped PyTree state dicts.
Accepts y as a StateDict (mapping from state-template base name
to a shaped array with the template's natural N-D shape) and returns a
StateDict of the same structure containing the derivative.
Enables the engine to skip the flatten/unflatten step entirely and
expose the full tensor structure to JAX/XLA.
ReactionPropensityFn
¶
Bases: Protocol
Callable propensity evaluator for one named reaction/transition.
Accepts y as a StateDict and returns an array shaped like the
reaction's from_axes (one independent rate per source cell) --
see :class:CompiledReaction.
ShapeGroup(cells, example_cell, example_expression)
dataclass
¶
Cells of one state template that share an expression shape.
StateString
¶
Bases: BaseModel
Structured representation of a state string.
A state string is either a bare state name like "S" or a state name
followed immediately by bracketed dimensions like "R[age,vax]".
Examples:
>>> StateString.model_validate("S")
StateString(name='S', dims=())
>>> recovery = StateString.model_validate("R[age,vax]")
>>> recovery
StateString(name='R', dims=('age', 'vax'))
>>> print(recovery)
R[age,vax]
>>> recovery.model_dump()
'R[age,vax]'
>>> StateString.model_validate("Foobar[ age , vax ]")
StateString(name='Foobar', dims=('age', 'vax'))
__str__()
¶
Return the compact string form.
Returns:
| Type | Description |
|---|---|
str
|
Compact state string. |
Examples:
>>> str(StateString(name="S", dims=()))
'S'
>>> str(StateString(name="R", dims=("age",)))
'R[age]'
>>> str(StateString(name="R", dims=("age", "vax")))
'R[age,vax]'
>>> str(StateString(name="lambda", dims=("age", "vax", "state")))
'lambda[age,vax,state]'
Source code in src/op_system/_state_string.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
TransitionsRhs(state_names, equations, aliases, param_names, all_symbols, meta, state_templates=(), shaped_params=(), time_varying_params=(), aliases_ir=dict(), equations_ir=(), aliases_ir_reduce=dict(), equations_ir_reduce=(), alias_templates=(), reactions_ir=())
dataclass
¶
Bases: _RhsBase
Normalized RHS for kind="transitions" specs (per-capita hazard diagram).
Produced by :func:normalize_transitions_rhs. Use :data:NormalizedRhs
as the union type when you need to accept both kinds.
ValidationReport(stages, errors=list(), cost=dict(), parameters=dict(), shape_groups=dict())
dataclass
¶
Result of validating one op_system specification.
Attributes:
| Name | Type | Description |
|---|---|---|
stages |
dict[str, str]
|
|
errors |
list[str]
|
Error messages from the failed stage. |
cost |
dict[str, int]
|
Compile-cost drivers (expanded states, templates, transitions, coordinate-pinned transitions, operators). |
parameters |
dict[str, tuple[str, ...]]
|
Parameters the spec consumes, mapped to their declared
axes (empty tuple for scalars); operator parameters use
|
shape_groups |
dict[str, list[ShapeGroup]]
|
When vectorization fails, the templates whose cells have more than one expression shape, with each distinct shape's count and an example cell. Empty otherwise, because comparing every cell's expanded equation is slow on large specs. |
ok
property
¶
Whether every stage passed.
array_namespace(value)
¶
Return an Array-API-compatible namespace for value.
array-api-compat recognizes both arrays that implement
__array_namespace__ and native arrays such as torch.Tensor that
need a compatibility namespace. Optional backends are imported only when
one of their arrays is supplied.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
object
|
Numerical array whose namespace should be selected. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The Array-API-compatible namespace for |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Source code in src/op_system/_array.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | |
axis_kernel_generator_rhs(state, generator, *, axis, velocity=1.0)
¶
Return velocity * state @ generator applied along axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
Any
|
Array with the kernel axis at position |
required |
generator
|
Any
|
Square matrix over the kernel axis; rows are sources. |
required |
axis
|
int
|
Position of the kernel axis in |
required |
velocity
|
Any
|
Scalar multiplier (for example a waning rate). |
1.0
|
Returns:
| Type | Description |
|---|---|
Any
|
The derivative contribution, with the same shape as |
Source code in src/op_system/_axis_kernel.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
axis_kernel_redistribute(flux, kernel, *, axis=-1)
¶
Return flux @ kernel - flux along axis for a transferred flux.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flux
|
Any
|
Per-coordinate flux already moved by an ordinary transfer. |
required |
kernel
|
Any
|
Row-stochastic matrix over the kernel axis. |
required |
axis
|
int
|
Position of the kernel axis in |
-1
|
Returns:
| Type | Description |
|---|---|
Any
|
The redistribution to add to the target slice. |
Source code in src/op_system/_axis_kernel.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
compile_rhs(rhs, *, xp=None)
¶
Compile a normalized RHS into a runnable evaluation function.
Always uses the vectorized eval path that operates on shaped buffers
(one tensor expression per state template) for specs that declare axes.
Specs without axes (genuinely scalar models) fall back to the scalar path.
Raising :class:UnsupportedFeatureError if an axis-indexed spec cannot be
vectorized, rather than silently falling back to the catastrophically slow
scalar path.
The returned eval_fn is namespace-polymorphic: it infers its
array namespace from the input y at call time
(through array_api_compat.array_namespace), and returns arrays in that same
namespace. Calling it with JAX arrays (or tracers) yields a JAX-native
computation suitable for jax.jit / jax.vmap without any
correctness wrapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
NormalizedRhs
|
Normalized RHS produced by |
required |
xp
|
object | None
|
Deprecated. Formerly the compile-time array backend
namespace. Now ignored — the namespace is resolved per call
from the input |
None
|
Returns:
| Type | Description |
|---|---|
CompiledRhs
|
A |
CompiledRhs
|
For axis-indexed specs the returned object also carries |
CompiledRhs
|
|
CompiledRhs
|
axes but the vectorizer cannot build a plan an |
CompiledRhs
|
|
CompiledRhs
|
message) rather than silently degrading to the scalar path. |
Source code in src/op_system/compile.py
2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 | |
compile_spec(spec, *, xp=None, backend=DEFAULT_ARRAY_BACKEND)
¶
Validate, normalize, and compile a RHS specification in one call.
This is the recommended public entrypoint for most users and adapters.
The compiled eval_fn is namespace-polymorphic: it infers its
array namespace from the input y at call time
(through array_api_compat.array_namespace), so one callable handles
NumPy, JAX (concrete and traced), and any other Array-API backend
natively. No compile-time backend selection is required.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
dict[str, object]
|
Raw RHS specification mapping (YAML/JSON friendly). |
required |
xp
|
object | None
|
Deprecated. Formerly the compile-time array backend
namespace. Now ignored — see |
None
|
backend
|
Literal['numpy', 'jax']
|
Deprecated. Formerly selected the compile-time
backend ( |
DEFAULT_ARRAY_BACKEND
|
Returns:
| Name | Type | Description |
|---|---|---|
CompiledRhs |
CompiledRhs
|
Runnable RHS callable container. |
Source code in src/op_system/__init__.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |
jump_integral_generator(kernel, *, axis_type, direction='both', boundary='reflecting', quadrature_weights=None)
¶
Build the conservative row-source generator for a jump kernel.
kernel[i, j] is the non-negative rate density from source coordinate
i to target coordinate j. Its diagonal is ignored. up keeps
only j > i; down keeps only j < i; both keeps every
off-diagonal entry. For a continuous axis each target column j is
multiplied by quadrature_weights[j] before the diagonal loss is set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kernel
|
Any
|
Square source-by-target rate-density matrix. |
required |
axis_type
|
str
|
|
required |
direction
|
str
|
Permitted movement in declared coordinate order. |
'both'
|
boundary
|
str
|
Boundary contract. Only |
'reflecting'
|
quadrature_weights
|
Any | None
|
Positive target weights required for continuous axes and forbidden for categorical or ordinal axes. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
A generator in the kernel's Array-API namespace. Rows sum to zero. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If static choices, shapes, or quadrature usage are invalid. |
Notes
Call :func:validate_jump_integral_kernel with concrete parameter
values at an orchestration boundary to check finiteness and signs.
This builder deliberately keeps array values dynamic under transforms.
Source code in src/op_system/_jump_integral.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
jump_integral_rhs(state, kernel, *, axis, axis_type, rate=1.0, direction='both', boundary='reflecting', quadrature_weights=None)
¶
Return a conservative jump-integral derivative contribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
Any
|
State array containing the jump axis. |
required |
kernel
|
Any
|
Source-by-target rate-density matrix. |
required |
axis
|
int
|
Position of the jump axis in |
required |
axis_type
|
str
|
|
required |
rate
|
Any
|
Scalar multiplier with inverse-time units after any continuous target quadrature has been applied. |
1.0
|
direction
|
str
|
|
'both'
|
boundary
|
str
|
Boundary contract; currently only |
'reflecting'
|
quadrature_weights
|
Any | None
|
Target quadrature weights for continuous axes. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
Derivative contribution with the same shape as |
Source code in src/op_system/_jump_integral.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |
normalize_expr_rhs(spec)
¶
Normalize an expression-based RHS specification.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
Mapping[str, Any]
|
Raw RHS specification mapping. |
required |
Returns:
| Type | Description |
|---|---|
ExprRhs
|
Backend-facing normalized RHS representation. |
Raises:
| Type | Description |
|---|---|
InvalidRhsSpecError
|
If validation fails. |
Source code in src/op_system/_normalize.py
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 | |
normalize_rhs(spec)
¶
Normalize a RHS specification dict into a backend-facing representation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
Mapping[str, Any] | None
|
Raw RHS specification mapping. |
required |
Returns:
| Type | Description |
|---|---|
NormalizedRhs
|
Backend-facing normalized RHS representation. |
Raises:
| Type | Description |
|---|---|
InvalidRhsSpecError
|
If validation fails. |
UnsupportedFeatureError
|
If validation fails. |
Source code in src/op_system/_normalize.py
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 | |
normalize_transitions_rhs(spec)
¶
Normalize a transition-based RHS specification (diagram/hazard semantics).
Returns:
| Type | Description |
|---|---|
TransitionsRhs
|
Backend-facing normalized RHS representation for the transitions kind. |
Raises:
| Type | Description |
|---|---|
InvalidRhsSpecError
|
If validation fails. |
Source code in src/op_system/_normalize.py
1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 | |
validate_axis_kernel_matrix(matrix, *, form, tolerance=1e-09)
¶
Return problems with a numeric kernel matrix for form (empty if valid).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matrix
|
Any
|
Candidate square matrix. |
required |
form
|
str
|
|
required |
tolerance
|
float
|
Absolute tolerance for sign and row-sum checks. |
1e-09
|
Returns:
| Type | Description |
|---|---|
list[str]
|
Human-readable problems; an empty list means the matrix is valid. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/op_system/_axis_kernel.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | |
validate_jump_integral_kernel(kernel, *, axis_type, direction='both', boundary='reflecting', quadrature_weights=None, tolerance=1e-09)
¶
Return problems with concrete jump-kernel values (empty if valid).
This eager validation belongs at parameter resolution or another host orchestration boundary, not inside a traced numerical solve.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kernel
|
Any
|
Candidate source-by-target rate-density matrix. |
required |
axis_type
|
str
|
|
required |
direction
|
str
|
|
'both'
|
boundary
|
str
|
Boundary contract; currently only |
'reflecting'
|
quadrature_weights
|
Any | None
|
Target quadrature weights for continuous axes. |
None
|
tolerance
|
float
|
Absolute tolerance for sign and diagonal checks. |
1e-09
|
Returns:
| Type | Description |
|---|---|
list[str]
|
Human-readable problems; an empty list means the values conform. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a static contract choice is unsupported. |
Source code in src/op_system/_jump_integral.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |
validate_spec(spec)
¶
Validate an op_system specification without raising.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
Mapping[str, Any]
|
A raw RHS specification mapping. |
required |
Returns:
| Type | Description |
|---|---|
ValidationReport
|
A report with per-stage status, error messages, compile-cost drivers, |
ValidationReport
|
consumed parameters, and expression-shape groups for templates whose |
ValidationReport
|
cells differ. |
Source code in src/op_system/_validate.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | |