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

Python: useful error when initialize_warpx not called before creating ParticleContainerWrapper #5412

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Python/pywarpx/particle_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ def __init__(self, species_name):
self.name = species_name

# grab the desired particle container
mypc = libwarpx.warpx.multi_particle_container()
# if initialize_warpx() has not been called, libwarpx will not have a `warpx` attribute.
# We catch this error and provide the user with some useful information.
try:
mypc = libwarpx.warpx.multi_particle_container()
except AttributeError as e:
msg = "This may be caused by attempting to create a ParticleContainerWrapper before initialize_warpx has been called"
raise AttributeError(msg) from e

self.particle_container = mypc.get_particle_container_from_name(self.name)

def add_particles(
Expand Down
Loading