From 5050f2df3e773f778b5b4960b0441a5eac6814ea Mon Sep 17 00:00:00 2001 From: Thomas Marks Date: Thu, 24 Oct 2024 17:11:09 -0400 Subject: [PATCH 1/2] 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( From 90231123c08265162d1dc12ea16fe0d82f943188 Mon Sep 17 00:00:00 2001 From: Thomas Marks Date: Thu, 24 Oct 2024 17:21:09 -0400 Subject: [PATCH 2/2] change wording --- Python/pywarpx/particle_containers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/pywarpx/particle_containers.py b/Python/pywarpx/particle_containers.py index 0986985002d..f0b6970108b 100644 --- a/Python/pywarpx/particle_containers.py +++ b/Python/pywarpx/particle_containers.py @@ -31,7 +31,7 @@ def __init__(self, species_name): 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." + 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)