unxts.parametric#

unxts.parametric provides ParametricQuantity (alias PQ): a quantity that encodes its physical dimension in its type. It is the opt-in counterpart to the lightweight, non-parametric default unxt.Quantity.

ParametricQuantity used to be the default Quantity in unxt v1. As of v2 the non-parametric class is the default and the parametric class lives here, in its own package. See the migration guide for the full mapping.

Install#

uv add unxts.parametric
pip install unxts.parametric

Throughout these pages we import unxt as u and unxts.parametric as up (so ParametricQuantity is up.PQ):

>>> import unxt as u
>>> import unxts.parametric as up

At a glance#

ParametricQuantity is used just like Quantity, but it encodes the physical dimension in its type โ€” and can check it at construction:

>>> up.PQ(1.0, "m")  # dimension inferred from the unit
ParametricQuantity(Array(1., dtype=float32, ...), unit='m')

>>> up.PQ["length"](1.0, "m")  # dimension checked against the unit
ParametricQuantity(Array(1., dtype=float32, ...), unit='m')

Should you use it?#

Reach for ParametricQuantity only when you need one of its two extra features:

  1. Runtime dimension checking โ€” up.PQ["length"](1, "s") raises; the default u.Q["length"](1, "s") accepts the subscript for compatibility but does not check it.

  2. Dispatch on specific dimensions โ€” up.PQ["length"] is a real type usable in plum dispatch annotations; u.Q["length"] is just Quantity.

Everything else โ€” arithmetic, unit conversion, JAX transforms, interop โ€” works identically with either class. The cost of the parametric class, and why the non-parametric one became the default, is set out in the core docs under Why Quantity is not parametric; the comparison table against StaticQuantity is in the sharp bits.

Pages#

Tutorial

Reference

  • ParametricQuantity โ€” construction, runtime dimension checking, dimension-specific dispatch, promotion with the default Quantity, and dimension_of on a parametrized class.

  • Configuration โ€” the include_params display option.

How-to

Discussion

Public API#

unxts.parametric exposes:

  • ParametricQuantity โ€” the dimension-parametrized quantity (alias PQ).

  • AbstractParametricQuantity โ€” its abstract base.

  • config โ€” the unxts.parametric.config singleton (see Configuration).

Importing unxts.parametric also registers, as import side effects, the promotion rules, plum conversions, and JAX primitive rules that let ParametricQuantity interoperate with the rest of unxt.