2
$\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, 2022 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 and acknowledge that you have read and understand our privacy policy and code of conduct.

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