cadrumo.domain.calculations.registry.formula_runtime_ops module¶
Formula-runtime operation helpers for registry calculations.
The formula evaluator delegates arithmetic dispatch, dated parameter lookup,
rounding, and input validation here while executing
ModeloRevision formula graphs.
Helpers raise RegistryValidationError
so domain.calculations.registry.formula_runtime.calculate_registry_snapshot()
reports contract failures through the registry error channel.
See also
domain.calculations.registry.formula_runtimeSnapshot evaluator that calls these helpers while materialising
RegistrySnapshotoutputs.domain.calculations.registry.runtime_graphFormula graph walkers that discover the casilla, binding, relation, and parameter refs consumed before operation dispatch starts.
domain.calculations.registry.authority.ValidatedRegistryAuthorityRegistry authority loaded by
read_parameter()for ad hoc parameter reads outside snapshot execution.
- exception UnresolvedFormulaDependencyError(dependency_ids)[source]¶
Bases:
RegistrySnapshotErrorRaised internally when a non-blocking source gap makes a formula unresolved.
Shared between
formula_runtimeand its per-family op-evaluator siblings (e.g._formula_runtime_irnr) so a family module can signal a deferred dependency without importing back into the dispatcher module.- code¶
- class RegistryUnresolvedOutcomeReason(*values)[source]¶
Bases:
StrEnumClosed reason catalogue for typed formula outcomes with no Decimal value.
- M210_BASELINE_TIPO_DEFERRED¶
- M210_CONVENIO_RATE_MISSING¶
- exception UnresolvedFormulaOutcomeError(reason, *, context)[source]¶
Bases:
RegistrySnapshotErrorRaised internally when a formula emits a typed unresolved outcome.
- Parameters:
reason (RegistryUnresolvedOutcomeReason)
- Return type:
None
- code¶
- numeric_casilla_value(casilla_id, ctx)[source]¶
Read a resolved numeric casilla value from the evaluation context.
Generic accessor shared by the M210/IRNR, M131 módulos, and M303 módulos IVA formula-op families; each raises
UnresolvedFormulaDependencyErrorthe same way for a casilla deferred by a non-blocking source gap.- Return type:
Decimal
- Parameters:
casilla_id (CasillaId)
ctx (_EvalContext)
- evaluate_args_op(op, args)[source]¶
Evaluate a resolved formula operation over decimal operands.
Operation names mirror
FormulaExpressionopvalues consumed bydomain.calculations.registry.formula_runtime.calculate_registry_snapshot().
- resolve_bracket(parameter, base, date_context)[source]¶
Resolve a bracket-table
ParameterDefinitionfor a base amount.The parameter’s bracket date axis must be present in
date_contextso registry-authored validity windows select exactly one bracket row.
- resolve_dated_value(parameter, date_context)[source]¶
Resolve the one dated value a
ParameterDefinitionselects.Exactly one
DatedValuemust match the selected date axes for the parameter lookup to be deterministic.Returns the RECORD rather than its scalar, because a value can carry more than the number: a threshold’s comparison operator moves independently of its amount, so a caller applying a threshold needs the value and the operator that the same redaction fixed.
resolve_parameter()delegates here so the selection lives in one place and the two cannot drift.- Return type:
- Returns:
The single matching
DatedValue.- Raises:
RegistryValidationError – If the parameter declares no values, a required date axis is absent from
date_context, or the match is not exactly one.- Parameters:
parameter (ParameterDefinition)
- resolve_parameter(parameter, date_context)[source]¶
Resolve one dated scalar from a
ParameterDefinition.- Return type:
- Returns:
The selected value’s scalar.
- Parameters:
parameter (ParameterDefinition)
- resolve_scalar_parameter(parameter_id, ctx, *, op)[source]¶
Resolve a scalar parameter and record its runtime provenance.
Formula-operation families share the same scalar type contract and must record the parameter id alongside the resolved Decimal in their common evaluation context. Keeping both actions together prevents a successful lookup from escaping the explainability surface.
- resolve_keyed_bracket(parameter, *, key, filing_year)[source]¶
Resolve one keyed-bracket row for a filing year.
A missing parameter or key is the caller’s explicit “not tabled” signal; overlapping matching windows are a contradictory registry definition and therefore fail closed instead of selecting an arbitrary first row.
- Return type:
- Parameters:
parameter (ParameterDefinition | None)
key (str)
filing_year (int)
- apply_rounding(value, rounding)[source]¶
Apply a registry rounding rule to a decimal formula result.
money-2usescore.money.rounding.round_to_cents();integeruses half-up quantization for registry-authored integer targets;integer-ceilingquantizes withdecimal.ROUND_CEILINGfor the targets whose governing provision takes the result to the next unit up rather than to the nearest one (LIVA art. 104.Dos, “se redondeará en la unidad superior”).ROUND_CEILINGleaves an already-integral value untouched, so a 50 % ratio stays 50.ROUND_CEILINGmoves toward positive infinity, which differs from away-from-zero for a negative operand. Everyinteger-ceilingtarget today is a registry-constrained non-negative percentage (sign = "non_negative",min_value = "0"), so the two readings coincide; a future negative-capable target must state which reading its provision means before enrolling here.- Return type:
- Parameters:
value (Decimal)
rounding (RegistryRoundingCode | None)
- reject_non_decimal(items, label)[source]¶
Reject non-decimal values before formula runtime consumption.
- validated_decimal_input_casilla_ids(inputs, *, revision)[source]¶
Canonicalise decimal input keys against a
ModeloRevision.Raw string keys become validated
CasillaIdvalues, thendomain.calculations.registry.casilla_membership.undeclared_casilla_ids()rejects inputs outside the revision’s declared casilla set.- Return type:
dict[CasillaId, Decimal]
- Parameters:
inputs (Mapping[InputKey, InputValue])
revision (ModeloRevision)
- reject_non_string(values, label)[source]¶
Reject empty or non-string external values before registry validation.
- reject_unknown_external_values(items, known_ids, label)[source]¶
Reject external ids not declared by the current registry snapshot.
Keyed on ids alone: the gate screens WHICH ids arrived, never what they carry, so every external channel – Decimal, truth value, date or enum – is screened by this one function rather than by a per-channel copy.
- read_parameter(modelo_id, revision_id, parameter_id, *, date_context, operation=None)[source]¶
Read a registry parameter through
ValidatedRegistryAuthority.The ad hoc public helper loads the same validated registry authority used by snapshot callers, narrows to the selected
ModeloRevision, and delegates the dated value lookup toresolve_parameter().When no operation is supplied, the helper leases one indexed authority generation for the point lookup; it never traverses a whole authority graph.
- Return type:
Decimal
- Parameters:
modelo_id (str)
revision_id (RevisionId)
parameter_id (str)
date_context (Mapping[str, date])
operation (PinnedAuthorityOperation | None)