unxt: A Python package for unit-aware computing with JAX

The paper introduces **unxt**, a Python package built on the **quax** framework that integrates **astropy.units** with **JAX** to enable seamless, high-performance, unit-aware scientific computing.

Nathaniel Starkman, Adrian Price-Whelan, Jake Nibauer

Published Wed, 11 Ma
📖 3 min read☕ Coffee break read

Imagine you are a chef in a high-speed kitchen. You have a super-fast robot assistant (let's call it JAX) that can chop, mix, and cook ingredients faster than any human ever could. It can even predict exactly how the flavors will change if you tweak a recipe, and it does all this on different types of stoves (CPUs, GPUs, TPUs) without breaking a sweat.

However, there's a catch: JAX only understands raw numbers. It doesn't know the difference between "5 cups of flour" and "5 pounds of sugar." If you tell it to add 5 cups to 5 pounds, it will just blindly add the numbers together to get "10" and serve you a disaster. In the real world, mixing up units (like the famous Mars Climate Orbiter crash, where one team used metric and another used imperial) can lead to catastrophic failures.

Enter unxt.

What is unxt?

Think of unxt as a smart translator and safety guard that sits between you and the super-fast robot.

  1. The Translator: It takes your "real-world" instructions (like "5 meters per second") and translates them into a format the robot understands, while keeping a tag on every single number that says, "Hey, this is a length!" or "This is time!"
  2. The Safety Guard: If you try to do something silly, like adding "5 meters" to "5 seconds," the translator stops you immediately and says, "Whoa, you can't mix those up!" This prevents the robot from making a mistake that could ruin your experiment or launch a rocket into the wrong planet.

How does it work?

The paper explains that unxt is built on top of a framework called quax.

  • Quax is like a universal adapter that lets the robot (JAX) talk to special, custom objects.
  • unxt uses this adapter to create a special kind of "smart number" (called a Quantity) that knows it has units attached to it.
  • It also uses the Astropy library (a giant, trusted encyclopedia of units used by astronomers) as its brain for knowing what a "kilogram" or a "light-year" actually means.

Why do we need it?

Before unxt, scientists who wanted to use the super-fast robot (JAX) had to choose:

  • Option A: Use JAX for speed, but lose the ability to check units (risky!).
  • Option B: Use a library like Astropy or Pint to check units, but lose the speed and power of JAX (slow!).

unxt solves this by letting you have your cake and eat it too. It lets you write code that is:

  • Fast: It runs on JAX's high-speed engine.
  • Safe: It automatically checks that you aren't mixing apples and oranges.
  • Easy: It feels familiar to scientists who already use Astropy, so they don't have to learn a whole new language.

The Bottom Line

unxt is a bridge. It connects the messy, complex world of physical measurements (meters, seconds, kilograms) with the clean, lightning-fast world of modern computer science. It ensures that when scientists run complex simulations—whether for weather forecasting, astrophysics, or engineering—the math is not only fast but also correct.

In short: It's the safety net that lets the super-fast robot cook without burning the kitchen down.