Callback function isn't called when passing a list of multiple circuits to the `run` method of a `PassManager`
Environment
- Qiskit version: Tested with 1.3.2 and 2.0.0
- Python version: 3.13.3
- Operating system: Arch Linux
What is happening?
When using the run method of a PassManager on a list of circuits containing more than one item, the callback function passed to the run method isn't called, though the circuits are correctly transpiled.
How can we reproduce the issue?
The following code shows that the callback function is correctly called with a list containing a single circuit (it also works when passing a single circuit outside a list) and shows that the circuit is correctly transpiled.
from qiskit.transpiler import generate_preset_pass_manager
from qiskit import QuantumCircuit
qc = QuantumCircuit(2)
qc.h(0)
def callback(**kwargs):
print("Called")
pm = generate_preset_pass_manager(optimization_level=1, seed_transpiler=42, basis_gates=["u"])
pm.run([qc], callback=callback)[0].draw()
The following code shows that though transpiling correctly, the run method doesn't seem to call the callback function anymore with multiple circuits.
from qiskit.transpiler import generate_preset_pass_manager
from qiskit import QuantumCircuit
qc = QuantumCircuit(2)
qc.h(0)
def callback(**kwargs):
print("Called")
pm = generate_preset_pass_manager(optimization_level=1, seed_transpiler=42, basis_gates=["u"])
pm.run([qc, qc], callback=callback)[0].draw()
What should happen?
The callback function should be called when transpiling multiple circuits.
Any suggestions?
No response
Thanks for the report! We're presumably just failing to pass along the option into the dispatched workers in the (potentially parallel) map of the compilation over the circuits.
We might face some problems with pickling, especially if the callback is defined as a lambda, but I'm fairly sure we already have dill kicking around in the parallel map anyway, so there may be a way to ease some of the user pain there, if necessary.
Can someone assign this to me please? I will try to fix it.
Can someone assign this one to me? Would love to take a crack at it if it's not already taken :)
Hi guys - sorry, I missed the comments. @rahaman-quantum is on the Qiskit team, so this one's already being worked on.