Skip to content

Speed up construction of single qubit pauli operations - cirq.X(q) #6316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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