Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into mapinversion
Browse files Browse the repository at this point in the history
  • Loading branch information
darioizzo committed Jun 27, 2024
2 parents acd4320 + cf0f89e commit 14d938d
Show file tree
Hide file tree
Showing 22 changed files with 839 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gh_actions_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ jobs:
- name: Build
shell: pwsh
run: |
conda install -y python=3.10 git pybind11 numpy cmake llvmdev tbb-devel tbb astroquery libboost-devel fmt spdlog sleef sympy cloudpickle zlib libzlib 'mppp=1.*' numba
conda install -y python=3.10 git pybind11 numpy<2 cmake llvmdev tbb-devel tbb astroquery libboost-devel fmt spdlog sleef sympy cloudpickle zlib libzlib 'mppp=1.*' numba
git clone --depth 1 https://github.com/bluescarni/heyoka.git heyoka_cpp
cd heyoka_cpp
mkdir build
Expand Down
2 changes: 2 additions & 0 deletions doc/api_model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ Functions
cart2geo
nrlmsise00_tn
jb08_tn
fixed_centres
pendulum
3 changes: 3 additions & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@
"thermoNETs*"
]

# Force printing traceback to stderr on execution error.
nb_execution_show_tb = True

latex_engine = "xelatex"

myst_enable_extensions = [
Expand Down
30 changes: 30 additions & 0 deletions doc/examples_var_ode_sys.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.. _examples_var_ode_sys:

Variational equations
=====================

.. only:: html

.. important::

.. raw:: html

<p>
Most of these examples can be launched as online interactive notebooks
thanks to the infrastructure provided by <a href="https://mybinder.org/">binder</a>.
Look for the rocket icon <i class="fas fa-rocket"></i> on top of each page!
</p>

.. important::

Some examples may use features not available yet in the latest stable release
of heyoka.py, and thus might fail to execute correctly in the online interactive
notebooks. Please refer to the :ref:`changelog <changelog>` for an overview of
the features currently
available only in the development version of heyoka.py.

.. toctree::
:maxdepth: 1

notebooks/tmap_pendulum
notebooks/learning_mascons
1 change: 1 addition & 0 deletions doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ advanced_tutorials
examples_astro
examples_event
examples_ml
examples_var_ode_sys
examples_others
```

Expand Down
458 changes: 458 additions & 0 deletions doc/notebooks/learning_mascons.ipynb

Large diffs are not rendered by default.

264 changes: 264 additions & 0 deletions doc/notebooks/tmap_pendulum.ipynb

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions heyoka/_test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def test_rotating(self):

def test_fixed_centres(self):
from . import model, make_vars, expression as ex, sqrt
from numpy import single

x, y, z, vx, vy, vz = make_vars("x", "y", "z", "vx", "vy", "vz")

Expand Down Expand Up @@ -140,6 +141,15 @@ def test_fixed_centres(self):
in str(cm.exception)
)

# Run also a small test with single-precision values.
dyn = model.fixed_centres(
Gconst=single(1.5), masses=[single(1.1)], positions=[[1.0, 2.0, 3.0]]
)

self.assertEqual(dyn[0][0], x)
self.assertEqual(dyn[0][1], ex("vx"))
self.assertTrue("1.10000002" in repr(dyn))

def test_nbody(self):
from . import model, expression, sqrt, make_vars

Expand Down
52 changes: 52 additions & 0 deletions heyoka/docstrings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,4 +678,56 @@ std::string var_args_all()
)";
}

std::string fixed_centres()
{
return R"(fixed_centres(Gconst: expression | str | numpy.single | float | numpy.longdouble = 1., masses: collections.abc.Sequence[expression | str | numpy.single | float | numpy.longdouble] = [], positions: collections.abc.Iterable = numpy.empty((0, 3), dtype=float)) -> list[tuple[expression, expression]]
Produces the expression for the dynamics in a fixed-centres problem.
In the fixed-centres problem, a test particle moves in the Newtonian gravitational field generated
by a number of massive particles whose positions are fixed in space. The test particle's Cartesian position and
velocity are represented by the variables ``[x, y, z]`` and ``[vx, vy, vz]`` respectively.
Several checks are run on the input arguments:
- *positions* must be convertible into an ``N x 3`` array, with each row containing
the Cartesian position vector of a mass,
- the number of elements in *masses* must be equal to the number of three-dimensional
position vectors in *positions*.
:param Gconst: the gravitational constant.
:param masses: the list of mass values (one for each particle).
:param positions: the positions of the particles.
:returns: the dynamics of the Newtonian fixed centres problem.
:raises ValueError: if one or more input arguments are malformed, as explained above.
)";
}

std::string pendulum()
{
return R"(pendulum(gconst: expression | str | numpy.single | float | numpy.longdouble = 1., length: expression | str | numpy.single | float | numpy.longdouble = 1.) -> list[tuple[expression, expression]]
Produces the expression for the dynamics of the simple pendulum.
The gravitational constant is *gconst*, while the length of the pendulum is *length*.
In the return value, the angle with respect to the downwards vertical is represented by
the state variable ``x``, while its time derivative is represented by the state
variable ``v``.
:param gconst: the gravitational constant.
:param length: the length of the pendulum.
:returns: the dynamics of the simple pendulum.
Examples:
>>> from heyoka import model
>>> model.pendulum()
[(x, v), (v, -sin(x))]
)";
}

} // namespace heyoka_py::docstrings
2 changes: 2 additions & 0 deletions heyoka/docstrings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ std::string hamiltonian();
std::string cart2geo();
std::string nrlmsise00_tn();
std::string jb08_tn();
std::string fixed_centres();
std::string pendulum();

// var_ode_sys() and related.
std::string var_args();
Expand Down
8 changes: 5 additions & 3 deletions heyoka/expose_models.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

#include "common_utils.hpp"
#include "custom_casters.hpp"
#include "docstrings.hpp"
#include "dtypes.hpp"
#include "expose_models.hpp"

Expand Down Expand Up @@ -207,7 +208,7 @@ void expose_models(py::module_ &m)

// A variant containing either an expression or a numerical/string
// type from which an expression can be constructed.
using vex_t = std::variant<hy::expression, std::string, double, long double
using vex_t = std::variant<hy::expression, std::string, float, double, long double
#if defined(HEYOKA_HAVE_REAL128)
,
mppp::real128
Expand Down Expand Up @@ -261,7 +262,7 @@ void expose_models(py::module_ &m)
m.def(
"_model_pendulum",
[](const vex_t &gconst, const vex_t &l) { return detail::pendulum_impl(hy::model::pendulum, gconst, l); },
"gconst"_a.noconvert() = 1., "length"_a.noconvert() = 1.);
"gconst"_a.noconvert() = 1., "length"_a.noconvert() = 1., docstrings::pendulum().c_str());
m.def(
"_model_pendulum_energy",
[](const vex_t &gconst, const vex_t &l) {
Expand All @@ -276,7 +277,8 @@ void expose_models(py::module_ &m)
return detail::fixed_centres_impl(hy::model::fixed_centres, Gconst, masses, positions);
},
"Gconst"_a.noconvert() = 1., "masses"_a.noconvert() = py::list{},
"positions"_a = py::array{py::dtype(get_dtype<double>()), py::array::ShapeContainer{0, 3}});
"positions"_a = py::array{py::dtype(get_dtype<double>()), py::array::ShapeContainer{0, 3}},
docstrings::fixed_centres().c_str());
m.def(
"_model_fixed_centres_energy",
[](const vex_t &Gconst, const std::vector<vex_t> &masses, const py::iterable &positions) {
Expand Down
2 changes: 1 addition & 1 deletion tools/circleci_conda_heyoka_head_310.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ wget https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge
export deps_dir=$HOME/local
export PATH="$HOME/miniforge/bin:$PATH"
bash miniforge.sh -b -p $HOME/miniforge
mamba create -y -p $deps_dir python=3.10 c-compiler cxx-compiler git pybind11 numpy mpmath cmake llvmdev tbb-devel tbb astroquery libboost-devel 'mppp=1.*' sleef fmt spdlog myst-nb matplotlib sympy scipy pykep cloudpickle 'sphinx=7.*' 'sphinx-book-theme=1.*'
mamba create -y -p $deps_dir python=3.10 c-compiler cxx-compiler git pybind11 'numpy<2' mpmath cmake llvmdev tbb-devel tbb astroquery libboost-devel 'mppp=1.*' sleef fmt spdlog myst-nb matplotlib sympy scipy pykep cloudpickle 'sphinx=7.*' 'sphinx-book-theme=1.*'
source activate $deps_dir

export HEYOKA_PY_PROJECT_DIR=`pwd`
Expand Down
2 changes: 1 addition & 1 deletion tools/circleci_conda_heyoka_head_312.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ wget https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge
export deps_dir=$HOME/local
export PATH="$HOME/miniforge/bin:$PATH"
bash miniforge.sh -b -p $HOME/miniforge
mamba create -y -p $deps_dir python=3.12 c-compiler cxx-compiler git pybind11 numpy mpmath cmake llvmdev tbb-devel tbb libboost-devel 'mppp=1.*' sleef fmt spdlog sympy cloudpickle
mamba create -y -p $deps_dir python=3.12 c-compiler cxx-compiler git pybind11 'numpy<2' mpmath cmake llvmdev tbb-devel tbb libboost-devel 'mppp=1.*' sleef fmt spdlog sympy cloudpickle
source activate $deps_dir

# Checkout, build and install heyoka's HEAD.
Expand Down
2 changes: 1 addition & 1 deletion tools/circleci_conda_heyoka_head_39.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ wget https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge
export deps_dir=$HOME/local
export PATH="$HOME/miniforge/bin:$PATH"
bash miniforge.sh -b -p $HOME/miniforge
mamba create -y -p $deps_dir python=3.9 c-compiler cxx-compiler git pybind11 numpy mpmath cmake llvmdev tbb-devel tbb astroquery libboost-devel 'mppp=1.*' sleef fmt spdlog myst-nb matplotlib sympy scipy pykep cloudpickle 'sphinx=7.*' 'sphinx-book-theme=1.*'
mamba create -y -p $deps_dir python=3.9 c-compiler cxx-compiler git pybind11 'numpy<2' mpmath cmake llvmdev tbb-devel tbb astroquery libboost-devel 'mppp=1.*' sleef fmt spdlog myst-nb matplotlib sympy scipy pykep cloudpickle 'sphinx=7.*' 'sphinx-book-theme=1.*'
source activate $deps_dir

export HEYOKA_PY_PROJECT_DIR=`pwd`
Expand Down
2 changes: 1 addition & 1 deletion tools/circleci_ubuntu_arm64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ wget https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge
export deps_dir=$HOME/local
export PATH="$HOME/miniforge/bin:$PATH"
bash miniforge.sh -b -p $HOME/miniforge
mamba create -y -q -p $deps_dir cxx-compiler c-compiler cmake llvmdev tbb-devel tbb astroquery libboost-devel 'mppp=1.*' sleef fmt spdlog python=3.10 pybind11 numpy mpmath sympy scipy cloudpickle myst-nb matplotlib 'sphinx=7.*' 'sphinx-book-theme=1.*'
mamba create -y -q -p $deps_dir cxx-compiler c-compiler cmake llvmdev tbb-devel tbb astroquery libboost-devel 'mppp=1.*' sleef fmt spdlog python=3.10 pybind11 'numpy<2' mpmath sympy scipy cloudpickle myst-nb matplotlib 'sphinx=7.*' 'sphinx-book-theme=1.*'
source activate $deps_dir

# Checkout, build and install heyoka's HEAD.
Expand Down
2 changes: 1 addition & 1 deletion tools/gha_conda_asan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export PATH="$HOME/miniconda/bin:$PATH"
bash miniconda.sh -b -p $HOME/miniconda
conda config --add channels conda-forge
conda config --set channel_priority strict
conda create -y -q -p $deps_dir python=3.10 git pybind11 numpy mpmath cmake llvmdev tbb-devel tbb libboost-devel 'mppp=1.*' sleef fmt spdlog sympy cloudpickle c-compiler cxx-compiler
conda create -y -q -p $deps_dir python=3.10 git pybind11 'numpy<2' mpmath cmake llvmdev tbb-devel tbb libboost-devel 'mppp=1.*' sleef fmt spdlog sympy cloudpickle c-compiler cxx-compiler
source activate $deps_dir

export CXXFLAGS="$CXXFLAGS -fsanitize=address"
Expand Down
2 changes: 1 addition & 1 deletion tools/gha_conda_docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export deps_dir=$HOME/local
export PATH="$HOME/miniforge/bin:$PATH"
bash miniforge.sh -b -p $HOME/miniforge
mamba create -y -p $deps_dir c-compiler cxx-compiler python=3.10 git pybind11 \
ninja numpy mpmath cmake llvmdev tbb-devel tbb astroquery libboost-devel \
ninja 'numpy<2' mpmath cmake llvmdev tbb-devel tbb astroquery libboost-devel \
'mppp=1.*' sleef fmt spdlog myst-nb matplotlib sympy scipy pykep cloudpickle \
'sphinx=7.*' 'sphinx-book-theme=1.*'
source activate $deps_dir
Expand Down
2 changes: 1 addition & 1 deletion tools/gha_conda_static.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export PATH="$HOME/miniconda/bin:$PATH"
bash miniconda.sh -b -p $HOME/miniconda
conda config --add channels conda-forge
conda config --set channel_priority strict
conda create -y -q -p $deps_dir python=3.10 git pybind11 numpy mpmath cmake llvmdev tbb-devel tbb libboost-devel 'mppp=1.*' sleef fmt spdlog sympy cloudpickle c-compiler cxx-compiler numba zlib
conda create -y -q -p $deps_dir python=3.10 git pybind11 'numpy<2' mpmath cmake llvmdev tbb-devel tbb libboost-devel 'mppp=1.*' sleef fmt spdlog sympy cloudpickle c-compiler cxx-compiler numba zlib
source activate $deps_dir

# Checkout, build and install heyoka's HEAD.
Expand Down
2 changes: 1 addition & 1 deletion tools/gha_osx_heyoka_head.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ wget https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge
export deps_dir=$HOME/local
export PATH="$HOME/miniconda/bin:$PATH"
bash miniconda.sh -b -p $HOME/miniconda
mamba create -y -p $deps_dir python=3.11 c-compiler cxx-compiler git pybind11 numpy cmake llvmdev tbb-devel tbb astroquery libboost-devel sleef fmt spdlog sympy cloudpickle 'mppp=1.*'
mamba create -y -p $deps_dir python=3.11 c-compiler cxx-compiler git pybind11 'numpy<2' cmake llvmdev tbb-devel tbb astroquery libboost-devel sleef fmt spdlog sympy cloudpickle 'mppp=1.*'
source activate $deps_dir

# Checkout, build and install heyoka's HEAD.
Expand Down
2 changes: 1 addition & 1 deletion tools/gha_osx_heyoka_head_static.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ wget https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge
export deps_dir=$HOME/local
export PATH="$HOME/miniconda/bin:$PATH"
bash miniconda.sh -b -p $HOME/miniconda
mamba create -y -p $deps_dir python=3.11 c-compiler cxx-compiler git pybind11 numpy cmake llvmdev tbb-devel tbb astroquery libboost-devel sleef fmt spdlog sympy cloudpickle 'mppp=1.*' numba
mamba create -y -p $deps_dir python=3.11 c-compiler cxx-compiler git pybind11 'numpy<2' cmake llvmdev tbb-devel tbb astroquery libboost-devel sleef fmt spdlog sympy cloudpickle 'mppp=1.*' numba
source activate $deps_dir

# Checkout, build and install heyoka's HEAD.
Expand Down
2 changes: 1 addition & 1 deletion tools/gha_osx_heyoka_stable.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export PATH="$HOME/miniconda/bin:$PATH"
bash miniconda.sh -b -p $HOME/miniconda
conda create -y -q -p $deps_dir
source activate $deps_dir
mamba install -y python=3.10 pybind11 numpy cmake heyoka libboost-devel
mamba install -y python=3.10 pybind11 'numpy<2' cmake heyoka libboost-devel

# Create the build dir and cd into it.
mkdir build
Expand Down
2 changes: 1 addition & 1 deletion tools/travis_ubuntu_ppc64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ curl -L -o miniconda.sh https://github.com/conda-forge/miniforge/releases/latest
export deps_dir=$HOME/local
export PATH="$HOME/miniconda/bin:$PATH"
bash miniconda.sh -b -p $HOME/miniconda
conda create -y -q -p $deps_dir cxx-compiler c-compiler cmake llvmdev tbb-devel tbb astroquery libboost-devel sleef xtensor xtensor-blas blas blas-devel fmt spdlog python pybind11 numpy mpmath sympy cloudpickle mppp git make
conda create -y -q -p $deps_dir cxx-compiler c-compiler cmake llvmdev tbb-devel tbb astroquery libboost-devel sleef xtensor xtensor-blas blas blas-devel fmt spdlog python pybind11 'numpy<2' mpmath sympy cloudpickle mppp git make
source activate $deps_dir

# Checkout, build and install heyoka's HEAD.
Expand Down

0 comments on commit 14d938d

Please sign in to comment.