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

ENH: fix compatibility issues with newest versions of SWIFT #4921

Merged
merged 9 commits into from
Jun 25, 2024

Conversation

smsutherland
Copy link
Contributor

@smsutherland smsutherland commented Jun 4, 2024

PR Summary

The SWIFT frontend is very out of date. The last significant commits are many years old, and in that time SWIFT has undergone breaking changes. This PR aims to update some of the breaks. This is by no means an exhaustive fix. It only addresses the issues I have encountered during my own use of yt with SWIFT. This includes loading SWIFT snapshots, and some issues regarding field naming.

PR Checklist

  • New features are documented, with docstrings and narrative docs
    No new features have been added.

  • Adds a test for any bugs fixed. Adds tests for new features.
    I have not added any new tests, since they would require adding new sample data to test from. Both snapshots on https://yt-project.org/data/ labeled SWIFT are run on an outdated version of SWIFT from 2018.

Copy link

welcome bot commented Jun 4, 2024

Hi! Welcome, and thanks for opening this pull request. We have some guidelines for new pull requests, and soon you'll hear back about the results of our tests and continuous integration checks. Thank you for your contribution!

@neutrinoceros
Copy link
Member

Thanks for working on this ! Just a very broad question for now, but are you sure this isn't an exhaustive fix, or just strongly suspecting ?

@neutrinoceros neutrinoceros added bug code frontends Things related to specific frontends labels Jun 4, 2024
@chrishavlin
Copy link
Contributor

nice! this may be answered by the full test suite... but any worry some of these changes would break backwards compatibility with old swift files?

@neutrinoceros
Copy link
Member

I haven't looked in detail yet but yes, backward compatibility concerns should be a essential concern to reviewers.

@smsutherland
Copy link
Contributor Author

Thanks for working on this ! Just a very broad question for now, but are you sure this isn't an exhaustive fix, or just strongly suspecting ?

I strongly suspect it is not exhaustive. I am very new to using yt. I am not familiar enough with all its aspects to know for certain one way or another. I only suspect it isn't exhaustive because it seems seems more likely than the alternative.

Copy link
Member

@neutrinoceros neutrinoceros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me that we indeed need to refine the patch for backward compatibility, but other than that I have no concerns with it. Thank you !

@@ -66,7 +66,7 @@ def _get_smoothing_length(self, sub_file, pdtype=None, pshape=None):
pcount = f["/Header"].attrs["NumPart_ThisFile"][ind].astype("int64")
pcount = np.clip(pcount - si, 0, ei - si)
# we upscale to float64
hsml = f[ptype]["SmoothingLength"][si:ei, ...]
hsml = f[ptype]["SmoothingLengths"][si:ei, ...]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we'd probably need to try both keys for backward compatibility. It's okay to give priority to the newest one but it would also help to add a comment specifying (at least broadly) which version of SWIFT made the change.

@@ -15,7 +16,7 @@ class SwiftParticleFile(ParticleFile):
class SwiftDataset(SPHDataset):
_load_requirements = ["h5py"]
_index_class = SPHParticleIndex
_field_info_class = SPHFieldInfo
_field_info_class = SwiftFieldInfo
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not clear to me what are the implications of this change in terms of backward compatibility

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyone want to comment here ? For the record, I don't think it's critical enough to hold back the PR, but I'd like an answer if possible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Someone with more of an expertise in swift data might want to chime in, but I just spent a while walking through the initialization and aliasing that happens and I don't see any issues. It will still check for all the fields defined by SPHFieldInfo, and the additional aliasing that SwiftFieldInfo adds will only happen if the new fields exist within the dataset.

@@ -113,7 +113,7 @@ def _parse_parameter_file(self):
self.dimensionality = int(header["Dimension"])

# SWIFT is either all periodic, or not periodic at all
periodic = int(runtime_parameters["PeriodicBoundariesOn"])
periodic = int(parameters["InitialConditions:periodic"])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too, we should really be checking both for new and old names.

