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

BUG: some RAMSES fields return different values depending on order of operations #4880

Closed
V-Nathir opened this issue Apr 18, 2024 · 5 comments · Fixed by #4907
Closed

BUG: some RAMSES fields return different values depending on order of operations #4880

V-Nathir opened this issue Apr 18, 2024 · 5 comments · Fixed by #4907
Labels
blocker Highest priority level bug
Milestone

Comments

@V-Nathir
Copy link

V-Nathir commented Apr 18, 2024

With RAMSES datasets, the outcome of some fields depend on previous fields having been accessed or not.

For example, the following script yields two different results depending on whether the line querying sp["gas", "metallicity"] is commented out or not.

Code for reproduction

import yt
import numpy as np
ds = yt.load(PATH_TO_OUTPUT)  # may need adapting
center = ds.arr([0.48722672, 0.50215806, 0.50503517], "code_length")
sp = ds.sphere(center, (100, "kpc"))
# sp["gas", "metallicity"]  # commenting this line generates another result. 
cooling = sp["gas", "cooling_metal"]
print(cooling.min(), cooling.max(), np.isnan(cooling).sum())

Results

# When sp["gas", "metallicity"] is commented out
2.0029169125304782e-101 cm**3*erg/s     8.56002136482532e-22 cm**3*erg/s 0
# When it is not
1.3095962168963732e-105 cm**3*erg/s      6.197260629648163e-20 cm**3*erg/s 0

Expected outcome

The two cases should yield the same results.

Extra information

  • yt version: development version
  • Python version: 3.12

In fields.py script we can find the function def create_cooling_fields(self) -> bool: that has this line for computing "cooling_metal" cool = ( cool * data["gas", "metallicity"] / 0.02 ) # Ramses uses Zsolar=0.02 If the values of metallicity are checked (if they are >1 ) there are two possibilities: 1) you call in your code data["gas", "metallicity"] first and then data["gas", "cooling_metal"], the result is ok. 2) you call directly data["gas", "cooling_metal"] the result is wrong; metallicities are >1.

I think the FieldDetector saves values into metallicity and those values do not overwrite with the correct ones. I do not know if more fields have the same issue.

Cheers!

Copy link

welcome bot commented Apr 18, 2024

Hi, and welcome to yt! Thanks for opening your first issue. We have an issue template that helps us to gather relevant information to help diagnosing and fixing the issue.

@cphyc cphyc changed the title BUG REPORT - Problem loading fields, erroneous data - main version BUG: some RAMSES fields return different values depending on order of operations Apr 18, 2024
@matthewturk
Copy link
Member

@V-Nathir are the incorrect values always the same?

@V-Nathir
Copy link
Author

I did a quick check and I would say yes. The incorrect values are always the same.

@matthewturk
Copy link
Member

Thank you, that's very helpful to know. If they are always the same, it's deterministic; if they are not bitwise identical, it might be coming from uninitialized memory.

@V-Nathir
Copy link
Author

V-Nathir commented May 20, 2024

Hi all, the bug is solved. I did the proper cheeks and looks good again. The solution provided by @cphyc in #4907 seems to work. Thanks a lot!!
image
image

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocker Highest priority level bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants