aeat.domain.calculations.registry._formula_runtime module¶
Registry-backed formula runtime using typed operation graphs.
Evaluates
FormulaExpression trees declared on
a ModeloRevision against casilla
inputs and binding values drawn from a
RegistrySnapshot.
The calculation entry point calculate_registry_snapshot() is the
primary surface used by
ValidatedRegistryAuthority-backed
callers to produce
CasillaObservation rows with full
provenance.
See also
domain.calculations.registry._runtime_graphProduces formula evaluation order and dependency projections.
domain.calculations.registry._formula_runtime_opsArithmetic, rounding, and parameter lookup helpers called by this evaluator.
domain.calculations.registry._formula_initial_valuesBuilds the initial casilla value map and materialised observation envelope for this runtime.
- class RegistryCalculationEntry(**data)[source]¶
Bases:
BaseModelOne trace row emitted by the registry formula runtime.
Carries the per-formula provenance for a single formula-computed
CasillaId. Entries cover only casillas computed by a registry formula; input and bound casillas remain inCasillaObservationstorage and must be read throughRegistryCalculationResult.observations.- Parameters:
- formula_id: FormulaId¶
- target_casilla_id: CasillaId¶
- op: str¶
- operand_refs: tuple[str, ...]¶
- operand_casilla_refs: tuple[CasillaId, ...]¶
- operand_values: tuple[Decimal, ...]¶
- value: Decimal¶
- legal_refs: tuple[LegalRefId, ...]¶
- source_refs: tuple[SourceRefId, ...]¶
- class RegistryCalculationUnresolvedOutcome(**data)[source]¶
Bases:
BaseModelOne formula target that could not produce a Decimal value.
The outcome rides beside
RegistryCalculationResult.observationsso the engine’s value channels remain Decimal-only. Legal/source refs and formula lineage mirrorCasillaObservationfor the same target.- Parameters:
casilla_id (CasillaId)
reason (RegistryUnresolvedOutcomeReason)
formula_id (FormulaId)
op (str)
operand_casilla_refs (tuple[CasillaId, ...])
legal_refs (tuple[LegalRefId, ...])
source_refs (tuple[SourceRefId, ...])
- casilla_id: CasillaId¶
- reason: RegistryUnresolvedOutcomeReason¶
- formula_id: FormulaId¶
- op: str¶
- operand_refs: tuple[str, ...]¶
- operand_casilla_refs: tuple[CasillaId, ...]¶
- operand_values: tuple[Decimal, ...]¶
- legal_refs: tuple[LegalRefId, ...]¶
- source_refs: tuple[SourceRefId, ...]¶
- context: Mapping[str, str]¶
- class RegistryCalculationResult(**data)[source]¶
Bases:
BaseModelCalculated outputs for one registry snapshot.
Canonical storage is
observations: a typed tuple ofCasillaObservationcovering every casilla on theRegistrySnapshotrevision (inputs, bound, and formula-computed). Each observation carries its final Decimalvalueplus the legal / source provenance for that casilla pulled from the registry. Formula-computed observations additionally carryformula_id,op,operand_refs, andoperand_valuesso the full evaluation lineage survives the engine boundary.The
valuesandentriesviews are derived convenience properties for readers that need the flat{casilla_id: Decimal}map or the formula-onlyRegistryCalculationEntrytuple. The typed envelope is the contract; the flat views never grow new fields.Coverage asymmetry preserved by the derivation:
valuescovers every observation (inputs, bound, computed), keyed bycasilla_idtovalue.entriescovers ONLY observations whereformula_idis set.len(entries) <= len(observations)always; equality holds only when every casilla is formula-computed (rare in practice).
Consumers that need provenance for non-computed casillas must iterate
observationsdirectly; the entries view drops them by design.- Parameters:
modelo (str)
revision (str)
observations (tuple[CasillaObservation, ...])
unresolved_outcomes (tuple[RegistryCalculationUnresolvedOutcome, ...])
- modelo: str¶
- revision: str¶
- observations: tuple[CasillaObservation, ...]¶
- unresolved_outcomes: tuple[RegistryCalculationUnresolvedOutcome, ...]¶
- property values: Mapping[CasillaId, Decimal]¶
Read-only view from registry casilla id to final Decimal value.
Deliberately a plain
@property, not a pydanticcomputed_field: the typedobservationsenvelope is canonical storage; exposing this in JSON would round-trip self-incompatibly underextra='forbid'because the loader would refuse the duplicate field on the way back in.
- property entries: tuple[RegistryCalculationEntry, ...]¶
Read-only view of formula-computed
RegistryCalculationEntryrows.Preserves the formula-only entry view with
target_casilla_idandopfields for the application-layer indexers that build{target_casilla_id: entry}dictionaries. Insertion order fromobservationsis preserved; the engine emits in formula evaluation order, which matches the originalentriesshape.
- calculate_registry_snapshot(snapshot, *, inputs, date_context, binding_values=None, enum_binding_values=None, relation_values=None, unresolved_relation_ids=(), unresolved_binding_ids=(), date_binding_values=None, text_inputs=None)[source]¶
Evaluate all computed formulas for a registry snapshot.
enum_binding_valuescarries string-valued bindings (typically profile-sourced enums likeCCAA) that thelookup_bracket_by_ccaaop routes against. They are kept in a separate mapping frombinding_valuesso the Decimal-only contract on numeric bindings stays intact.date_binding_valuescarries date-valued profile facts (e.g. birth_date) consumed by theage_at_year_endop. Date facts cannot flow through the Decimalbinding_valueschannel; keeping them in a dedicated channel preserves the Decimal-only invariant.The returned
RegistryCalculationResultstoresCasillaObservationrows for all materialised casillas. Input validation is delegated todomain.calculations.registry._formula_runtime_opsanddomain.calculations.registry._formula_text_inputs; initial casilla values and absent-by-design markers are delegated todomain.calculations.registry._formula_initial_values.- Parameters:
snapshot (
RegistrySnapshot) – TheRegistrySnapshotthat supplies the revision, casilla definitions, and formula graph to evaluate.inputs (
Mapping[TypeVar(InputKey),TypeVar(InputValue)]) – Operator-supplied input casilla values; rejected if any value is not adecimal.Decimal.date_context (
Mapping[str,date]) – Date-axis context (e.g.filing_period) consumed by date-aware ops;filing_perioddefaults to the snapshot’s year-end when absent.binding_values (
Mapping[TypeAliasType,Decimal] |None) – Optional resolved numeric binding values keyed byDataBindingDefinitionid; Decimal-only.enum_binding_values (
Mapping[TypeAliasType,str] |None) – Optional string-valued bindings (e.g. profile CCAA) keyed by binding id; consumed by enum-routed ops.relation_values (
Mapping[TypeAliasType,Decimal] |None) – Optional resolved relation values keyed byrelation.id; Decimal-only.unresolved_relation_ids (
tuple[TypeAliasType,...]) – Relation ids that source resolution proved missing/incomplete but non-blocking. Formula targets depending on these ids are omitted instead of zero-contributed; relation ids not listed here remain hard validation errors when absent.unresolved_binding_ids (
tuple[TypeAliasType,...]) – Binding ids whose enrolled resolver ran for a present source but produced no value (expected-but-missing). Formula targets depending on these ids are omitted instead of raisingbinding_value_missing; binding ids not listed here remain hard validation errors when absent frombinding_values.date_binding_values (
Mapping[TypeAliasType,date] |None) – Optional date-valued profile bindings (e.g.birth_date) consumed by date-aware ops.text_inputs (
Mapping[TypeVar(TextInputKey),TypeVar(TextInputValue)] |None) – Optional string-valued operator inputs keyed by casilla id; consumed by text-routed ops.
- Return type: