Skip to content

Commit

Permalink
Unify reset_statepoint logic across methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
bdice committed Feb 19, 2021
1 parent f2e0cea commit 5c32722
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions signac/contrib/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,18 @@ def reset_statepoint(self, new_statepoint):
The job's new state point.
"""
self.statepoint.reset(new_statepoint)
if self._statepoint_requires_init:
# Instantiate state point data lazily - no load is required, since
# we are provided with the new state point data.
self._statepoint = _StatePointDict(
jobs=[self], filename=self._statepoint_filename, data=new_statepoint
)

# Update the project's state point cache when loaded lazily
self._project._register(self.id, new_statepoint)
self._statepoint_requires_init = False
else:
self.statepoint.reset(new_statepoint)

def update_statepoint(self, update, overwrite=False):
"""Change the state point of this job while preserving job data.
Expand Down Expand Up @@ -411,9 +422,12 @@ def update_statepoint(self, update, overwrite=False):
if not overwrite:
for key, value in update.items():
if statepoint.get(key, value) != value:
raise KeyError(key)
raise KeyError(
f"Key {key} was provided but already exists in the "
"mapping with another value."
)
statepoint.update(update)
self.statepoint.reset(statepoint)
self.reset_statepoint(statepoint)

@property
def statepoint(self):
Expand Down Expand Up @@ -460,7 +474,7 @@ def statepoint(self, new_statepoint):
The new state point to be assigned.
"""
self.statepoint.reset(new_statepoint)
self.reset_statepoint(new_statepoint)

@property
def sp(self):
Expand Down

0 comments on commit 5c32722

Please sign in to comment.