Skip to content

Can't use EngineSampler in multiprocessing #3666

@mpharrigan

Description

@mpharrigan

I was trying to call run from a function which I am using multiprocessing.Pool.map to run a couple in parallel. Multiprocessing requires the function you're mapping over to be pickle-able to send it to the spawned processes. Lambda functions aren't pickleable, and there's something in cirq.google gumming up the works:

~/cirq/cirq/cirq/experiments/fidelity_estimation.py in sample_2q_xeb_circuits(sampler, circuits, cycle_depths, repetitions)
    444     with tqdm.tqdm(total=n_tasks) as progress:
    445         with multiprocessing.Pool(2) as pool:
--> 446             records = pool.map(executor, tasks)
    447         progress.update(chunksize)
    448 

~/cirq/env/lib/python3.7/multiprocessing/pool.py in map(self, func, iterable, chunksize)
    266         in a list that is returned.
    267         '''
--> 268         return self._map_async(func, iterable, mapstar, chunksize).get()
    269 
    270     def starmap(self, func, iterable, chunksize=None):

~/cirq/env/lib/python3.7/multiprocessing/pool.py in get(self, timeout)
    655             return self._value
    656         else:
--> 657             raise self._value
    658 
    659     def _set(self, i, obj):

~/cirq/env/lib/python3.7/multiprocessing/pool.py in _handle_tasks(taskqueue, put, outqueue, pool, cache)
    429                         break
    430                     try:
--> 431                         put(task)
    432                     except Exception as e:
    433                         job, idx = task[:2]

~/cirq/env/lib/python3.7/multiprocessing/connection.py in send(self, obj)
    204         self._check_closed()
    205         self._check_writable()
--> 206         self._send_bytes(_ForkingPickler.dumps(obj))
    207 
    208     def recv_bytes(self, maxlength=None):

~/cirq/env/lib/python3.7/multiprocessing/reduction.py in dumps(cls, obj, protocol)
     49     def dumps(cls, obj, protocol=None):
     50         buf = io.BytesIO()
---> 51         cls(buf, protocol).dump(obj)
     52         return buf.getbuffer()
     53 

PicklingError: Can't pickle <function <lambda> at 0x7fb82ee9e5f0>: attribute lookup <lambda> on cirq.google.common_serializers failed

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/google/enginekind/bug-reportSomething doesn't seem to work.priority/p2Next release should contain ittriage/acceptedA consensus emerged that this bug report, feature request, or other action should be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions