unxt 0.10.7
pip install unxt==0.10.7
Released:
Quantities in JAX
Navigation
Unverified details
These details have not been verified by PyPIProject links
Meta
- License: BSD License (BSD 3-Clause License Copyright (c) 2023, Nathaniel Starkman. All rights reserved. Redistribution a...)
- Author: Nathaniel Starkman
- Requires: Python >=3.10
-
Provides-Extra:
all
,dev
,docs
,test
Classifiers
- Development Status
- Intended Audience
- License
- Operating System
- Programming Language
- Topic
- Typing
Project description
unxt
Unitful Quantities in JAX
Unxt is unitful quantities and calculations in JAX, built on Equinox and Quax.
Yes, it supports auto-differentiation (grad
, jacobian
, hessian
) and
vectorization (vmap
, etc).
Installation
pip install unxt
Documentation
Coming soon. In the meantime, if you've used astropy.units
, then unxt
should
be familiar!
Quick example
from unxt import Quantity
x = Quantity(jnp.arange(1, 5, dtype=float), "kpc")
print(x)
# Quantity['length'](Array([1., 2., 3., 4.], dtype=float64), unit='kpc')
# Addition / Subtraction
print(x + x)
# Quantity['length'](Array([2., 4., 6., 8.], dtype=float64), unit='kpc')
# Multiplication / Division
print(2 * x)
# Quantity['length'](Array([2., 4., 6., 8.], dtype=float64), unit='kpc')
y = Quantity(jnp.arange(4, 8, dtype=float), "Gyr")
print(x / y)
# Quantity['speed'](Array([0.25 , 0.4 , 0.5 , 0.57142857], dtype=float64), unit='kpc / Gyr')
# Exponentiation
print(x**2)
# Quantity['area'](Array([0., 1., 4., 9.], dtype=float64), unit='kpc2')
# Unit Checking on operations
try:
x + y
except Exception as e:
print(e)
# 'Gyr' (time) and 'kpc' (length) are not convertible
unxt
is built on quax
, which
enables custom array-ish objects in JAX. For convenience we use the
quaxed
library, which is just a quax
wrapper around jax
to avoid boilerplate wrappers.
from quaxed import grad, vmap
import quaxed.numpy as jnp
print(jnp.square(x))
# Quantity['area'](Array([ 1., 4., 9., 16.], dtype=float64), unit='kpc2')
print(qnp.power(x, 3))
# Quantity['volume'](Array([ 1., 8., 27., 64.], dtype=float64), unit='kpc3')
print(vmap(grad(lambda x: x**3))(x))
# Quantity['area'](Array([ 3., 12., 27., 48.], dtype=float64), unit='kpc2')
Since Quantity
is parametric, it can do runtime dimension checking!
LengthQuantity = Quantity["length"]
print(LengthQuantity(2, "km"))
# Quantity['length'](Array(2, dtype=int64, weak_type=True), unit='km')
try:
LengthQuantity(2, "s")
except ValueError as e:
print(e)
# Physical type mismatch.
Citation
If you found this library to be useful in academic work, then please cite.
Development
We welcome contributions!
Project details
Unverified details
These details have not been verified by PyPIProject links
Meta
- License: BSD License (BSD 3-Clause License Copyright (c) 2023, Nathaniel Starkman. All rights reserved. Redistribution a...)
- Author: Nathaniel Starkman
- Requires: Python >=3.10
-
Provides-Extra:
all
,dev
,docs
,test
Classifiers
- Development Status
- Intended Audience
- License
- Operating System
- Programming Language
- Topic
- Typing
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file unxt-0.10.7.tar.gz
.
File metadata
- Download URL: unxt-0.10.7.tar.gz
- Upload date:
- Size: 42.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
26cc636259cc97db2f0566c69db5ce2895f4e47abf77464f14245b8d31af21ae
|
|
MD5 |
bd6f37b7255b9b1546597cb5f01789e6
|
|
BLAKE2b-256 |
a40322b858379246ca7169c85c19ac6f21c65cc20d862e2f69a624d22c1a21e4
|
File details
Details for the file unxt-0.10.7-py3-none-any.whl
.
File metadata
- Download URL: unxt-0.10.7-py3-none-any.whl
- Upload date:
- Size: 36.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
67c232f585f3920e5e3b5c83ba04ddeba637fdb81569c37925c11d718ac047b5
|
|
MD5 |
1872a4cf6c986b9ceb11f6f502f4b47f
|
|
BLAKE2b-256 |
2dd22abedcce2507b2b0f4146206effff5e13fdfe0ec3c83a33852bcd4cfd602
|