Coordinates¶
coordinates
¶
Explicit mixed identity/log solver coordinates with natural-state outputs.
The original CompiledRhs remains in physical coordinates. Construct a view once, encode initial states, and use its evaluator for deterministic integration.
CoordinateResult
¶
Bases: NamedTuple, Generic[_StateT]
Transformed state and a namespace-native scalar domain flag.
Attributes:
| Name | Type | Description |
|---|---|---|
state |
_StateT
|
Array or PyTree after transformation; no floor or clamp is applied. |
valid |
Array
|
Finite state with strictly positive selected physical components. For decoding this also flags exp underflow to zero and overflow. |
StateCoordinateView(natural, log_indices, log_bases, eval_fn, pytree_eval_fn, block_pytree_eval_fn, observables)
dataclass
¶
Deterministic evaluators in explicitly selected solver coordinates.
Natural model state, reactions, scientific declarations and observations
remain available on natural. This view does not export jump artifacts,
balance laws or original derivative-affinity claims in solver coordinates.
Attributes:
| Name | Type | Description |
|---|---|---|
natural |
CompiledRhs
|
Source model, in natural coordinates (possibly gauge-fixed). |
log_indices |
tuple[int, ...]
|
Selected expanded flat state components. |
log_bases |
tuple[str, ...]
|
State bases using log coordinates, shared over their templates. |
eval_fn |
EvalFn
|
Coordinate derivative, with the source flat evaluator contract. |
pytree_eval_fn |
PytreeEvalFn | None
|
Optional coordinate derivative for shaped state buffers. |
block_pytree_eval_fn |
PytreeEvalFn | None
|
Optional coordinate derivative for stripped blocks. |
observables |
Mapping[str, CompiledObservable]
|
Natural-scale observables evaluated from encoded states. |
Examples:
>>> import numpy as np
>>> from op_system import compile_spec
>>> model = compile_spec({
... "kind": "expr",
... "state": ["x"],
... "state_metadata": {"x": {"scale": "log"}},
... "equations": {"x": "-rate*x"},
... })
>>> view = model.coordinate_view()
>>> z0 = view.encode(np.array([2.0]))
>>> np.allclose(view.eval_fn(0, z0, rate=0.5), [-0.5])
True
>>> np.allclose(view.decode(z0), [2.0])
True
param_names
property
¶
Source equation parameter requirements, omitting gauge anchors.
state_names
property
¶
Source component order; selected values now store log states.
__post_init__()
¶
Cache component selection once, independently of execution namespace.
Source code in src/op_system/coordinates.py
168 169 170 171 172 173 174 175 | |
__reduce__()
¶
Rebuild evaluators from the retained natural source when unpickling.
Returns:
| Type | Description |
|---|---|
tuple[object, tuple[CompiledRhs]]
|
Module factory and source model, without serialized closures. |
Source code in src/op_system/coordinates.py
332 333 334 335 336 337 338 | |
bind(params)
¶
Bind source parameters to the coordinate derivative.
Returns:
| Type | Description |
|---|---|
Callable[[object, object], Float64Array]
|
A two-argument deterministic RHS, with solver-coordinate state. |
Source code in src/op_system/coordinates.py
317 318 319 320 321 322 323 324 325 326 327 328 329 330 | |
decode(state, *, state_axis=0)
¶
Return native decoded values without an eager domain check.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
Array
|
Floating solver coordinates. |
required |
state_axis
|
int
|
Component axis; use 1 for output trajectories. |
0
|
Returns:
| Type | Description |
|---|---|
Array
|
Natural-scale array, for transformed computations and observations. |
Array
|
Use decode_native or decode_checked when checking representation. |
Source code in src/op_system/coordinates.py
236 237 238 239 240 241 242 243 244 245 246 247 | |
decode_checked(state, *, state_axis=0)
¶
Decode and eagerly reject underflow/overflow or invalid values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
Array
|
Floating solver coordinates. |
required |
state_axis
|
int
|
Component axis in source order. |
0
|
Returns:
| Type | Description |
|---|---|
Array
|
A finite natural state, positive in selected components. |
Source code in src/op_system/coordinates.py
249 250 251 252 253 254 255 256 257 258 259 260 261 | |
decode_native(state, *, state_axis=0)
¶
Decode natural values and flag finite-precision representation failures.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
Array
|
Floating solver coordinates. |
required |
state_axis
|
int
|
Component axis; use 1 for output trajectories. |
0
|
Returns:
| Type | Description |
|---|---|
CoordinateResult[Array]
|
Natural values and finite/positive-domain flag. exp can underflow or |
CoordinateResult[Array]
|
overflow; the flag is not an integration-accuracy assessment. |
Source code in src/op_system/coordinates.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 | |
decode_pytree_native(state)
¶
Decode complete buffers and return native representation flags.
Returns:
| Type | Description |
|---|---|
CoordinateResult[dict[str, Array]]
|
Natural buffers with a native finite/positive flag. |
Source code in src/op_system/coordinates.py
307 308 309 310 311 312 313 314 315 | |
encode(state, *, state_axis=0)
¶
Check a physical initial state eagerly before taking logarithms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
Array
|
Finite floating natural state, positive in selected components. |
required |
state_axis
|
int
|
Component axis, in source order. |
0
|
Returns:
| Type | Description |
|---|---|
Array
|
Initial state in solver coordinates. Use encode_native under JIT/AD. |
Source code in src/op_system/coordinates.py
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | |
encode_native(state, *, state_axis=0)
¶
Map physical arrays to selected log coordinates, with native flags.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
Array
|
Real floating natural state, with component axis in source order. |
required |
state_axis
|
int
|
Component axis; use 1 for output trajectories. |
0
|
Returns:
| Type | Description |
|---|---|
CoordinateResult[Array]
|
Encoded state and scalar flag without host extraction. Invalid |
CoordinateResult[Array]
|
selected inputs produce nonfinite logarithms; no floor is applied. |
Source code in src/op_system/coordinates.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
encode_pytree_native(state)
¶
Encode complete buffers and return native finite/positive flags.
Returns:
| Type | Description |
|---|---|
CoordinateResult[dict[str, Array]]
|
Solver-coordinate buffers with a native domain flag. |
Source code in src/op_system/coordinates.py
297 298 299 300 301 302 303 304 305 | |