Support for arbitrary precision attributes for (e.g.) Brutus
Brutus particle sets currently do not support arbitrary precision..most elegant would be to allow particle attributes to be mpmath or gmpy arbitrary precision numbers and send those over as strings (using the lowlevel functions that are already implemented for brutus)
this is important to allow saving and resuming sims at arbitrary precision
Hi,
This seems related to a problem I had at some point, where I wanted to store lower-precision numbers. Nathan wrote the following then:
Quantities in amuse get their data type from their unit. This may sound strange, but it's actually quite natural if you consider enumeration units, string units and particle keys. The default dtype of a unit is indeed a double precision float. This is very easy to override, if you know how to do it ;)
from amuse.units.core import unit_with_specific_dtype
from amuse.lab import *
import numpy
set = Particles(4)
set.mass = [0.01] | unit_with_specific_dtype(units.kg, numpy.float32)
set.radius = [0.9] | unit_with_specific_dtype(units.m, numpy.int32)
print set
key mass radius
- kg_<type 'numpy.float32'> m_<type 'numpy.int32'>
==================== =========== ===========
3563617830469061953 1.000e-02 0
1881275734648031197 1.000e-02 0
93170770887821082 1.000e-02 0
9144493898677132023 1.000e-02 0
==================== =========== ===========
Maybe this would work similarly for arbitrary precision number particle sets?
I am not sure I like the unit_with_specific_dtype (not because currently it is buggy), I think it should be enough that number has a certain dtype...(but maybe it isn't??)..as a side note: enumeration units, string units and particle key units should maybe be deprecated (no longer necessary(?))...
its not pretty but:
m_= unit_with_specific_dtype(units.m, object)
in combination with:
a=numpy.array(gmpy.mpf(i) for i in range(10)], dtype=object) | m_
p=Particles(10)
p.x=a
substantially works, there are some ugly bits though (unit string= m_object), there may not be more than 1 m_object etc, e.g. copies between inmem sets work, copies to code sets will not work I think... (not checked)
note the comment on #579