-
Notifications
You must be signed in to change notification settings - Fork 199
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
Python: useful error when initialize_warpx
not called before creating ParticleContainerWrapper
#5412
Conversation
I would suggest handling this in a different way. Now, the issue is that the |
Got it, thanks for the feedback! |
for more information, see https://pre-commit.ci
Ok, I've modified the PR to now lazy initialize the particle container (and boundary buffers) only when they're first needed instead of in |
Changes made. That's definitely a lot cleaner. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! This looks good to me.
self.name | ||
) | ||
except AttributeError as e: | ||
msg = "This is likely caused by attempting to access a ParticleContainerWrapper before initialize_warpx has been called" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this PR! Sorry for just seeing it now, I was just on parental leave when the PR was opened.
I thought we could also add one more fallback, right in the library loader, where we assign the libwarpx.warpx
attribute.
In essence, we could assign an initial attribute that throws when accessed with a more distinct error message ("initialize_warpx was not yet called!"), to catch all. More specific exceptions like this one are great to add and keep.
One initialization, we then just overwrite the attribute.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh neat idea! I can open a new PR shortly!
Follows up on, #5412, using @ax3l's [suggestion](#5412 (review)) to catch warpx not being initialized when accessing libwarpx.warpx
Currently, WarpX is initialized when
sim.step
is called, or when the user callsinitialize_warpx
. However, if the user tries to create aParticleContainerWrapper
before this point, they get an error along the following lines:This is confusing. When I got this, I assumed I had maybe installed WarpX wrong. I added a catch for this exception that re-raises it with some additional context that should help direct the user to call
initialize_warpx