def convert_one(self, op: ops.Operation) -> ops.OP_TREE: """Convert a single (one- or two-qubit) operation into ion trap native gates. Args: op: The gate operation to be converted. Returns: The desired operations implemented with ion trap gates. Raises: TypeError: If the operation cannot be converted. """ # Known gate name if not isinstance(op, ops.GateOperation): raise TypeError(f"{op!r} is not a gate operation.") if op in self.gateset: return [op] # one choice of known Hadamard gate decomposition if isinstance(op.gate, ops.HPowGate) and op.gate.exponent == 1: return [ ops.rx(np.pi).on(op.qubits[0]), ops.ry(-1 * np.pi / 2).on(op.qubits[0]) ] # one choice of known CNOT gate decomposition if isinstance(op.gate, ops.CNotPowGate) and op.gate.exponent == 1: return [ ops.ry(np.pi / 2).on(op.qubits[0]), ms(np.pi / 4).on(op.qubits[0], op.qubits[1]), ops.rx(-1 * np.pi / 2).on(op.qubits[0]), ops.rx(-1 * np.pi / 2).on(op.qubits[1]), ops.ry(-1 * np.pi / 2).on(op.qubits[0]), ] # Known matrix mat = protocols.unitary(op, None) if len(op.qubits) <= 2 else None if mat is not None and len(op.qubits) == 1: gates = transformers.single_qubit_matrix_to_phased_x_z(mat) return [g.on(op.qubits[0]) for g in gates] if mat is not None and len(op.qubits) == 2: return two_qubit_matrix_to_ion_operations(op.qubits[0], op.qubits[1], mat) if self.ignore_failures: return [op] raise TypeError("Don't know how to work with {!r}. " "It isn't a native Ion Trap operation, " "a 1 or 2 qubit gate with a known unitary, " "or composite.".format(op.gate))
def _parity_interaction( q0: 'cirq.Qid', q1: 'cirq.Qid', rads: float, atol: float, gate: Optional[ops.Gate] = None ): """Yields an XX interaction framed by the given operation.""" if abs(rads) < atol: return if gate is not None: g = cast(ops.Gate, gate) yield g.on(q0), g.on(q1) yield ms(-1 * rads).on(q0, q1) if gate is not None: g = protocols.inverse(gate) yield g.on(q0), g.on(q1)