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

region arithmetic funniness #2560

Closed
zingale opened this issue Apr 25, 2020 · 2 comments · Fixed by #2561
Closed

region arithmetic funniness #2560

zingale opened this issue Apr 25, 2020 · 2 comments · Fixed by #2561
Labels

Comments

@zingale
Copy link
Member

zingale commented Apr 25, 2020

Bug report

Bug summary

If I mix ds.domain_left_edge with a list composed of components of ds.domain_*, I get a YTUnitOperationError

Code for reproduction

import numpy as np
import yt

plotfile = "smallplt00595"

ds = yt.load(plotfile)



center = ds.domain_center
lower_left = ds.domain_left_edge
upper_right = ds.domain_right_edge

ll = [lower_left[0], lower_left[1], lower_left[2]]
rr = [center[0], upper_right[1], upper_right[2]]
region1 = ds.box(ll, rr)
print(region1)

ll = lower_left
rr = [center[0], upper_right[1], upper_right[2]]

region2 = ds.box(ll, rr)

Actual outcome

$ python3 test_region.py
yt : [INFO     ] 2020-04-25 14:16:34,930 Parameters: current_time              = 7.24422756567562
yt : [INFO     ] 2020-04-25 14:16:34,930 Parameters: domain_dimensions         = [512 512 512]
yt : [INFO     ] 2020-04-25 14:16:34,930 Parameters: domain_left_edge          = [-5.12e+09 -5.12e+09 -5.12e+09]
yt : [INFO     ] 2020-04-25 14:16:34,930 Parameters: domain_right_edge         = [5.12e+09 5.12e+09 5.12e+09]
YTRegion (smallplt00595): , center=[-2.56e+09  0.00e+00  0.00e+00] cm, left_edge=[-5.12e+09 -5.12e+09 -5.12e+09] cm, right_edge=[0.00e+00 5.12e+09 5.12e+09] cm
Traceback (most recent call last):
  File "test_region.py", line 22, in <module>
    region2 = ds.box(ll, rr)
  File "/raid/zingale/development/yt/yt/data_objects/static_output.py", line 854, in box
    c = (left_edge + right_edge)/2.0
  File "/raid/zingale/development/yt/yt/units/yt_array.py", line 1414, in __array_ufunc__
    inps, units, ufunc, ret_class)
  File "/raid/zingale/development/yt/yt/units/yt_array.py", line 174, in handle_preserve_units
    raise YTUnitOperationError(ufunc, *units)
yt.utilities.exceptions.YTUnitOperationError: The <ufunc 'add'> operator for YTArrays with units (code_length) and (dimensionless) is not well defined.

Expected outcome

I would expect to for both of these ways to compose a region to work.

Version Information

  • Operating System: Fedora 31
  • Python Version: 3.7.6
  • yt version: 3.7.dev0
  • Other Libraries (if applicable): numpy 1.17.4

yt built from source (python setup.py develop)

@triage-new-issues triage-new-issues bot added the triage Triage needed label Apr 25, 2020
@triage-new-issues triage-new-issues bot removed the triage Triage needed label Apr 25, 2020
@neutrinoceros
Copy link
Member

neutrinoceros commented Apr 25, 2020

I was able to reproduce this using yt.testing.fake_amr_ds() as a dataset, though the error I'm getting is not exactly the same but it gave some insight.
I think what's happening here is that, because of how Dataset.box() forces the args (left/right_edge) as numpy arrays, it behaves differently depending on the arguments' form

In those cases, here's what happens during the conversion:

  • [0.0 code_length, 0.0 code_length, 0.0 code_length] -> [0.0, 0.0, 0.0] (units are gone !)
  • YTArray([0., 0., 0.]) code_length -> stays unchanged

So, unless your error actually goes deeper, I think I catch patch this very quickly.

@zingale
Copy link
Member Author

zingale commented Apr 25, 2020

I tested your PR and it fixes my issue. Thanks!

munkm added a commit that referenced this issue Apr 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants