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

Catch warpx not being initialized in library loader #5567

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
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: 6 additions & 3 deletions Python/pywarpx/_libwarpx.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,14 @@ def __getattr__(self, attribute):
# Once loaded, it gets added to the dictionary so this code won't be called again.
self.load_library()
return self.__dict__[attribute]
elif attribute == "warpx":
# A `warpx` attribute has not yet been assigned, so `initialize_warpx` has not been called.
raise AttributeError(
"Trying to access libwarpx.warpx before initialize_warpx has been called!"
)
else:
# For any other attribute, call the built-in routine - this should always
# return an AttributeException.
# return an AttributeError.
return self.__getattribute__(attribute)

def _get_package_root(self):
Expand Down Expand Up @@ -143,8 +148,6 @@ def initialize(self, argv=None, mpi_comm=None):
self.libwarpx_so.execute_python_callback("afterinit")
self.libwarpx_so.execute_python_callback("particleloader")

# self.libwarpx_so.warpx_init()

self.initialized = True

def finalize(self, finalize_mpi=1):
Expand Down
4 changes: 2 additions & 2 deletions Python/pywarpx/particle_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def particle_container(self):
self.name
)
except AttributeError as e:
msg = "This is likely caused by attempting to access a ParticleContainerWrapper before initialize_warpx has been called"
msg = "You must initialize WarpX before accessing a ParticleContainerWrapper's particle_container."
raise AttributeError(msg) from e

return self._particle_container
Expand Down Expand Up @@ -777,7 +777,7 @@ def particle_buffer(self):
try:
self._particle_buffer = libwarpx.warpx.get_particle_boundary_buffer()
except AttributeError as e:
msg = "This is likely caused by attempting to access a ParticleBoundaryBufferWrapper before initialize_warpx has been called"
msg = "You must initialize WarpX before accessing a ParticleBoundaryBufferWrapper's particle_buffer."
raise AttributeError(msg) from e

return self._particle_buffer
Expand Down
Loading