From 5050f2df3e773f778b5b4960b0441a5eac6814ea Mon Sep 17 00:00:00 2001 From: Thomas Marks Date: Thu, 24 Oct 2024 17:11:09 -0400 Subject: [PATCH] add useful error message when user forgets to call initialize_warpx in picmi --- Python/pywarpx/particle_containers.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Python/pywarpx/particle_containers.py b/Python/pywarpx/particle_containers.py index bc6b2d74106..0986985002d 100644 --- a/Python/pywarpx/particle_containers.py +++ b/Python/pywarpx/particle_containers.py @@ -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(