Skip to content
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

Athena "temperature" issue #2486

Closed
matthewturk opened this issue Mar 17, 2020 · 4 comments
Closed

Athena "temperature" issue #2486

matthewturk opened this issue Mar 17, 2020 · 4 comments
Labels
code frontends Things related to specific frontends units

Comments

@matthewturk
Copy link
Member

There is something strange going on with athena's temperature field for the case that pressure does not exist on-disk.

Unfortunately, surfacing the specific error requires changing a line of source code. In yt/fields/field_info_container.py change line 47 as follows:

diff --git a/yt/fields/field_info_container.py b/yt/fields/field_info_container.py
index fd87796c1..5d10d1d82 100644
--- a/yt/fields/field_info_container.py
+++ b/yt/fields/field_info_container.py
@@ -44,7 +44,7 @@ class FieldInfoContainer(dict):
     extra_union_fields = ()
 
     def __init__(self, ds, field_list, slice_info = None):
-        self._show_field_errors = []
+        self._show_field_errors = [("gas", "temperature")]
         self.ds = ds
         # Now we start setting things up.
         self.field_list = field_list

Now, this script, using the MHD Blast wave sample dataset:

import yt
ds = yt.load("MHDBlast/id0/Blast.0100.vtk")

produces this strange error:

Traceback (most recent call last):
  File "/home/mturk/yt/unyt/unyt/unit_registry.py", line 72, in __getitem__
    ret = self.lut[str(key)]
KeyError: 'code_pressure'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/mturk/yt/unyt/unyt/unit_registry.py", line 75, in __getitem__
    _lookup_unit_symbol(str(key), self.lut)
  File "/home/mturk/yt/unyt/unyt/unit_registry.py", line 331, in _lookup_unit_symbol
    "Could not find unit symbol '%s' in the provided " "symbols." % symbol_str
unyt.exceptions.UnitParseError: Could not find unit symbol 'code_pressure' in the provided symbols.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/mturk/yt/yt/yt/convenience.py", line 70, in load
    return candidates[0](*args, **kwargs)
  File "/home/mturk/yt/yt/yt/frontends/athena/data_structures.py", line 450, in __init__
    self.index
  File "/home/mturk/yt/yt/yt/data_objects/static_output.py", line 448, in index
    self.create_field_info()
  File "/home/mturk/yt/yt/yt/data_objects/static_output.py", line 523, in create_field_info
    deps, unloaded = self.field_info.check_derived_fields()
  File "/home/mturk/yt/yt/yt/fields/field_info_container.py", line 400, in check_derived_fields
    fd = fi.get_dependencies(ds = self.ds)
  File "/home/mturk/yt/yt/yt/fields/derived_field.py", line 223, in get_dependencies
    e[self.name]
  File "/home/mturk/yt/yt/yt/fields/field_detector.py", line 109, in __missing__
    vv = finfo(self)
  File "/home/mturk/yt/yt/yt/fields/derived_field.py", line 263, in __call__
    dd = self._function(self, data)
  File "/home/mturk/yt/yt/yt/frontends/athena/fields.py", line 104, in _temperature
    return data.ds.mu*mh*data["gas","pressure"]/data["gas","density"]/kboltz
  File "/home/mturk/yt/unyt/unyt/array.py", line 1751, in __array_ufunc__
    mul, unit = unit_operator(u0, u1)
  File "/home/mturk/yt/unyt/unyt/array.py", line 163, in _multiply_units
    ret = (unit1 * unit2).simplify()
  File "/home/mturk/yt/unyt/unyt/unit_object.py", line 732, in simplify
    self.expr = _cancel_mul(expr, self.registry)
  File "/home/mturk/yt/unyt/unyt/unit_object.py", line 767, in _cancel_mul
    u1 = _create_unit_from_factor(pair[0], registry)
  File "/home/mturk/yt/unyt/unyt/unit_object.py", line 756, in _create_unit_from_factor
    f = registry[str(base)]
  File "/home/mturk/yt/unyt/unyt/unit_registry.py", line 79, in __getitem__
    "The symbol '%s' does not exist in this registry." % key
unyt.exceptions.SymbolNotFoundError: The symbol 'code_pressure' does not exist in this registry.

I genuinely can't figure out how to address this. Especially because, from what I can see, the unit registry should have code_pressure -- and in fact, if I just let it go without raising the error, it actually shows up in ds.unit_registry . I'm reluctant to say this is a unyt issue as I fear that there's some order of operations issue I'm not seeing. Is it possible that this is occuring because of a different unit registry during field detection, that doesn't have code_pressure defined?

@triage-new-issues triage-new-issues bot added the triage Triage needed label Mar 17, 2020
@matthewturk matthewturk added code frontends Things related to specific frontends units labels Mar 17, 2020
@triage-new-issues triage-new-issues bot removed the triage Triage needed label Mar 17, 2020
@matthewturk
Copy link
Member Author

It seems that the issue is that multiplication in unyt is not precisely commutative -- changing the definition of the temperature field from

data.ds.mu*mh*data["gas","pressure"]/data["gas","density"]/kboltz

to

data.ds.mu*data["gas","pressure"]/data["gas","density"]/kboltz*mh

fixes the issue! Only the first unit gets checked for a registry. A hotfix here would be to change to the second definition -- not sure if that's the long-term solution.

@matthewturk
Copy link
Member Author

(Also, thanks to @Xarthisius for figuring this out)

@brittonsmith
Copy link
Member

I believe this is the same as what was happening in PR #2454.

@neutrinoceros
Copy link
Member

It seems that the issue is that multiplication in unyt is not precisely commutative

I think this is resolved upstream since yt-project/unyt#164 (included in unyt 2.8.0, which is the latest release to date and the minimal required version as of yt 4.0)
Indeed, I cannot reproduce the error now, so let's close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code frontends Things related to specific frontends units
Projects
None yet
Development

No branches or pull requests

3 participants