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

Fix checkpoint with runtime components through the Python interface. #2332

Merged
merged 11 commits into from
Oct 8, 2021

Conversation

atmyers
Copy link
Member

@atmyers atmyers commented Sep 23, 2021

Fix #2295.

Specifically, this makes three changes:

  1. It adds the particle component names to the Checkpoint files
  2. If a Checkpoint file contains a runtime component that has not yet been added, it will be added on the fly.
  3. If a runtime component has already been added, subsequent calls not not add it again.

@atmyers atmyers added bug: affects latest release Bug also exists in latest release version component: diagnostics all types of outputs labels Sep 23, 2021
@ax3l ax3l self-assigned this Sep 24, 2021
@ax3l ax3l self-requested a review September 24, 2021 01:59
@ax3l
Copy link
Member

ax3l commented Sep 24, 2021

Let's rebase this one after #2335 / #2341 are merged, which add more restart safeguards

@ax3l ax3l added the bug Something isn't working label Sep 24, 2021
@EtherealMC-Bit
Copy link
Contributor

The script in the original issue now verifies that the runtime attributes were added correctly, so it looks like this fixes it!

@ax3l ax3l added the component: checkpoint/restart Checkpointing & restarts label Sep 27, 2021
@ax3l
Copy link
Member

ax3l commented Sep 27, 2021

@atmyers ready for rebase :)

@@ -159,8 +159,35 @@ FlushFormatCheckpoint::CheckpointParticles (
const amrex::Vector<ParticleDiag>& particle_diags) const
{
for (unsigned i = 0, n = particle_diags.size(); i < n; ++i) {
Copy link
Member

Choose a reason for hiding this comment

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

In this function and potentially after this look, we probably also need to treat the laser particles to write our their positions

cc @RemiLehe

Copy link
Member Author

Choose a reason for hiding this comment

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

Support for this is added in PR #2360 - I recommend we merge that PR first, then rebase this one.

Source/Diagnostics/ParticleIO.cpp Show resolved Hide resolved
@ax3l
Copy link
Member

ax3l commented Sep 27, 2021

The current implementation looks good to me. Can we design or repurpose an existing test to cover this permanently? :)
cc @MKieburtz

@EtherealMC-Bit
Copy link
Contributor

I'm not sure about an existing test, although the script in #2295 is a nice and clean way of demonstrating that this works correctly.

@ax3l
Copy link
Member

ax3l commented Sep 28, 2021

LGTM, it's short and small. let's add this one? :)

@ax3l
Copy link
Member

ax3l commented Oct 4, 2021

@atmyers thank you for #2360 - do you like to rebase the PR here now? :)

@atmyers
Copy link
Member Author

atmyers commented Oct 7, 2021

I have now added a CI test for this, based on the original script from modern electron.

@@ -1085,6 +1086,10 @@ def initialize_inputs(self):
self.diagnostic.diag_type = 'Full'
self.diagnostic.format = 'checkpoint'

if self.write_dir is not None or self.file_prefix is not None:
Copy link
Member Author

Choose a reason for hiding this comment

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

I needed to modify the Python interface a bit here so that Checkpoint files could be configured to use a custom file prefix, as needed by the regression testing suite. Maybe @dpgrote could weigh in on whether this is the right way to fix this?

I could also split this into a separate PR, if needed.

Copy link
Member

@ax3l ax3l Oct 8, 2021

Choose a reason for hiding this comment

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

LGTM. I think you can even remove the if line here with the logic in the next two lines

Let's also add an inline comment to document the need for this modification, otherwise this convention looks a bit magical to future readers

@lgtm-com
Copy link
Contributor

lgtm-com bot commented Oct 7, 2021

This pull request introduces 1 alert when merging 2a1bfff into fb2ef4c - view on LGTM.com

new alerts:

  • 1 for Unused import

Comment on lines +1089 to +1092
if self.write_dir is not None or self.file_prefix is not None:
write_dir = (self.write_dir or 'diags')
file_prefix = (self.file_prefix or self.name)
self.diagnostic.file_prefix = write_dir + '/' + file_prefix
Copy link
Member

@ax3l ax3l Oct 8, 2021

Choose a reason for hiding this comment

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

Suggested change
if self.write_dir is not None or self.file_prefix is not None:
write_dir = (self.write_dir or 'diags')
file_prefix = (self.file_prefix or self.name)
self.diagnostic.file_prefix = write_dir + '/' + file_prefix
# use checkpoint naming scheme expected by WarpX regression test suite
write_dir = (self.write_dir or 'diags')
file_prefix = (self.file_prefix or self.name)
self.diagnostic.file_prefix = write_dir + '/' + file_prefix

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not really specific to the test suite - the other diagnostic types FieldDiagnostic and ParticleDiagnostic already let you pass in a custom file prefix for whatever reason you want, as you can in the C++ interface. This just makes the Checkpoints behave the same way. This if block is basically just copied from there.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, this looks good. My preference is to keep the if check - this is a subtle difference but with the if, diagnostic.file_prefix won't be set if write_dir and file_prefix are not set and so it will rely on its default value in the C++ (this avoids having a default value defined in two different places).

I just noticed this - it should be self.diagnostic.file_prefix = os.path.join(write_dir, file_prefix) to be proper Python.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good - I'll issue a follow-up PR to change the + '/' +, I think the modern electron folks are waiting on this one to be merged.

Copy link
Member

@ax3l ax3l left a comment

Choose a reason for hiding this comment

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

Thanks a lot for this, that's great!
The patch & test looks generally good to me.

Comment on the Python side and just double-checking the extra SoA attributes for ionization/QED are there.

@atmyers atmyers merged commit 0c73e9b into ECP-WarpX:development Oct 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug: affects latest release Bug also exists in latest release version bug Something isn't working component: checkpoint/restart Checkpointing & restarts component: diagnostics all types of outputs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Checkpoints for restarting don't handle runtime attributes
4 participants