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

Copy and update __dict__ #176

Merged
merged 4 commits into from
Jan 30, 2024
Merged
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
4 changes: 1 addition & 3 deletions pyiron_workflow/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,11 +729,9 @@ def __round__(self):

# Because we override __getattr__ we need to get and set state for serialization
def __getstate__(self):
return self.__dict__
return dict(self.__dict__)

def __setstate__(self, state):
# Update instead of overriding in case some other attributes were added on the
# main process while a remote process was working away
self.__dict__.update(**state)


Expand Down
4 changes: 4 additions & 0 deletions pyiron_workflow/composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ def process_run_result(self, run_output):
return DotDict(self.outputs.to_value_dict())

def _parse_remotely_executed_self(self, other_self):
# Un-parent existing nodes before ditching them
for node in self:
node._parent = None
other_self.running = False # It's done now
self.__setstate__(other_self.__getstate__())

def disconnect_run(self) -> list[tuple[Channel, Channel]]:
Expand Down
4 changes: 2 additions & 2 deletions pyiron_workflow/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ def __getitem__(self, item):
) from e

def __getstate__(self):
return self.__dict__
return dict(self.__dict__)

def __setstate__(self, state):
self.__dict__ = state
self.__dict__.update(**state)

def register(self, package_identifier: str, domain: Optional[str] = None) -> None:
"""
Expand Down
2 changes: 1 addition & 1 deletion pyiron_workflow/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def to_dict(self):

def __getstate__(self):
# Compatibility with python <3.11
return self.__dict__
return dict(self.__dict__)

def __setstate__(self, state):
# Because we override getattr, we need to use __dict__ assignment directly in
Expand Down
2 changes: 1 addition & 1 deletion pyiron_workflow/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ def replace_with(self, other: Node | type[Node]):
warnings.warn(f"Could not replace_node {self.label}, as it has no parent.")

def __getstate__(self):
state = self.__dict__
state = dict(self.__dict__)
state["_parent"] = None
# I am not at all confident that removing the parent here is the _right_
# solution.
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/test_macro.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ def test_with_executor(self):

returned_nodes = result.result(timeout=120) # Wait for the process to finish
sleep(1)
self.assertFalse(
macro.running,
msg="Macro should be done running"
)
self.assertIsNot(
original_one,
returned_nodes.one,
Expand Down
Loading