STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
engine.pipeline.assumptions Namespace Reference

Functions

List[Dict[str, Dict[str, Any]]] _active_scopes ()
Any assume (str name, Any value, *, str unit="", str reason="")
Iterator[Dict[str, Dict[str, Any]]] scope ()
List[Dict[str, Any]] as_list (Dict[str, Dict[str, Any]] registry)
Dict[str, Dict[str, Any]] get_assumptions ()
List[Dict[str, Any]] fallbacks_used ()
None clear ()

Variables

 _log = logging.getLogger(__name__)
 _lock = threading.Lock()
dict _registry = {}
 _local = threading.local()

Detailed Description

Runtime assumptions registry — make every silent fallback VISIBLE (UNIFICATION_PLAN Phase 2c).

Motivation: the hardcoded-Cd incident. A value nobody remembers choosing (injector Cd_inf=0.4) sat in
a config default and silently wrecked optimizer runs. The fix pattern is not "no defaults" — solvers
need to keep running when a property is missing — it is **no INVISIBLE defaults**: every time the code
substitutes an assumed value for missing config data, that substitution is recorded here and surfaced
(rich stability report `assumptions.fallbacks_used`, logs, future /api/assumptions endpoint).

Usage (call-site pattern)::

    from engine.pipeline.assumptions import assume
    rho = cfg_rho if cfg_rho is not None else assume(
        "stability.rho_oxidizer", 1140.0, unit="kg/m^3",
        reason="fluids.oxidizer.density missing from config")

Registry is per-process (optimizer workers each carry their own — diagnostic, not authoritative).
``clear()`` at the start of an evaluation scope if per-run isolation matters.

Function Documentation

◆ _active_scopes()

List[Dict[str, Dict[str, Any]]] engine.pipeline.assumptions._active_scopes ( )
protected

Definition at line 40 of file assumptions.py.

Referenced by assume(), and scope().

◆ as_list()

List[Dict[str, Any]] engine.pipeline.assumptions.as_list ( Dict[str, Dict[str, Any]] registry)
Compact list form of a scope's collection, matching ``fallbacks_used()``.

Definition at line 97 of file assumptions.py.

◆ assume()

Any engine.pipeline.assumptions.assume ( str name,
Any value,
* ,
str unit = "",
str reason = "" )
Record that ``value`` is being ASSUMED (config did not provide it) and return it.

Re-recording the same name updates the count rather than spamming the log — fallbacks inside
optimizer loops fire thousands of times.

Definition at line 48 of file assumptions.py.

References _active_scopes().

◆ clear()

None engine.pipeline.assumptions.clear ( )

Definition at line 114 of file assumptions.py.

◆ fallbacks_used()

List[Dict[str, Any]] engine.pipeline.assumptions.fallbacks_used ( )
Compact list form for report payloads: [{name, value, unit, reason, count}, ...].

Definition at line 108 of file assumptions.py.

◆ get_assumptions()

Dict[str, Dict[str, Any]] engine.pipeline.assumptions.get_assumptions ( )
Snapshot of all assumptions used so far in this process.

Definition at line 102 of file assumptions.py.

◆ scope()

Iterator[Dict[str, Dict[str, Any]]] engine.pipeline.assumptions.scope ( )
Collect the assumptions recorded inside this block, leaving the global registry alone.

Use it around one evaluation whose report must say what *that* evaluation assumed::

    with assumptions.scope() as used:
        ...
    payload["fallbacks_used"] = assumptions.as_list(used)

Thread-local and re-entrant. It does NOT suppress the global record -- `get_assumptions()` still
returns everything the process has assumed, which is what the logs and the future
/api/assumptions endpoint want.

Definition at line 75 of file assumptions.py.

References _active_scopes().

Variable Documentation

◆ _local

engine.pipeline.assumptions._local = threading.local()
protected

Definition at line 37 of file assumptions.py.

◆ _lock

engine.pipeline.assumptions._lock = threading.Lock()
protected

Definition at line 28 of file assumptions.py.

◆ _log

engine.pipeline.assumptions._log = logging.getLogger(__name__)
protected

Definition at line 27 of file assumptions.py.

◆ _registry

dict engine.pipeline.assumptions._registry = {}
protected

Definition at line 29 of file assumptions.py.