Skip to content

Commit 90b250b

Browse files
committed
use cloudpickle in get and set state
1 parent 7de2048 commit 90b250b

2 files changed

Lines changed: 9 additions & 40 deletions

File tree

adaptive/learner/base_learner.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import abc
22
from contextlib import suppress
3-
from copy import deepcopy
3+
4+
import cloudpickle
45

56
from adaptive.utils import _RequireAttrsABCMeta, load, save
67

@@ -191,7 +192,7 @@ def load(self, fname, compress=True):
191192
self._set_data(data)
192193

193194
def __getstate__(self):
194-
return deepcopy(self.__dict__)
195+
return cloudpickle.dumps(self.__dict__)
195196

196197
def __setstate__(self, state):
197-
self.__dict__ = state
198+
self.__dict__ = cloudpickle.loads(state)

adaptive/learner/learnerND.py

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from collections import OrderedDict
55
from collections.abc import Iterable
66

7+
import cloudpickle
78
import numpy as np
89
import scipy.spatial
910
from scipy import interpolate
@@ -1179,42 +1180,9 @@ def _get_plane_color(simplex):
11791180
)
11801181

11811182
def _get_data(self):
1182-
return (
1183-
self._vdim,
1184-
self.data,
1185-
self._tri,
1186-
self._losses,
1187-
self._min_value,
1188-
self._max_value,
1189-
self._output_multiplier,
1190-
self._simplex_queue,
1191-
self._old_scale,
1192-
self.pending_points,
1193-
)
1183+
return cloudpickle.dumps(self.__dict__)
11941184

11951185
def _set_data(self, state):
1196-
(
1197-
self._vdim,
1198-
self.data,
1199-
self._tri,
1200-
self._losses,
1201-
self._min_value,
1202-
self._max_value,
1203-
self._output_multiplier,
1204-
self._simplex_queue,
1205-
self._old_scale,
1206-
self.pending_points,
1207-
) = state
1208-
1209-
def __getstate__(self):
1210-
return (
1211-
self.function,
1212-
self.bounds,
1213-
self.loss_per_simplex,
1214-
self._get_data(),
1215-
)
1216-
1217-
def __setstate__(self, state):
1218-
function, bounds, loss_per_simplex, data = state
1219-
self.__init__(function, bounds, loss_per_simplex)
1220-
self._set_data(data)
1186+
state = cloudpickle.loads(state)
1187+
for k, v in state.items():
1188+
setattr(self, k, v)

0 commit comments

Comments
 (0)