{"id":13521002,"url":"https://github.com/GalacticDynamics/unxt","last_synced_at":"2025-03-31T20:30:24.233Z","repository":{"id":213770480,"uuid":"734877295","full_name":"GalacticDynamics/unxt","owner":"GalacticDynamics","description":"Unitful Quantities in JAX","archived":false,"fork":false,"pushed_at":"2024-10-29T12:33:40.000Z","size":1156,"stargazers_count":13,"open_issues_count":16,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-29T14:59:11.831Z","etag":null,"topics":["array","auto-differentiation","jax","quantities","units"],"latest_commit_sha":null,"homepage":"https://unxt.readthedocs.io/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GalacticDynamics.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-12-22T22:13:31.000Z","updated_at":"2024-10-29T12:33:44.000Z","dependencies_parsed_at":"2023-12-31T01:42:11.219Z","dependency_job_id":"6f3ec356-455c-41ab-b06e-6a4543576b48","html_url":"https://github.com/GalacticDynamics/unxt","commit_stats":null,"previous_names":["galacticdynamics/jax-quantity","galacticdynamics/unxt"],"tags_count":64,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GalacticDynamics%2Funxt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GalacticDynamics%2Funxt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GalacticDynamics%2Funxt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GalacticDynamics%2Funxt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GalacticDynamics","download_url":"https://codeload.github.com/GalacticDynamics/unxt/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246535707,"owners_count":20793308,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["array","auto-differentiation","jax","quantities","units"],"created_at":"2024-08-01T06:00:25.934Z","updated_at":"2025-03-31T20:30:24.227Z","avatar_url":"https://github.com/GalacticDynamics.png","language":"Python","funding_links":[],"categories":["Models and Projects","Libraries"],"sub_categories":[],"readme":"\u003ch1 align='center'\u003e unxt \u003c/h1\u003e\n\u003ch3 align=\"center\"\u003eUnitful Quantities in JAX\u003c/h3\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://pypi.org/project/unxt/\"\u003e \u003cimg alt=\"PyPI: unxt\" src=\"https://img.shields.io/pypi/v/unxt?style=flat\" /\u003e \u003c/a\u003e\n    \u003ca href=\"https://pypi.org/project/unxt/\"\u003e \u003cimg alt=\"PyPI versions: unxt\" src=\"https://img.shields.io/pypi/pyversions/unxt\" /\u003e \u003c/a\u003e\n    \u003ca href=\"https://unxt.readthedocs.io/en/\"\u003e \u003cimg alt=\"ReadTheDocs\" src=\"https://img.shields.io/badge/read_docs-here-orange\" /\u003e \u003c/a\u003e\n    \u003ca href=\"https://pypi.org/project/unxt/\"\u003e \u003cimg alt=\"unxt license\" src=\"https://img.shields.io/github/license/GalacticDynamics/unxt\" /\u003e \u003c/a\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://scientific-python.org/specs/spec-0000/\"\u003e \u003cimg alt=\"ruff\" src=\"https://img.shields.io/badge/SPEC-0-green?labelColor=%23004811\u0026color=%235CA038\" /\u003e \u003c/a\u003e\n    \u003ca href=\"https://docs.astral.sh/ruff/\"\u003e \u003cimg alt=\"ruff\" src=\"https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json\" /\u003e \u003c/a\u003e\n    \u003ca href=\"https://pre-commit.com\"\u003e \u003cimg alt=\"pre-commit\" src=\"https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit\" /\u003e \u003c/a\u003e\n    \u003ca href=\"https://codspeed.io/GalacticDynamics/unxt\"\u003e\u003cimg src=\"https://img.shields.io/endpoint?url=https://codspeed.io/badge.json\" alt=\"CodSpeed Badge\"/\u003e\u003c/a\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/GalacticDynamics/unxt/actions\"\u003e \u003cimg alt=\"CI status\" src=\"https://github.com/GalacticDynamics/unxt/actions/workflows/ci.yml/badge.svg?branch=main\" /\u003e \u003c/a\u003e\n    \u003ca href=\"https://unxt.readthedocs.io/en/\"\u003e \u003cimg alt=\"ReadTheDocs\" src=\"https://readthedocs.org/projects/unxt/badge/?version=latest\" /\u003e \u003c/a\u003e\n    \u003ca href=\"https://codecov.io/gh/GalacticDynamics/unxt\"\u003e \u003cimg alt=\"codecov\" src=\"https://codecov.io/gh/GalacticDynamics/unxt/graph/badge.svg\" /\u003e \u003c/a\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n    \u003ca style=\"border-width:0\" href=\"https://doi.org/10.21105/joss.07771\"\u003e \u003cimg src=\"https://joss.theoj.org/papers/10.21105/joss.07771/status.svg\" alt=\"DOI badge\" \u003e \u003c/a\u003e\n\u003c/p\u003e\n\n---\n\nUnxt is unitful quantities and calculations in [JAX][jax], built on\n[Equinox][equinox] and [Quax][quax].\n\nUnxt supports JAX's compelling features:\n\n- JIT compilation (`jit`)\n- vectorization (`vmap`, etc.)\n- auto-differentiation (`grad`, `jacobian`, `hessian`)\n- GPU/TPU/multi-host acceleration\n\nAnd best of all, `unxt` doesn't force you to use special unit-compatible\nre-exports of JAX libraries. You can use `unxt` with existing JAX code, and with\n[quax][quax]'s simple decorator, JAX will work with `unxt.Quantity`.\n\n## Installation\n\n[![PyPI version][pypi-version]][pypi-link]\n[![PyPI platforms][pypi-platforms]][pypi-link]\n\n```bash\npip install unxt\n```\n\n\u003cdetails\u003e\n  \u003csummary\u003eusing \u003ccode\u003euv\u003c/code\u003e\u003c/summary\u003e\n\n```bash\nuv add unxt\n```\n\n\u003c/details\u003e\n\u003cdetails\u003e\n  \u003csummary\u003efrom source, using pip\u003c/summary\u003e\n\n```bash\npip install git+https://https://github.com/GalacticDynamics/unxt.git\n```\n\n\u003c/details\u003e\n\u003cdetails\u003e\n  \u003csummary\u003ebuilding from source\u003c/summary\u003e\n\n```bash\ncd /path/to/parent\ngit clone https://https://github.com/GalacticDynamics/unxt.git\ncd unxt\npip install -e .  # editable mode\n```\n\n\u003c/details\u003e\n\n## [Documentation][rtd-link]\n\n[![Read The Docs](https://img.shields.io/badge/read_docs-here-orange)](https://unxt.readthedocs.io/en/)\n\n### Quick example\n\n```python\nimport unxt as u\nimport jax.numpy as jnp\n\nx = u.Quantity(jnp.arange(1, 5, dtype=float), \"km\")\nprint(x)\n# Quantity['length'](Array([1., 2., 3., 4.], dtype=float64), unit='km')\n```\n\nThe constituent value and unit are accessible as attributes:\n\n```python\nprint(x.value)\n# Array([1., 2., 3., 4.], dtype=float64)\n\nprint(x.unit)\n# Unit(\"m\")\n```\n\n`Quantity` objects obey the rules of unitful arithmetic.\n\n```python\n# Addition / Subtraction\nprint(x + x)\n# Quantity['length'](Array([2., 4., 6., 8.], dtype=float64), unit='km')\n\n# Multiplication / Division\nprint(2 * x)\n# Quantity['length'](Array([2., 4., 6., 8.], dtype=float64), unit='km')\n\ny = u.Quantity(jnp.arange(4, 8, dtype=float), \"yr\")\n\nprint(x / y)\n# Quantity['speed'](Array([0.25      , 0.4       , 0.5       , 0.57142857], dtype=float64), unit='km / yr')\n\n# Exponentiation\nprint(x**2)\n# Quantity['area'](Array([0., 1., 4., 9.], dtype=float64), unit='km2')\n\n# Unit checking on operations\ntry:\n    x + y\nexcept Exception as e:\n    print(e)\n# 'yr' (time) and 'km' (length) are not convertible\n```\n\nQuantities can be converted to different units:\n\n```python\nprint(u.uconvert(\"m\", x))  # via function\n# Quantity['length'](Array([1000., 2000., 3000., 4000.], dtype=float64), unit='m')\n\nprint(x.uconvert(\"m\"))  # via method\n# Quantity['length'](Array([1000., 2000., 3000., 4000.], dtype=float64), unit='m')\n```\n\nSince `Quantity` is parametric, it can do runtime dimension checking!\n\n```python\nLengthQuantity = u.Quantity[\"length\"]\nprint(LengthQuantity(2, \"km\"))\n# Quantity['length'](Array(2, dtype=int64, weak_type=True), unit='km')\n\ntry:\n    LengthQuantity(2, \"s\")\nexcept ValueError as e:\n    print(e)\n# Physical type mismatch.\n```\n\n`unxt` is built on [`quax`][quax], which enables custom array-ish objects in\nJAX. For convenience we use the [`quaxed`][quaxed] library, which is just a\n`quax.quaxify` wrapper around `jax` to avoid boilerplate code.\n\n\u003e [!NOTE]\n\u003e\n\u003e Using [`quaxed`][quaxed] is optional. You can directly use `quaxify`, and even\n\u003e apply it to the top-level function instead of individual functions.\n\n```python\nfrom quaxed import grad, vmap\nimport quaxed.numpy as jnp\n\nprint(jnp.square(x))\n# Quantity['area'](Array([ 1.,  4.,  9., 16.], dtype=float64), unit='km2')\n\nprint(jnp.power(x, 3))\n# Quantity['volume'](Array([ 1.,  8., 27., 64.], dtype=float64), unit='km3')\n\nprint(vmap(grad(lambda x: x**3))(x))\n# Quantity['area'](Array([ 3., 12., 27., 48.], dtype=float64), unit='km2')\n```\n\nSee the [documentation][rtd-link] for more examples and details of JIT and AD\n\n## Citation\n\n[![DOI][zenodo-badge]][zenodo-link]\n\nIf you found this library to be useful and want to support the development and\nmaintenance of lower-level code libraries for the scientific community, please\nconsider citing this work.\n\n## Contributing and Development\n\n[![Actions Status][actions-badge]][actions-link]\n[![Documentation Status][rtd-badge]][rtd-link]\n[![codecov][codecov-badge]][codecov-link]\n[![SPEC 0 — Minimum Supported Dependencies][spec0-badge]][spec0-link]\n[![pre-commit][pre-commit-badge]][pre-commit-link]\n[![ruff][ruff-badge]][ruff-link]\n[![CodSpeed Badge](https://img.shields.io/endpoint?url=https://codspeed.io/badge.json)](https://codspeed.io/GalacticDynamics/unxt)\n\nWe welcome contributions! Contributions are how open source projects improve and\ngrow.\n\nTo contribute to `unxt`, please\n[fork](https://github.com/GalacticDynamics/unxt/fork) the repository, make a\ndevelopment branch, develop on that branch, then\n[open a pull request](https://github.com/GalacticDynamics/unxt/compare) from the\nbranch in your fork to main.\n\nTo report bugs, request features, or suggest other ideas, please\n[open an issue](https://github.com/GalacticDynamics/unxt/issues/new/choose).\n\nFor more information, see [CONTRIBUTING.md](CONTRIBUTING.md).\n\n\u003c!-- prettier-ignore-start --\u003e\n[equinox]: https://docs.kidger.site/equinox/\n[jax]: https://jax.readthedocs.io/en/latest/\n[quax]: https://github.com/patrick-kidger/quax\n[quaxed]: https://github.com/GalacticDynamics/quaxed\n\n[actions-badge]:            https://github.com/GalacticDynamics/unxt/actions/workflows/ci.yml/badge.svg?branch=main\n[actions-link]:             https://github.com/GalacticDynamics/unxt/actions\n[codecov-badge]:            https://codecov.io/gh/GalacticDynamics/unxt/graph/badge.svg\n[codecov-link]:             https://codecov.io/gh/GalacticDynamics/unxt\n[pre-commit-badge]:         https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit\n[pre-commit-link]:          https://pre-commit.com\n[pypi-link]:                https://pypi.org/project/unxt/\n[pypi-platforms]:           https://img.shields.io/pypi/pyversions/unxt\n[pypi-version]:             https://img.shields.io/pypi/v/unxt\n[rtd-badge]:                https://readthedocs.org/projects/unxt/badge/?version=latest\n[rtd-link]:                 https://unxt.readthedocs.io/en/\n[ruff-badge]:               https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json\n[ruff-link]:                https://docs.astral.sh/ruff/\n[spec0-badge]:              https://img.shields.io/badge/SPEC-0-green?labelColor=%23004811\u0026color=%235CA038\n[spec0-link]:               https://scientific-python.org/specs/spec-0000/\n[zenodo-badge]:             https://zenodo.org/badge/734877295.svg\n[zenodo-link]:              https://zenodo.org/doi/10.5281/zenodo.10850455\n\n\u003c!-- prettier-ignore-end --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGalacticDynamics%2Funxt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FGalacticDynamics%2Funxt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGalacticDynamics%2Funxt/lists"}