Comment on lines 134 to 136
self.omega_matter = float(parameters["Cosmology:Omega_b"]) + float(
parameters["Cosmology:Omega_cdm"]
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a bug fix or is the Cosmology:Omega_cdm key new in some version of SWIFT ? If old versions don't have it, we need to fallback to the old value somehow.

yt/frontends/swift/data_structures.py Show resolved Hide resolved
yt/frontends/swift/data_structures.py Show resolved Hide resolved
@chrishavlin
Copy link
Contributor

I have not added any new tests, since they would require adding new sample data to test from. Both snapshots on https://yt-project.org/data/ labeled SWIFT are run on an outdated version of SWIFT from 2018.

Do you have any new sample data we could add? Would be great if possible, I'm happy to help get it where it needs to go so we can run tests against it.

@smsutherland
Copy link
Contributor Author

I have not added any new tests, since they would require adding new sample data to test from. Both snapshots on https://yt-project.org/data/ labeled SWIFT are run on an outdated version of SWIFT from 2018.

Do you have any new sample data we could add? Would be great if possible, I'm happy to help get it where it needs to go so we can run tests against it.

The only SWIFT snapshots I have are many gigabytes. I can contribute one if you'd like (it's better than nothing I suppose), but a file of that size may be impractical for testing purposes or as a sample.
For reference, the EAGLE_6 sample data already present is a (6.25Mpc)^3 volume and 71Mb. The snapshot I was basing my changes on is (37Mpc)^3 and 6.6Gb.

@neutrinoceros
Copy link
Member

neutrinoceros commented Jun 5, 2024

watch out, existing tests are failing. The good news is that the test suite will apparently not let us get away with backward incompatible changes after all

@chrishavlin
Copy link
Contributor

The only SWIFT snapshots I have are many gigabytes.

Ya, that is a common issue with keeping yt's test data up to date. Given that the changes here are pretty minimal, I'd say not worth adding a file that large for the changes here.

Copy link
Member

@neutrinoceros neutrinoceros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's gotten a lot better, thank you !
Still a couple questions and suggestions, but we're definitely on the right track !

yt/frontends/swift/data_structures.py Show resolved Hide resolved
yt/frontends/swift/io.py Show resolved Hide resolved
@@ -15,7 +16,7 @@ class SwiftParticleFile(ParticleFile):
class SwiftDataset(SPHDataset):
_load_requirements = ["h5py"]
_index_class = SPHParticleIndex
_field_info_class = SPHFieldInfo
_field_info_class = SwiftFieldInfo
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyone want to comment here ? For the record, I don't think it's critical enough to hold back the PR, but I'd like an answer if possible.

In newer versions of SWIFT, Cosmology:Omega_m still exists, but it just
has a value of -1. We need to check whether Omega_cdm exists, not
whether Omega_m exists.
Copy link
Member

@neutrinoceros neutrinoceros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's one approval from me.
If nobody complains about it I'll merge it in a week or two. Thanks again for your work and patience !

@smsutherland
Copy link
Contributor Author

And thank you for your help with this!

@chrishavlin
Copy link
Contributor

@yt-fido test this please

@chrishavlin
Copy link
Contributor

chrishavlin commented Jun 11, 2024

re-triggered the tests because the last run skipped 333 tests due to not finding files... if this is due to yt-project.org being down, those same tests will be skipped again and we should re-trigger after yt-project is back up.

EDIT: ignore this... i was looking at the wrong test, jenkins test suite is running fine.

Copy link
Contributor

@chrishavlin chrishavlin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! thanks @smsutherland !

@chrishavlin
Copy link
Contributor

If nobody complains about it I'll merge it in a week or two.

Even with the 2 approvals now, I think it'd still be good to wait a bit to see if anyone with more expertise in swift wants to take a look.

@neutrinoceros
Copy link
Member

Fine by me. I'll post-pone my personal reminder to merge this in 2 weeks from now.

@neutrinoceros neutrinoceros merged commit 7f0f4b9 into yt-project:main Jun 25, 2024
13 checks passed
Copy link

welcome bot commented Jun 25, 2024

Hooray! Congratulations on your first merged pull request! We hope we keep seeing you around! 🎆

@neutrinoceros neutrinoceros changed the title SWIFT frontend update ENH: fix compatibility issues with newest versions of SWIFT Jun 25, 2024
@neutrinoceros neutrinoceros added this to the 4.4.0 milestone Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug code frontends Things related to specific frontends
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants