unitflow.core

Dimensions, scales, units, quantities, and display resolution.

Semantic core exports for unitflow.

class unitflow.core.Dimension(exponents)[source]

Bases: object

Immutable exponent vector over the fixed base-dimension basis.

Parameters:

exponents (tuple[int, ...])

exponents: tuple[int, ...]
classmethod zero()[source]

Return the dimensionless exponent vector.

Return type:

Dimension

classmethod base(name)[source]

Return a single base dimension by its canonical name.

Parameters:

name (str)

Return type:

Dimension

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:

Dimension

property is_dimensionless: bool

Whether all exponents are zero.

to_mapping()[source]

Return a sparse mapping of non-zero exponents by base-dimension name.

Return type:

dict[str, int]

class unitflow.core.Quantity(magnitude, unit)[source]

Bases: object

Concrete magnitude plus semantic unit.

Parameters:
  • magnitude (Any)

  • unit (Unit)

magnitude: Any
unit: Unit
to(target_unit)[source]
Parameters:

target_unit (Unit)

Return type:

Quantity

is_close(other, *, rel_tol=1e-09, abs_tol=0.0)[source]
Parameters:
  • other (object)

  • rel_tol (float)

  • abs_tol (float)

Return type:

bool

class unitflow.core.Scale(coefficient, pi_power=0)[source]

Bases: object

Exact scale represented as a rational coefficient times an integer power of pi.

Parameters:
  • coefficient (Fraction)

  • pi_power (int)

coefficient: Fraction
pi_power: int
classmethod one()[source]
Return type:

Scale

classmethod zero()[source]
Return type:

Scale

classmethod from_int(value)[source]
Parameters:

value (int)

Return type:

Scale

classmethod from_ratio(numerator, denominator=1, *, pi_power=0)[source]
Parameters:
  • numerator (int)

  • denominator (int)

  • pi_power (int)

Return type:

Scale

classmethod pi()[source]
Return type:

Scale

property is_zero: bool
as_float()[source]

Lossy float conversion for debugging and later backend integration.

Return type:

float

class unitflow.core.Unit(dimension, scale, name=None, symbol=None, aliases=(), family=None, quantity_kind=None)[source]

Bases: object

Immutable semantic unit definition.

Parameters:
  • dimension (Dimension)

  • scale (Scale)

  • name (str | None)

  • symbol (str | None)

  • aliases (tuple[str, ...])

  • family (UnitFamily | None)

  • quantity_kind (str | None)

dimension: Dimension
scale: Scale
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:

Unit

is_compatible_with(other)[source]
Parameters:

other (Unit)

Return type:

bool

conversion_factor_to(other)[source]
Parameters:

other (Unit)

Return type:

Scale

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:

Unit

class unitflow.core.UnitFamily(name, description)[source]

Bases: object

Semantic metadata for units that share a meaningful family.

Parameters:
  • name (str)

  • description (str)

name: str
description: str