Skip to content

Commit

Permalink
implicit self
Browse files Browse the repository at this point in the history
  • Loading branch information
jeandut committed Jan 11, 2024
1 parent be02744 commit 71dc969
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions fedeca/strategies/bootstraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,16 +268,26 @@ def local_computation(self, datasamples, shared_state=None) -> list:
for idx, seed in enumerate(bootstrap_seeds_list):
rng = np.random.default_rng(seed)
bootstrapped_data = datasamples.sample(datasamples.shape[0], replace=True, random_state=rng)

# Loading the correct state into the current main algo
if self.checkpoints_list[idx] is not None:
self._update_from_checkpoint(self.checkpoints_list[idx])
# We need this old state tto avoid side effects from the function
# on the instance
old_state = copy.deepcopy(self)
if shared_state is None:
res = local_function(datasamples=bootstrapped_data, _skip=True)
else:
res = local_function(
datasamples=bootstrapped_data, shared_state=shared_state[idx], _skip=True
)
self.checkpoints_list[idx] = self._get_state_to_save()

# We restore the algo to its old state
for att_name, att in vars(self).items():
if att != old_state.__getattribute__(att_name):
self.__setattr__(att_name, old_state.__getattribute__(att_name))

results.append(res)

return results
Expand Down

0 comments on commit 71dc969

Please sign in to comment.