unitflow.expr¶
Symbolic expressions, equations, inequalities, and constraints.
Symbolic expression and constraint layer.
- exception unitflow.expr.BooleanCoercionError[source]¶
Bases:
ExprErrorRaised when a constraint is coerced to boolean.
- exception unitflow.expr.CompilationError[source]¶
Bases:
ExprErrorRaised when numeric compilation of an expression fails.
- class unitflow.expr.Conjunction(left: 'Constraint', right: 'Constraint')[source]¶
Bases:
Constraint- Parameters:
left (Constraint)
right (Constraint)
- left: Constraint¶
- right: Constraint¶
- evaluate(context, *, rel_tol=1e-09, abs_tol=0.0)[source]¶
Evaluate this constraint against a context of realized scalar values.
Context keys must be the same Symbol instances used to build the constraint. Array-backed quantities are not supported in v0. Tolerance parameters are explicit per call, never global state.
- class unitflow.expr.Constraint[source]¶
Bases:
objectBase class for all symbolic constraints.
- evaluate(context, *, rel_tol=1e-09, abs_tol=0.0)[source]¶
Evaluate this constraint against a context of realized scalar values.
Context keys must be the same Symbol instances used to build the constraint. Array-backed quantities are not supported in v0. Tolerance parameters are explicit per call, never global state.
- exception unitflow.expr.DimensionMismatchExprError[source]¶
Bases:
ExprErrorRaised when expressions have mismatched dimensions in operations.
- class unitflow.expr.Disjunction(left: 'Constraint', right: 'Constraint')[source]¶
Bases:
Constraint- Parameters:
left (Constraint)
right (Constraint)
- left: Constraint¶
- right: Constraint¶
- evaluate(context, *, rel_tol=1e-09, abs_tol=0.0)[source]¶
Evaluate this constraint against a context of realized scalar values.
Context keys must be the same Symbol instances used to build the constraint. Array-backed quantities are not supported in v0. Tolerance parameters are explicit per call, never global state.
- class unitflow.expr.Equation(left: 'Expr', right: 'Expr')[source]¶
Bases:
Constraint- evaluate(context, *, rel_tol=1e-09, abs_tol=0.0)[source]¶
Evaluate this constraint against a context of realized scalar values.
Context keys must be the same Symbol instances used to build the constraint. Array-backed quantities are not supported in v0. Tolerance parameters are explicit per call, never global state.
- exception unitflow.expr.EvaluationError[source]¶
Bases:
ExprErrorRaised when expression evaluation fails (e.g. unbound symbol).
- class unitflow.expr.Expr[source]¶
Bases:
objectBase class for all symbolic expressions.
- exception unitflow.expr.ExprError[source]¶
Bases:
UnitflowErrorRaised for general expression and symbolic errors.
- class unitflow.expr.Negation(constraint: 'Constraint')[source]¶
Bases:
Constraint- Parameters:
constraint (Constraint)
- constraint: Constraint¶
- evaluate(context, *, rel_tol=1e-09, abs_tol=0.0)[source]¶
Evaluate this constraint against a context of realized scalar values.
Context keys must be the same Symbol instances used to build the constraint. Array-backed quantities are not supported in v0. Tolerance parameters are explicit per call, never global state.
- class unitflow.expr.NonStrictInequality(left: 'Expr', right: 'Expr', operator: 'str')[source]¶
Bases:
Constraint- operator: str¶
- evaluate(context, *, rel_tol=1e-09, abs_tol=0.0)[source]¶
Evaluate this constraint against a context of realized scalar values.
Context keys must be the same Symbol instances used to build the constraint. Array-backed quantities are not supported in v0. Tolerance parameters are explicit per call, never global state.
- class unitflow.expr.PowExpr(base: 'Expr', power: 'int')[source]¶
Bases:
Expr- Parameters:
base (Expr)
power (int)
- power: int¶
- class unitflow.expr.QuantityExpr(value: 'Quantity')[source]¶
Bases:
Expr- Parameters:
value (Quantity)
- class unitflow.expr.StrictInequality(left: 'Expr', right: 'Expr', operator: 'str')[source]¶
Bases:
Constraint- operator: str¶
- evaluate(context, *, rel_tol=1e-09, abs_tol=0.0)[source]¶
Evaluate this constraint against a context of realized scalar values.
Context keys must be the same Symbol instances used to build the constraint. Array-backed quantities are not supported in v0. Tolerance parameters are explicit per call, never global state.
- class unitflow.expr.Symbol(name, _dimension, unit=None, quantity_kind=None)[source]¶
Bases:
ExprA symbolic variable with dimension and optional unit bindings.
- name: str¶
- quantity_kind: str | None¶
- evaluate(context)[source]¶
Look up this symbol’s value in the context.
Context keys must be the same Symbol instances used to build the expression (identity-based lookup). Constructing a new Symbol with the same name/unit and using it as a key will fail because Expr.__eq__ returns an Equation, not a bool.
- unitflow.expr.compile_numeric(expr, symbols, reference_units)[source]¶
Compile an expression into a fast float function.
The returned callable takes one positional float argument per symbol (in the order given by
symbols) and returns a float.All unit conversions and constant quantities are baked into the generated function at compile time so the inner loop is pure arithmetic.
- Args:
expr: The expression to compile. symbols: Ordered list of symbols that become positional arguments. reference_units: The unit each symbol’s float value is expressed in.
- Raises:
- CompilationError: If a symbol in the expression is not in
symbols, or if dimensional validation fails.
- CompilationError: If a symbol in the expression is not in
- unitflow.expr.compile_residual(equation, symbols, reference_units)[source]¶
Compile an Equation into a residual function (lhs - rhs).
The returned callable takes one positional float argument per symbol and returns
lhs - rhsas a float. This is the standard form for scipy.optimize.root and similar solvers.- Args:
equation: The equation to compile as a residual. symbols: Ordered list of symbols that become positional arguments. reference_units: The unit each symbol’s float value is expressed in.
- Raises:
- CompilationError: If a symbol in the equation is not in
symbols, or if dimensional validation fails.
- CompilationError: If a symbol in the equation is not in