Installing and running the code¶
System requirements¶
The code requires Python and JAX (only CPU suffices, optionally with GPU support).
If you are installing the code on a Windows machine, you will need to first install the Microsoft Visual C++ Build Tools. You can find the installer here. If prompted, select "Desktop development with C++" and install the required components.
Installation¶
If you want to run the code in the project only, you can install the required packages from the pyproject.toml
file using the following command:
pip install -e .
If you want to develop the code, you can install the required packages from the pyproject.toml
file using the following command:
pip install -e .[dev]
We will discuss the individual components in the sections to come.
Example run¶
We'll cover the detail of what's going on in the code below later, but for now we can check everything is installed correctly by simulating and visualising the trajectory of an three-body system. If you get an error when running the code below, read the error carefully and try to fix it.
import jax.numpy as jnp
import matplotlib.pyplot as plt
from hdynamics.dynamics import Nbody
nbody = Nbody(dim=2, n_bodies=3)
initial_conditions = jnp.array([1, 2, 0, 0, 2, 1, -0.1, 0.1, 0.1, -0.2, 0.1, 0.2])
trajectory, t_span = nbody.generate_trajectory(initial_conditions, 0.01, 5000)
fig, ax = plt.subplots()
nbody.plot_trajectory(trajectory, t_span, ax)