Skip to content

Commit

Permalink
add useful error message when user forgets to call initialize_warpx i…
Browse files Browse the repository at this point in the history
…n picmi
  • Loading branch information
archermarx committed Oct 24, 2024
1 parent 1c676b9 commit 5050f2d
Showing 1 changed file with 8 additions and 1 deletion.
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 forgetting to call initialize_warpx() before creating a ParticleContainerWrapper."
raise AttributeError(msg) from e

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

def add_particles(
Expand Down

0 comments on commit 5050f2d

Please sign in to comment.