diff --git a/cirq-core/cirq/ops/pauli_gates.py b/cirq-core/cirq/ops/pauli_gates.py index c91805250ce..a2132a6a4bb 100644 --- a/cirq-core/cirq/ops/pauli_gates.py +++ b/cirq-core/cirq/ops/pauli_gates.py @@ -15,6 +15,7 @@ from typing import Any, cast, Tuple, TYPE_CHECKING, Union, Dict from cirq._doc import document +from cirq._import import LazyLoader from cirq.ops import common_gates, raw_types, identity from cirq.type_workarounds import NotImplementedType @@ -29,6 +30,9 @@ ) # pragma: no cover +pauli_string = LazyLoader("pauli_string", globals(), "cirq.ops.pauli_string") + + class Pauli(raw_types.Gate, metaclass=abc.ABCMeta): """Represents the Pauli gates. @@ -97,9 +101,8 @@ def on(self, *qubits: 'cirq.Qid') -> 'SingleQubitPauliStringGateOperation': """ if len(qubits) != 1: raise ValueError(f'Expected a single qubit, got <{qubits!r}>.') - from cirq.ops.pauli_string import SingleQubitPauliStringGateOperation - return SingleQubitPauliStringGateOperation(self, qubits[0]) + return pauli_string.SingleQubitPauliStringGateOperation(self, qubits[0]) @property def _canonical_exponent(self): diff --git a/cirq-core/cirq/ops/pauli_string.py b/cirq-core/cirq/ops/pauli_string.py index 21ce7be0dac..f9e6896bffe 100644 --- a/cirq-core/cirq/ops/pauli_string.py +++ b/cirq-core/cirq/ops/pauli_string.py @@ -42,7 +42,7 @@ import sympy import cirq -from cirq import value, protocols, linalg, qis +from cirq import value, protocols, linalg, qis, _compat from cirq._doc import document from cirq._import import LazyLoader from cirq.ops import ( @@ -184,7 +184,7 @@ def __init__( Raises: TypeError: If the `qubit_pauli_map` has values that are not Paulis. """ - if qubit_pauli_map is not None: + if _compat.__cirq_debug__.get() and qubit_pauli_map is not None: for v in qubit_pauli_map.values(): if not isinstance(v, pauli_gates.Pauli): raise TypeError(f'{v} is not a Pauli')