From 712ca374b0612b07a3ee8c8808797bc755883f3a Mon Sep 17 00:00:00 2001 From: elkogerville Date: Thu, 28 May 2026 16:36:50 +0200 Subject: [PATCH 01/31] def adding_example_code_tidymess in index.rst --- doc/tutorial/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/tutorial/index.rst b/doc/tutorial/index.rst index 7be640b60a..2760f8a26d 100644 --- a/doc/tutorial/index.rst +++ b/doc/tutorial/index.rst @@ -16,4 +16,4 @@ Tutorials legacy_code plot grid_boundary - + adding_example_code_tidymess From 63e003a1b23cfa97a9c5412a9a88091cb7e23861 Mon Sep 17 00:00:00 2001 From: elkogerville Date: Thu, 28 May 2026 16:39:58 +0200 Subject: [PATCH 02/31] new documentation file about adding tidymess to amuse --- doc/tutorial/adding_example_code_tidymess.rst | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 doc/tutorial/adding_example_code_tidymess.rst diff --git a/doc/tutorial/adding_example_code_tidymess.rst b/doc/tutorial/adding_example_code_tidymess.rst new file mode 100644 index 0000000000..43297b0b4a --- /dev/null +++ b/doc/tutorial/adding_example_code_tidymess.rst @@ -0,0 +1,66 @@ +.. _adding_example_code_tidymess: + +Adding a C++ N-Body Code to AMUSE +================================= + +In this tutorial, we will create an interface from scratch for the +TIdal DYnamics of Multi-body ExtraSolar Systems code, or ``TIDYMESS``, +written by Dr. Tjarda Boekholt and Dr. Alexandre Correia. This code +implements detailed tidal forces into an N-body code to track the deformation +of bodies. This community code has already been implemented into AMUSE so you +can follow along this tutorial. + +Getting Started +=============== + +This tutorial assumes you have a working amuse or amuse development build, +preferrably in seperated environment (virtualenv, venv or conda etc). +Please ensure that amuse is setup correctly, this can be verified by running the +``amusifier`` . + +.. code-block:: bash + + > amusifier --help + +Naming our project +~~~~~~~~~~~~~~~~~~ +Amuse naming conventions typically follows PascalCase, so we will name our project Tidymess. + +Creating the initial directory structure +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +To start, we need to create the directory structure for ``Tidymess``, along with the +necessary files to build our interface. The fastest method to setup the directory is +by using the ``amusifier`` script with ``--mode=dir``. + +Since ``TIDYMESS`` is a native C++ code with no other dependencies, we will specify +``--type=c``, but the ``amusifier`` can also build the interface directory for +``f90`` and ``python`` codes. + +.. code-block:: bash + + > amusifier --type=c --mode=dir Tidymess + +Having run the ``amusifier``, we now have our new directory in ``amuse/src/amuse_tidymess``. +There should be all the required folders for building our interface, as well as a few code +stubs to expand upon. + +Building the code +================= +Before we start working on the interface, we should try and install and compile ``TIDYMESS`` +inside of ``AMUSE``. + +Defining dependencies +~~~~~~~~~~~~~~~~~~~~~ +The ``AMUSE`` build system needs to know what packages and libraries our project depends on. +Navigate to ``amuse_tidymess/packages/amuse_tidymess.amuse_deps``, which is where we define every +dependency we will need. By default it will look like: + +.. code-block:: text + + c c++ fortran java python cmake install download mpi openmp cuda opencl x11 opengl blas lapack gsl gmp mpfr fftw hdf5 netcdf4 + +Since ``TIDYMESS`` is a standalone C++ code, we can simplify our dependencies to: + +.. code-block:: text + + c c++ From e1cdab5242946a71a827a7d4e2340401517fd719 Mon Sep 17 00:00:00 2001 From: elkogerville Date: Fri, 29 May 2026 12:17:10 +0200 Subject: [PATCH 03/31] more docs on adding tidymess to amuse --- doc/tutorial/adding_example_code_tidymess.rst | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/doc/tutorial/adding_example_code_tidymess.rst b/doc/tutorial/adding_example_code_tidymess.rst index 43297b0b4a..1f4dfaabd6 100644 --- a/doc/tutorial/adding_example_code_tidymess.rst +++ b/doc/tutorial/adding_example_code_tidymess.rst @@ -59,8 +59,23 @@ dependency we will need. By default it will look like: c c++ fortran java python cmake install download mpi openmp cuda opencl x11 opengl blas lapack gsl gmp mpfr fftw hdf5 netcdf4 -Since ``TIDYMESS`` is a standalone C++ code, we can simplify our dependencies to: +Since ``TIDYMESS`` is a standalone C++ code, we can delete most of those and simplify our dependencies to: .. code-block:: text c c++ + +Setting up Autoconf +~~~~~~~~~~~~~~~~~~~ +The ``amuse_deps`` file we just created informs the ``AMUSE`` build system about whether or not our +package is buildable given the available compilers and libraries detected on your computer. We now need +to determine what compilers and libraries are on the system and how to use them. For this we will edit +the ``configure.ac`` file in ``amuse_tidymess/support/``. This file contains a set of macros which will +detect the tools and libraries needed to build our package. The template should contain all the macros +needed for our package, so its just a matter of deleting what we don't need. + +.. WARNING:: + + Make sure the the ``amuse_tidymess/support/shared/`` folder is a simlink to ``amuse/support/shared/`` + to ensure that there is no code duplication in the codebase, and that bug fixes are propagated to each + package automatically. From cc3f2ffbb8449331a6e0efa6857d9db9c0ff5f6d Mon Sep 17 00:00:00 2001 From: elkogerville Date: Fri, 29 May 2026 15:58:59 +0200 Subject: [PATCH 04/31] more sections on tidymess docs --- doc/tutorial/adding_example_code_tidymess.rst | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/doc/tutorial/adding_example_code_tidymess.rst b/doc/tutorial/adding_example_code_tidymess.rst index 1f4dfaabd6..af73f53be7 100644 --- a/doc/tutorial/adding_example_code_tidymess.rst +++ b/doc/tutorial/adding_example_code_tidymess.rst @@ -10,6 +10,12 @@ implements detailed tidal forces into an N-body code to track the deformation of bodies. This community code has already been implemented into AMUSE so you can follow along this tutorial. +.. NOTE:: + + In this guide, ``TIDYMESS`` refers to the standalone simulation package, + while ``Tidymess`` refers to the ``TIDYMESS`` package inside of ``AMUSE``. + + Getting Started =============== @@ -72,10 +78,26 @@ package is buildable given the available compilers and libraries detected on you to determine what compilers and libraries are on the system and how to use them. For this we will edit the ``configure.ac`` file in ``amuse_tidymess/support/``. This file contains a set of macros which will detect the tools and libraries needed to build our package. The template should contain all the macros -needed for our package, so its just a matter of deleting what we don't need. +needed for our package, so its just a matter of deleting what we don't need. Delete any comment prefaced +with ``#####``, but only after following the direction of the comment. + +Once ``configure.ac`` is setup correctly, we can edit ``config.mk.in``, and remove any unneeded variables +as well as any ``#####`` comment. This file is a template for ``config.mk``, which will contain a description +of all the compiler and library variables needed for our package. + +Once these files are cleaned up, run ``autoreconf`` to (re)create the ``configure`` script, then run +``./configure``. This will test the detection and check for errors. As a sanity check, run ``cat config.mk`` +and ensure that there are no ``@VARIABLE@`` symbols left! If there are, check that ``configure.ac`` and +``config.mk.in`` were setup correctly. .. WARNING:: Make sure the the ``amuse_tidymess/support/shared/`` folder is a simlink to ``amuse/support/shared/`` to ensure that there is no code duplication in the codebase, and that bug fixes are propagated to each - package automatically. + package automatically. This should be done automatically by the ``amusifier`` but can be a source of bugs + if not setup correctly. + +Setting up the Makefile +~~~~~~~~~~~~~~~~~~~~~~~ +With our build system detection working, we now need to download ``TIDYMESS`` into ``AMUSE``! +This is where the Makefiles come in. ``AMUSE`` packages typically have 2 Makefiles. From 4eb451ad76930e108e0aa83e97a7ec08777fc298 Mon Sep 17 00:00:00 2001 From: elkogerville Date: Mon, 1 Jun 2026 19:27:13 +0200 Subject: [PATCH 05/31] started section on creating tidymess interface --- doc/tutorial/adding_example_code_tidymess.rst | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/doc/tutorial/adding_example_code_tidymess.rst b/doc/tutorial/adding_example_code_tidymess.rst index af73f53be7..5c73d4afec 100644 --- a/doc/tutorial/adding_example_code_tidymess.rst +++ b/doc/tutorial/adding_example_code_tidymess.rst @@ -101,3 +101,45 @@ Setting up the Makefile ~~~~~~~~~~~~~~~~~~~~~~~ With our build system detection working, we now need to download ``TIDYMESS`` into ``AMUSE``! This is where the Makefiles come in. ``AMUSE`` packages typically have 2 Makefiles. + + +Creating the Interfaces +======================= +With ``TIDYMESS`` compiled into ``AMUSE``, we can now begin the process of creating our interface! +The interface system allows community codes, which are all unique and depend on diverse libraries and +programming languages, to communicate with the ``AMUSE`` framework, which is native Python. ``AMUSE`` +interfaces define a number of interface functions, which provide a standardized way for ``AMUSE`` to +communicate with each community code. This way, the experience of using any ``AMUSE`` code is identical: +all codes can be evolved with the ``evolve_model`` method, particles are represented as +``amuse.datamodel.particles``, etc... The strength of ``AMUSE`` lies in its ability to prototype quickly: +If the user wants to see what solution a different code would give for the same calculation, all they have +to do is switch which code they are using, and the script most likely does not need to change. + +Therefore, our job when creating an interface is to map the community code functions to the ``AMUSE`` interface +functions. The amusifier already created all the files we need: the ``interface.py`` and the ``interface.cc``. + +Defining the Python interface +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +The ``interface.py`` actually defines two classes: the high-level and low-level Python interfaces. The high-level +interface is what the user interacts with when using the community code. This defines the methods, parameters, +and properties of each community code, and defines how the ``amuse.datamodel.particles`` work within that code. +The ``amusifer`` generates a minimal code stub for the ``interface.py``, which is enough to get us started. +The process of defining our interface starts with figuring out what type of code we are adding to ``AMUSE``. +``AMUSE`` has a set of predefined Python interfaces we can use to build our interface from. + + ++----------------------------------+-------------------------------------------+ +| Interface: | Example codes: | ++----------------------------------+-------------------------------------------+ +| ``GravitationDynamicsInterface`` | N-body: Tidymess, Ph4, Huyano | ++----------------------------------+-------------------------------------------+ +| ``HydrodynamicsInterface`` | Hydrodynamical: Capreole | ++----------------------------------+-------------------------------------------+ +| ``MagnetoHydrodynamicsInterface``| MHD: Athena | ++----------------------------------+-------------------------------------------+ +| ``StellarEvolutionInterface`` | Stellar: MESA, EVtwin, SeBa | ++----------------------------------+-------------------------------------------+ + +These interfaces define many +of the required interface functions so that we don't have to. +In this case, ``TIDYMESS`` is a N-Body code, and therefore falls under the From b84528b6ab97e4db66da802ef67336827ecbcd09 Mon Sep 17 00:00:00 2001 From: elkogerville Date: Tue, 2 Jun 2026 16:09:04 +0200 Subject: [PATCH 06/31] typo fixes and improvments on adding tidymess example code --- doc/tutorial/adding_example_code_tidymess.rst | 53 ++++++++++++++++--- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/doc/tutorial/adding_example_code_tidymess.rst b/doc/tutorial/adding_example_code_tidymess.rst index 5c73d4afec..12171cc3a2 100644 --- a/doc/tutorial/adding_example_code_tidymess.rst +++ b/doc/tutorial/adding_example_code_tidymess.rst @@ -20,8 +20,8 @@ Getting Started =============== This tutorial assumes you have a working amuse or amuse development build, -preferrably in seperated environment (virtualenv, venv or conda etc). -Please ensure that amuse is setup correctly, this can be verified by running the +preferably in seperated environment (virtualenv, venv or conda etc). +Please ensure that amuse is set up correctly, this can be verified by running the ``amusifier`` . .. code-block:: bash @@ -30,7 +30,7 @@ Please ensure that amuse is setup correctly, this can be verified by running the Naming our project ~~~~~~~~~~~~~~~~~~ -Amuse naming conventions typically follows PascalCase, so we will name our project Tidymess. +PEP-8 naming conventions for classes follows PascalCase, so we will name our project Tidymess. Creating the initial directory structure ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -40,10 +40,11 @@ by using the ``amusifier`` script with ``--mode=dir``. Since ``TIDYMESS`` is a native C++ code with no other dependencies, we will specify ``--type=c``, but the ``amusifier`` can also build the interface directory for -``f90`` and ``python`` codes. +``f90`` and ``python`` codes. Make sure you run the ``amusifier`` in the ``amuse/src/`` directory. .. code-block:: bash + > cd amuse/src/ > amusifier --type=c --mode=dir Tidymess Having run the ``amusifier``, we now have our new directory in ``amuse/src/amuse_tidymess``. @@ -52,7 +53,7 @@ stubs to expand upon. Building the code ================= -Before we start working on the interface, we should try and install and compile ``TIDYMESS`` +Before we start working on the interface, we should try to install and compile ``TIDYMESS`` inside of ``AMUSE``. Defining dependencies @@ -69,7 +70,43 @@ Since ``TIDYMESS`` is a standalone C++ code, we can delete most of those and sim .. code-block:: text - c c++ + c++ + +To test that we did everything properly, we can run the ``./setup`` script from the root directory of ``AMUSE``:: + + > cd amuse/ + > ./setup + Checking for dependencies, one moment please... + + *** Configuration complete *** + Detected features: c c++ fortran python python-dev gmake cmake install download patch tar unzip gunzip bunzip2 unxz perl bison mpi openmp blas lapack gsl gmp mpfr fftw libz hdf5 netcdf4 qhull healpix-cxx + + ** Enabled packages ** + + Packages marked i) are currently installed. + + i) amuse-framework amuse-hop amuse-petar + amuse-aarsethzare amuse-huayno-openmp amuse-ph4 + amuse-adaptb amuse-huayno amuse-phantom + amuse-athena amuse-kepler amuse-phigrape + amuse-bhtree amuse-kepler-orbiters amuse-rebound + amuse-brutus amuse-krome amuse-sakura + amuse-bse amuse-mameclot amuse-seba + amuse-capreole amuse-mercury amuse-secularmultiple + amuse-evtwin amuse-mesa-r15140 amuse-sei + amuse-fastkick amuse-mesa-r2208 amuse-simplex + amuse-fi amuse-mi6 amuse-smalln + amuse-fractalcluster amuse-mikkola amuse-sphray + amuse-gadget2 amuse-mmams amuse-sse + amuse-galactics amuse-mobse amuse-symple + amuse-galaxia amuse-mocassin amuse-tidymess + amuse-halogen amuse-mosse amuse-tupan + amuse-hermite amuse-mpiamrvac amuse-twobody + amuse-hermite-grx amuse-nbody6xx amuse-vader + +We can see that the ``AMUSE`` framework is correctly installed, indicated by the ``i)`` symbol. We can +also see our package ``amuse-tidymess`` is listed meaning the ``AMUSE`` build system now knows of our project +and we are ready to move on! Setting up Autoconf ~~~~~~~~~~~~~~~~~~~ @@ -92,7 +129,7 @@ and ensure that there are no ``@VARIABLE@`` symbols left! If there are, check th .. WARNING:: - Make sure the the ``amuse_tidymess/support/shared/`` folder is a simlink to ``amuse/support/shared/`` + Make sure the the ``amuse_tidymess/support/shared/`` folder is a symlink to ``amuse/support/shared/`` to ensure that there is no code duplication in the codebase, and that bug fixes are propagated to each package automatically. This should be done automatically by the ``amusifier`` but can be a source of bugs if not setup correctly. @@ -131,7 +168,7 @@ The process of defining our interface starts with figuring out what type of code +----------------------------------+-------------------------------------------+ | Interface: | Example codes: | +----------------------------------+-------------------------------------------+ -| ``GravitationDynamicsInterface`` | N-body: Tidymess, Ph4, Huyano | +| ``GravitationDynamicsInterface`` | N-body: Tidymess, Ph4, Huayano | +----------------------------------+-------------------------------------------+ | ``HydrodynamicsInterface`` | Hydrodynamical: Capreole | +----------------------------------+-------------------------------------------+ From 7759a39b7d086f53dbbed450ac9fdb98bb4fd6fd Mon Sep 17 00:00:00 2001 From: elkogerville Date: Tue, 2 Jun 2026 16:16:33 +0200 Subject: [PATCH 07/31] more doc revisions --- doc/tutorial/adding_example_code_tidymess.rst | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/doc/tutorial/adding_example_code_tidymess.rst b/doc/tutorial/adding_example_code_tidymess.rst index 12171cc3a2..c9c4a31243 100644 --- a/doc/tutorial/adding_example_code_tidymess.rst +++ b/doc/tutorial/adding_example_code_tidymess.rst @@ -30,7 +30,7 @@ Please ensure that amuse is set up correctly, this can be verified by running th Naming our project ~~~~~~~~~~~~~~~~~~ -PEP-8 naming conventions for classes follows PascalCase, so we will name our project Tidymess. +PEP-8 naming conventions for classes follows PascalCase, so we will name our project ``Tidymess``. Creating the initial directory structure ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -72,10 +72,11 @@ Since ``TIDYMESS`` is a standalone C++ code, we can delete most of those and sim c++ -To test that we did everything properly, we can run the ``./setup`` script from the root directory of ``AMUSE``:: +To test that we did everything properly, we can run ``./setup`` from the top-level directory of ``AMUSE``:: > cd amuse/ > ./setup + Checking for dependencies, one moment please... *** Configuration complete *** @@ -110,9 +111,7 @@ and we are ready to move on! Setting up Autoconf ~~~~~~~~~~~~~~~~~~~ -The ``amuse_deps`` file we just created informs the ``AMUSE`` build system about whether or not our -package is buildable given the available compilers and libraries detected on your computer. We now need -to determine what compilers and libraries are on the system and how to use them. For this we will edit +We now need to determine what compilers and libraries are on the system and how to use them. For this we will edit the ``configure.ac`` file in ``amuse_tidymess/support/``. This file contains a set of macros which will detect the tools and libraries needed to build our package. The template should contain all the macros needed for our package, so its just a matter of deleting what we don't need. Delete any comment prefaced From 436762441a77e203d243eedf286cf704201b1a0a Mon Sep 17 00:00:00 2001 From: elkogerville Date: Tue, 2 Jun 2026 16:34:27 +0200 Subject: [PATCH 08/31] expanded configure section of adding tidymess docs --- doc/tutorial/adding_example_code_tidymess.rst | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/doc/tutorial/adding_example_code_tidymess.rst b/doc/tutorial/adding_example_code_tidymess.rst index c9c4a31243..affdd5a72f 100644 --- a/doc/tutorial/adding_example_code_tidymess.rst +++ b/doc/tutorial/adding_example_code_tidymess.rst @@ -115,11 +115,17 @@ We now need to determine what compilers and libraries are on the system and how the ``configure.ac`` file in ``amuse_tidymess/support/``. This file contains a set of macros which will detect the tools and libraries needed to build our package. The template should contain all the macros needed for our package, so its just a matter of deleting what we don't need. Delete any comment prefaced -with ``#####``, but only after following the direction of the comment. +with ``#####``, but only after following the direction of the comment. Since ``TIDYMESS`` is a native C++ code, +most of the optional macros can be deleted, especially the ones related to external libraries like ``CUDA``, +``MPI``, ``FFTW``, etc... The only library we will keep is ``AMUSE_LIB_STOPCOND()`` for enabling stopping +conditions in our project, as well as ``AMUSE_DOWNLOAD()`` and ``AC_CHECK_TOOL(TAR, tar)`` for dynamically +downloading ``TIDYMESS`` from github into our project when the user tries to install it (so we don't need to package +the source code directly into ``AMUSE``). Once ``configure.ac`` is setup correctly, we can edit ``config.mk.in``, and remove any unneeded variables as well as any ``#####`` comment. This file is a template for ``config.mk``, which will contain a description -of all the compiler and library variables needed for our package. +of all the compiler and library variables needed for our package. Just like ``configure.ac``, the only optional variables +we will keep are again related to the ``STOPCOND`` library and downloading our package. Once these files are cleaned up, run ``autoreconf`` to (re)create the ``configure`` script, then run ``./configure``. This will test the detection and check for errors. As a sanity check, run ``cat config.mk`` @@ -164,17 +170,17 @@ The process of defining our interface starts with figuring out what type of code ``AMUSE`` has a set of predefined Python interfaces we can use to build our interface from. -+----------------------------------+-------------------------------------------+ -| Interface: | Example codes: | -+----------------------------------+-------------------------------------------+ -| ``GravitationDynamicsInterface`` | N-body: Tidymess, Ph4, Huayano | -+----------------------------------+-------------------------------------------+ -| ``HydrodynamicsInterface`` | Hydrodynamical: Capreole | -+----------------------------------+-------------------------------------------+ -| ``MagnetoHydrodynamicsInterface``| MHD: Athena | -+----------------------------------+-------------------------------------------+ -| ``StellarEvolutionInterface`` | Stellar: MESA, EVtwin, SeBa | -+----------------------------------+-------------------------------------------+ ++-----------------------------------+-------------------------------------------+ +| Interface: | Example codes: | ++-----------------------------------+-------------------------------------------+ +| ``GravitationDynamicsInterface`` | N-body: Tidymess, Ph4, Huayano | ++-----------------------------------+-------------------------------------------+ +| ``HydrodynamicsInterface`` | Hydrodynamical: Capreole | ++-----------------------------------+-------------------------------------------+ +| ``MagnetoHydrodynamicsInterface`` | MHD: Athena | ++-----------------------------------+-------------------------------------------+ +| ``StellarEvolutionInterface`` | Stellar: MESA, EVtwin, SeBa | ++-----------------------------------+-------------------------------------------+ These interfaces define many of the required interface functions so that we don't have to. From 143162429645e468ff9cf2c3072487296da3f099 Mon Sep 17 00:00:00 2001 From: elkogerville Date: Tue, 2 Jun 2026 16:47:34 +0200 Subject: [PATCH 09/31] minor adjustment --- doc/tutorial/adding_example_code_tidymess.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/tutorial/adding_example_code_tidymess.rst b/doc/tutorial/adding_example_code_tidymess.rst index affdd5a72f..b2ba5a27d7 100644 --- a/doc/tutorial/adding_example_code_tidymess.rst +++ b/doc/tutorial/adding_example_code_tidymess.rst @@ -117,7 +117,7 @@ detect the tools and libraries needed to build our package. The template should needed for our package, so its just a matter of deleting what we don't need. Delete any comment prefaced with ``#####``, but only after following the direction of the comment. Since ``TIDYMESS`` is a native C++ code, most of the optional macros can be deleted, especially the ones related to external libraries like ``CUDA``, -``MPI``, ``FFTW``, etc... The only library we will keep is ``AMUSE_LIB_STOPCOND()`` for enabling stopping +``MPI``, ``FFTW``, etc... The only optional macros we will keep are ``AMUSE_LIB_STOPCOND()`` for enabling stopping conditions in our project, as well as ``AMUSE_DOWNLOAD()`` and ``AC_CHECK_TOOL(TAR, tar)`` for dynamically downloading ``TIDYMESS`` from github into our project when the user tries to install it (so we don't need to package the source code directly into ``AMUSE``). From af42fdc18d759b67476c3225f4974cd952f9e4f4 Mon Sep 17 00:00:00 2001 From: elkogerville Date: Fri, 26 Jun 2026 14:38:17 +0200 Subject: [PATCH 10/31] cleanup docs --- doc/tutorial/adding_example_code_tidymess.rst | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/doc/tutorial/adding_example_code_tidymess.rst b/doc/tutorial/adding_example_code_tidymess.rst index b2ba5a27d7..1855dbaab2 100644 --- a/doc/tutorial/adding_example_code_tidymess.rst +++ b/doc/tutorial/adding_example_code_tidymess.rst @@ -4,16 +4,17 @@ Adding a C++ N-Body Code to AMUSE ================================= In this tutorial, we will create an interface from scratch for the -TIdal DYnamics of Multi-body ExtraSolar Systems code, or ``TIDYMESS``, -written by Dr. Tjarda Boekholt and Dr. Alexandre Correia. This code -implements detailed tidal forces into an N-body code to track the deformation -of bodies. This community code has already been implemented into AMUSE so you +TIdal DYnamics of Multi-body ExtraSolar Systems code, or TIDYMESS, +written by Dr. Tjarda Boekholt and Dr. Alexandre Correia +(https://doi.org/10.48550/arXiv.2209.03955). This code implements detailed +tidal forces into an N-body code to track the deformation of bodies. +This community code has already been implemented into AMUSE so you can follow along this tutorial. .. NOTE:: - In this guide, ``TIDYMESS`` refers to the standalone simulation package, - while ``Tidymess`` refers to the ``TIDYMESS`` package inside of ``AMUSE``. + In this guide, TIDYMESS refers to the standalone simulation package, + while ``Tidymess`` refers to the TIDYMESS package inside of AMUSE. Getting Started @@ -38,7 +39,7 @@ To start, we need to create the directory structure for ``Tidymess``, along with necessary files to build our interface. The fastest method to setup the directory is by using the ``amusifier`` script with ``--mode=dir``. -Since ``TIDYMESS`` is a native C++ code with no other dependencies, we will specify +Since TIDYMESS is a native C++ code with no other dependencies, we will specify ``--type=c``, but the ``amusifier`` can also build the interface directory for ``f90`` and ``python`` codes. Make sure you run the ``amusifier`` in the ``amuse/src/`` directory. @@ -53,12 +54,12 @@ stubs to expand upon. Building the code ================= -Before we start working on the interface, we should try to install and compile ``TIDYMESS`` +Before we start working on the interface, we should try to install and compile TIDYMESS inside of ``AMUSE``. Defining dependencies ~~~~~~~~~~~~~~~~~~~~~ -The ``AMUSE`` build system needs to know what packages and libraries our project depends on. +The AMUSE build system needs to know what packages and libraries our project depends on. Navigate to ``amuse_tidymess/packages/amuse_tidymess.amuse_deps``, which is where we define every dependency we will need. By default it will look like: @@ -72,7 +73,9 @@ Since ``TIDYMESS`` is a standalone C++ code, we can delete most of those and sim c++ -To test that we did everything properly, we can run ``./setup`` from the top-level directory of ``AMUSE``:: +To test that we did everything properly, we can run ``./setup`` from the top-level directory of AMUSE + +.. code-block:: text > cd amuse/ > ./setup @@ -80,7 +83,9 @@ To test that we did everything properly, we can run ``./setup`` from the top-lev Checking for dependencies, one moment please... *** Configuration complete *** - Detected features: c c++ fortran python python-dev gmake cmake install download patch tar unzip gunzip bunzip2 unxz perl bison mpi openmp blas lapack gsl gmp mpfr fftw libz hdf5 netcdf4 qhull healpix-cxx + Detected features: c c++ fortran python python-dev gmake cmake install + download patch tar unzip gunzip bunzip2 unxz perl bison mpi openmp blas + lapack gsl gmp mpfr fftw libz hdf5 netcdf4 qhull healpix-cxx ** Enabled packages ** @@ -105,8 +110,8 @@ To test that we did everything properly, we can run ``./setup`` from the top-lev amuse-hermite amuse-mpiamrvac amuse-twobody amuse-hermite-grx amuse-nbody6xx amuse-vader -We can see that the ``AMUSE`` framework is correctly installed, indicated by the ``i)`` symbol. We can -also see our package ``amuse-tidymess`` is listed meaning the ``AMUSE`` build system now knows of our project +We can see that the AMUSE framework is correctly installed, indicated by the ``i)`` symbol. We can +also see our package ``amuse-tidymess`` is listed meaning the AMUSE build system now knows of our project and we are ready to move on! Setting up Autoconf @@ -115,12 +120,12 @@ We now need to determine what compilers and libraries are on the system and how the ``configure.ac`` file in ``amuse_tidymess/support/``. This file contains a set of macros which will detect the tools and libraries needed to build our package. The template should contain all the macros needed for our package, so its just a matter of deleting what we don't need. Delete any comment prefaced -with ``#####``, but only after following the direction of the comment. Since ``TIDYMESS`` is a native C++ code, +with ``#####``, but only after following the direction of the comment. Since TIDYMESS is a native C++ code, most of the optional macros can be deleted, especially the ones related to external libraries like ``CUDA``, ``MPI``, ``FFTW``, etc... The only optional macros we will keep are ``AMUSE_LIB_STOPCOND()`` for enabling stopping conditions in our project, as well as ``AMUSE_DOWNLOAD()`` and ``AC_CHECK_TOOL(TAR, tar)`` for dynamically -downloading ``TIDYMESS`` from github into our project when the user tries to install it (so we don't need to package -the source code directly into ``AMUSE``). +downloading TIDYMESS from github into our project when the user tries to install it (so we don't need to package +the source code directly into AMUSE). Once ``configure.ac`` is setup correctly, we can edit ``config.mk.in``, and remove any unneeded variables as well as any ``#####`` comment. This file is a template for ``config.mk``, which will contain a description From ae1dceebbc6c730593750c6a43ee95777004272e Mon Sep 17 00:00:00 2001 From: elkogerville Date: Fri, 26 Jun 2026 14:40:44 +0200 Subject: [PATCH 11/31] expanded dep section of docs --- doc/tutorial/adding_example_code_tidymess.rst | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/doc/tutorial/adding_example_code_tidymess.rst b/doc/tutorial/adding_example_code_tidymess.rst index 1855dbaab2..ec8eabfdde 100644 --- a/doc/tutorial/adding_example_code_tidymess.rst +++ b/doc/tutorial/adding_example_code_tidymess.rst @@ -137,6 +137,30 @@ Once these files are cleaned up, run ``autoreconf`` to (re)create the ``configur and ensure that there are no ``@VARIABLE@`` symbols left! If there are, check that ``configure.ac`` and ``config.mk.in`` were setup correctly. +.. code-block:: text + + > cd amuse/src/amuse_tidymess/support/ + > autoreconf + > ./configure + > cat config.mk + + # Compilers + CXX = arm64-apple-darwin20.0.0-clang++ + + MPICXX = mpicxx + + CPU_COUNT = 8 + + # Tools + AR = arm64-apple-darwin20.0.0-ar + RANLIB = arm64-apple-darwin20.0.0-ranlib + DOWNLOAD = curl -L + TAR = tar + + # AMUSE framework libraries + STOPCOND_CFLAGS = -I/Users/astro/miniconda3/envs/tidymess/include + STOPCOND_LIBS = -lstopcond + .. WARNING:: Make sure the the ``amuse_tidymess/support/shared/`` folder is a symlink to ``amuse/support/shared/`` From 6bb5d486814043cf07752d3820bce1179cec3c08 Mon Sep 17 00:00:00 2001 From: elkogerville Date: Fri, 26 Jun 2026 14:45:47 +0200 Subject: [PATCH 12/31] added makefile section to docs --- doc/tutorial/adding_example_code_tidymess.rst | 148 +++++++++++++++++- 1 file changed, 145 insertions(+), 3 deletions(-) diff --git a/doc/tutorial/adding_example_code_tidymess.rst b/doc/tutorial/adding_example_code_tidymess.rst index ec8eabfdde..0588bebce4 100644 --- a/doc/tutorial/adding_example_code_tidymess.rst +++ b/doc/tutorial/adding_example_code_tidymess.rst @@ -170,9 +170,150 @@ and ensure that there are no ``@VARIABLE@`` symbols left! If there are, check th Setting up the Makefile ~~~~~~~~~~~~~~~~~~~~~~~ -With our build system detection working, we now need to download ``TIDYMESS`` into ``AMUSE``! -This is where the Makefiles come in. ``AMUSE`` packages typically have 2 Makefiles. +With our build system detection working, we now need to download TIDYMESS into AMUSE and compile the code. +The ``amusifier`` already created our ``Makefile`` for us in ``src/amuse_tidymess/``, which has most of the code we +will need for this step. The ``Makefile`` has several responsibilities: downloading and patching the community code +source, compiling it into a static library, and linking that library with the auto-generated worker stub to produce +the ``tidymess_worker``. This is the executable AMUSE spawns to communicate with the community code at runtime. +The first thing to do is to set the ``VERSION`` variable at the top of the ``Makefile`` to the correct commit hash +or tag of TIDYMESS. AMUSE does not bundle the source code of each community code: it downloads it dynamically at install +time and pins it to a specific ``VERSION``. This decouples AMUSE from upstream changes, and makes version upgrades easy +by simply changing the commit hash. Thankfully, TIDYMESS is open source, so we can freely download it +from GitHub. + +.. code-block:: make + + # Downloading the code + VERSION = 4f97bfe11e8c638fdda744ca288e57565efe718a + + tidymess.tar.gz: + $(DOWNLOAD) https://github.com/tidymess-code/tidymess/archive/$(VERSION).tar.gz >$@ + + src/tidymess: tidymess.tar.gz + tar xf $< + mv tidymess-$(VERSION) src/tidymess + +AMUSE will download ``tidymess.tar.gz`` from github, unpack it with the ``tar`` command, and move the newly downloaded +TIDYMESS source code into ``amuse/src/amuse_tidymess/src``. + +The next step is to build the code into a static library. The ``amusifier`` generated ``Makefile`` will have all the +flags needed for every AMUSE dependency by default, so we must remove any flag added to ``DEPFLAGS`` that will not +be used by ``Tidymess``. These flags are generated from running ``./configure`` and are found in ``config.mk``! + +.. code-block:: make + + ##### Remove anything not needed ##### + DEPFLAGS += $(STOPCOND_CFLAGS) $(STOPCONDMPI_CFLAGS) $(AMUSE_MPI_CFLAGS) + DEPFLAGS += $(SIMPLE_HASH_CFLAGS) $(G6LIB_CFLAGS) + DEPFLAGS += $(SAPPORO_LIGHT_CFLAGS) + + ##### Pick whichever language is applicable for the code ##### + DEPFLAGS += $(OPENMP_CFLAGS) $(OPENMP_FFLAGS) $(OPENMP_CXXFLAGS) + + ##### Remove anything not needed ##### + DEPFLAGS += $(CUDA_FLAGS) + DEPFLAGS += $(CL_CFLAGS) + ##### LAPACK doesn't have flags, only libs... ##### + DEPFLAGS += $(GSL_FLAGS) + DEPFLAGS += $(GMP_FLAGS) + DEPFLAGS += $(MPFR_FLAGS) + DEPFLAGS += $(FFTW_FLAGS) + CFLAGS += $(DEPFLAGS) + LDFLAGS += $(CUDA_LDFLAGS) + + LDLIBS += -lm $(STOPCOND_LIBS) $(STOPCONDMPI_LIBS) $(AMUSE_MPI_LIBS) + LDLIBS += $(SIMPLE_HASH_LIBS) $(G6LIB_LIBS) + LDLIBS += $(SAPPORO_LIGHT_LIBS) + + # TODO CUDA, anything else? + LDLIBS += $(CL_LIBS) + LDLIBS += $(LAPACK_LIBS) $(BLAS_LIBS) $(LIBS) $(FLIBS) + LDLIBS += $(GSL_LIBS) + LDLIBS += $(GMP_LIBS) + LDLIBS += $(MPFR_LIBS) + LDLIBS += $(FFTW_LIBS) + +Since TIDYMESS only depends on C++, we can remove most of the flags. We will keep the ``STOPCOND`` related flags +to keep stopping conditions support in our package. + +.. code-block:: make + + # Building the code into a static library + DEPFLAGS += $(STOPCOND_CFLAGS) + CXXFLAGS += $(DEPFLAGS) + + LDLIBS += -lm $(STOPCOND_LIBS) + +We can then move on to compiling TIDYMESS as a static library (``libtidymess.a``). The ``|`` before ``src/tidymess`` +signifies an **order-only prerequisite**, which ensures that the source code is extracted before compilation, +but is not redownloaded even if the timestep changes. This is so that we only redownload the source +code if it is missing. + +.. code-block:: make + + CODELIB = src/libtidymess.a + + .PHONY: $(CODELIB) + $(CODELIB): | src/tidymess + $(MAKE) -C src -j $(CPU_COUNT) all + +The last step is linking, where the ``amusifier`` reads the ``interface.py`` and generates the +worker ``tidymess_worker.cc``. + +.. code-block:: make + + # Building the workers + tidymess_worker.h: interface.py + amusifier --type=h interface.py TidymessInterface -o $@ + + tidymess_worker.cc: interface.py + amusifier --type=c interface.py TidymessInterface -o $@ + + tidymess_worker.o: tidymess_worker.cc tidymess_worker.h + $(MPICXX) -c -o $@ $(CXXFLAGS) $< + + tidymess_worker: interface.o tidymess_worker.o $(CODELIB) + $(MPICXX) -o $@ $(LDFLAGS) $^ $(LDLIBS) + + interface.o: interface.cc tidymess_worker.h | src/tidymess + $(MPICXX) -o $@ -c -I src/tidymess/integrator/include $(CXXFLAGS) $< + +The final bits of code at the end of the Makefile are for building and installing the package, as well +as defining how to uninstall and cleanup the package. + +.. code-block:: make + + # Which packages contain which workers? + amuse-tidymess_contains: tidymess_worker + + # Building and installing packages + develop-%: %_contains + support/shared/uninstall.sh $* + python -m pip install -e packages/$* + + install-%: %_contains + support/shared/uninstall.sh $* + python -m pip install packages/$* + + package-%: %_contains + python3 -m pip install -vv --no-cache-dir --no-deps --no-build-isolation --prefix ${PREFIX} packages/$* + + test-%: + cd packages/$* && pytest + + # Cleaning up + .PHONY: clean + clean: + $(MAKE) -C src clean + rm -rf *.o *worker* + + .PHONY: distclean + distclean: clean + rm -f support/config.mk support/config.log support/config.status + rm -rf support/autom4te.cache + +A typical AMUSE package will have a second ``Makefile`` Creating the Interfaces ======================= @@ -189,6 +330,7 @@ to do is switch which code they are using, and the script most likely does not n Therefore, our job when creating an interface is to map the community code functions to the ``AMUSE`` interface functions. The amusifier already created all the files we need: the ``interface.py`` and the ``interface.cc``. + Defining the Python interface ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The ``interface.py`` actually defines two classes: the high-level and low-level Python interfaces. The high-level @@ -202,7 +344,7 @@ The process of defining our interface starts with figuring out what type of code +-----------------------------------+-------------------------------------------+ | Interface: | Example codes: | +-----------------------------------+-------------------------------------------+ -| ``GravitationDynamicsInterface`` | N-body: Tidymess, Ph4, Huayano | +| ``GravitationDynamicsInterface`` | N-body: Tidymess, Ph4, Huayno | +-----------------------------------+-------------------------------------------+ | ``HydrodynamicsInterface`` | Hydrodynamical: Capreole | +-----------------------------------+-------------------------------------------+ From 52b136ca577b101f3766e4239376b35c573afdca Mon Sep 17 00:00:00 2001 From: elkogerville Date: Thu, 1 Oct 2026 16:55:33 +0200 Subject: [PATCH 13/31] update makefile section of docs --- doc/tutorial/adding_example_code_tidymess.rst | 194 ++++++++++++------ 1 file changed, 129 insertions(+), 65 deletions(-) diff --git a/doc/tutorial/adding_example_code_tidymess.rst b/doc/tutorial/adding_example_code_tidymess.rst index 0588bebce4..25c2021247 100644 --- a/doc/tutorial/adding_example_code_tidymess.rst +++ b/doc/tutorial/adding_example_code_tidymess.rst @@ -166,89 +166,83 @@ and ensure that there are no ``@VARIABLE@`` symbols left! If there are, check th Make sure the the ``amuse_tidymess/support/shared/`` folder is a symlink to ``amuse/support/shared/`` to ensure that there is no code duplication in the codebase, and that bug fixes are propagated to each package automatically. This should be done automatically by the ``amusifier`` but can be a source of bugs - if not setup correctly. + if not setup correctly. You can verify it with: + + .. code-block:: console + + > cd amuse/src/amuse_tidymess/support/ + > ls -l + + You should see: + + .. code-block:: text + + lrwxr-xr-x 1 user user 24 May 13 16:16 shared -> ../../../support/shared/ + Setting up the Makefile -~~~~~~~~~~~~~~~~~~~~~~~ -With our build system detection working, we now need to download TIDYMESS into AMUSE and compile the code. -The ``amusifier`` already created our ``Makefile`` for us in ``src/amuse_tidymess/``, which has most of the code we -will need for this step. The ``Makefile`` has several responsibilities: downloading and patching the community code -source, compiling it into a static library, and linking that library with the auto-generated worker stub to produce -the ``tidymess_worker``. This is the executable AMUSE spawns to communicate with the community code at runtime. - -The first thing to do is to set the ``VERSION`` variable at the top of the ``Makefile`` to the correct commit hash -or tag of TIDYMESS. AMUSE does not bundle the source code of each community code: it downloads it dynamically at install -time and pins it to a specific ``VERSION``. This decouples AMUSE from upstream changes, and makes version upgrades easy -by simply changing the commit hash. Thankfully, TIDYMESS is open source, so we can freely download it -from GitHub. +======================= +The ``amusifier`` already created our ``Makefile`` +for us in ``src/amuse_tidymess/``, which has most of the code we will need for this step. The ``Makefile`` +has several responsibilities: downloading and patching the community code source, compiling it into a static library, +and linking that library with the auto-generated worker stub to produce the ``tidymess_worker``. + +Downloading and patching the source +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +AMUSE does not bundle community code sources. The ``Makefile`` downloads a +pinned release at install time, which decouples AMUSE from upstream changes. +Three edits are needed: + +1. Set ``VERSION`` to the upstream commit hash or tag. +2. Set the URL in the ``tidymess.tar.gz`` rule to match the upstream archive. +3. Set the extraction target. This rule unpacks the archive and moves the + resulting directory into ``src/``. The extracted directory is named + ``tidymess-$(VERSION)``, so the generated target + ``src/tidymess-$(VERSION)`` changes with every version. Renaming it with + ``mv`` to the fixed name ``src/tidymess`` keeps all later paths + independent of ``VERSION``. .. code-block:: make - # Downloading the code VERSION = 4f97bfe11e8c638fdda744ca288e57565efe718a tidymess.tar.gz: - $(DOWNLOAD) https://github.com/tidymess-code/tidymess/archive/$(VERSION).tar.gz >$@ + $(DOWNLOAD) https://github.com/tidymess-code/tidymess/archive/$(VERSION).tar.gz >$@ src/tidymess: tidymess.tar.gz tar xf $< mv tidymess-$(VERSION) src/tidymess -AMUSE will download ``tidymess.tar.gz`` from github, unpack it with the ``tar`` command, and move the newly downloaded -TIDYMESS source code into ``amuse/src/amuse_tidymess/src``. - -The next step is to build the code into a static library. The ``amusifier`` generated ``Makefile`` will have all the -flags needed for every AMUSE dependency by default, so we must remove any flag added to ``DEPFLAGS`` that will not -be used by ``Tidymess``. These flags are generated from running ``./configure`` and are found in ``config.mk``! +If for some reason the source code needs to be modified, the ``Makefile`` allows us to +include ``.patch`` files to override the source code. Tidymess needs no patches, so we can +safely skip this step. + +Selecting compiler flags +~~~~~~~~~~~~~~~~~~~~~~~~ +The generated ``Makefile`` adds the flags and libraries of every dependency +AMUSE supports (``DEPFLAGS`` for compilation, ``LDLIBS`` for linking). The +values come from ``config.mk``, which ``./configure`` generates. Edits: + +1. Delete every dependency the code does not use. Each retained one adds a + link-time requirement and can fail the build on systems lacking that library. + Since Tidymess has no external libraries, delete any flag related to CUDA, + GSL, GMP, FFTW, etc... +2. Keep only the variants matching the code's language. TIDYMESS is a C++ code + so any Fortran related flags should be deleted. +3. Append ``DEPFLAGS`` to the variable matching the compiler: ``CXXFLAGS`` + for C++ (the template uses ``CFLAGS``). +4. Remove linker-related lines the code does not need (``LDLIBS``). + We keep ``STOPCOND`` to support AMUSE stopping conditions. .. code-block:: make - ##### Remove anything not needed ##### - DEPFLAGS += $(STOPCOND_CFLAGS) $(STOPCONDMPI_CFLAGS) $(AMUSE_MPI_CFLAGS) - DEPFLAGS += $(SIMPLE_HASH_CFLAGS) $(G6LIB_CFLAGS) - DEPFLAGS += $(SAPPORO_LIGHT_CFLAGS) - - ##### Pick whichever language is applicable for the code ##### - DEPFLAGS += $(OPENMP_CFLAGS) $(OPENMP_FFLAGS) $(OPENMP_CXXFLAGS) - - ##### Remove anything not needed ##### - DEPFLAGS += $(CUDA_FLAGS) - DEPFLAGS += $(CL_CFLAGS) - ##### LAPACK doesn't have flags, only libs... ##### - DEPFLAGS += $(GSL_FLAGS) - DEPFLAGS += $(GMP_FLAGS) - DEPFLAGS += $(MPFR_FLAGS) - DEPFLAGS += $(FFTW_FLAGS) - CFLAGS += $(DEPFLAGS) - LDFLAGS += $(CUDA_LDFLAGS) - - LDLIBS += -lm $(STOPCOND_LIBS) $(STOPCONDMPI_LIBS) $(AMUSE_MPI_LIBS) - LDLIBS += $(SIMPLE_HASH_LIBS) $(G6LIB_LIBS) - LDLIBS += $(SAPPORO_LIGHT_LIBS) - - # TODO CUDA, anything else? - LDLIBS += $(CL_LIBS) - LDLIBS += $(LAPACK_LIBS) $(BLAS_LIBS) $(LIBS) $(FLIBS) - LDLIBS += $(GSL_LIBS) - LDLIBS += $(GMP_LIBS) - LDLIBS += $(MPFR_LIBS) - LDLIBS += $(FFTW_LIBS) - -Since TIDYMESS only depends on C++, we can remove most of the flags. We will keep the ``STOPCOND`` related flags -to keep stopping conditions support in our package. - -.. code-block:: make - - # Building the code into a static library DEPFLAGS += $(STOPCOND_CFLAGS) CXXFLAGS += $(DEPFLAGS) LDLIBS += -lm $(STOPCOND_LIBS) -We can then move on to compiling TIDYMESS as a static library (``libtidymess.a``). The ``|`` before ``src/tidymess`` -signifies an **order-only prerequisite**, which ensures that the source code is extracted before compilation, -but is not redownloaded even if the timestep changes. This is so that we only redownload the source -code if it is missing. +Building the static library +~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: make @@ -258,8 +252,76 @@ code if it is missing. $(CODELIB): | src/tidymess $(MAKE) -C src -j $(CPU_COUNT) all -The last step is linking, where the ``amusifier`` reads the ``interface.py`` and generates the -worker ``tidymess_worker.cc``. +- ``CODELIB``: path of the static library, relative to this ``Makefile``. +- ``.PHONY``: the outer ``Makefile`` cannot see which files the inner build + depends on. Marking the library phony forces ``make -C src`` to run on every + invocation. The inner ``Makefile`` then decides what to recompile. +- ``| src/tidymess``: an order-only prerequisite. Normally, ``make`` rebuilds a target whenever one + of its prerequisites is newer than the target. An order-only prerequisite only + has to exist before the recipe runs, and its timestamp is ignored. In our case, + this means we will only redownload the source code if it is missing. This is very important + as otherwise any local edits would be overwritten when compiling! +- ``-j $(CPU_COUNT)``: compile in parallel. + +The inner Makefile +~~~~~~~~~~~~~~~~~~ +The outer ``Makefile`` delegates compilation to a second ``Makefile`` in +``src/amuse_tidymess/src/``. The ``amusifier`` also generates this one. It +must provide: + +- ``all``: builds the static library ``libtidymess.a`` in ``src/``. +- ``clean``: removes the build products. + +.. code-block:: make + + CFLAGS += -Wall -g + CXXFLAGS += $(CFLAGS) + + CODELIB := libtidymess.a + + SRCDIR := tidymess/integrator/src + INCDIR := tidymess/integrator/include + + SRC := $(wildcard $(SRCDIR)/*.cpp) + CODEOBJS := $(SRC:$(SRCDIR)/%.cpp=%.o) + + all: $(CODELIB) + + clean: + rm -f *.o *.a + + distclean: clean + + $(CODELIB): $(CODEOBJS) + rm -f $@ + $(AR) -ruv $@ $(CODEOBJS) + $(RANLIB) $@ + + %.o: $(SRCDIR)/%.cpp + $(CXX) $(CXXFLAGS) -c -o $@ -I$(INCDIR) $< + +TIDYMESS keeps its sources and headers in separate directories inside the +downloaded tree. ``SRCDIR`` tells ``make`` where to find the ``.cpp`` files, +and ``INCDIR`` is passed to the compiler with ``-I`` so that ``#include`` +directives resolve. Both are relative to the inner ``Makefile`` and must be +adapted to the layout of the community code. + +Building the worker +~~~~~~~~~~~~~~~~~~~ +The worker is the executable AMUSE spawns to communicate with the community +code. Building it takes three steps. + +1. Generate the stub. ``amusifier`` reads ``interface.py`` and writes + ``tidymess_worker.h`` and ``tidymess_worker.cc``. Both are rebuilt when + ``interface.py`` changes. +2. ``tidymess_worker.o`` compiles the stub. ``interface.o`` + compiles ``interface.cc``, which implements the functions the stub calls. + Its ``-I`` flag must point to the code's headers. It depends on + ``| src/tidymess`` so that the headers exist before compilation. +3. Link. ``tidymess_worker`` combines both objects with ``$(CODELIB)``. + +Package targets +~~~~~~~~~~~~~~~ .. code-block:: make @@ -279,6 +341,9 @@ worker ``tidymess_worker.cc``. interface.o: interface.cc tidymess_worker.h | src/tidymess $(MPICXX) -o $@ -c -I src/tidymess/integrator/include $(CXXFLAGS) $< +- ``amuse-tidymess_contains``: lists the workers the package ships. Add one worker per + line for multi-worker packages. It guarantees the workers are built before ``pip`` installs the package. + The final bits of code at the end of the Makefile are for building and installing the package, as well as defining how to uninstall and cleanup the package. @@ -313,7 +378,6 @@ as defining how to uninstall and cleanup the package. rm -f support/config.mk support/config.log support/config.status rm -rf support/autom4te.cache -A typical AMUSE package will have a second ``Makefile`` Creating the Interfaces ======================= From d503b24ee8b92b6f8cb730e094898cc1377f29bc Mon Sep 17 00:00:00 2001 From: elkogerville Date: Thu, 5 Nov 2026 16:17:47 +0100 Subject: [PATCH 14/31] update docs --- doc/tutorial/adding_example_code_tidymess.rst | 56 ++++++++++++------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/doc/tutorial/adding_example_code_tidymess.rst b/doc/tutorial/adding_example_code_tidymess.rst index 25c2021247..2500b0923d 100644 --- a/doc/tutorial/adding_example_code_tidymess.rst +++ b/doc/tutorial/adding_example_code_tidymess.rst @@ -29,10 +29,12 @@ Please ensure that amuse is set up correctly, this can be verified by running th > amusifier --help + Naming our project ~~~~~~~~~~~~~~~~~~ PEP-8 naming conventions for classes follows PascalCase, so we will name our project ``Tidymess``. + Creating the initial directory structure ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ To start, we need to create the directory structure for ``Tidymess``, along with the @@ -52,11 +54,13 @@ Having run the ``amusifier``, we now have our new directory in ``amuse/src/amuse There should be all the required folders for building our interface, as well as a few code stubs to expand upon. + Building the code ================= Before we start working on the interface, we should try to install and compile TIDYMESS inside of ``AMUSE``. + Defining dependencies ~~~~~~~~~~~~~~~~~~~~~ The AMUSE build system needs to know what packages and libraries our project depends on. @@ -114,6 +118,7 @@ We can see that the AMUSE framework is correctly installed, indicated by the ``i also see our package ``amuse-tidymess`` is listed meaning the AMUSE build system now knows of our project and we are ready to move on! + Setting up Autoconf ~~~~~~~~~~~~~~~~~~~ We now need to determine what compilers and libraries are on the system and how to use them. For this we will edit @@ -187,6 +192,7 @@ for us in ``src/amuse_tidymess/``, which has most of the code we will need for t has several responsibilities: downloading and patching the community code source, compiling it into a static library, and linking that library with the auto-generated worker stub to produce the ``tidymess_worker``. + Downloading and patching the source ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ AMUSE does not bundle community code sources. The ``Makefile`` downloads a @@ -217,6 +223,7 @@ If for some reason the source code needs to be modified, the ``Makefile`` allows include ``.patch`` files to override the source code. Tidymess needs no patches, so we can safely skip this step. + Selecting compiler flags ~~~~~~~~~~~~~~~~~~~~~~~~ The generated ``Makefile`` adds the flags and libraries of every dependency @@ -241,6 +248,7 @@ values come from ``config.mk``, which ``./configure`` generates. Edits: LDLIBS += -lm $(STOPCOND_LIBS) + Building the static library ~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -263,6 +271,7 @@ Building the static library as otherwise any local edits would be overwritten when compiling! - ``-j $(CPU_COUNT)``: compile in parallel. + The inner Makefile ~~~~~~~~~~~~~~~~~~ The outer ``Makefile`` delegates compilation to a second ``Makefile`` in @@ -306,6 +315,7 @@ and ``INCDIR`` is passed to the compiler with ``-I`` so that ``#include`` directives resolve. Both are relative to the inner ``Makefile`` and must be adapted to the layout of the community code. + Building the worker ~~~~~~~~~~~~~~~~~~~ The worker is the executable AMUSE spawns to communicate with the community @@ -320,9 +330,6 @@ code. Building it takes three steps. ``| src/tidymess`` so that the headers exist before compilation. 3. Link. ``tidymess_worker`` combines both objects with ``$(CODELIB)``. -Package targets -~~~~~~~~~~~~~~~ - .. code-block:: make # Building the workers @@ -341,11 +348,11 @@ Package targets interface.o: interface.cc tidymess_worker.h | src/tidymess $(MPICXX) -o $@ -c -I src/tidymess/integrator/include $(CXXFLAGS) $< -- ``amuse-tidymess_contains``: lists the workers the package ships. Add one worker per - line for multi-worker packages. It guarantees the workers are built before ``pip`` installs the package. -The final bits of code at the end of the Makefile are for building and installing the package, as well -as defining how to uninstall and cleanup the package. +Package targets +~~~~~~~~~~~~~~~ +The worker is the executable AMUSE spawns to communicate with the community +code. .. code-block:: make @@ -378,21 +385,26 @@ as defining how to uninstall and cleanup the package. rm -f support/config.mk support/config.log support/config.status rm -rf support/autom4te.cache +- ``amuse-tidymess_contains``: lists the workers the package ships. For multi-worker packages, list each worker here. + It guarantees the workers are built before ``pip`` installs the package. +- ``install`` and ``develop`` rules allow for both regular and develop install of the package. A develop install + means you do not need to recompile the code if any Python changes are made to either AMUSE or our interface. + Creating the Interfaces ======================= -With ``TIDYMESS`` compiled into ``AMUSE``, we can now begin the process of creating our interface! -The interface system allows community codes, which are all unique and depend on diverse libraries and -programming languages, to communicate with the ``AMUSE`` framework, which is native Python. ``AMUSE`` -interfaces define a number of interface functions, which provide a standardized way for ``AMUSE`` to -communicate with each community code. This way, the experience of using any ``AMUSE`` code is identical: -all codes can be evolved with the ``evolve_model`` method, particles are represented as -``amuse.datamodel.particles``, etc... The strength of ``AMUSE`` lies in its ability to prototype quickly: -If the user wants to see what solution a different code would give for the same calculation, all they have -to do is switch which code they are using, and the script most likely does not need to change. +With TIDYMESS compiled into AMUSE, we can begin creating the interface. An AMUSE community code is accessed +through two interfaces: a Python interface and a native interface. The user only calls the Python interface +(i.e. ``tidymess.evolve_model``). AMUSE handles this call and translates it into a call to the native interface. +The native interface is written in the language of the community code (here C++) and either calls the code or +accesses its data. -Therefore, our job when creating an interface is to map the community code functions to the ``AMUSE`` interface -functions. The amusifier already created all the files we need: the ``interface.py`` and the ``interface.cc``. +The first step is writing the Python interface. Community codes are all unique and depend on diverse libraries +and programming languages. To make them interchangeable, AMUSE defines standard interfaces: sets of interface +functions that each code is mapped onto. Consequently, using any AMUSE code is standardized. + +Our job is therefore to map the TIDYMESS functions onto the AMUSE interface functions. The amusifier already +generated the required files: ``interface.py`` (Python interface) and ``interface.cc`` (native interface). Defining the Python interface @@ -408,14 +420,16 @@ The process of defining our interface starts with figuring out what type of code +-----------------------------------+-------------------------------------------+ | Interface: | Example codes: | +-----------------------------------+-------------------------------------------+ -| ``GravitationDynamicsInterface`` | N-body: Tidymess, Ph4, Huayno | +| ``GravitationDynamicsInterface`` | N-body: Tidymess, Ph4, Huayno, Fi | +-----------------------------------+-------------------------------------------+ -| ``HydrodynamicsInterface`` | Hydrodynamical: Capreole | +| ``HydrodynamicsInterface`` | Hydro: Capreole | +-----------------------------------+-------------------------------------------+ -| ``MagnetoHydrodynamicsInterface`` | MHD: Athena | +| ``MagnetoHydrodynamicsInterface`` | Magneto Hydro: Athena | +-----------------------------------+-------------------------------------------+ | ``StellarEvolutionInterface`` | Stellar: MESA, EVtwin, SeBa | +-----------------------------------+-------------------------------------------+ +| ``ChemicalEvolutionInterface`` | Chemistry: Krome, Uclchem, KromeSph | ++-----------------------------------+-------------------------------------------+ These interfaces define many of the required interface functions so that we don't have to. From 7314024680d3f2c9359570a0fce22f99ae61e4ae Mon Sep 17 00:00:00 2001 From: elkogerville Date: Mon, 16 Nov 2026 14:03:55 +0100 Subject: [PATCH 15/31] small doc fixes --- doc/Makefile | 2 +- doc/install/installing.rst | 4 ++-- doc/interactive_tutorial/00-Welcome.ipynb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/Makefile b/doc/Makefile index 91386950dd..09621657b6 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -31,7 +31,7 @@ help: amuse_examples: ln -s ../examples amuse_examples - + clean: -rm -rf $(BUILDDIR)/* -rm -rf html diff --git a/doc/install/installing.rst b/doc/install/installing.rst index 118cce7daa..78b4ac68b8 100644 --- a/doc/install/installing.rst +++ b/doc/install/installing.rst @@ -138,8 +138,8 @@ properly available. .. _installing_amuse: -Installing AMUSE ----------------- +Installing the AMUSE Package +---------------------------- To get a copy of the most recent release of AMUSE, go to AMUSE_Releases_ and look up the most recent release. At the bottom of the description, you'll see a link **Source code diff --git a/doc/interactive_tutorial/00-Welcome.ipynb b/doc/interactive_tutorial/00-Welcome.ipynb index 49f0970ee5..5af5da94b7 100644 --- a/doc/interactive_tutorial/00-Welcome.ipynb +++ b/doc/interactive_tutorial/00-Welcome.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Welcome to ***AMUSE*** \n", + "# Welcome to ***AMUSE*** \n", "\n", "You are currently viewing the AMUSE tutorial. This is a [Jupyter Notebook web-application](https://jupyter.org/ \"Jupyter\"). With this application you can create, edit and run Python scripts on your local computer. We will be using it for these AMUSE tutorials, but you can use it for all your interactive explorations of Python and it's many libraries, scripts and applications. This first tutorial is for users unfamiliar with the notebook interface. We will assume some familiarity with Python, though not at very advanced level and even if you are not, you will probably be able to follow most examples and work out the exercises." ] From 0e73f008997f3ab64b07898e8c7a440e3a747911 Mon Sep 17 00:00:00 2001 From: elkogerville Date: Mon, 16 Nov 2026 16:02:14 +0100 Subject: [PATCH 16/31] fix conf.py doc settings --- doc/Makefile | 5 +---- doc/conf.py | 15 +++++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/doc/Makefile b/doc/Makefile index 09621657b6..07e0c17b8f 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -4,12 +4,9 @@ # You can set these variables from the command line. SPHINXOPTS = SPHINXBUILD = sphinx-build -PAPER = a4 BUILDDIR = build # Internal variables. -PAPEROPT_a4 = -D latex_paper_size=a4 -PAPEROPT_letter = -D latex_paper_size=letter ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . .PHONY: help clean html dirhtml pickle json htmlhelp qthelp latex changes linkcheck doctest @@ -50,7 +47,7 @@ release: amuse_examples latexpdf $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) html make -C build/latex tar FMT=pdf rm -Rf pdf - tar -xvf build/latex/docs-pdf.tar + tar -xvf build/latex/docs-pdf.tar mv docs-pdf pdf # cp -R build/plot_directive . diff --git a/doc/conf.py b/doc/conf.py index 3b60c2c267..af5071301b 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -32,10 +32,10 @@ 'sphinx.ext.autodoc', 'sphinx.ext.autosummary', 'sphinx.ext.autosectionlabel', - 'sphinx.ext.doctest', + 'sphinx.ext.doctest', 'sphinx.ext.todo', - #'sphinx.ext.imgmath', - 'sphinx.ext.ifconfig', + #'sphinx.ext.imgmath', + 'sphinx.ext.ifconfig', 'sphinx.ext.graphviz', 'sphinx.ext.inheritance_diagram', 'sphinx.ext.doctest', @@ -44,6 +44,9 @@ 'sphinx_rtd_theme', ] +autosectionlabel_prefix_document = True +autosectionlabel_maxdepth = 2 + if not is_running_in_rtd: extensions.extend([ 'matplotlib.sphinxext.plot_directive', @@ -203,9 +206,9 @@ # -- Options for LaTeX output -------------------------------------------------- - -# The paper size ('letter' or 'a4'). -#latex_paper_size = 'letter' +latex_elements = { + 'papersize': 'a4paper', +} # The font size ('10pt', '11pt' or '12pt'). #latex_font_size = '10pt' From 71620cc37a89f3a4e5e53f352dfdc1342be9d0ab Mon Sep 17 00:00:00 2001 From: elkogerville Date: Mon, 16 Nov 2026 16:04:28 +0100 Subject: [PATCH 17/31] fixed missing headers in interactive tutorial --- doc/index.rst | 9 +++++---- doc/interactive_tutorial/01-Loading_AMUSE.ipynb | 7 +++++++ doc/interactive_tutorial/02-Quantities_with_units.ipynb | 7 +++++++ doc/interactive_tutorial/03-Generic_units.ipynb | 7 +++++++ .../04-Collections_of_Particles.ipynb | 7 +++++++ ...ttributes_and_functions_on_particle_collections.ipynb | 7 +++++++ doc/interactive_tutorial/06-Using_a_community_code.ipynb | 7 +++++++ doc/interactive_tutorial/07-Channels.ipynb | 7 +++++++ doc/interactive_tutorial/08-Grids.ipynb | 7 +++++++ doc/interactive_tutorial/09-Units_and_functions.ipynb | 9 +++++++++ doc/interactive_tutorial/10-Radiative_transfer.ipynb | 7 +++++++ 11 files changed, 77 insertions(+), 4 deletions(-) diff --git a/doc/index.rst b/doc/index.rst index f53f003247..95576629dd 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -10,16 +10,17 @@ Contents: .. toctree:: :maxdepth: 2 - + install/index tutorial/index interactive_tutorial/index reference/index developing/index - -.. htmlonly:: + +.. only:: html + - `Examples `_ - + Indices and tables ================== diff --git a/doc/interactive_tutorial/01-Loading_AMUSE.ipynb b/doc/interactive_tutorial/01-Loading_AMUSE.ipynb index b3d24925d8..f8c999788b 100644 --- a/doc/interactive_tutorial/01-Loading_AMUSE.ipynb +++ b/doc/interactive_tutorial/01-Loading_AMUSE.ipynb @@ -1,5 +1,12 @@ { "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Loading ***AMUSE***" + ] + }, { "cell_type": "code", "execution_count": null, diff --git a/doc/interactive_tutorial/02-Quantities_with_units.ipynb b/doc/interactive_tutorial/02-Quantities_with_units.ipynb index 29144276d2..e84b36c248 100644 --- a/doc/interactive_tutorial/02-Quantities_with_units.ipynb +++ b/doc/interactive_tutorial/02-Quantities_with_units.ipynb @@ -1,5 +1,12 @@ { "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Quantities with Units" + ] + }, { "cell_type": "code", "execution_count": null, diff --git a/doc/interactive_tutorial/03-Generic_units.ipynb b/doc/interactive_tutorial/03-Generic_units.ipynb index bf1b80df1d..1f31ff0ac8 100644 --- a/doc/interactive_tutorial/03-Generic_units.ipynb +++ b/doc/interactive_tutorial/03-Generic_units.ipynb @@ -1,5 +1,12 @@ { "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Generic Units" + ] + }, { "cell_type": "code", "execution_count": null, diff --git a/doc/interactive_tutorial/04-Collections_of_Particles.ipynb b/doc/interactive_tutorial/04-Collections_of_Particles.ipynb index d90b6b0874..caeaa7da13 100644 --- a/doc/interactive_tutorial/04-Collections_of_Particles.ipynb +++ b/doc/interactive_tutorial/04-Collections_of_Particles.ipynb @@ -1,5 +1,12 @@ { "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Collections of Particles" + ] + }, { "cell_type": "code", "execution_count": null, diff --git a/doc/interactive_tutorial/05-Attributes_and_functions_on_particle_collections.ipynb b/doc/interactive_tutorial/05-Attributes_and_functions_on_particle_collections.ipynb index 3296145d3d..07965eb54b 100644 --- a/doc/interactive_tutorial/05-Attributes_and_functions_on_particle_collections.ipynb +++ b/doc/interactive_tutorial/05-Attributes_and_functions_on_particle_collections.ipynb @@ -1,5 +1,12 @@ { "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Attributes and Functions on Particle Collections" + ] + }, { "cell_type": "code", "execution_count": null, diff --git a/doc/interactive_tutorial/06-Using_a_community_code.ipynb b/doc/interactive_tutorial/06-Using_a_community_code.ipynb index de1a3b60e7..132b57a9b5 100644 --- a/doc/interactive_tutorial/06-Using_a_community_code.ipynb +++ b/doc/interactive_tutorial/06-Using_a_community_code.ipynb @@ -1,5 +1,12 @@ { "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Using a Community Code" + ] + }, { "cell_type": "code", "execution_count": null, diff --git a/doc/interactive_tutorial/07-Channels.ipynb b/doc/interactive_tutorial/07-Channels.ipynb index f8f685f694..a50a87bb4b 100644 --- a/doc/interactive_tutorial/07-Channels.ipynb +++ b/doc/interactive_tutorial/07-Channels.ipynb @@ -1,5 +1,12 @@ { "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Channels" + ] + }, { "cell_type": "code", "execution_count": null, diff --git a/doc/interactive_tutorial/08-Grids.ipynb b/doc/interactive_tutorial/08-Grids.ipynb index b72da1223a..df22715090 100644 --- a/doc/interactive_tutorial/08-Grids.ipynb +++ b/doc/interactive_tutorial/08-Grids.ipynb @@ -1,5 +1,12 @@ { "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Grids" + ] + }, { "cell_type": "code", "execution_count": null, diff --git a/doc/interactive_tutorial/09-Units_and_functions.ipynb b/doc/interactive_tutorial/09-Units_and_functions.ipynb index dc876cc101..e768c10e5b 100644 --- a/doc/interactive_tutorial/09-Units_and_functions.ipynb +++ b/doc/interactive_tutorial/09-Units_and_functions.ipynb @@ -1,5 +1,14 @@ { "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Units and Functions" + ] + }, { "cell_type": "code", "execution_count": null, diff --git a/doc/interactive_tutorial/10-Radiative_transfer.ipynb b/doc/interactive_tutorial/10-Radiative_transfer.ipynb index 54711f26eb..3f69ab9dc5 100644 --- a/doc/interactive_tutorial/10-Radiative_transfer.ipynb +++ b/doc/interactive_tutorial/10-Radiative_transfer.ipynb @@ -1,5 +1,12 @@ { "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Radiative Transfer" + ] + }, { "cell_type": "code", "execution_count": null, From 04bde9134804b0271e81449a952b773692699063 Mon Sep 17 00:00:00 2001 From: elkogerville Date: Mon, 16 Nov 2026 16:05:43 +0100 Subject: [PATCH 18/31] fixed missing headers in interactive tutorial --- doc/interactive_tutorial/Makefile | 13 +++++++------ doc/interactive_tutorial/index.rst | 26 +++++++++++++------------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/doc/interactive_tutorial/Makefile b/doc/interactive_tutorial/Makefile index 2da355a244..033454b41f 100644 --- a/doc/interactive_tutorial/Makefile +++ b/doc/interactive_tutorial/Makefile @@ -1,15 +1,15 @@ -# convert all ipynb to rst files for inclusion into the +# convert all ipynb to rst files for inclusion into the # amuse documentation # -# makefile depends on nbconvert script +# makefile depends on nbconvert script # # nbconvert from github: # https://github.com/ipython/nbconvert -# nbconvert depends on +# nbconvert depends on # ipython, markdown and pygments python modules # plus pandoc app (pandoc needs haskell platform installed) # -# +# # AMUSE_DIR?=../.. @@ -20,6 +20,7 @@ NBCONVERT=jupyter nbconvert PYTHONPATH=$(AMUSE_DIR)/src PAGES=\ + 00-Welcome.ipynb\ 01-Loading_AMUSE.ipynb\ 02-Quantities_with_units.ipynb\ 03-Generic_units.ipynb\ @@ -37,10 +38,10 @@ all: $(RSTPAGES) clean: rm -f $(RSTPAGES) rm -Rf $(RSTFILES) - + %.rst:%.ipynb $(NBCONVERT) --to rst "$<" - + %.txt:%.rst python create_title.py "$<" > "$@" cat "$<" >> "$@" diff --git a/doc/interactive_tutorial/index.rst b/doc/interactive_tutorial/index.rst index 358a1f9177..36c2c515ef 100644 --- a/doc/interactive_tutorial/index.rst +++ b/doc/interactive_tutorial/index.rst @@ -11,34 +11,35 @@ and you can start it in that distribution with: .. code-block:: sh ./amuse-tutorial - -For the source distribution you can also run the interactive tutorial -but you will need to install IPython notebook first (`ipythonnb`_). + +For the source distribution you can also run the interactive tutorial +but you will need to install IPython notebook first (`ipythonnb`_). Once you have installed ipython you can run the notebook with: .. code-block:: sh export PYTHONPATH=$PWD/src:$PYTHONPATH - + cd doc/interactive_tutorial/ - - ipython notebook --pylab inline + + ipython notebook --pylab inline .. note:: - - You will need to run the ipython command from the + + You will need to run the ipython command from the interactive tutorial directory. You also need to have amuse in your python path. .. note:: - - The ipython notebook code depends on the `tornado` and the `pyzmq` - modules. You will need to install these before + + The ipython notebook code depends on the `tornado` and the `pyzmq` + modules. You will need to install these before installing the ipython notebook. - + .. toctree:: :maxdepth: 1 + 00-Welcome 01-Loading_AMUSE 02-Quantities_with_units 03-Generic_units @@ -50,4 +51,3 @@ Once you have installed ipython you can run the notebook with: .. _ipythonnb: http://ipython.org/ipython-doc/dev/interactive/htmlnotebook.html - From 97c39f71c8e13d74f0c6476c98613e23837abd22 Mon Sep 17 00:00:00 2001 From: elkogerville Date: Mon, 16 Nov 2026 16:09:26 +0100 Subject: [PATCH 19/31] fix broken tables --- doc/reference/available-codes.rst | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/doc/reference/available-codes.rst b/doc/reference/available-codes.rst index 17c18d10ae..3aaa2eefdb 100644 --- a/doc/reference/available-codes.rst +++ b/doc/reference/available-codes.rst @@ -49,7 +49,7 @@ Code comparison table Note: holds for AMUSE implementation. -+---------+---------------------+-----------------+--------+---------+------+---------+--------------+-------------+ ++---------+---------------------+-----------------+--------+---------+------+---------+--------------+-------------+ |name |approximation scheme |timestep scheme |CPU |GPU |GRAPE |language |stopcond (1) |parallel (2) | | | | | | | | | | | +=========+=====================+=================+========+=========+======+=========+==============+=============+ @@ -78,13 +78,13 @@ Note: holds for AMUSE implementation. |mercury |MVS symplectic | |Y |N |N |FORTRAN | |N | | | | | | | | | | | +---------+---------------------+-----------------+--------+---------+------+---------+--------------+-------------+ -|octgrav |tree |shared |N |Y |N |C/C++ |S |N | +|octgrav |tree |shared |N |Y |N |C/C++ |S |N | | | | | | | | | | | +---------+---------------------+-----------------+--------+---------+------+---------+--------------+-------------+ |rebound | | | | | | | |N | | | | | | | | | | | +---------+---------------------+-----------------+--------+---------+------+---------+--------------+-------------+ -|phigrape |direct |block/variable |Y g6 |Y |Y |FORTAN |CSPT |N | +|phigrape |direct |block/variable |Y g6 |Y |Y |FORTAN |CSPT |N | | | | | |sapporo | | | | | +---------+---------------------+-----------------+--------+---------+------+---------+--------------+-------------+ |smallN |direct Hermite 4th |individual |Y |N |N |C/C++ | |N | @@ -98,10 +98,10 @@ Note: holds for AMUSE implementation. (1) stopping conditions - + ==== ========================== code name of stopping condition - ==== ========================== + ==== ========================== C Collision detection E Escaper detection S Number of steps detection @@ -908,7 +908,6 @@ Parameters |mass_galaxy |0.0 |mass |total mass for | | | | |analytical galaxy | | | | |potential | - +------------------------------------+---------------+---------------+-------------------+ |r_core_plummer |0.0 |length |core radius for | | | | |analytical plummer | @@ -931,10 +930,10 @@ Parameters |max_step |-3.0 |none |exponent which defi| | | | |nes the maximum | | | | |time step allowed | -| | | |for stars | +| | | |for stars | | | | |(2^exponent) | +------------------------------------+---------------+---------------+-------------------+ -|n_Print |1000000 |none |maximum number of | +|n_Print |1000000 |none |maximum number of | | | | |snapshots | | | | | | +------------------------------------+---------------+---------------+-------------------+ @@ -943,15 +942,15 @@ Parameters | | | |diagnostics | | | | |output | +------------------------------------+---------------+---------------+-------------------+ -|n_gpu |2 |none |number of GPUs per | +|n_gpu |2 |none |number of GPUs per | | | | |node | | | | | | +------------------------------------+---------------+---------------+-------------------+ -|gpu_name |GeForce GTX 480|none |GPUs to use | +|gpu_name |GeForce GTX 480|none |GPUs to use | | | | | | | | | | | +------------------------------------+---------------+---------------+-------------------+ -|Threads |128 |none |number of gpus | +|Threads |128 |none |number of gpus | | | | |threads per block | | | | | | +------------------------------------+---------------+---------------+-------------------+ From ce6ab0fbc7f1877e0bf3f9de7c6d15e0d2637f73 Mon Sep 17 00:00:00 2001 From: elkogerville Date: Mon, 16 Nov 2026 16:10:36 +0100 Subject: [PATCH 20/31] missing ref label --- doc/reference/cartesius.rst | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/doc/reference/cartesius.rst b/doc/reference/cartesius.rst index 4a45612ce0..3f55c5fd73 100755 --- a/doc/reference/cartesius.rst +++ b/doc/reference/cartesius.rst @@ -2,9 +2,12 @@ Running AMUSE on The Cartesius supercomputer ============================================= -The Cartesius is the Dutch national supercomputer. For more information on e.g. obtaining an account, see the SURFSara website: https://userinfo.surfsara.nl/systems/cartesius. +The Cartesius is the Dutch national supercomputer. For more information on e.g. obtaining an account, +see the SURFSara website: https://userinfo.surfsara.nl/systems/cartesius. -Using AMUSE on the Cartesius is relatively straightforward. Below is a tested method for installing and using AMUSE using the prerequisites, though other options (e.g. using only software pre-installed on the machine) should also be possible. For a generic description of the installation of prerequisites, see the :ref:`prerequisite-label` section. +Using AMUSE on the Cartesius is relatively straightforward. Below is a tested method for installing and using AMUSE +using the prerequisites, though other options (e.g. using only software pre-installed on the machine) should also be possible. +For a generic description of the installation of prerequisites, see the :ref:`prerequisite-label` section. Obtaining AMUSE --------------- @@ -49,6 +52,9 @@ Also make sure that .bashrc is loaded in your .bash_profile. This way, the envir **Note: be sure to re-connect to the machine for these changes to take effect.** + +.. _prerequisite-label: + Install AMUSE prerequisites --------------------------- From 4915f63452cd291eab86e35bd3a332fb99a910fe Mon Sep 17 00:00:00 2001 From: elkogerville Date: Mon, 16 Nov 2026 16:14:50 +0100 Subject: [PATCH 21/31] fix broken lists and headers --- doc/reference/code_management.rst | 2 +- doc/reference/distributed.rst | 100 ++++++++++++++++++------------ 2 files changed, 61 insertions(+), 41 deletions(-) diff --git a/doc/reference/code_management.rst b/doc/reference/code_management.rst index 13f7046312..1db3c95533 100644 --- a/doc/reference/code_management.rst +++ b/doc/reference/code_management.rst @@ -6,7 +6,7 @@ Source Code Management Committing Code --------------- +--------------- Git repository location diff --git a/doc/reference/distributed.rst b/doc/reference/distributed.rst index 606ea9d2e7..875fb94c80 100644 --- a/doc/reference/distributed.rst +++ b/doc/reference/distributed.rst @@ -29,26 +29,31 @@ To check if the installation is set-up properly, run all the tests related to th > cd $AMUSE_DIR > nosetests -v test/codes_tests/test*implementation.py - -Note that Distributed AMUSE is mostly tested with the version of MPI includes in the amuse "prerequisites". -If you get MPI errors while running remote (parallel) workers, try using the install.py script included in AMUSE to install the prerequisites. + +Note that Distributed AMUSE is mostly tested with the version of MPI includes in the amuse "prerequisites". +If you get MPI errors while running remote (parallel) workers, try using the install.py script included in AMUSE to install the prerequisites. Overview -------- -Usage of Distributed Amuse is (by design) very close to the usage of any other code in AMUSE. +Usage of Distributed Amuse is (by design) very close to the usage of any other code in AMUSE. The main difference being it contains resources, pilots, and jobs, instead of particles. -Resource - Description of a machine capable of running jobs. - For each resource distributed AMUSE will launch a support process (HUB) to facilitate communication and coordination between the workers and AMUSE - -Pilot - Process running on a resource (often within a reservation on a resource) waiting for jobs to run on behalf of AMUSE. +**Resource** + Description of a machine capable of running jobs. + + For each resource distributed AMUSE will launch a support process (HUB) + to facilitate communication and coordination between the workers and AMUSE. + +**Pilot** + Process running on a resource (often within a reservation on a resource) + waiting for jobs to run on behalf of AMUSE. + Can consist of multiple machines. - -Job - Worker process. + +**Job** + Worker process. + Will search for a suitable pilot to run on. In general, a user will first define resources, then deploy pilots on these resources, and finally create codes that make use of the machines offered by the pilots. @@ -69,40 +74,48 @@ Distributed Amuse can be initialized like any other code: Parameters ---------- -Distributed AMUSE supports a few parameters to adjust settings. +Distributed AMUSE supports a few parameters to adjust settings. All parameters need to be set before any resource, pilot or job is made to have effect. Overview of settings: -debug - Boolean parameters, defaults to False. +**debug** + Boolean parameters, defaults to False. + If true/enabled, will output additional debugging information and logs, both in the code output, and in a `distributed-amuse-logs` folder on any target machine used. -webinterface_port - Port on which a simple webinterface is available for monitoring. - Defaults to "0", for a port determined automatically. -start_hubs - To facilitate communication across different networks (with for instance firewalls), as hub is by default started on each resource. - This can be turned off if needed, for instance if all resources are within the same network. -worker_queue_timeout - The user is responsible for making sure enough slots are available to run a worker. - If not, it will end up in the queue. - The time the worker will wait before giving up can be set using this parameter. -worker_startup_timeout - The distributed code starts AMUSE workers running the actual codes. - This can take a while on some machines. + +**webinterface_port** + Port on which a simple webinterface is available for monitoring. + + Defaults to "0", for a port determined automatically. + +**start_hubs** + To facilitate communication across different networks (with for instance firewalls), as hub is by default started on each resource. + + This can be turned off if needed, for instance if all resources are within the same network. + +**worker_queue_timeout** + The user is responsible for making sure enough slots are available to run a worker. + + If not, it will end up in the queue. The time the worker will wait before giving up can be set using this parameter. + +**worker_startup_timeout** + The distributed code starts AMUSE workers running the actual codes. + + This can take a while on some machines. If needed, this parameter can be used to increase the time waited. - + >>> instance.parameters.debug = True >>> instance.parameters.webinterface_port = 5555 >>> instance.commit_parameters() >>> >>> print instance.parameters.webinterface_port - + Monitoring ---------- -Distributed Amuse has a small build-in webinterface for monitoring. +Distributed Amuse has a small build-in webinterface for monitoring. A utility function is available to get the url: >>> import webbrowser @@ -126,21 +139,28 @@ As a side effect, a communication hub is also started on the (frontend of) the r Overview of all options: -name +**name** Some user chosen name for the resource -location + +**location** Address of the resource. Usually a hostname (e.g. somehost.somedomain.com). Could also be an IP address -amuse_dir + +**amuse_dir** Location of amuse on the remote machine (e.g. /home/user/amuse-svn) -tmp_dir + +**tmp_dir** Where all temporary files will be put on the remote machine -gateway + +**gateway** Sometimes a machine is not reachable directly due to firewalls and such. Use this setting to provide an intermediate resource to route traffic via. This resource should already have been created. -scheduler_type + +**scheduler_type** The type of scheduler present on the remote machine. Defaults to 'ssh' useful for single machines. Current supported scheduler types: 'ssh', 'sge', 'slurm' -hub_queue_name + +**hub_queue_name** Normally the support process is started on the front end. However, it can also be submitted to a queue by specifying it here. -hub_time_minutes + +**hub_time_minutes** When a hub is submitted, this option denotes the time the hub will be available. From 0b83993a659345fe6ca5bfb5e1e47b04b395509f Mon Sep 17 00:00:00 2001 From: elkogerville Date: Mon, 16 Nov 2026 16:16:02 +0100 Subject: [PATCH 22/31] fix glossary and formatting --- doc/reference/distributed.rst | 59 +++++++++------ doc/reference/glossary.rst | 137 +++++++++++++++++----------------- 2 files changed, 103 insertions(+), 93 deletions(-) diff --git a/doc/reference/distributed.rst b/doc/reference/distributed.rst index 875fb94c80..d21a9bbb14 100644 --- a/doc/reference/distributed.rst +++ b/doc/reference/distributed.rst @@ -179,35 +179,41 @@ Note that pilots may not be started for a while. A function is available to wait >>> pilot.label='local' >>> >>> instance.pilots.add_pilot(pilot) - >>> + >>> >>> print "Pilots:" >>> print instance.pilots - >>> + >>> >>> print "Waiting for pilots" >>> instance.wait_for_pilots() Overview of all options: -resource_name +**resource_name** name of the resource to start the pilot on -queue_name + +**queue_name** queue to use to run the pilot (cluster specific, not used in case of ssh) -node_count + +**node_count** number of nodes to start the pilot on -time + +**time** time to keep the pilot active -slots_per_node + +**slots_per_node** number of workers to start on a node. Usually the number of cores, but could be less if memory is a limiting factor, or workers are multi-core capable -label + +**label** label to attach to the pilot. Can be used when starting workers to run workers on specific pilots -options + +**options** Additional options. Usually not required. Starting jobs ------------- -When running remote workers, they can be started as normal. +When running remote workers, they can be started as normal. However, AMUSE needs to be signalled to use the distributed code to start them instead of the normal process. A function is available to enable and disable this. @@ -230,37 +236,42 @@ Or, even pass the instance of the distributed code you would like to use, in the Worker options -------------- -This section lists all the relevant worker options for Distributed AMUSE. +This section lists all the relevant worker options for Distributed AMUSE. Most are new, some are also supported in the other channel implementations. You are normally not required to use any options. -number_of_workers - Number of worker processes started (thus working as normally the case). +**number_of_workers** + Number of worker processes started (thus working as normally the case). Each worker takes up a slot of the pilot (see above) -label - Label of the pilot to use. By default any pilot with enough free slots found will be used to start this worker. + +**label** + Label of the pilot to use. By default any pilot with enough free slots found will be used to start this worker. Using the labels an explicit selection can be done. -number_of_threads - Number of threads used in the process. + +**number_of_threads** + Number of threads used in the process. This can be used to explicitly set the OMP_NUM_THREADS environment variable in the worker -channel_type - Set this to "distributed" to start workers using the distributed code. + +**channel_type** + Set this to "distributed" to start workers using the distributed code. Alternatively, use the use_for_all_workers functions as described above to set this by default -distributed_instance + +**distributed_instance** This is a reference to the distributed instance used to start the worker, in the rare case you have multiple distributed codes. -dynamic_python_code - Boolean option stating if this code is a dynamic python code. + +**dynamic_python_code** + Boolean option stating if this code is a dynamic python code. If so, all .py files in the worker directory will be copied to the remote machine before starting the code. Labels ------ -By default workers are started on any available pilot with enough slots available. +By default workers are started on any available pilot with enough slots available. However, sometimes you would like to have more control over which worker is started where, for instance if special hardware is present on some machines. The concept of labels can be used within Distributed AMUSE to get this functionality. -If a label is attached to a worker (one of the parameters when starting a worker, see above), only pilots with exactly the same label (specified when the pilot is started) are considered candidates for running the worker. +If a label is attached to a worker (one of the parameters when starting a worker, see above), only pilots with exactly the same label (specified when the pilot is started) are considered candidates for running the worker. The name of labels is completely up to the user. For instance, say a simulation uses a number of workers running on a CPU, and a single GPU worker. diff --git a/doc/reference/glossary.rst b/doc/reference/glossary.rst index e349fa5761..3dd093e0f5 100644 --- a/doc/reference/glossary.rst +++ b/doc/reference/glossary.rst @@ -5,133 +5,132 @@ Glossary .. glossary:: :sorted: - - + Physical Domain - A region in space, time and objects (stars / gas clouds) that can be - described by a set of physical models. A physical domain is a - limited description of the physics of a stellar system. For example - in the gravity domain the gravitational forces are taken into - account but not the evolution of stars or the hydrodynamics of th - interstellar medium - + A region in space, time and objects (stars / gas clouds) that can be + described by a set of physical models. A physical domain is a + limited description of the physics of a stellar system. For example + in the gravity domain the gravitational forces are taken into + account but not the evolution of stars or the hydrodynamics of the + interstellar medium. + Module - Interface to a code in AMUSE. Also, file containing python definitions. - These definitions can be imported into the main Python program + Interface to a code in AMUSE. Also, file containing python definitions. + These definitions can be imported into the main Python program. Unit test - Automatic test case for a part of the code. For example one can - define a unit tests that checks the result of one method given a + Automatic test case for a part of the code. For example one can + define a unit test that checks the result of one method given a specified argument. Application A script that combines modules into a multi-physical simulator. - + Run - During a run the physical models are evolved to a wanted end state. - A run can end when a certain model time has passed. For example, one + During a run the physical models are evolved to a wanted end state. + A run can end when a certain model time has passed. For example, one can run a script until the age is 12 million years. - + Evolve - Work out / develop the physical model equations. Usually, small steps - in time are taken, the new state of the system is calculated from the + Work out / develop the physical model equations. Usually, small steps + in time are taken, the new state of the system is calculated from the previous state. Step - An identifiable stage in a run or evolve. A code can take multiple - steps during one evolve step. A step can be the integrator step, + An identifiable stage in a run or evolve. A code can take multiple + steps during one evolve step. A step can be the integrator step, force calculation step. - + Data-model A single representation model for data of different physical codes. Set - A collection of identifyable objects (for example all stars in a + A collection of identifiable objects (for example all stars in a globular cluster). Every value in the set can be seen as belonging to an object. - + Grid - A collection of identifyable locations or regions (for example a box - of interstellar medium with a density, molecular composition). Every - value in the collection can be seen as belongin to a specific + A collection of identifyable locations or regions (for example a box + of interstellar medium with a density, molecular composition). Every + value in the collection can be seen as belonging to a specific location (x,y,z point). Code - A computer program to solve or approximate the equations of state of - a physical domain. Codes are usually written in Fortran or C/C++. + A computer program to solve or approximate the equations of state of + a physical domain. Codes are usually written in Fortran or C/C++. For example 'sse' is a code to perform stellar evolution. - + Production Code - A code used for modelling stellar systems and described in published + A code used for modelling stellar systems and described in published articles. - + Toy Code - A code with limited accurancy but that is easy to use. - + A code with limited accuracy but that is easy to use. + Numerical Experiment - + A numerical simulation designed to investigate a physical system. + SPH, smoothed particle hydrodynamics - A computational method used for simulating fluid flows + A computational method used for simulating fluid flows. AMR, adaptive mesh refinement - + A numerical technique that dynamically refines the computational mesh + in regions requiring higher spatial resolution. + Input / output format + The format used to read input data or write simulation results. Binary star - Two stars in close orbit - - + Two stars in bound orbit. + Star Cluster - A group of stars. The mean distance between the stars in smaller - than the mean distance between stars in the galaxy disks. Two types + A group of stars. The mean distance between the stars is smaller + than the mean distance between stars in the galaxy disks. Two types of star clusters exist: globular clusters, open clusters Dense stellar systems - + Bound conglomerate of stars with at least one 90º turnaround within a crossing time. + Interstellar Medium - The matter between the stars in a galaxy. + The matter between the stars in a galaxy. Interstellar Cloud - Generic name for an accumulation of gas, plasma and dust. A denser - region of the insterstellar medium - + Generic name for an accumulation of gas, plasma and dust. A denser + region of the interstellar medium. + Molecular Cloud - A type of insterstellar cloud whose density and size permits the - formation of molecules, - + A type of interstellar cloud whose density and size permits the formation of molecules. + Gravity Domain + A physical domain in which gravitational interactions are taken into account. Hydrodynamics + The study of the motion and behaviour of fluids, under the influence of forces such as pressure and gravity. - Star - + Star + Luminous spheroid of plasma held together by self-gravity. Stellar Evolution - + The physical processes governing the structural and chemical evolution of a star over time. + ZAMS, zero age main sequence Start of the main sequence in the evolution of a star. Stable stage - after formation of the star from a collapsing gas cloud - + after formation of the star from a collapsing gas cloud. + Main sequence star - A star that derives its energy from the conversion of hydrogen into + A star that derives its energy from the conversion of hydrogen into helium in its core. - - Star cluster - - + Metallicity - Proportion of star matter made up of chemical elements other than + Proportion of star matter made up of chemical elements other than hydrogen and helium. - + Galaxy + A gravitationally bound system consisting of stars, stellar remnants, + interstellar gas and dust, and dark matter. Star Core + The central region of a star. Star Envelope - - - - - - - + The outer layers of a star surrounding its core. From bdc35cd87823d5338167ae57c0bdb1e1e3494c00 Mon Sep 17 00:00:00 2001 From: elkogerville Date: Mon, 16 Nov 2026 16:26:08 +0100 Subject: [PATCH 23/31] no-index fixes --- .../hydrodynamics_interface_specification.rst | 33 +++++++++++-------- doc/reference/particle_attributes.rst | 7 ++-- doc/reference/particles.rst | 13 ++++---- ...ellar_dynamics_interface_specification.rst | 23 ++++++++----- 4 files changed, 44 insertions(+), 32 deletions(-) diff --git a/doc/reference/hydrodynamics_interface_specification.rst b/doc/reference/hydrodynamics_interface_specification.rst index 89ff732c5e..5cde5b9c68 100644 --- a/doc/reference/hydrodynamics_interface_specification.rst +++ b/doc/reference/hydrodynamics_interface_specification.rst @@ -14,32 +14,34 @@ Parameters ~~~~~~~~~~ All parameters have to be accessed with functions following the template of the ``get_timestep`` and ``set_timestep`` functions. -A parameter access function may only retrieve or -update the value of a single parameter. After all parameters have been set, the +A parameter access function may only retrieve or +update the value of a single parameter. After all parameters have been set, the ``commit_parameters`` function should be called, this gives the code the opportunity prepare the model. .. autoclass:: amuse.community.interface.hydro.HydrodynamicsInterface - :members: set_timestep, get_timestep, commit_parameters - + :members: commit_parameters + Grid Management ~~~~~~~~~~~~~~~~~ -Most hydrodynamical codes work on grids or a hierarchy of grids. The following -methods define the functionality to setup and query the grids. +Most hydrodynamical codes work on grids or a hierarchy of grids. The following +methods define the functionality to setup and query the grids. .. autoclass:: amuse.community.interface.hydro.HydrodynamicsInterface + :no-index: :members: get_index_range_inclusive, set_boundary, setup_mesh, get_position_of_index, get_index_of_position - + Grid state ~~~~~~~~~~~~ Grid points in a hydrodynamics code have a well known, *minimal* state. This state is is defined -by a density, momentum density and energy density. The state can +by a density, momentum density and energy density. The state can be retrieved and updated with the following functions. .. autoclass:: amuse.community.interface.hydro.HydrodynamicsInterface + :no-index: :members: set_grid_state, get_grid_state - + Grid State, Extension Mechanism ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -49,7 +51,8 @@ functions must get or set one scalar property (1 argument) or a vector property .. autoclass:: amuse.community.interface.hydro.HydrodynamicsInterface - :members: get_density, set_grid_density, get_momentum_density, set_grid_momentum_density, get_energy_density, set_grid_energy_density + :no-index: + :members: get_grid_density, set_grid_density, get_grid_momentum_density, set_grid_momentum_density, get_grid_energy_density, set_grid_energy_density Model evolution @@ -58,15 +61,17 @@ The hydrodynamics codes evolve the properties all grid cells in time. The follow are needed to control the evolution in the code. .. autoclass:: amuse.community.interface.hydro.HydrodynamicsInterface - :members: initialize_grid, evolve + :no-index: + :members: initialize_grid, evolve_model Diagnostics ~~~~~~~~~~~ -The state of the code can be queried, before, during and after the model calculations. The following +The state of the code can be queried, before, during and after the model calculations. The following function can be used to query the exact model time. .. autoclass:: amuse.community.interface.hydro.HydrodynamicsInterface + :no-index: :members: get_time External fields @@ -74,6 +79,6 @@ External fields Some Hydrodynamics codes support external acceleration or potential fields. The following functions can be used to enter a gravitational potential field. -.. autoclass:: amuse.community.interface.hydro.HydrodynamicsInterface +.. autoclass:: amuse.community.interface.hydro.HydrodynamicsWithExternalGravitationalPotentialInterface + :no-index: :members: set_has_external_gravitational_potential, get_has_external_gravitational_potential, get_index_range_for_potential, set_potential, get_potential - diff --git a/doc/reference/particle_attributes.rst b/doc/reference/particle_attributes.rst index b8cc8b3ed9..295cae7151 100644 --- a/doc/reference/particle_attributes.rst +++ b/doc/reference/particle_attributes.rst @@ -24,11 +24,12 @@ To access these functions as an attribute do: .. code-block:: python from amuse.lab import new_plummer_sphere - + particles = new_plummer_sphere(100) - + print particles.kinetic_energy() - + .. automodule:: amuse.datamodel.particle_attributes + :no-index: :members: diff --git a/doc/reference/particles.rst b/doc/reference/particles.rst index e5dd4ec1b6..72f2803fa1 100644 --- a/doc/reference/particles.rst +++ b/doc/reference/particles.rst @@ -245,29 +245,30 @@ data of a particle is stored in the set. .. autoclass:: Particle :members: - + .. automethod:: __add__ .. automethod:: __sub__ - + Methods to retreive physical properties of the particles set ------------------------------------------------------------ - + .. automodule:: amuse.datamodel.particle_attributes + :no-index: - .. autofunction:: center_of_mass + .. autofunction:: center_of_mass :noindex: .. autofunction:: center_of_mass_velocity :noindex: .. autofunction:: kinetic_energy :noindex: - .. autofunction:: potential_energy + .. autofunction:: potential_energy :noindex: .. autofunction:: particle_specific_kinetic_energy :noindex: .. autofunction:: particle_potential :noindex: - + Implementation -------------- diff --git a/doc/reference/stellar_dynamics_interface_specification.rst b/doc/reference/stellar_dynamics_interface_specification.rst index 3ea8c19ff4..3822d90148 100644 --- a/doc/reference/stellar_dynamics_interface_specification.rst +++ b/doc/reference/stellar_dynamics_interface_specification.rst @@ -12,33 +12,35 @@ Parameters Gravity dynamics codes have at least one specified parameter. Other parameters need to be specified on a per code basis. All parameters have to be accessed with functions following the template of the ``get_eps`` and ``set_eps`` functions. A parameter access function may only -retrieve or update the value of a single parameter. After all parameters have been set, the +retrieve or update the value of a single parameter. After all parameters have been set, the ``initialize_code`` function should be called, this gives the code the opportunity prepare the model. .. autoclass:: amuse.community.interface.gd.GravitationalDynamicsInterface :members: get_eps2, set_eps2, initialize_code - + Object Management ~~~~~~~~~~~~~~~~~ -Most gravitational dynamics codes work on particles (stars, black holes or gas). The following -methods define the functionality to create, remove and query the particles in the code. *Currently +Most gravitational dynamics codes work on particles (stars, black holes or gas). The following +methods define the functionality to create, remove and query the particles in the code. *Currently the interface does not handle different types of particles* .. autoclass:: amuse.community.interface.gd.GravitationalDynamicsInterface + :no-index: :members: new_particle, delete_particle, get_number_of_particles, get_index_of_first_particle, get_index_of_next_particle - + Object state ~~~~~~~~~~~~ Particles in gravitational dynamics have a well known, *minimal* state. This state is is defined -by a location, velocity and mass and radius. The state can be retrieved and updated with +by a location, velocity and mass and radius. The state can be retrieved and updated with the following functions. .. autoclass:: amuse.community.interface.gd.GravitationalDynamicsInterface + :no-index: :members: get_state, set_state - + Object State, Extension Mechanism ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -48,6 +50,7 @@ functions must get or set one scalar property (1 argument) or a vector property .. autoclass:: amuse.community.interface.gd.GravitationalDynamicsInterface + :no-index: :members: get_mass, set_mass, get_position, set_position, get_acceleration, get_potential @@ -57,15 +60,17 @@ The gravitational dynamics codes evolve the properties of the particles in time. are needed to control the evolution in the code. .. autoclass:: amuse.community.interface.gd.GravitationalDynamicsInterface - :members: commit_particles, evolve + :no-index: + :members: commit_particles, evolve_model Diagnostics ~~~~~~~~~~~ -The state of the code can be queried, before, during and after the model calculations. The following +The state of the code can be queried, before, during and after the model calculations. The following function can be used to query the exact model time, the total energies and colliding particles. .. autoclass:: amuse.community.interface.gd.GravitationalDynamicsInterface + :no-index: :members: get_time, get_kinetic_energy, get_potential_energy, get_indices_of_colliding_particles, get_center_of_mass_velocity, get_center_of_mass_position, get_total_mass, get_total_radius Services From 05543dd774bc9c8232dc237f10e3f784c9776fb2 Mon Sep 17 00:00:00 2001 From: elkogerville Date: Mon, 16 Nov 2026 16:29:00 +0100 Subject: [PATCH 24/31] fix interface spec rst files --- ...tellar_dynamics_interface_specification.rst | 4 ++-- ...ellar_evolution_interface_specification.rst | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/doc/reference/stellar_dynamics_interface_specification.rst b/doc/reference/stellar_dynamics_interface_specification.rst index 3822d90148..f57018ec41 100644 --- a/doc/reference/stellar_dynamics_interface_specification.rst +++ b/doc/reference/stellar_dynamics_interface_specification.rst @@ -78,5 +78,5 @@ Services Some Gravitational Dynamics codes can provide services for other codes. Currently calculating the gravity at a given point is the only specified function. -.. autoclass:: amuse.community.interface.gd.GravitationalDynamicsInterface - :members: get_gravity_at_point +.. autoclass:: amuse.community.interface.gd.GravityFieldInterface + :members: get_gravity_at_point, get_potential_at_point diff --git a/doc/reference/stellar_evolution_interface_specification.rst b/doc/reference/stellar_evolution_interface_specification.rst index 5410c80a99..6c6e8d6f10 100644 --- a/doc/reference/stellar_evolution_interface_specification.rst +++ b/doc/reference/stellar_evolution_interface_specification.rst @@ -7,28 +7,29 @@ Introduction In this chapter we describe the common interface for stellar evolution codes. Currently the interface for stellar evolutions codes that store state of a star is specified. The Stellar Evolution codes that get all the needed -state from the function interface (are stateless), are not yet described. +state from the function interface (are stateless), are not yet described. Parameters ~~~~~~~~~~ Stellar Evolution codes have at least one specified parameter. Other parameters need to be specified on a per code basis. All parameters have to be accessed with functions following the template of the ``get_metallicity`` and ``set_metallicity`` functions. A parameter access function may only -retrieve or update the value of a single parameter. After all parameters have been set, the +retrieve or update the value of a single parameter. After all parameters have been set, the ``initialize_code`` function should be called, this gives the code the opportunity prepare the model. -.. autoclass:: amuse.community.interface.se.StellarEvolution +.. autoclass:: amuse.community.interface.se.StellarEvolutionInterface :members: get_metallicity, set_metallicity, initialize_code - + Object Management ~~~~~~~~~~~~~~~~~ -A number of stellar evolution codes work on star objects. The following -methods define the functionality to create, remove and query the particles in the code. +A number of stellar evolution codes work on star objects. The following +methods define the functionality to create, remove and query the particles in the code. *Currently the interface does not specify query function for stellar evolution, see stellar evolution for possible direction* -.. autoclass:: amuse.community.interface.se.StellarEvolution +.. autoclass:: amuse.community.interface.se.StellarEvolutionInterface + :no-index: :members: new_particle, delete_star Object State @@ -37,7 +38,8 @@ To support properties (like acceleration), the code must define ``get_`` and ``s functions must get or set one scalar property (1 argument) or a vector property (3 arguments) *Currently only get functions are specified* -.. autoclass:: amuse.community.interface.se.StellarEvolution +.. autoclass:: amuse.community.interface.se.StellarEvolutionInterface + :no-index: :members: get_mass, get_radius, get_luminosity, get_temperature, get_age, get_stellar_type, get_stellar_type From 6af952ee79baae3622fdca138b214c7f0ce7642f Mon Sep 17 00:00:00 2001 From: elkogerville Date: Mon, 16 Nov 2026 16:30:40 +0100 Subject: [PATCH 25/31] fix tidymess tutorial doc --- doc/tutorial/adding_example_code_tidymess.rst | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/doc/tutorial/adding_example_code_tidymess.rst b/doc/tutorial/adding_example_code_tidymess.rst index 2500b0923d..775012716d 100644 --- a/doc/tutorial/adding_example_code_tidymess.rst +++ b/doc/tutorial/adding_example_code_tidymess.rst @@ -4,17 +4,17 @@ Adding a C++ N-Body Code to AMUSE ================================= In this tutorial, we will create an interface from scratch for the -TIdal DYnamics of Multi-body ExtraSolar Systems code, or TIDYMESS, -written by Dr. Tjarda Boekholt and Dr. Alexandre Correia -(https://doi.org/10.48550/arXiv.2209.03955). This code implements detailed -tidal forces into an N-body code to track the deformation of bodies. +TIdal DYnamics of Multi-body ExtraSolar Systems code, or +`TIDYMESS `_, +written by Dr. Tjarda Boekholt and Dr. Alexandre Correia. This code implements +detailed tidal forces into an N-body code to track the deformation of bodies. This community code has already been implemented into AMUSE so you can follow along this tutorial. .. NOTE:: In this guide, TIDYMESS refers to the standalone simulation package, - while ``Tidymess`` refers to the TIDYMESS package inside of AMUSE. + while ``Tidymess`` refers to the TIDYMESS code inside of AMUSE. Getting Started @@ -417,19 +417,19 @@ The process of defining our interface starts with figuring out what type of code ``AMUSE`` has a set of predefined Python interfaces we can use to build our interface from. -+-----------------------------------+-------------------------------------------+ -| Interface: | Example codes: | -+-----------------------------------+-------------------------------------------+ -| ``GravitationDynamicsInterface`` | N-body: Tidymess, Ph4, Huayno, Fi | -+-----------------------------------+-------------------------------------------+ -| ``HydrodynamicsInterface`` | Hydro: Capreole | -+-----------------------------------+-------------------------------------------+ -| ``MagnetoHydrodynamicsInterface`` | Magneto Hydro: Athena | -+-----------------------------------+-------------------------------------------+ -| ``StellarEvolutionInterface`` | Stellar: MESA, EVtwin, SeBa | -+-----------------------------------+-------------------------------------------+ -| ``ChemicalEvolutionInterface`` | Chemistry: Krome, Uclchem, KromeSph | -+-----------------------------------+-------------------------------------------+ ++------------------------------------+---------------------------------------------------+ +| Interface: | Example codes: | ++------------------------------------+---------------------------------------------------+ +| ``GravitationalDynamicsInterface`` | N-body: ``Tidymess``, ``Ph4``, ``Huayno``, ``Fi`` | ++------------------------------------+---------------------------------------------------+ +| ``HydrodynamicsInterface`` | Hydro: ``Capreole`` | ++------------------------------------+---------------------------------------------------+ +| ``MagnetoHydrodynamicsInterface`` | Magneto Hydro: ``Athena`` | ++------------------------------------+---------------------------------------------------+ +| ``StellarEvolutionInterface`` | Stellar: ``MESA``, ``EVtwin``, ``SeBa`` | ++------------------------------------+---------------------------------------------------+ +| ``ChemicalEvolutionInterface`` | Chemistry: ``Krome``, ``Uclchem``, ``KromeSph`` | ++------------------------------------+---------------------------------------------------+ These interfaces define many of the required interface functions so that we don't have to. From 8938eb58b40469778402e6af54a357edddcca895 Mon Sep 17 00:00:00 2001 From: elkogerville Date: Mon, 16 Nov 2026 16:35:11 +0100 Subject: [PATCH 26/31] fix docstrings --- doc/tutorial/gravitational_dynamics_code.rst | 8 +++-- doc/tutorial/legacy_code.rst | 37 ++++++++++---------- doc/tutorial/plot.rst | 2 +- src/amuse/datamodel/base.py | 12 +++---- src/amuse/datamodel/particle_attributes.py | 5 ++- 5 files changed, 33 insertions(+), 31 deletions(-) diff --git a/doc/tutorial/gravitational_dynamics_code.rst b/doc/tutorial/gravitational_dynamics_code.rst index 11e6ec506f..f14d5e0309 100644 --- a/doc/tutorial/gravitational_dynamics_code.rst +++ b/doc/tutorial/gravitational_dynamics_code.rst @@ -503,15 +503,17 @@ interface, as in the following code snippet: include_headers = ['worker_code.h'] def __init__ (self, **keyword_arguments): - CodeInterface.__init__(self, + CodeInterface.__init__(self, name_of_the_worker="simplegrav_worker", **keyword_arguments) LiteratureReferencesMixIn.__init__(self) Upon finishing a script using ``SimpleGrav`` we will get the following warning: -.. code-block:: - /home/.../amuse/src/amuse/support/literature.py:78: AmuseWarning: + +.. code-block:: text + + /home/.../amuse/src/amuse/support/literature.py:78: AmuseWarning: You have used the following codes, which contain literature references: diff --git a/doc/tutorial/legacy_code.rst b/doc/tutorial/legacy_code.rst index 466b4429f5..92d8d356a5 100644 --- a/doc/tutorial/legacy_code.rst +++ b/doc/tutorial/legacy_code.rst @@ -2,16 +2,16 @@ Create an low-level Interface to a Code ======================================= -In this tutorial we will create an interface to a code. +In this tutorial we will create an interface to a code. .. warning:: - - This tutorial does not use the build script provided with + + This tutorial does not use the build script provided with AMUSE. All files and directories need to be created "by hand". Use this tutorial if you want to get a deeper understanding of how the build process works and which steps are involved in creating a low level interface. To learn how to create - an interface to a code we recommend :doc:`c_code` and + an interface to a code we recommend :doc:`c_code` and :doc:`fortran_code`. @@ -61,39 +61,39 @@ The contents of the code.c file: } We need to access these function from another C file, so we need to -define a header file. +define a header file. The contents of the code.h file: .. code-block:: cpp double sum(double x, double y); - + int divide(double x, double y, double * result); The interface code ~~~~~~~~~~~~~~~~~~ -Now we can define the interface class for our code in python. An +Now we can define the interface class for our code in python. An interface needs to inherit from the class "CodeInterface". .. code-block:: python :linenos: - + from amuse.community import * - + class MyCode(CodeInterface): include_headers = ['code.h'] - + def __init__(self): CodeInterface.__init__(self) - -In this example we first import names from the ``amuse.community`` -module on line 1. The ``amuse.community`` module defines the typical -classes and function needed to write a legacy interface. On line 3 -we define our class and inherit from ``CodeInterface``. The class -will be used to generate a C++ file. In this file we will need the -definitions of our legacy functions. So, on line 4 we specify the + +In this example we first import names from the ``amuse.community`` +module on line 1. The ``amuse.community`` module defines the typical +classes and function needed to write a legacy interface. On line 3 +we define our class and inherit from ``CodeInterface``. The class +will be used to generate a C++ file. In this file we will need the +definitions of our legacy functions. So, on line 4 we specify the necessary include files in a array of strings. Each string will be converted to an include statement. @@ -105,11 +105,12 @@ the build process. .. code-block:: make :linenos: + ifeq ($(origin AMUSE_DIR), undefined) AMUSE_DIR := $(shell amusifier --get-amuse-dir) endif -include ${AMUSE_DIR}/config.mk - + CXXFLAGS = -Wall -g -DTOOLBOX $(MUSE_INCLUDE_DIR) LDFLAGS = -lm $(MUSE_LD_FLAGS) diff --git a/doc/tutorial/plot.rst b/doc/tutorial/plot.rst index 642104717b..95533ad7db 100644 --- a/doc/tutorial/plot.rst +++ b/doc/tutorial/plot.rst @@ -81,7 +81,7 @@ Supported functions Example code ------------ -.. literalinclude:: ../../examples/applications/test_plot.py +.. literalinclude:: ../../src/tests/core_tests/test_plot.py .. image:: plots/plot1.png :width: 18cm diff --git a/src/amuse/datamodel/base.py b/src/amuse/datamodel/base.py index 6fee8dcbea..7f6c0f1c4b 100644 --- a/src/amuse/datamodel/base.py +++ b/src/amuse/datamodel/base.py @@ -1251,12 +1251,12 @@ def copy( The history of the set is not copied over. - - Keyword arguments: - memento -- internal, a dictionary to keep track of already copied sets in - case of links between particles (default: None, will be created) - keep_structure -- internal, if True, in case of a sub or super set make a copy of - the original set and return a new subset (default: False) + :parameter memento: internal, a dictionary to keep track of already copied sets in + case of links between particles (default: None, will be created) + :parameter keep_structure: internal, if True, in case of a sub or super set make a copy of + the original set and return a new subset (default: False) + :parameter filter_attributes: callable ``f(particles, attribute_name) -> bool``; + only attributes for which it returns True are copied """ raise NotImplementedError() diff --git a/src/amuse/datamodel/particle_attributes.py b/src/amuse/datamodel/particle_attributes.py index 0d00943d74..ddf8fb5005 100644 --- a/src/amuse/datamodel/particle_attributes.py +++ b/src/amuse/datamodel/particle_attributes.py @@ -58,7 +58,7 @@ def scale_to_standard( when the particles are in si units a convert_nbody is needed :argument smoothing_length_squared: needed for calculating the potential energy correctly. - :argument virial_ratio: scale velocities to Q=K/|U|, (kinetic/potential energy); + :argument virial_ratio: scale velocities to ``Q = K/|U|``, (kinetic/potential energy); Q = virial_ratio > 0.5: supervirial, will expand Q = virial_ratio < 0.5: subvirial, will collapse """ @@ -1014,8 +1014,7 @@ def Qparameter(parts, distfunc=None): for a projection of the particle set. :argument distfunc: distfunc is the distance function which can be used to select - the projection plane. - + the projection plane. """ if distfunc is None: From 0f91cb96f57281c03ec7ab41585eff933e0b3864 Mon Sep 17 00:00:00 2001 From: elkogerville Date: Mon, 16 Nov 2026 16:42:23 +0100 Subject: [PATCH 27/31] fixed docstrings --- ...llar_evolution_interface_specification.rst | 9 +-- doc/reference/stopping_conditions.rst | 4 +- src/amuse/units/generic_unit_converter.py | 20 +++---- src/amuse_hermite/interface.py | 59 +++++++++++-------- 4 files changed, 50 insertions(+), 42 deletions(-) diff --git a/doc/reference/stellar_evolution_interface_specification.rst b/doc/reference/stellar_evolution_interface_specification.rst index 6c6e8d6f10..18f874b852 100644 --- a/doc/reference/stellar_evolution_interface_specification.rst +++ b/doc/reference/stellar_evolution_interface_specification.rst @@ -48,17 +48,18 @@ Model evolution The stellar evolution codes evolve the properties of the star in time. The following functions are needed to control the evolution in the code. -.. autoclass:: amuse.community.interface.se.StellarEvolution - :members: commit_particles, evolve +.. autoclass:: amuse.community.interface.se.StellarEvolutionInterface + :no-index: + :members: commit_particles, evolve_for, evolve_one_step Diagnostics ~~~~~~~~~~~ -The state of the code can be queried, before, during and after the model calculations. +The state of the code can be queried, before, during and after the model calculations. *Currently no specific stellar evolution diagnostics functions have been defined* Services ~~~~~~~~ -Some stellar evolution codes can provide services for other codes. +Some stellar evolution codes can provide services for other codes. *Currently no specific stellar evolution service functions have been defined* diff --git a/doc/reference/stopping_conditions.rst b/doc/reference/stopping_conditions.rst index 975e89fa96..b103d0b8ba 100644 --- a/doc/reference/stopping_conditions.rst +++ b/doc/reference/stopping_conditions.rst @@ -446,11 +446,11 @@ based, i.e. the conditions are met if the outer loop took a certain time or a reached a certain number of steps (iterations). The parameters are accessed through the following procedures: -.. c:function:: int set_stopping_condition_timeout_parameter(double value); +.. c:function:: int set_stopping_condition_timeout_parameter(double value); Sets the computer (wall-clock) time parameter. -.. c:function:: get_stopping_condition_timeout_parameter(double *value); +.. c:function:: int get_stopping_condition_timeout_parameter(double *value); Gets the computer (wall-clock) time parameter. diff --git a/src/amuse/units/generic_unit_converter.py b/src/amuse/units/generic_unit_converter.py index 1c99ea4c73..16ebd46223 100644 --- a/src/amuse/units/generic_unit_converter.py +++ b/src/amuse/units/generic_unit_converter.py @@ -15,46 +15,46 @@ class NotAQuantityException(exceptions.AmuseException): class NotAScalarException(exceptions.AmuseException): formatstring = 'Converters need to be initialized with scalar quantities, argument[{0}] {1!r} is not a scalar' - + class GenericToSiConverter(object): def __init__(self, generic_to_si): self.generic_to_si = generic_to_si - + def from_source_to_target(self, quantity): if hasattr(quantity, 'unit') and not quantity.unit.is_non_numeric(): - return self.generic_to_si.to_si(quantity) + return self.generic_to_si.to_si(quantity) else: return quantity - + def from_target_to_source(self, quantity): if hasattr(quantity, 'unit') and not quantity.unit.is_non_numeric(): return self.generic_to_si.to_generic(quantity) else: return quantity - + class SiToGenericConverter(object): def __init__(self, generic_to_si): self.generic_to_si = generic_to_si - + def from_source_to_target(self, quantity): if hasattr(quantity, 'unit') and not quantity.unit.is_non_numeric(): - return self.generic_to_si.to_generic(quantity) + return self.generic_to_si.to_generic(quantity) else: return quantity - + def from_target_to_source(self, quantity): if hasattr(quantity, 'unit') and not quantity.unit.is_non_numeric(): return self.generic_to_si.to_si(quantity) else: return quantity - + class ConvertBetweenGenericAndSiUnits(object): """ A ConvertBetweenGenericAndSiUnits object is a converter from arbitrary units which user gives, to si units (and vice versa). - The ``generic_unit_converter'' **ConvertBetweenGenericAndSiUnits** + The ``generic_unit_converter`` **ConvertBetweenGenericAndSiUnits** is the actual class through which you define the unit system. Upon instantiation you choose the base units. In the example below we chose the speed of light as a unit: *c* = 1 unit length/second, diff --git a/src/amuse_hermite/interface.py b/src/amuse_hermite/interface.py index 04075f1aeb..ffd5cdc799 100644 --- a/src/amuse_hermite/interface.py +++ b/src/amuse_hermite/interface.py @@ -1,8 +1,13 @@ +import textwrap + from amuse.community import * -from amuse.community.interface.gd import GravitationalDynamicsInterface -from amuse.community.interface.gd import GravitationalDynamics -from amuse.community.interface.gd import SinglePointGravityFieldInterface -from amuse.community.interface.gd import GravityFieldCode +from amuse.community.interface.gd import ( + GravitationalDynamics, + GravitationalDynamicsInterface, + GravityFieldCode, + SinglePointGravityFieldInterface, +) + class HermiteInterface(CodeInterface, LiteratureReferencesMixIn, @@ -152,14 +157,15 @@ def get_time(): could not retrieve parameter """ return function - + @legacy_function def get_end_time_accuracy_factor(): """ Get the end time accuracy factor: - < 0 will stop between factor * dt befor the end time and the end time - 0 will stop at exactly the end time - > 0 will stop between the end time and factor * dt after the end time + + - Negative values stop between ``factor * dt`` before the end time and after the end time. + - Zero stops exactly at the end time. + - Positive values stop between the end time and ``factor * dt`` after the end time. """ function = LegacyFunctionSpecification() function.addParameter('value', dtype='float64', @@ -219,52 +225,53 @@ def define_state(self, handler): GravitationalDynamics.define_state(self, handler) GravityFieldCode.define_state(self, handler) self.stopping_conditions.define_state(handler) - + def define_parameters(self, handler): handler.add_method_parameter( "get_eps2", - "set_eps2", - "epsilon_squared", - "smoothing parameter for gravity calculations", + "set_eps2", + "epsilon_squared", + "smoothing parameter for gravity calculations", default_value = 0.0 | nbody_system.length * nbody_system.length ) handler.add_method_parameter( "get_dt_param", "set_dt_param", "dt_param", - "timestep scaling factor", + "timestep scaling factor", default_value = 0.03 ) handler.add_method_parameter( "get_end_time_accuracy_factor", "set_end_time_accuracy_factor", "end_time_accuracy_factor", - """ - Get the end time accuracy factor: - < 0.0 will stop on or before the end time (larger factor, more before) - 0.0 will stop at exactly the end time - > 0.0 will stop on or after the end time - - Valid factors are between -1.0 and 1.0 - """, + textwrap.dedent(""" + Get the end time accuracy factor: + + - Negative values will stop on or before the end time (larger factor, more before) + - Zero stops at exactly the end time + - Positive values will stop on or after the end time + + Valid factors are between -1.0 and 1.0. + """), default_value = 0.0 ) handler.add_method_parameter( "get_dt_dia", "set_dt_dia", - "dt_dia", - "time interval between diagnostics output", + "dt_dia", + "time interval between diagnostics output", default_value = 1.0 | nbody_system.time ) handler.add_method_parameter( "get_is_time_reversed_allowed", "set_is_time_reversed_allowed", - "is_time_reversed_allowed", - "if True will calculate back in time when evolve_model end time is less than systemtime", + "is_time_reversed_allowed", + "if True will calculate back in time when evolve_model end time is less than systemtime", default_value = False ) - + handler.add_method_parameter( "get_begin_time", "set_begin_time", From aa7f93f1ea96243de16dc5e87a6b3a7e0754ea98 Mon Sep 17 00:00:00 2001 From: elkogerville Date: Wed, 18 Nov 2026 14:50:35 +0100 Subject: [PATCH 28/31] try getting rtd to build correctly --- .readthedocs.yml | 2 ++ doc/reference/available-codes.rst | 13 +++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.readthedocs.yml b/.readthedocs.yml index ae24e555b2..6aed44a8df 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -24,3 +24,5 @@ formats: [] python: install: - requirements: doc/requirements.txt + - method: pip + path: . diff --git a/doc/reference/available-codes.rst b/doc/reference/available-codes.rst index 3aaa2eefdb..7a4b8f57f5 100644 --- a/doc/reference/available-codes.rst +++ b/doc/reference/available-codes.rst @@ -1051,13 +1051,18 @@ Eccentricity 0.0 1.0 seba ---- -Single-star and binary evolution is performed by the **rapid** stellar evolution algorithm SeBa. Stars are evolved from the zero-age main sequence until remnant formation and beyond. -Single stellar evolution is modeled with **analytical formulae** based on fits to detailed single star tracks at different metallicities (Hurley, Pols & Tout, 2000, 315, 543). Stars are parametrised by mass, radius, luminosity, core mass, etc. as functions of time and initial mass. Mass loss from winds, which is substantial e.g. for massive stars and post main-sequence stars, is included. +Single-star and binary evolution is performed by the **rapid** stellar evolution algorithm SeBa. Stars are evolved from +the zero-age main sequence until remnant formation and beyond. +Single stellar evolution is modeled with **analytical formulae** based on fits to detailed single star tracks at different metallicities (Hurley, Pols & Tout, 2000, 315, 543). Stars are parametrised by mass, radius, luminosity, core mass, etc. as functions of time and initial mass. Mass +loss from winds, which is substantial e.g. for massive stars and +post main-sequence stars, is included. Furthermore, the SeBa package contains an algorithm for **rapid** binary evolution calculations. Binary interactions such as wind accretion, tidal interaction and angular momentum loss through (wind) mass loss, magnetic braking, or gravitational radiation are taken into account at every timestep with appropriate recipes. -The stability and rate of mass transfer are dependent on the reaction to mass change of the stellar radii and the corresponding Roche lobes. If the mass transfer takes place on the dynamical timescale of the donor star, the mass transfer becomes quickly unstable, and a common-envelope phase follows. If mass transfer occurs in a stable way, SeBa models the response of the companion star and possible mass loss and angular momentum loss at every timestep. -After mass transfer ceases in a binary system, the donor star turns into a remnant or a helium-burning star without a hydrogen envelope. When instead, the mass transfer leads to a merger between the binary stars, the resulting stellar product is estimated and the subsequent evolution is followed. +The stability and rate of mass transfer are dependent on the reaction to mass +change of the stellar radii and the corresponding Roche lobes. If the mass transfer takes place on the dynamical timescale of the donor star, the mass transfer becomes quickly unstable, and a common-envelope phase follows. If mass transfer occurs in a stable way, SeBa models the response of the companion star and possible mass loss and angular momentum loss at every timestep. +After mass transfer ceases in a binary system, the donor star turns into a remnant or a helium-burning +star without a hydrogen envelope. When instead, the mass transfer leads to a merger between the binary stars, the resulting stellar product is estimated and the subsequent evolution is followed. More information on SeBa can be found in the papers: From f95fa5fc1336dc0f66affe18473f811525ebe781 Mon Sep 17 00:00:00 2001 From: elkogerville Date: Wed, 18 Nov 2026 14:55:03 +0100 Subject: [PATCH 29/31] fix path to toml --- .readthedocs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.readthedocs.yml b/.readthedocs.yml index 6aed44a8df..8a94ab742e 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -25,4 +25,4 @@ python: install: - requirements: doc/requirements.txt - method: pip - path: . + path: src/ From 26d3947b94fb76c85825a4465ebf13acf0d00559 Mon Sep 17 00:00:00 2001 From: elkogerville Date: Wed, 18 Nov 2026 15:00:03 +0100 Subject: [PATCH 30/31] try another fix --- .readthedocs.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.readthedocs.yml b/.readthedocs.yml index 8a94ab742e..a419caa5f9 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -10,6 +10,9 @@ build: os: ubuntu-22.04 tools: python: "3.7" + jobs: + post_install: + - python -m pip install --no-deps -e ./src sphinx: configuration: doc/conf.py @@ -24,5 +27,3 @@ formats: [] python: install: - requirements: doc/requirements.txt - - method: pip - path: src/ From 8f25662346319b1511380b218cbe258b0d8a953f Mon Sep 17 00:00:00 2001 From: elkogerville Date: Tue, 1 Dec 2026 17:02:33 +0100 Subject: [PATCH 31/31] more tidymess tutorial docs and doc fixes --- .../hydrodynamics_interface_specification.rst | 2 + ...ellar_dynamics_interface_specification.rst | 2 + ...llar_evolution_interface_specification.rst | 2 + doc/tutorial/adding_example_code_tidymess.rst | 238 +++++++++++++++--- .../interface/stopping_conditions.py | 2 +- 5 files changed, 210 insertions(+), 36 deletions(-) diff --git a/doc/reference/hydrodynamics_interface_specification.rst b/doc/reference/hydrodynamics_interface_specification.rst index 5cde5b9c68..4744125c15 100644 --- a/doc/reference/hydrodynamics_interface_specification.rst +++ b/doc/reference/hydrodynamics_interface_specification.rst @@ -1,3 +1,5 @@ +.. _hydrodynamics_interface: + ================================== Hydrodynamics Interface Definition ================================== diff --git a/doc/reference/stellar_dynamics_interface_specification.rst b/doc/reference/stellar_dynamics_interface_specification.rst index f57018ec41..3c1a803328 100644 --- a/doc/reference/stellar_dynamics_interface_specification.rst +++ b/doc/reference/stellar_dynamics_interface_specification.rst @@ -1,3 +1,5 @@ +.. _gravity_interface: + ===================================== Stellar Dynamics Interface Definition ===================================== diff --git a/doc/reference/stellar_evolution_interface_specification.rst b/doc/reference/stellar_evolution_interface_specification.rst index 18f874b852..5f976a31b9 100644 --- a/doc/reference/stellar_evolution_interface_specification.rst +++ b/doc/reference/stellar_evolution_interface_specification.rst @@ -1,3 +1,5 @@ +.. _stellar_evol_interface: + ======================================= Stellar Evolution Interface Definition ======================================= diff --git a/doc/tutorial/adding_example_code_tidymess.rst b/doc/tutorial/adding_example_code_tidymess.rst index 775012716d..c1fcce4b86 100644 --- a/doc/tutorial/adding_example_code_tidymess.rst +++ b/doc/tutorial/adding_example_code_tidymess.rst @@ -393,44 +393,212 @@ code. Creating the Interfaces ======================= -With TIDYMESS compiled into AMUSE, we can begin creating the interface. An AMUSE community code is accessed -through two interfaces: a Python interface and a native interface. The user only calls the Python interface -(i.e. ``tidymess.evolve_model``). AMUSE handles this call and translates it into a call to the native interface. -The native interface is written in the language of the community code (here C++) and either calls the code or -accesses its data. -The first step is writing the Python interface. Community codes are all unique and depend on diverse libraries -and programming languages. To make them interchangeable, AMUSE defines standard interfaces: sets of interface -functions that each code is mapped onto. Consequently, using any AMUSE code is standardized. +With TIDYMESS compiled into AMUSE, we can begin creating the interfaces. An AMUSE community code is accessed +through two interfaces: -Our job is therefore to map the TIDYMESS functions onto the AMUSE interface functions. The amusifier already -generated the required files: ``interface.py`` (Python interface) and ``interface.cc`` (native interface). +- **Python interface** (``interface.py``): what the user calls, e.g. ``tidymess.evolve_model``. +- **Native interface** (``interface.cc``): written in the language of the community code (here C++). + It calls the code or accesses its data. +A user call is handled as follows: + +1. The user calls a method of the Python interface. +2. AMUSE translates the call (arguments, units, particle sets) and sends it to the worker, a separate process + that is built from the native interface and the community code. +3. The worker executes the matching native function, which calls the code or reads/writes its data. +4. The return values travel back to the Python interface, and hence back to the user. + +The first step is writing the Python interface. + +Our job is therefore to map the TIDYMESS functions onto the AMUSE interface functions. The amusifier has already +generated stubs for both files: ``interface.py`` (Python interface) and ``interface.cc`` (native interface). Defining the Python interface ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -The ``interface.py`` actually defines two classes: the high-level and low-level Python interfaces. The high-level -interface is what the user interacts with when using the community code. This defines the methods, parameters, -and properties of each community code, and defines how the ``amuse.datamodel.particles`` work within that code. -The ``amusifer`` generates a minimal code stub for the ``interface.py``, which is enough to get us started. -The process of defining our interface starts with figuring out what type of code we are adding to ``AMUSE``. -``AMUSE`` has a set of predefined Python interfaces we can use to build our interface from. - - -+------------------------------------+---------------------------------------------------+ -| Interface: | Example codes: | -+------------------------------------+---------------------------------------------------+ -| ``GravitationalDynamicsInterface`` | N-body: ``Tidymess``, ``Ph4``, ``Huayno``, ``Fi`` | -+------------------------------------+---------------------------------------------------+ -| ``HydrodynamicsInterface`` | Hydro: ``Capreole`` | -+------------------------------------+---------------------------------------------------+ -| ``MagnetoHydrodynamicsInterface`` | Magneto Hydro: ``Athena`` | -+------------------------------------+---------------------------------------------------+ -| ``StellarEvolutionInterface`` | Stellar: ``MESA``, ``EVtwin``, ``SeBa`` | -+------------------------------------+---------------------------------------------------+ -| ``ChemicalEvolutionInterface`` | Chemistry: ``Krome``, ``Uclchem``, ``KromeSph`` | -+------------------------------------+---------------------------------------------------+ - -These interfaces define many -of the required interface functions so that we don't have to. -In this case, ``TIDYMESS`` is a N-Body code, and therefore falls under the + +``interface.py`` defines two classes: + +- ``TidymessInterface``: declares the functions that exist in the native interface, with their argument and + return types. Works on plain numbers and arrays, without units. This is the bridge to the worker. +- ``Tidymess``: the class the user instantiates. Wraps ``TidymessInterface`` and defines the methods, parameters + and properties of the code, the units, and how ``amuse.datamodel.particles`` map onto the code. + + +Choosing a standard interface +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Community codes are all unique and depend on diverse libraries and programming languages. To make them +interchangeable, AMUSE defines *standard interfaces*: sets of interface functions that each code of a +given type is mapped onto. This way, AMUSE users do not need to learn how to use each code, but rather only +the AMUSE framework. It is our job to figure out how to map TIDYMESS to these interface methods. + +The first decision is which type of code is being added. AMUSE provides predefined standard interfaces to inherit from: + ++--------------------------------------------------------------+---------------------------------------------------+ +| Interface: | Example codes: | ++--------------------------------------------------------------+---------------------------------------------------+ +| :ref:`GravitationalDynamicsInterface `: | N-body: ``Tidymess``, ``Ph4``, ``Huayno``, ``Fi`` | ++--------------------------------------------------------------+---------------------------------------------------+ +| :ref:`HydrodynamicsInterface `: | Hydro: ``Capreole`` | ++--------------------------------------------------------------+---------------------------------------------------+ +| MagnetoHydrodynamicsInterface | Magneto Hydro: ``Athena`` | ++--------------------------------------------------------------+---------------------------------------------------+ +| :ref:`StellarEvolutionInterface `: | Stellar: ``MESA``, ``EVtwin``, ``SeBa`` | ++--------------------------------------------------------------+---------------------------------------------------+ +| ChemicalEvolutionInterface | Chemistry: ``Krome``, ``Uclchem``, ``KromeSph`` | ++--------------------------------------------------------------+---------------------------------------------------+ + +Inheriting from a standard interface provides most of the required interface functions, so we do not have to +declare them ourselves. ``TIDYMESS`` is an N-body code and therefore inherits from the gravitational dynamics +interface. + + +Minimal starting point +~~~~~~~~~~~~~~~~~~~~~~ + +Below is a minimal starting point for our Nbody code interface. Note that this was slightly modified +from the ``interface.py`` automatically generated by the ``amusifier`` script. + +.. code-block:: python + + from amuse.community.interface.gd import ( + GravitationalDynamics, + GravitationalDynamicsInterface, + ) + from amuse.community.interface.stopping_conditions import ( + StoppingConditionInterface, + StoppingConditions, + ) + from amuse.rfi.core import ( + CodeInterface, + LegacyFunctionSpecification, + legacy_function, + remote_function, + ) + from amuse.support.literature import LiteratureReferencesMixIn + + + class TidymessInterface( + CodeInterface, + LiteratureReferencesMixIn, + GravitationalDynamicsInterface, + StoppingConditionsInterface, + ): + """ + Tidymess is a N-Body code with tides. + + .. [#] Boekholt & Correia (MNRAS 2023, vol. 522, pp. 2885–2900) + """ + include_headers = ["tidymess_worker.h", "stopcond.h"] + + def __init__(self, **keyword_arguments): + CodeInterface.__init__( + self, name_of_the_worker="tidymess_worker", **keyword_arguments + ) + LiteratureReferencesMixIn.__init__(self) + + + class Tidymess(GravitationalDynamics): + def __init__(self, convert_nbody=None, **options): + super().__init__( + self, TidymessInterface(**options), convert_nbody, **options + ) + self.stopping_conditions = StoppingConditions(self) + + +Low level Python Interface: ``TidymessInterface`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The low level Python interface acts like a bridge between the the user and underlying native interface. +Here, every method in the public API of our code must be defined as a ``legacy_function``. We can inherit +a set of useful standard interfaces to avoid having to redefine every function. + +- ``CodeInterface``: Abstract base class for all AMUSE interfaces. Required for + managing the code worker, channels, and communication between the python interface and the native interface. +- ``GravitationalDynamicsInterface``: Base class for stellar dynamics in AMUSE. Useful for managing + particles acting under gravity. +- ``LiteratureReferenceMixIn``: Adds citations to your interface which are displayed each time someone + uses your code. Each ``.. [#]`` adds a new citation. + + +Defining Legacy Functions +------------------------- + +Having inherited from the ``GravitationalDynamicsInterface``, we need to define only the functions +specific to TIDYMESS. There is one exception to this rule: we must redefine any function whose +signature does not match with TIDYMESS. For example, ``new_particle`` by default has the input +parameters ``mass``, ``x``, ``y``, ``z``, ``vx``, ``vy``, ``vz``, and ``radius``. Tidymess particles +have all of these attributes, in addition to the tidal paramters ``xi``, ``kf``, ``tau``, ``wx``, +``wy``, ``wz``, and ``a_mb``. We unfortunately will have to redefine some but not all of the +inherited functions. Below is typical syntax for defining a ``legacy_function``. + +.. code-block:: python + + particle_attributes = [ + 'mass', + 'radius', + 'x', 'y', 'z', + 'vx', 'vy', 'vz', + 'xi', 'kf', 'tau', + 'wx', 'wy', 'wz', + 'a_mb' + ] + + @legacy_function + def new_particle(): + """Add a particle to Tidymess.""" + function = LegacyFunctionSpecification() + function.can_handle_array = True + function.addParameter('index_of_the_particle', dtype='i', direction=function.OUT) + for name in particle_attributes: + function.addParameter(name, dtype='d', direction=function.IN) + function.result_type = 'i' + function.result_doc = """ + 0 - OK + particle was created and added to Tidymess + -1 - ERROR + particle could not be created + """ + return function + + +- The ``@legacy_function`` decorator is required for the method to work within AMUSE. +- ``can_handle_array`` allows AMUSE to send over arrays for lower overhead during communication. +- For each parameter (``x``, ``mass``, etc), add it via the ``addParameter`` method. The first + argument specifies the name of the parameter, the second the dtype and the third the direction. + Direction signifies whether the parameter is an input or an output. +- All ``legacy_functions`` mirror C type functions and therefore return a status code (int). + This is indicated by ``result_type``. + +For functions unique to TIDYMESS (i.e. functions that are not implemented in a standard interface), +it is possible to use the simplified ``legacy_function`` interface, or a ``remote_function``. +For more information, see :ref:`simplified interface function definitions `. + +.. code-block:: python + + @remote_function + def get_roche_mode(): + """ + Retrieve Tidymess roche mode parameter. + + Returns + ------- + roche_mode : int + Roche mode parameter: 0=off, 1=flag, 2=exception. + """ + returns (roche_mode='i') + + +High level: ``Tidymess`` +~~~~~~~~~~~~~~~~~~~~~~~~ + +The high level Python interface acts as the public API for users using our ``Tidymess`` code. Any legacy function +defined in ``TidymessInterface`` must also be defined in ``Tidymess``. However, this time we must choose the role +of each legacy function. High level interfaces sort each legacy function as either a method, parameter, or property. +We also define how particle sets are managed, as well as the AMUSE state model. Just like the ``TidymessInterface``, +we can also inherit a set of interfaces to avoid redefining certain functions. + + +- ``GravitationalDynamics``: Base class which provides useful methods, parameters, and properties for any + gravitational dynamics code. diff --git a/src/amuse/community/interface/stopping_conditions.py b/src/amuse/community/interface/stopping_conditions.py index 5d746c1000..92c7a1690e 100644 --- a/src/amuse/community/interface/stopping_conditions.py +++ b/src/amuse/community/interface/stopping_conditions.py @@ -134,7 +134,7 @@ def get_stopping_condition_info(): """ Generic function for getting the information connected to a stopping condition. Index can be between 0 and - the result of the :method:`get_number_of_stopping_conditions_set` + the result of the :meth:`get_number_of_stopping_conditions_set` method. """ function = LegacyFunctionSpecification()