1
$\begingroup$

How can I merge two consecutive cirq.Y**0.5 gates into a single cirq.Y gate with a transformer?

I can use cirq.merge_k_qubit_unitaries to merge the two gate but the result is not a cirq.EigenGate anymore. I want to keep the EigenGate type after the transformation.

$\endgroup$
1
  • $\begingroup$ You should multiply that by a global phase gate I think $\endgroup$ Nov 11 at 10:11

1 Answer 1

0
$\begingroup$

A flexible way is to use the cirq.merge_operations transformer which lets you pass in your own merge function that decides what operations to merge and how. For example:

def merge_func(op1: cirq.Operation, op2: cirq.Operation) -> Optional[cirq.Operation]:
    if not isinstance(op1, cirq.GateOperation):
        return None
    if not isinstance(op2, cirq.GateOperation):
        return None
    if not isinstance(op1.gate, cirq.YPowGate):
        return None
    if not isinstance(op2.gate, cirq.YPowGate):
        return None

    return cirq.Y(*op1.qubits)**(op1.gate.exponent + op2.gate.exponent)

circuit = cirq.merge_operations(circuit, merge_func)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.