def _decompose_(self, qubits): a, b = qubits return [ ops.XX(a, b)**0.5, ops.YY(a, b)**0.25, ]
def _translate_two_qubit_braket_instruction_to_cirq_operation( instr: Instruction, ) -> List["cirq.Operation"]: """Converts the two-qubit braket instruction to Cirq. Args: instr: Two-qubit Braket instruction to convert. Raises: ValueError: If the instruction cannot be converted to Cirq. """ qubits = [LineQubit(int(qubit)) for qubit in instr.target] gate = instr.operator # Two-qubit non-parameterized gates. if isinstance(gate, braket_gates.CNot): return [cirq_ops.CNOT.on(*qubits)] elif isinstance(gate, braket_gates.Swap): return [cirq_ops.SWAP.on(*qubits)] elif isinstance(gate, braket_gates.ISwap): return [cirq_ops.ISWAP.on(*qubits)] elif isinstance(gate, braket_gates.CZ): return [cirq_ops.CZ.on(*qubits)] elif isinstance(gate, braket_gates.CY): return [ cirq_ops.S.on(qubits[1]) ** -1, cirq_ops.CNOT.on(*qubits), cirq_ops.S.on(qubits[1]), ] # Two-qubit parameterized gates. elif isinstance(gate, braket_gates.CPhaseShift): return [cirq_ops.CZ.on(*qubits) ** (gate.angle / np.pi)] elif isinstance(gate, braket_gates.CPhaseShift00): return [ cirq_ops.XX(*qubits), cirq_ops.CZ.on(*qubits) ** (gate.angle / np.pi), cirq_ops.XX(*qubits), ] elif isinstance(gate, braket_gates.CPhaseShift01): return [ cirq_ops.X(qubits[0]), cirq_ops.CZ.on(*qubits) ** (gate.angle / np.pi), cirq_ops.X(qubits[0]), ] elif isinstance(gate, braket_gates.CPhaseShift10): return [ cirq_ops.X(qubits[1]), cirq_ops.CZ.on(*qubits) ** (gate.angle / np.pi), cirq_ops.X(qubits[1]), ] elif isinstance(gate, braket_gates.PSwap): return [ cirq_ops.SWAP.on(*qubits), cirq_ops.CNOT.on(*qubits), cirq_ops.Z.on(qubits[1]) ** (gate.angle / np.pi), cirq_ops.CNOT.on(*qubits), ] elif isinstance(gate, braket_gates.XX): return [ cirq_ops.XXPowGate( exponent=gate.angle / np.pi, global_shift=-0.5 ).on(*qubits) ] elif isinstance(gate, braket_gates.YY): return [ cirq_ops.YYPowGate( exponent=gate.angle / np.pi, global_shift=-0.5 ).on(*qubits) ] elif isinstance(gate, braket_gates.ZZ): return [ cirq_ops.ZZPowGate( exponent=gate.angle / np.pi, global_shift=-0.5 ).on(*qubits) ] elif isinstance(gate, braket_gates.XY): return [cirq_ops.ISwapPowGate(exponent=gate.angle / np.pi).on(*qubits)] else: _raise_braket_to_cirq_error(instr)