def _try_convert_to_quirk_gate( op: ops.Operation, prefer_unknown_gate_to_failure: bool) -> QuirkOp: quirk_gate = known_quirk_op_for_operation(op) if quirk_gate is not None: return quirk_gate matrix_op = single_qubit_matrix_gate(protocols.unitary(op, None)) if matrix_op is not None: return matrix_op if prefer_unknown_gate_to_failure: return UNKNOWN_GATE raise TypeError(f'Unrecognized operation: {op!r}')
def _try_convert_to_quirk_gate( op: ops.Operation, prefer_unknown_gate_to_failure: bool) -> QuirkOp: quirk_gate = quirk_gate_ext.try_cast(QuirkOp, op) if quirk_gate is not None: return quirk_gate known_matrix_gate = quirk_gate_ext.try_cast(ops.KnownMatrix, op) if known_matrix_gate is not None: raw = single_qubit_matrix_gate(known_matrix_gate) if raw is not None: return raw if prefer_unknown_gate_to_failure: return UNKNOWN_GATE raise TypeError('Unrecognized operation: {!r}'.format(op))
def _try_convert_to_quirk_gate( gate: ops.Gate, prefer_unknown_gate_to_failure: bool) -> QuirkGate: quirk_gate = quirk_gate_ext.try_cast(gate, QuirkGate) if quirk_gate is not None: return quirk_gate known_matrix_gate = quirk_gate_ext.try_cast(gate, ops.KnownMatrixGate) if known_matrix_gate is not None: raw = single_qubit_matrix_gate(known_matrix_gate) if raw is not None: return raw if prefer_unknown_gate_to_failure: return UNKNOWN_GATE raise TypeError('Unrecognized gate: {!r}'.format(gate))
def _try_convert_to_quirk_gate(op: ops.Operation, prefer_unknown_gate_to_failure: bool ) -> QuirkOp: quirk_gate = quirk_gate_ext.try_cast(QuirkOp, op) if quirk_gate is not None: return quirk_gate known_matrix_gate = quirk_gate_ext.try_cast(ops.KnownMatrix, op) if known_matrix_gate is not None: raw = single_qubit_matrix_gate(known_matrix_gate) if raw is not None: return raw if prefer_unknown_gate_to_failure: return UNKNOWN_GATE raise TypeError('Unrecognized operation: {!r}'.format(op))