unitflow¶
Top-level package: re-exports quantities, units, symbols, constraints, serialization helpers, and common catalog symbols.
Public package surface for the current semantic core.
- exception unitflow.BooleanCoercionError[source]¶
Bases:
ExprErrorRaised when a constraint is coerced to boolean.
- class unitflow.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.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.
- class unitflow.Dimension(exponents)[source]¶
Bases:
objectImmutable exponent vector over the fixed base-dimension basis.
- Parameters:
exponents (tuple[int, ...])
- exponents: tuple[int, ...]¶
- classmethod base(name)[source]¶
Return a single base dimension by its canonical name.
- Parameters:
name (str)
- Return type:
- classmethod from_mapping(exponents_by_name)[source]¶
Construct a dimension vector from a sparse base-dimension mapping.
- Parameters:
exponents_by_name (dict[str, int])
- Return type:
- property is_dimensionless: bool¶
Whether all exponents are zero.
- exception unitflow.DimensionError[source]¶
Bases:
SemanticCoreErrorRaised when dimension construction or algebra is invalid.
- exception unitflow.DimensionMismatchError[source]¶
Bases:
QuantityErrorRaised when quantity arithmetic requires compatible dimensions and they do not match.
- exception unitflow.DimensionMismatchExprError[source]¶
Bases:
ExprErrorRaised when expressions have mismatched dimensions in operations.
- class unitflow.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.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.
- class unitflow.Expr[source]¶
Bases:
objectBase class for all symbolic expressions.
- exception unitflow.ExprError[source]¶
Bases:
UnitflowErrorRaised for general expression and symbolic errors.
- exception unitflow.IncompatibleUnitError[source]¶
Bases:
UnitErrorRaised when unit compatibility is required but not satisfied.
- class unitflow.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.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.Quantity(magnitude, unit)[source]¶
Bases:
objectConcrete magnitude plus semantic unit.
- Parameters:
magnitude (Any)
unit (Unit)
- magnitude: Any¶
- exception unitflow.QuantityError[source]¶
Bases:
SemanticCoreErrorRaised when quantity construction or quantity arithmetic is invalid.
- class unitflow.Scale(coefficient, pi_power=0)[source]¶
Bases:
objectExact scale represented as a rational coefficient times an integer power of pi.
- Parameters:
coefficient (Fraction)
pi_power (int)
- coefficient: Fraction¶
- pi_power: int¶
- classmethod from_ratio(numerator, denominator=1, *, pi_power=0)[source]¶
- Parameters:
numerator (int)
denominator (int)
pi_power (int)
- Return type:
- property is_zero: bool¶
- exception unitflow.ScaleError[source]¶
Bases:
SemanticCoreErrorRaised when exact scale construction or algebra is invalid.
- exception unitflow.SemanticCoreError[source]¶
Bases:
UnitflowErrorRaised for invalid operations in the semantic core.
- exception unitflow.SerializationError[source]¶
Bases:
UnitflowErrorRaised when serialization or deserialization fails.
- class unitflow.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.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.
- class unitflow.Unit(dimension, scale, name=None, symbol=None, aliases=(), family=None, quantity_kind=None)[source]¶
Bases:
objectImmutable semantic unit definition.
- Parameters:
dimension (Dimension)
scale (Scale)
name (str | None)
symbol (str | None)
aliases (tuple[str, ...])
family (UnitFamily | None)
quantity_kind (str | None)
- name: str | None¶
- symbol: str | None¶
- aliases: tuple[str, ...]¶
- family: UnitFamily | None¶
- quantity_kind: str | None¶
- classmethod dimensionless(*, name=None, symbol=None, aliases=(), family=None, quantity_kind=None)[source]¶
- Parameters:
name (str | None)
symbol (str | None)
aliases (tuple[str, ...])
family (UnitFamily | None)
quantity_kind (str | None)
- Return type:
- with_metadata(*, name=<object object>, symbol=<object object>, aliases=<object object>, family=<object object>, quantity_kind=<object object>)[source]¶
- Parameters:
name (str | None | object)
symbol (str | None | object)
aliases (tuple[str, ...] | None | object)
family (UnitFamily | None | object)
quantity_kind (str | None | object)
- Return type:
- exception unitflow.UnitError[source]¶
Bases:
SemanticCoreErrorRaised when unit construction or unit algebra is invalid.
- class unitflow.UnitFamily(name, description)[source]¶
Bases:
objectSemantic metadata for units that share a meaningful family.
- Parameters:
name (str)
description (str)
- name: str¶
- description: str¶
- exception unitflow.UnitFamilyError[source]¶
Bases:
SemanticCoreErrorRaised when unit-family metadata is invalid.
- class unitflow.UnitNamespace(name)[source]¶
Bases:
objectA simple named namespace for unit lookup by symbol, name, or alias.
- Parameters:
name (str)
- define_unit(*, name, symbol, expr, aliases=(), family=None, quantity_kind=None)[source]¶
- Parameters:
name (str)
symbol (str)
aliases (tuple[str, ...])
family (UnitFamily | None)
quantity_kind (str | None)
- Return type:
- class unitflow.UnitRegistry(name='registry')[source]¶
Bases:
objectA lightweight registry that resolves identifiers across namespaces.
- Parameters:
name (str)
- add_namespace(namespace)[source]¶
- Parameters:
namespace (UnitNamespace)
- Return type:
- exception unitflow.UnitflowError[source]¶
Bases:
ExceptionBase exception for all unitflow-specific errors.
- unitflow.define_unit(*, name, symbol, expr, aliases=(), family=None, quantity_kind=None)[source]¶
Define a new semantic unit from an existing unit or exact quantity expression.
- Parameters:
name (str)
symbol (str)
aliases (tuple[str, ...])
family (UnitFamily | None)
quantity_kind (str | None)
- Return type:
- unitflow.generate_prefixes(namespace, base_unit, *, prefixes=None, include=None, exclude=None, resolver=None)[source]¶
Generate prefixed variants of a base unit and register them in a namespace.
Returns a dict mapping prefix names to the created units.
- Parameters:
namespace (UnitNamespace)
base_unit (Unit)
prefixes (dict[str, tuple[str, Fraction]] | None)
include (set[str] | None)
exclude (set[str] | None)
resolver (DisplayResolver | None)
- Return type:
dict[str, Unit]
- unitflow.serialize_constraint(constraint)[source]¶
- Parameters:
constraint (Constraint)
- Return type:
dict[str, Any]
- unitflow.serialize_dimension(dimension)[source]¶
- Parameters:
dimension (Dimension)
- Return type:
dict[str, Any]
- unitflow.serialize_quantity(quantity)[source]¶
- Parameters:
quantity (Quantity)
- Return type:
dict[str, Any]
- unitflow.serialize_unit_family(family)[source]¶
- Parameters:
family (UnitFamily)
- Return type:
dict[str, Any]