Closed andreamari closed 2 years ago
A simpler example of the unexpected behavior was found in https://github.com/unitaryfund/mitiq/pull/1369#issue-1285873175, copied below.
test_circuit_qiskit = QuantumCircuit(4)
test_circuit_qiskit.x(0)
test_circuit_qiskit.x(2)
test_circuit_qiskit.barrier(0,1,2)
test_folded = zne.scaling.fold_gates_at_random(test_circuit_qiskit, 1.0)
print(f"Input circuit:\n{test_circuit_qiskit}")
print(f"Folded circuit:\n{test_folded}")
Input circuit:
┌───┐ ░
q_0: ┤ X ├─░─
└───┘ ░
q_1: ──────░─
┌───┐ ░
q_2: ┤ X ├─░─
├───┤ ░
q_3: ┤ I ├───
└───┘
Folded circuit:
┌───┐
q_0: ┤ X ├
├───┤
q_1: ┤ X ├
├───┤
q_2: ┤ I ├
└───┘
q_3: ─────
Issue Description
Folding functions with Qiskit circuits with barriers and measurements have unexpected behaviors.
How to Reproduce
It is actually quite hard to reproduce. I couldn't find a simple example. So I need to copy and paste a long example.
Code Snippet
The bug is that, in
folded_circuit_wrong
, the operations applied to qubit q[7] are erroneously moved to q[6].Solution
For some reason the problem doesn't happen if barriers are manually removed. So there could be some problem with how Mitiq remove barriers.
So, until this bug is fixed, a workaround is to apply
circuit_without_barriers = RemoveBarriers()(circuit)
before folding.Environment Context