diff --git a/.readthedocs.yml b/.readthedocs.yml index ae24e555b2..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 diff --git a/doc/Makefile b/doc/Makefile index 91386950dd..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 @@ -31,7 +28,7 @@ help: amuse_examples: ln -s ../examples amuse_examples - + clean: -rm -rf $(BUILDDIR)/* -rm -rf html @@ -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' 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/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." ] 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, 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 - diff --git a/doc/reference/available-codes.rst b/doc/reference/available-codes.rst index 17c18d10ae..7a4b8f57f5 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 | | | | | | +------------------------------------+---------------+---------------+-------------------+ @@ -1052,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: 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 --------------------------- 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..d21a9bbb14 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. @@ -159,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. @@ -210,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. diff --git a/doc/reference/hydrodynamics_interface_specification.rst b/doc/reference/hydrodynamics_interface_specification.rst index 89ff732c5e..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 ================================== @@ -14,32 +16,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 +53,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 +63,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 +81,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..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 ===================================== @@ -12,33 +14,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 +52,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 +62,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 @@ -73,5 +80,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..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 ======================================= @@ -7,28 +9,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 +40,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 @@ -46,17 +50,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/doc/tutorial/adding_example_code_tidymess.rst b/doc/tutorial/adding_example_code_tidymess.rst new file mode 100644 index 0000000000..c1fcce4b86 --- /dev/null +++ b/doc/tutorial/adding_example_code_tidymess.rst @@ -0,0 +1,604 @@ +.. _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. + +.. NOTE:: + + In this guide, TIDYMESS refers to the standalone simulation package, + while ``Tidymess`` refers to the TIDYMESS code inside of AMUSE. + + +Getting Started +=============== + +This tutorial assumes you have a working amuse or amuse development build, +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 + + > 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 +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. 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``. +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. +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 delete most of those and simplify our dependencies to: + +.. code-block:: text + + c++ + +To test that we did everything properly, we can run ``./setup`` from the top-level directory of AMUSE + +.. code-block:: text + + > 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 +~~~~~~~~~~~~~~~~~~~ +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 +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). + +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. 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`` +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/`` + 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. 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 +======================= +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 + + 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 + +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 + + DEPFLAGS += $(STOPCOND_CFLAGS) + CXXFLAGS += $(DEPFLAGS) + + LDLIBS += -lm $(STOPCOND_LIBS) + + +Building the static library +~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. code-block:: make + + CODELIB = src/libtidymess.a + + .PHONY: $(CODELIB) + $(CODELIB): | src/tidymess + $(MAKE) -C src -j $(CPU_COUNT) all + +- ``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)``. + +.. 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) $< + + +Package targets +~~~~~~~~~~~~~~~ +The worker is the executable AMUSE spawns to communicate with the community +code. + +.. 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 + +- ``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 begin creating the interfaces. An AMUSE community code is accessed +through two interfaces: + +- **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 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +``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/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/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 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/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() 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: 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",