Skip to content

Commit

Permalink
Speed up construction of single qubit pauli operations - cirq.X(q) (#…
Browse files Browse the repository at this point in the history
…6316)

Co-authored-by: Matthew Neeley <maffoo@google.com>
  • Loading branch information
tanujkhattar and maffoo authored Dec 20, 2023
1 parent 181d7aa commit a2530fe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions cirq-core/cirq/ops/pauli_gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions cirq-core/cirq/ops/pauli_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit a2530fe

Please sign in to comment.