Skip to content

Commit df07803

Browse files
robkhcmnrd
authored andcommitted
mapper: utils: Passing hydra config to the child processes in serialized form with cloudpickle.
In Python 3.6, typing.List[str] cannot be pickled, therefore hydra configuration cannot be passed with pickle. PEP 560 fixes the issue in Python 3.7. As a workaround, we use more advanced serializtin library cloudpickle. See also: python/typing#511
1 parent 85f6cff commit df07803

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

mocasin/mapper/utils.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
import os
88
from time import process_time
99

10+
import cloudpickle
1011
import csv
1112
import h5py
1213
import hydra
1314
import numpy as np
15+
import pickle
1416

1517
from hydra.core.hydra_config import HydraConfig
1618

@@ -162,9 +164,10 @@ def simulate(self, input_mappings):
162164
# As a workaround, suggested in
163165
# https://github.com/facebookresearch/hydra/issues/1005
164166
# we pass the hydra configuration to the child processes
165-
config = None
167+
cfg_pickled = None
166168
if HydraConfig.initialized():
167169
config = HydraConfig.get()
170+
cfg_pickled = cloudpickle.dumps(config)
168171
for i, mapping in enumerate(mappings):
169172
# skip if this particular mapping is in the cache
170173
if lookups[i]:
@@ -174,7 +177,7 @@ def simulate(self, input_mappings):
174177
self.platform, self.graph, mapping, self.trace
175178
)
176179

177-
simulations.append((simulation, config))
180+
simulations.append((simulation, cfg_pickled))
178181
if self.parallel and len(simulations) > self.chunk_size:
179182
# since mappings are simulated in parallel, whole simulation time
180183
# is added later as offset
@@ -258,8 +261,9 @@ def run_simulation(arguments):
258261
# As a workaround, suggested in
259262
# https://github.com/facebookresearch/hydra/issues/1005
260263
# we pass the hydra configuration from the main process
261-
simulation, config = arguments
262-
if config:
264+
simulation, cfg_pickled = arguments
265+
if cfg_pickled:
266+
config = pickle.loads(cfg_pickled)
263267
hydra.core.utils.configure_log(config.job_logging, config.verbose)
264268
with simulation:
265269
start_time = process_time()

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
install_requirements = [
1414
"arpeggio",
15+
"cloudpickle",
1516
"cvxopt",
1617
"cvxpy!=1.1.8,<1.2" if sys.version_info < (3, 7) else "cvxpy!=1.1.8",
1718
"deap",

0 commit comments

Comments
 (0)