-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Pass to remove diagonal gates before measurement #2208
Conversation
why not T, S Tdg, Sdg, U1 etc. Can we make this remove diagonal gates. |
…skit-terra into rz_and_z_optimization
T, S Tdg, Sdg and U1 added (and pass renamed). Is there any other diagonal gate? |
We could also remove control Z if the measurement is on both the qubits. |
Updated to include |
Yes, and also RZZGate. |
|
qiskit/transpiler/passes/remove_diagonal_gates_before_measurere.py
Outdated
Show resolved
Hide resolved
test/python/transpiler/test_remove_diagonal_gates_before_measure.py
Outdated
Show resolved
Hide resolved
qiskit/transpiler/passes/remove_diagonal_gates_before_measurere.py
Outdated
Show resolved
Hide resolved
Consider this example: from qiskit import QuantumRegister, QuantumCircuit, ClassicalRegister
from qiskit.transpiler import PassManager, transpile
from qiskit.transpiler.passes import RemoveDiagonalGatesBeforeMeasure, DAGFixedPoint
qr = QuantumRegister(2, 'qr')
cr = ClassicalRegister(1, 'cr')
circuit = QuantumCircuit(qr, cr)
circuit.rz(0.1, qr[1]).c_if(cr, 1)
circuit.barrier()
circuit.h(qr[0])
circuit.measure(qr[0], cr[0])
pm = PassManager()
pm.append(RemoveDiagonalGatesBeforeMeasure())
new_circuit = pm.run(circuit) Here, this circuit:
gets transformed into:
which is incorrect. The reason, as I explained above, is that the |
test/python/transpiler/test_remove_diagonal_gates_before_measure.py
Outdated
Show resolved
Hide resolved
good catch about the classical predecessor situation! |
In general I think going with |
…skit-terra into rz_and_z_optimization
Your second example can also be addressed with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good now! the quantum predecessors do the trick.
* rz_and_z_optimization * bug fixing and more testing * changelog * lint * RemoveRZandZbeforeMeasure -> RemoveDiagonalGatesBeforeMeasure * changelog * invalid-name * test * diagonal_control_gates * CrzGate, Cu1Gate, RZZGate * lint * from qiskit.compiler import transpile * remove_diagonal_gates_before_measurere * diagonal_control_gates -> diagonal_2q_gates * quantum_predecessors * use quantum_predecessors * test_optimize_1rzz_2measure docstring * lint
This pass removes gates RZ and Z before measurement.