def duration_of(self, operation): g = xmon_gate_ext.try_cast(operation.gate, xmon_gates.XmonGate) if isinstance(g, xmon_gates.Exp11Gate): return self._exp_z_duration if isinstance(g, xmon_gates.ExpWGate): return self._exp_w_duration if isinstance(g, xmon_gates.XmonMeasurementGate): return self._measurement_duration if isinstance(g, xmon_gates.ExpZGate): return Duration() # Z gates are performed in the control software. raise ValueError('Unsupported gate type: {}'.format(repr(g)))
def duration_of(self, operation): if isinstance(operation, ops.GateOperation): g = xmon_gate_ext.try_cast(xmon_gates.XmonGate, operation.gate) if isinstance(g, xmon_gates.Exp11Gate): return self._exp_z_duration if isinstance(g, xmon_gates.ExpWGate): return self._exp_w_duration if isinstance(g, xmon_gates.XmonMeasurementGate): return self._measurement_duration if isinstance(g, xmon_gates.ExpZGate): # Z gates are performed in the control software. return Duration() raise ValueError('Unsupported gate type: {!r}'.format(operation))
def duration_of(self, operation): if isinstance(operation, ops.GateOperation): if isinstance(operation.gate, ops.Rot11Gate): return self._exp_z_duration if isinstance(operation.gate, ops.MeasurementGate): return self._measurement_duration g = xmon_gate_ext.try_cast(xmon_gates.XmonGate, operation.gate) if isinstance(g, xmon_gates.ExpWGate): return self._exp_w_duration if isinstance(operation.gate, ops.RotZGate): # Z gates are performed in the control software. return Duration() raise ValueError('Unsupported gate type: {!r}'.format(operation))
def _convert_one(self, op: ops.Operation) -> ops.OP_TREE: # Already supported? if XmonGate.is_supported_op(op): return op # Maybe we know how to wrap it? if isinstance(op, ops.GateOperation): xmon = xmon_gate_ext.try_cast(XmonGate, op.gate) # type: ignore if xmon is not None: return xmon.on(*op.qubits) # 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 = single_qubit_matrix_to_native_gates(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_operations(op.qubits[0], op.qubits[1], mat, allow_partial_czs=True) # Provides a decomposition? composite_op = xmon_gate_ext.try_cast( # type: ignore ops.CompositeOperation, op) if composite_op is not None: return composite_op.default_decompose() # Just let it be? if self.ignore_failures: return op raise TypeError("Don't know how to work with {!r}. " "It isn't a GateOperation with an XmonGate, " "a 1 or 2 qubit gate with a known unitary, " "or a CompositeOperation.".format(op))
def _convert_one(self, op: ops.Operation) -> ops.OP_TREE: # Maybe we know how to wrap it? if isinstance(op, ops.GateOperation): xmon = xmon_gate_ext.try_cast(XmonGate, op.gate) # type: ignore if xmon is not None: return xmon.on(*op.qubits) # 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 = single_qubit_matrix_to_native_gates(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_operations(op.qubits[0], op.qubits[1], mat, allow_partial_czs=True) return NotImplemented