Skip to content

Commit

Permalink
Handle Covalent version mismatches more gracefully
Browse files Browse the repository at this point in the history
Accessing electron attributes directly in `Electron.__call__` can
cause problems if those attributes happen to be missing.
  • Loading branch information
cjao committed May 28, 2024
1 parent 6b8406d commit 8cf7858
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions covalent/_workflow/electron.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,11 @@ def __call__(self, *args, **kwargs) -> Union[Any, "Electron"]:
active_lattice.replace_electrons[name] = replacement_electron
return bound_electron

# Avoid direct attribute access since that might trigger
# Electron.__getattr__ when executors build sublattices
# constructed with older versions of Covalent
function_string = self.__dict__.get("_function_string")

# Handle sublattices by injecting _build_sublattice_graph node
if isinstance(self.function, Lattice):
parent_metadata = active_lattice.metadata.copy()
Expand All @@ -443,7 +448,6 @@ def __call__(self, *args, **kwargs) -> Union[Any, "Electron"]:
)

name = sublattice_prefix + self.function.__name__
function_string = self._function_string
bound_electron = sub_electron(
self.function, json.dumps(parent_metadata), *args, **kwargs
)
Expand All @@ -464,7 +468,7 @@ def __call__(self, *args, **kwargs) -> Union[Any, "Electron"]:
name=self.function.__name__,
function=self.function,
metadata=self.metadata.copy(),
function_string=self._function_string,
function_string=function_string,
task_group_id=self.task_group_id if self.packing_tasks else None,
)
self.task_group_id = self.task_group_id if self.packing_tasks else self.node_id
Expand Down

0 comments on commit 8cf7858

Please sign in to comment.