New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Long term solution for units in AuxReaders and in general #3792
Comments
Personally I think we will need to move to a units management system at some point. |
We'd also need to decide if more exotic units should be converted or not. Some of the units that can occur in EDR files are
and a few of these are not yet mentioned in our docs. What do we want to do with pressures and dipole moments, for example? |
Most should be derivable from our base units, eg pressure is Force/Area so should be kJ/molA^3? And dipole moment eA. But I agree this is a bit of a challenge and we should enhance docs whatever we decide. |
I am going to add this as a discussion point for 3.0 ? If we are going to change to a units package 3.0 would be a good time to do it. |
Xarray just transitioned to using pint. Check out their blog on the subject. |
Compared to my comment in the other thread - long enough ago I forget having written it - I'd recommend Pint as the one solution to reach for. Something else to consider is that Pint makes it easy to create your own unit registry, if you need exotic stuff not explicitly included in the default >>> from openff.units import unit as unit1
>>> import pint
>>> unit2 = pint.UnitRegistry()
>>> 1.0 * unit1.meter + 1.0 * unit2.meter
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/mattthompson/miniconda3/envs/openff-interchange-env/lib/python3.9/site-packages/pint/quantity.py", line 1154, in __add__
return self._add_sub(other, operator.add)
File "/Users/mattthompson/miniconda3/envs/openff-interchange-env/lib/python3.9/site-packages/pint/quantity.py", line 139, in wrapped
return f(self, *args, **kwargs)
File "/Users/mattthompson/miniconda3/envs/openff-interchange-env/lib/python3.9/site-packages/pint/quantity.py", line 1032, in _add_sub
if not self._check(other):
File "/Users/mattthompson/miniconda3/envs/openff-interchange-env/lib/python3.9/site-packages/pint/util.py", line 846, in _check
raise ValueError(
ValueError: Cannot operate with Quantity and Quantity of different registries. I'm a bit curious, though, is the proposal to change most uses of
If I'm assuming incorrectly and the idea is to use |
Thanks @mattwthompson! Super useful info and good to get a perspective from an ecosystem that uses Interesting comments about speed, given what you have said I imagine we won't switch to |
Yeah, so I think in discussions with @orbeckst @richardjgowers and @lilyminium we were also quite wary of the extra costs, I think there was maybe some rough idea where we would keep |
My objections lay mainly along having to contort code to fit operations that pint doesn't support, similar to what @mattwthompson's mentioned. Given that we return a copy of a numpy array every time we request xarray has gotten around some of this with their numpy support ( |
Is your feature request related to a problem?
Some discussions on #3749 brought up conversion of units in the
AuxReaders
. Our current solution used in the coordinate readers is to hardcode the units for the relevant format in and then convert while required.While this may be an OK solution for the coordinates where the units are relatively simple, the more exotic units that are possible to read in an EDR file for example make this process more complicated. This is a general problem for all proposed AuxReaders, as they are generally aimed at providing an interface to those "more exotic" pieces of information obtained from a simulation.
Additionally this solution doesn't scale well to packages like LAMMPs where you can use up to 8 different unit systems. We will probably need consider if some kind of units package is the best way to deal with this long term.
Use of
unyt
orpint
where raised in the related issue #2230The text was updated successfully, but these errors were encountered: