Skip to main content

JAX-native Hermite integrators for N-body dynamics with Diffrax-facing solver hooks

Project description

nornax

nornax Logo

nornax is a JAX-native Hermite integrator package for gravitational N-body dynamics.

The current direction is:

  • standalone and general-purpose first
  • Diffrax-facing solver design
  • GPU-efficient JAX kernels
  • clean backend adapters so jaccpot can plug in later

Current Scope

The current implementation includes:

  • immutable NBodyState / ForceDerivatives PyTrees
  • backend-agnostic ForceModel protocol
  • standalone DirectSumGravity reference backend (O(N^2) all-pairs; the default path materializes N×N pair tensors, and an opt-in block_size caps peak memory at O(block_size × N) for larger N — jaccpot remains the scalable backend)
  • standalone and Diffrax-backed Hermite-4, Hermite-6, and Hermite-8
  • adaptive global timestep control through Diffrax
  • diagnostics for total energy and angular momentum
  • convergence and long-run conservation tests

Installation

Install from source:

pip install -e .

Install with development tooling:

pip install -e ".[dev]"

Quick Start

import jax
import jax.numpy as jnp

from nornax import AarsethController, solve_adaptive_to_time, total_energy
from nornax.forces import DirectSumGravity

jax.config.update("jax_enable_x64", True)

force_model = DirectSumGravity()
result = solve_adaptive_to_time(
    jnp.asarray([[-1.0, 0.0, 0.0], [1.0, 0.0, 0.0]]),
    jnp.asarray([[0.0, 0.5, 0.0], [0.0, -0.5, 0.0]]),
    jnp.asarray([1.0, 1.0]),
    force_model,
    t_final=1.0,
    order=8,
    controller=AarsethController(eta=0.03, min_dt=1.0e-4, max_dt=5.0e-2),
    atol=1.0e-8,
)
print(result.final_state.time, total_energy(result.final_state))

Examples:

Notebooks:

Jaccpot Adapter

nornax now includes a first adapter for jaccpot via JaccpotForceModel. This is useful today for Hermite-4, because the current jaccpot runtime exposes acceleration and jerk, but not higher time derivatives.

import jax.numpy as jnp

from jaccpot import FastMultipoleMethod
from nornax import AarsethController, JaccpotForceModel, solve_adaptive_to_time

solver = FastMultipoleMethod(preset="fast", basis="solidfmm")
force_model = JaccpotForceModel(solver)

result = solve_adaptive_to_time(
    jnp.asarray([[1.0, 0.0, 0.0], [-1.0, 0.0, 0.0]]),
    jnp.asarray([[0.0, 0.2, 0.0], [0.0, -0.2, 0.0]]),
    jnp.asarray([1.0, 1.0]),
    force_model,
    t_final=0.1,
    order=4,
    controller=AarsethController(eta=0.03, min_dt=1.0e-4, max_dt=5.0e-2),
    atol=1.0e-6,
    args={"leaf_size": 8, "max_order": 2, "jerk_mode": "fast_approx"},
)

Current limitation:

  • use JaccpotForceModel with Hermite-4 for now
  • Hermite-6 and Hermite-8 still require higher time derivatives than jaccpot currently provides

Planned Architecture

  • nornax.state: particle state and cached force derivatives
  • nornax.forces: standalone direct-sum backend plus future adapters
  • nornax.solvers: Hermite kernels and Diffrax-facing solver classes
  • nornax.terms: thin Diffrax integration hooks

The scientific target is the family of higher-order Hermite methods discussed by Nitadori, Iwasawa, and Makino. The current implementation follows that paper through Hermite-8, including direct derivatives through crackle and higher-order adaptive timestep criteria.

Validation

The test suite currently covers:

  • direct-force derivatives through crackle
  • Hermite-4/6/8 kernel behavior
  • Diffrax custom solver smoke tests for 4/6/8
  • convergence checks for 4/6/8
  • adaptive public solve APIs
  • long-run two-body energy-drift ordering across 4/6/8

Benchmarks and examples live in bench/bench_direct_sum.py and examples/compare_hermite_orders.py.

Development

Run quality gates locally:

black --check .
isort --check-only .
pytest

Or run pre-commit hooks:

pre-commit run --all-files

Runtime Type Checking

Enable package-wide runtime checks (jaxtyping + beartype) at import time:

export NORNAX_RUNTIME_TYPECHECK=1

License

MIT.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nornax-0.0.1.tar.gz (23.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nornax-0.0.1-py3-none-any.whl (29.8 kB view details)

Uploaded Python 3

File details

Details for the file nornax-0.0.1.tar.gz.

File metadata

  • Download URL: nornax-0.0.1.tar.gz
  • Upload date:
  • Size: 23.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nornax-0.0.1.tar.gz
Algorithm Hash digest
SHA256 78a6526a9530234b3efd5b38b397b2ccb725a29438d029b897defdd8d9329556
MD5 13b622f529be8d0640096b3924a3d06f
BLAKE2b-256 6751bf72376d9bdbc818a572c417de228a1dbaf1634644ddce8290cbd44d087f

See more details on using hashes here.

Provenance

The following attestation bundles were made for nornax-0.0.1.tar.gz:

Publisher: release.yml on TobiBu/nornax

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nornax-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: nornax-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 29.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nornax-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6cc6d833d0eda3c6ac85c2710cf772b8b697d7a32f171ce15d4998f44255587d
MD5 ecd9a24ada9be54ad1ea667224a21317
BLAKE2b-256 6dd0e5d20ef736ea016ac333c99112ab3ed011351b006399bc1291888484c2fc

See more details on using hashes here.

Provenance

The following attestation bundles were made for nornax-0.0.1-py3-none-any.whl:

Publisher: release.yml on TobiBu/nornax

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page