Common Errors and Pitfalls
This page collects common errors and easy pitfalls encountered by beginners (and sometimes even advanced!) users of AMUSE. It is organized in a list of common mistakes and pitfalls, a selection of common error messages, which may not be easily decipherable and a list of code specific issues.
Common mistakes and Pitfalls
Being written in Python, AMUSE not always behaves in a way that users may expect.
unit handling
an expression like:
>>> print 1.|units.m + 1.|units.m
will evaluate to an error message:
Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unsupported operand type(s) for +: 'base_unit' and 'float'
The reason for this is the low precedence of the '|' used for constructing quantities. The correct way to write the above is:
>>> print (1.|units.m) + (1.|units.m)
Liberal use of parentheses is recommended for unit expressions.
unit none
As of feb 2012 and for release versions after 5.1 arithmetic expressions with result in a quantity with unit.none will automatically drop the unit none. If you get an error in an existing script which converted to a float, e.g.:
>>> print ((1| units.km)/(1| units.cm)).value_in(unit.none) Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'float' object has no attribute 'value_in'
remove the .value_in(unit.none) bit:
>>> print ((1| units.km)/(1| units.cm)) 100000.0
python lists and numpy arrays
Python lists and numpy arrays can both be used in AMUSE (e.g. in combination with units. Beware of the differences:
>>> print [0.] *3 |units.m [0.0, 0.0, 0.0] m >>> print numpy.array([1.]) *3 |units.m [3.0] m
Common error message
AMUSE will often generate quite verbose error messages. We list here the most common error messages with their cause and solution. If you repeatedly encounter an error that is not listed here please join us on the #amuse irc channel to discuss this.
- " TypeError: unsupported operand type(s) for +: 'base_unit' and 'float' "
this error indicates a syntax error writing an unit expression, see unit handling.
- " ImportError: No module named amuse.units "
If you try to start an amuse script and you get an import error, e.g.:> python salpeter.py Traceback (most recent call last): File "salpeter.py", line 3, in <module> from amuse.units import units ImportError: No module named amuse.unitsthis often indicates that python can not find the amuse components. run through the amuse.sh script:> path/to/amuse/amuse.sh salpeter.py
or set the PYTHONPATH environment variable to include the amuse src directory.
- " amuse.support.exceptions.CodeException: The worker application does not exists, it should be at: ... "
This error message is accompanied by a verbose error, e.g.:./amuse.sh examples/simple/molecular_cloud.py Traceback (most recent call last): File "examples/simple/molecular_cloud.py", line 99, in <module> run_mc(10000,Mcloud=1000. | units.MSun,Rcloud=1. | units.parsec) File "examples/simple/molecular_cloud.py", line 59, in run_mc sph=Fi(conv) File "/data2/pelupes/amuse/amuse-new/src/amuse/community/fi/interface.py", line 1522, in __init__ legacy_interface = FiInterface(mode = mode, **options) File "/data2/pelupes/amuse/amuse-new/src/amuse/community/fi/interface.py", line 34, in __init__ CodeInterface.__init__(self, name_of_the_worker = self.name_of_the_worker(mode), **options) File "/data2/pelupes/amuse/amuse-new/src/amuse/support/codes/core.py", line 586, in __init__ self.channel = self.channel_factory(name_of_the_worker, type(self), **options) File "/data2/pelupes/amuse/amuse-new/src/amuse/support/codes/channel.py", line 553, in __init__ self.full_name_of_the_worker = self.get_full_name_of_the_worker( legacy_interface_type) File "/data2/pelupes/amuse/amuse-new/src/amuse/support/codes/channel.py", line 463, in get_full_name_of_the_worker raise exceptions.CodeException("The worker application does not exists, it should be at: {0}".format(tried_workers)) amuse.support.exceptions.CodeException: The worker application does not exists, it should be at: ['/data2/pelupes/amuse/amuse-new/src/amuse/community/fi/fi_worker', '/data2/pelupes/amuse/amuse-new/src/amuse/support/codes/fi_worker']This may be caused by amuse not being compiled, type:> make
in the amuse root. Or it may be that compiling the code in question has failed. This latter may be caused by missing components which should be downloaded first or by an error encountered during the compilation. Downloadable components will be installed if you set the DOWNLOAD_CODES environment variable and do make in the AMUSE root. If the compilation of a code failed you can type:make name_of_the_code.code
in the AMUSE root to get a hint of the reason why it failed.
- " TclError: no display name and no $DISPLAY environment variable "
This error occurs when matplotlib fails to open an interactive backend, for example when you're logged in to a machine remotely. If you want to use the interactive window, re-login and try enabling X11 forwarding with the -X option:> ssh -X user@remote_machine
On the other hand, if you don't need the interactive window and you only use matplotlib to save the plots to file, try using a different, non-interactive backend such as Agg (for PNGs), PDF, SVG or PS. The best way to make any of these the default is by creating a file called matplotlibrc in your current working directory, which contains a line selecting the backend of your choice:backend: Agg
Code specific issues
Although most codes have a similar interfaces, some codes have special features or options that you may need to be aware of.
Gadget
Some modes of operation for Gadget are not accessible from within the AMUSE interface, but need to be set in the makefile_options file in the gadget /src directory.
gadget has the following predefined modes: periodic, nogravity, which you can use by starting up the interface with for example:
gadget=gadget2(mode="periodic")
Sometimes you run into problems with timesteps which are too small. Check the value of parameter time_max and make sure it is not too big. It is also good practice to limit the internal gadget timestep (by setting parameter max_size_timestep) to be smaller than the timestep in your script. It is also a good idea to make the time_max an integer power of 2 multiple of the timestep in the script (internally gadget uses an integer timeline)
Fi
A common error is caused by the fact that Fi uses a fixed computational box (set by the parameter periodic_box_size, even if not using the periodic mode). This parameter is set to 300 in internal units by default, but can be set to any value. Recomendation is to set it explicitly.