Cirq icon indicating copy to clipboard operation
Cirq copied to clipboard

`DiagGatesBeforeMeasurement` transformer

Open vtomole opened this issue 3 years ago • 2 comments

Is your feature request related to a use case or problem? Please describe. There is currently no transformer that optimizes a circuit like

import cirq

qubits = cirq.LineQubit.range(2)
c = cirq.Circuit(cirq.Z(qubits[0]), cirq.CZ(qubits[0], qubits[1]), 
                 cirq.measure(qubits[1]))

Which should come out to be the identity

Describe the solution you'd like

import cirq

qubits = cirq.LineQubit.range(2)
c = cirq.Circuit(cirq.Z(qubits[0]), cirq.CZ(qubits[0], qubits[1]), 
                 cirq.Z(qubits[1]), cirq.measure(qubits[0]), 
                 cirq.measure(qubits[1]))
print(c)
print('-'* 100)
cirq.EjectZ().optimize_circuit(c)

print(c)

outputs

0: ───Z───@───M───────
          │
1: ───────@───Z───M───
--------------------------------------------------------------
0: ──────────M───────
          
1: ──────────────M───

[optional] Describe alternatives/workarounds you've considered Looking the the circuit and seeing that the CZ gates doesn't do anything and manually removing them. What is the urgency from your perspective for this issue? Is it blocking important work? P3 - I'm not really blocked by it, it is an idea I'd like to discuss / suggestion based on principle

vtomole avatar Feb 02 '22 20:02 vtomole

@mhucka i would like to work on this.

Vivek1106-04 avatar Nov 26 '25 18:11 Vivek1106-04

Discussed in Cirq Cynq 2025-12-10: there is concern about doing this kind of operation on measurements that are not terminal measurements. Need to examine this aspect.

mhucka avatar Dec 10 '25 18:12 mhucka