Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instruction schedule map cannot be pickled with python3.6 #6944

Closed
nkanazawa1989 opened this issue Aug 25, 2021 · 1 comment · Fixed by #6950
Closed

Instruction schedule map cannot be pickled with python3.6 #6944

nkanazawa1989 opened this issue Aug 25, 2021 · 1 comment · Fixed by #6950
Labels
bug Something isn't working
Milestone

Comments

@nkanazawa1989
Copy link
Contributor

Information

  • Qiskit Terra version: master (see note)
  • Python version: 3.6.9
  • Operating system: 18.04.5 LTS (Bionic Beaver), WSL2.0

What is the current behavior?

from qiskit.test.mock import FakeAthens
from qiskit.tools.parallel import parallel_map

backend = FakeAthens()
inst_map = backend.defaults().instruction_schedule_map

def task(inst_map):
    print(inst_map.instructions)

result = parallel_map(task, [inst_map, inst_map])

This causes _pickle.PicklingError: Can't pickle typing.Union[qiskit.circuit.parameterexpression.ParameterExpression, float]: it's not the same object as typing.Union and hangs the parallel map. This is the blocker of #6759 .

I was thinking this is fork issue and tried to deep copy the inst_map, but seems like this is a different problem.

Note

To test above code, a part of #6759 is needed (the master uses lambda function here but this cannot be pickled).
https://github.com/Qiskit/qiskit-terra/blob/0f9aa882b8cbdcef4614b94031ddd3244832d8d6/qiskit/pulse/instruction_schedule_map.py#L73-L76

What is the expected behavior?

Currently inst map depends on the builtin inspect module, because the map accepts both callback function and Schedule with Parameter to define a template schedule. From InstructionScheduleMap.get method, these programs look like a function that has several named arguments (i.e. pulse parameters), but can have default values and also partially assigned if the program is Schedule. To support this complicated behavior, we implemented parameter signature management and assignment logic with instpect.Signature. For example,

https://github.com/Qiskit/qiskit-terra/blob/a34b2ab002c0e0935d02691026ae676ee0adf90b/qiskit/pulse/instruction_schedule_map.py#L190-L197

This object cannot be dropped unless we find alternative approach.

Suggested solutions

No idea. Seems like a defect of python3.6.

@nkanazawa1989 nkanazawa1989 added the bug Something isn't working label Aug 25, 2021
@nkanazawa1989
Copy link
Contributor Author

There is an similar issue here huggingface/transformers#8212
Seems like the solution is to upgrade Python (drop py36 test) or change implementation of InstructionScheduleMap.

@mergify mergify bot closed this as completed in #6950 Aug 26, 2021
@kdk kdk added this to the 0.19 milestone Nov 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants