cirq-core 1.4.0.dev20231221183905__py3-none-any.whl → 1.4.0.dev20240111191543__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
cirq/_compat.py CHANGED
@@ -61,12 +61,6 @@ def with_debug(value: bool) -> Iterator[None]:
61
61
  __cirq_debug__.reset(token)
62
62
 
63
63
 
64
- try:
65
- from functools import cached_property # pylint: disable=unused-import
66
- except ImportError:
67
- from backports.cached_property import cached_property # type: ignore[no-redef]
68
-
69
-
70
64
  # Sentinel used by wrapped_no_args below when method has not yet been cached.
71
65
  _NOT_FOUND = object()
72
66
 
cirq/_compat_test.py CHANGED
@@ -38,7 +38,6 @@ import cirq.testing
38
38
  from cirq._compat import (
39
39
  block_overlapping_deprecation,
40
40
  cached_method,
41
- cached_property,
42
41
  proper_repr,
43
42
  dataclass_repr,
44
43
  deprecated,
@@ -1011,23 +1010,6 @@ def test_block_overlapping_deprecation():
1011
1010
  f(5)
1012
1011
 
1013
1012
 
1014
- def test_cached_property():
1015
- class Foo:
1016
- def __init__(self):
1017
- self.bar_calls = 0
1018
-
1019
- @cached_property
1020
- def bar(self):
1021
- self.bar_calls += 1
1022
- return []
1023
-
1024
- foo = Foo()
1025
- bar = foo.bar
1026
- bar2 = foo.bar
1027
- assert bar2 is bar
1028
- assert foo.bar_calls == 1
1029
-
1030
-
1031
1013
  class Bar:
1032
1014
  def __init__(self) -> None:
1033
1015
  self.foo_calls: Dict[int, int] = collections.Counter()
cirq/_version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "1.4.0.dev20231221183905"
1
+ __version__ = "1.4.0.dev20240111191543"
@@ -19,6 +19,7 @@ applied as part of a larger circuit, a CircuitOperation will execute all
19
19
  component operations in order, including any nested CircuitOperations.
20
20
  """
21
21
  import math
22
+ from functools import cached_property
22
23
  from typing import (
23
24
  Callable,
24
25
  cast,
@@ -38,7 +39,7 @@ import numpy as np
38
39
  import sympy
39
40
 
40
41
  from cirq import circuits, ops, protocols, value, study
41
- from cirq._compat import cached_property, proper_repr
42
+ from cirq._compat import proper_repr
42
43
 
43
44
  if TYPE_CHECKING:
44
45
  import cirq
@@ -12,6 +12,7 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
  """An immutable version of the Circuit data structure."""
15
+ from functools import cached_property
15
16
  from typing import (
16
17
  AbstractSet,
17
18
  FrozenSet,
@@ -90,7 +91,7 @@ class FrozenCircuit(AbstractCircuit, protocols.SerializableByKey):
90
91
  """Returns a tuple of the Circuit's tags."""
91
92
  return self._tags
92
93
 
93
- @_compat.cached_property
94
+ @cached_property
94
95
  def untagged(self) -> 'cirq.FrozenCircuit':
95
96
  """Returns the underlying FrozenCircuit without any tags."""
96
97
  return self._from_moments(self._moments) if self.tags else self
@@ -148,7 +149,7 @@ class FrozenCircuit(AbstractCircuit, protocols.SerializableByKey):
148
149
  def all_qubits(self) -> FrozenSet['cirq.Qid']:
149
150
  return super().all_qubits()
150
151
 
151
- @_compat.cached_property
152
+ @cached_property
152
153
  def _all_operations(self) -> Tuple['cirq.Operation', ...]:
153
154
  return tuple(super().all_operations())
154
155
 
@@ -17,9 +17,10 @@
17
17
 
18
18
  import abc
19
19
  from dataclasses import dataclass, field
20
+ from functools import cached_property
20
21
  from typing import Dict, TYPE_CHECKING, List, Set, Type
21
22
 
22
- from cirq import _compat, ops, devices
23
+ from cirq import ops, devices
23
24
  from cirq.devices import noise_utils
24
25
 
25
26
  if TYPE_CHECKING:
@@ -131,7 +132,7 @@ class SuperconductingQubitsNoiseProperties(devices.NoiseProperties, abc.ABC):
131
132
  p_error -= noise_utils.decoherence_pauli_error(self.t1_ns[q], self.tphi_ns[q], time_ns)
132
133
  return p_error
133
134
 
134
- @_compat.cached_property
135
+ @cached_property
135
136
  def _depolarizing_error(self) -> Dict[noise_utils.OpIdentifier, float]:
136
137
  """Returns the portion of Pauli error from depolarization."""
137
138
  depol_errors = {}
@@ -14,6 +14,7 @@
14
14
 
15
15
  import dataclasses
16
16
  import itertools
17
+ import functools
17
18
 
18
19
  from typing import (
19
20
  Any,
@@ -58,11 +59,11 @@ class Cliffords:
58
59
  s1_y
59
60
  """
60
61
 
61
- c1_in_xy: List[List[ops.Gate]]
62
- c1_in_xz: List[List[ops.Gate]]
63
- s1: List[List[ops.Gate]]
64
- s1_x: List[List[ops.Gate]]
65
- s1_y: List[List[ops.Gate]]
62
+ c1_in_xy: List[List[ops.SingleQubitCliffordGate]]
63
+ c1_in_xz: List[List[ops.SingleQubitCliffordGate]]
64
+ s1: List[List[ops.SingleQubitCliffordGate]]
65
+ s1_x: List[List[ops.SingleQubitCliffordGate]]
66
+ s1_y: List[List[ops.SingleQubitCliffordGate]]
66
67
 
67
68
 
68
69
  class RandomizedBenchMarkResult:
@@ -256,10 +257,9 @@ def single_qubit_randomized_benchmarking(
256
257
  A RandomizedBenchMarkResult object that stores and plots the result.
257
258
  """
258
259
 
259
- qubits = cast(Iterator['cirq.Qid'], (qubit,))
260
260
  result = parallel_single_qubit_randomized_benchmarking(
261
261
  sampler,
262
- qubits,
262
+ (qubit,),
263
263
  use_xy_basis,
264
264
  num_clifford_range=num_clifford_range,
265
265
  num_circuits=num_circuits,
@@ -270,7 +270,7 @@ def single_qubit_randomized_benchmarking(
270
270
 
271
271
  def parallel_single_qubit_randomized_benchmarking(
272
272
  sampler: 'cirq.Sampler',
273
- qubits: Iterator['cirq.Qid'],
273
+ qubits: Sequence['cirq.Qid'],
274
274
  use_xy_basis: bool = True,
275
275
  *,
276
276
  num_clifford_range: Sequence[int] = tuple(
@@ -299,17 +299,14 @@ def parallel_single_qubit_randomized_benchmarking(
299
299
  A dictionary from qubits to RandomizedBenchMarkResult objects.
300
300
  """
301
301
 
302
- cliffords = _single_qubit_cliffords()
303
- c1 = cliffords.c1_in_xy if use_xy_basis else cliffords.c1_in_xz
304
- clifford_mats = np.array([_gate_seq_to_mats(gates) for gates in c1])
302
+ clifford_group = _single_qubit_cliffords()
303
+ c1 = clifford_group.c1_in_xy if use_xy_basis else clifford_group.c1_in_xz
305
304
 
306
305
  # create circuits
307
306
  circuits_all: List['cirq.AbstractCircuit'] = []
308
307
  for num_cliffords in num_clifford_range:
309
308
  for _ in range(num_circuits):
310
- circuits_all.append(
311
- _create_parallel_rb_circuit(qubits, num_cliffords, c1, clifford_mats)
312
- )
309
+ circuits_all.append(_create_parallel_rb_circuit(qubits, num_cliffords, c1))
313
310
 
314
311
  # run circuits
315
312
  results = sampler.run_batch(circuits_all, repetitions=repetitions)
@@ -562,13 +559,16 @@ def two_qubit_state_tomography(
562
559
 
563
560
 
564
561
  def _create_parallel_rb_circuit(
565
- qubits: Iterator['cirq.Qid'], num_cliffords: int, c1: list, clifford_mats: np.ndarray
562
+ qubits: Sequence['cirq.Qid'], num_cliffords: int, c1: list
566
563
  ) -> 'cirq.Circuit':
567
- circuits_to_zip = [
568
- _random_single_q_clifford(qubit, num_cliffords, c1, clifford_mats) for qubit in qubits
569
- ]
570
- circuit = circuits.Circuit.zip(*circuits_to_zip)
571
- return circuits.Circuit.from_moments(*circuit, ops.measure_each(*qubits))
564
+ sequences_to_zip = [_random_single_q_clifford(qubit, num_cliffords, c1) for qubit in qubits]
565
+ # Ensure each sequence has the same number of moments.
566
+ num_moments = max(len(sequence) for sequence in sequences_to_zip)
567
+ for q, sequence in zip(qubits, sequences_to_zip):
568
+ if (n := len(sequence)) < num_moments:
569
+ sequence.extend([ops.SingleQubitCliffordGate.I(q)] * (num_moments - n))
570
+ moments = zip(*sequences_to_zip)
571
+ return circuits.Circuit.from_moments(*moments, ops.measure_each(*qubits))
572
572
 
573
573
 
574
574
  def _indices_after_basis_rot(i: int, j: int) -> Tuple[int, Sequence[int], Sequence[int]]:
@@ -612,18 +612,13 @@ def _two_qubit_clifford_matrices(
612
612
 
613
613
 
614
614
  def _random_single_q_clifford(
615
- qubit: 'cirq.Qid',
616
- num_cfds: int,
617
- cfds: Sequence[Sequence['cirq.Gate']],
618
- cfd_matrices: np.ndarray,
619
- ) -> 'cirq.Circuit':
615
+ qubit: 'cirq.Qid', num_cfds: int, cfds: Sequence[Sequence['cirq.Gate']]
616
+ ) -> List['cirq.Operation']:
620
617
  clifford_group_size = 24
618
+ operations = [[gate(qubit) for gate in gates] for gates in cfds]
621
619
  gate_ids = list(np.random.choice(clifford_group_size, num_cfds))
622
- gate_sequence = [gate for gate_id in gate_ids for gate in cfds[gate_id]]
623
- idx = _find_inv_matrix(_gate_seq_to_mats(gate_sequence), cfd_matrices)
624
- gate_sequence.extend(cfds[idx])
625
- circuit = circuits.Circuit(gate(qubit) for gate in gate_sequence)
626
- return circuit
620
+ adjoint = _reduce_gate_seq([gate for gate_id in gate_ids for gate in cfds[gate_id]]) ** -1
621
+ return [op for gate_id in gate_ids for op in operations[gate_id]] + [adjoint(qubit)]
627
622
 
628
623
 
629
624
  def _random_two_q_clifford(
@@ -681,11 +676,13 @@ def _matrix_bar_plot(
681
676
  ax.set_title(title)
682
677
 
683
678
 
684
- def _gate_seq_to_mats(gate_seq: Sequence['cirq.Gate']) -> np.ndarray:
685
- mat_rep = protocols.unitary(gate_seq[0])
679
+ def _reduce_gate_seq(
680
+ gate_seq: Sequence[ops.SingleQubitCliffordGate],
681
+ ) -> ops.SingleQubitCliffordGate:
682
+ cur = gate_seq[0]
686
683
  for gate in gate_seq[1:]:
687
- mat_rep = np.dot(protocols.unitary(gate), mat_rep)
688
- return mat_rep
684
+ cur = cur.merged_with(gate)
685
+ return cur
689
686
 
690
687
 
691
688
  def _two_qubit_clifford(
@@ -793,11 +790,16 @@ def _single_qubit_gates(
793
790
  yield gate(qubit)
794
791
 
795
792
 
793
+ @functools.cache
796
794
  def _single_qubit_cliffords() -> Cliffords:
797
- X, Y, Z = ops.X, ops.Y, ops.Z
795
+ X, Y, Z = (
796
+ ops.SingleQubitCliffordGate.X,
797
+ ops.SingleQubitCliffordGate.Y,
798
+ ops.SingleQubitCliffordGate.Z,
799
+ )
798
800
 
799
- c1_in_xy: List[List['cirq.Gate']] = []
800
- c1_in_xz: List[List['cirq.Gate']] = []
801
+ c1_in_xy: List[List[ops.SingleQubitCliffordGate]] = []
802
+ c1_in_xz: List[List[ops.SingleQubitCliffordGate]] = []
801
803
 
802
804
  for phi_0, phi_1 in itertools.product([1.0, 0.5, -0.5], [0.0, 0.5, -0.5]):
803
805
  c1_in_xy.append([X**phi_0, Y**phi_1])
@@ -820,8 +822,20 @@ def _single_qubit_cliffords() -> Cliffords:
820
822
  for z0, x, z1 in phi_xz:
821
823
  c1_in_xz.append([Z**z0, X**x, Z**z1])
822
824
 
823
- s1: List[List['cirq.Gate']] = [[X**0.0], [Y**0.5, X**0.5], [X**-0.5, Y**-0.5]]
824
- s1_x: List[List['cirq.Gate']] = [[X**0.5], [X**0.5, Y**0.5, X**0.5], [Y**-0.5]]
825
- s1_y: List[List['cirq.Gate']] = [[Y**0.5], [X**-0.5, Y**-0.5, X**0.5], [Y, X**0.5]]
825
+ s1: List[List[ops.SingleQubitCliffordGate]] = [
826
+ [X**0.0],
827
+ [Y**0.5, X**0.5],
828
+ [X**-0.5, Y**-0.5],
829
+ ]
830
+ s1_x: List[List[ops.SingleQubitCliffordGate]] = [
831
+ [X**0.5],
832
+ [X**0.5, Y**0.5, X**0.5],
833
+ [Y**-0.5],
834
+ ]
835
+ s1_y: List[List[ops.SingleQubitCliffordGate]] = [
836
+ [Y**0.5],
837
+ [X**-0.5, Y**-0.5, X**0.5],
838
+ [Y, X**0.5],
839
+ ]
826
840
 
827
841
  return Cliffords(c1_in_xy, c1_in_xz, s1, s1_x, s1_y)
@@ -75,9 +75,32 @@ def test_single_qubit_cliffords():
75
75
 
76
76
  # Check that XZ decomposition has at most one X gate per clifford.
77
77
  for gates in cliffords.c1_in_xz:
78
- num_x = len([gate for gate in gates if isinstance(gate, cirq.XPowGate)])
79
- num_z = len([gate for gate in gates if isinstance(gate, cirq.ZPowGate)])
80
- assert num_x + num_z == len(gates)
78
+ num_i = len([gate for gate in gates if gate == cirq.ops.SingleQubitCliffordGate.I])
79
+ num_x = len(
80
+ [
81
+ gate
82
+ for gate in gates
83
+ if gate
84
+ in (
85
+ cirq.ops.SingleQubitCliffordGate.X,
86
+ cirq.ops.SingleQubitCliffordGate.X_sqrt,
87
+ cirq.ops.SingleQubitCliffordGate.X_nsqrt,
88
+ )
89
+ ]
90
+ )
91
+ num_z = len(
92
+ [
93
+ gate
94
+ for gate in gates
95
+ if gate
96
+ in (
97
+ cirq.ops.SingleQubitCliffordGate.Z,
98
+ cirq.ops.SingleQubitCliffordGate.Z_sqrt,
99
+ cirq.ops.SingleQubitCliffordGate.Z_nsqrt,
100
+ )
101
+ ]
102
+ )
103
+ assert num_x + num_z + num_i == len(gates)
81
104
  assert num_x <= 1
82
105
 
83
106
 
cirq/ops/clifford_gate.py CHANGED
@@ -14,11 +14,13 @@
14
14
 
15
15
  from typing import Any, Dict, List, Optional, Sequence, Tuple, TYPE_CHECKING, Union
16
16
 
17
-
17
+ import functools
18
+ from dataclasses import dataclass
18
19
  import numpy as np
19
20
 
20
21
  from cirq import protocols, value, linalg, qis
21
22
  from cirq._import import LazyLoader
23
+ from cirq._compat import cached_method
22
24
  from cirq.ops import common_gates, named_qubit, raw_types, pauli_gates, phased_x_z_gate
23
25
  from cirq.ops.pauli_gates import Pauli
24
26
  from cirq.type_workarounds import NotImplementedType
@@ -356,6 +358,8 @@ class CommonCliffordGates(metaclass=CommonCliffordGateMetaClass):
356
358
  class CliffordGate(raw_types.Gate, CommonCliffordGates):
357
359
  """Clifford rotation for N-qubit."""
358
360
 
361
+ _clifford_tableau: qis.CliffordTableau
362
+
359
363
  def __init__(self, *, _clifford_tableau: qis.CliffordTableau) -> None:
360
364
  # We use the Clifford tableau to represent a Clifford gate.
361
365
  # It is crucial to note that the meaning of tableau here is different
@@ -376,7 +380,7 @@ class CliffordGate(raw_types.Gate, CommonCliffordGates):
376
380
  # more precisely the conjugate transformation of ZI by this gate, becomes -ZI.
377
381
  # (Note the real clifford tableau has to satify the Symplectic property.
378
382
  # here is just for illustration)
379
- self._clifford_tableau = _clifford_tableau.copy()
383
+ object.__setattr__(self, '_clifford_tableau', _clifford_tableau.copy())
380
384
 
381
385
  @property
382
386
  def clifford_tableau(self):
@@ -399,6 +403,12 @@ class CliffordGate(raw_types.Gate, CommonCliffordGates):
399
403
  def __pow__(self, exponent) -> 'CliffordGate':
400
404
  if exponent == -1:
401
405
  return CliffordGate.from_clifford_tableau(self.clifford_tableau.inverse())
406
+ if exponent == 0:
407
+ return CliffordGate.from_clifford_tableau(
408
+ qis.CliffordTableau(num_qubits=self._num_qubits_())
409
+ )
410
+ if exponent == 1:
411
+ return self
402
412
  if exponent > 0 and int(exponent) == exponent:
403
413
  base_tableau = self.clifford_tableau.copy()
404
414
  for _ in range(int(exponent) - 1):
@@ -457,6 +467,7 @@ class CliffordGate(raw_types.Gate, CommonCliffordGates):
457
467
  return NotImplemented
458
468
 
459
469
 
470
+ @dataclass(frozen=True, init=False, eq=False, repr=False)
460
471
  @value.value_equality(manual_cls=True)
461
472
  class SingleQubitCliffordGate(CliffordGate):
462
473
  """Any single qubit Clifford rotation."""
@@ -468,6 +479,7 @@ class SingleQubitCliffordGate(CliffordGate):
468
479
  return 1
469
480
 
470
481
  @staticmethod
482
+ @functools.cache
471
483
  def from_clifford_tableau(tableau: qis.CliffordTableau) -> 'SingleQubitCliffordGate':
472
484
  if not isinstance(tableau, qis.CliffordTableau):
473
485
  raise ValueError('Input argument has to be a CliffordTableau instance.')
@@ -679,6 +691,10 @@ class SingleQubitCliffordGate(CliffordGate):
679
691
  * {middle point of xyz in 4 Quadrant} * 120 is [[0, 1], [1, 1]]
680
692
  * {middle point of xyz in 4 Quadrant} * 240 is [[1, 1], [1, 0]]
681
693
  """
694
+ return self._to_phased_xz_gate
695
+
696
+ @functools.cached_property
697
+ def _to_phased_xz_gate(self) -> phased_x_z_gate.PhasedXZGate:
682
698
  x_to_flip, z_to_flip = self.clifford_tableau.rs
683
699
  flip_index = int(z_to_flip) * 2 + x_to_flip
684
700
  a, x, z = 0.0, 0.0, 0.0
@@ -716,7 +732,7 @@ class SingleQubitCliffordGate(CliffordGate):
716
732
  z = -0.5 if x_to_flip else 0.5
717
733
  return phased_x_z_gate.PhasedXZGate(x_exponent=x, z_exponent=z, axis_phase_exponent=a)
718
734
 
719
- def __pow__(self, exponent) -> 'SingleQubitCliffordGate':
735
+ def __pow__(self, exponent: Union[float, int]) -> 'SingleQubitCliffordGate':
720
736
  # First to check if we can get the sqrt and negative sqrt Clifford.
721
737
  if self._get_sqrt_map().get(exponent, None):
722
738
  pow_gate = self._get_sqrt_map()[exponent].get(self, None)
@@ -761,6 +777,7 @@ class SingleQubitCliffordGate(CliffordGate):
761
777
  to, flip = self.pauli_tuple(pauli)
762
778
  return to == pauli and not flip
763
779
 
780
+ @cached_method
764
781
  def merged_with(self, second: 'SingleQubitCliffordGate') -> 'SingleQubitCliffordGate':
765
782
  """Returns a SingleQubitCliffordGate such that the circuits
766
783
  --output-- and --self--second--
@@ -773,6 +790,10 @@ class SingleQubitCliffordGate(CliffordGate):
773
790
  return True
774
791
 
775
792
  def _unitary_(self) -> np.ndarray:
793
+ return self._unitary
794
+
795
+ @functools.cached_property
796
+ def _unitary(self) -> np.ndarray:
776
797
  mat = np.eye(2)
777
798
  qubit = named_qubit.NamedQubit('arbitrary')
778
799
  for op in protocols.decompose_once_with_qubits(self, (qubit,)):
@@ -787,6 +808,10 @@ class SingleQubitCliffordGate(CliffordGate):
787
808
  clifford gate if applied in order. This decomposition agrees with
788
809
  cirq.unitary(self), including global phase.
789
810
  """
811
+ return self._decompose_gate
812
+
813
+ @functools.cached_property
814
+ def _decompose_gate(self) -> Sequence['cirq.Gate']:
790
815
  if self == SingleQubitCliffordGate.H:
791
816
  return [common_gates.H]
792
817
  rotations = self.decompose_rotation()
@@ -802,6 +827,10 @@ class SingleQubitCliffordGate(CliffordGate):
802
827
  Note that the combined unitary effect of these rotations may
803
828
  differ from cirq.unitary(self) by a global phase.
804
829
  """
830
+ return self._decompose_rotation
831
+
832
+ @functools.cached_property
833
+ def _decompose_rotation(self) -> Sequence[Tuple[Pauli, int]]:
805
834
  x_rot = self.pauli_tuple(pauli_gates.X)
806
835
  y_rot = self.pauli_tuple(pauli_gates.Y)
807
836
  z_rot = self.pauli_tuple(pauli_gates.Z)
@@ -895,6 +924,10 @@ class SingleQubitCliffordGate(CliffordGate):
895
924
  )
896
925
 
897
926
  def _value_equality_values_(self):
927
+ return self._value_equality_values
928
+
929
+ @functools.cached_property
930
+ def _value_equality_values(self):
898
931
  return self._clifford_tableau.matrix().tobytes() + self._clifford_tableau.rs.tobytes()
899
932
 
900
933
  def _value_equality_values_cls_(self):
@@ -12,10 +12,11 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
  import abc
15
+ from functools import cached_property
15
16
  from typing import Collection, Tuple, TYPE_CHECKING, Any, Dict, Iterator, Optional, Sequence, Union
16
17
  import itertools
17
18
 
18
- from cirq import protocols, value, _compat
19
+ from cirq import protocols, value
19
20
 
20
21
  if TYPE_CHECKING:
21
22
  import cirq
@@ -144,7 +145,7 @@ class ProductOfSums(AbstractControlValues):
144
145
  (cv,) if isinstance(cv, int) else tuple(sorted(set(cv))) for cv in data
145
146
  )
146
147
 
147
- @_compat.cached_property
148
+ @cached_property
148
149
  def is_trivial(self) -> bool:
149
150
  return self._qubit_sums == ((1,),) * self._num_qubits_()
150
151
 
@@ -252,7 +253,7 @@ class SumOfProducts(AbstractControlValues):
252
253
  if not all(len(p) == num_qubits for p in self._conjunctions):
253
254
  raise ValueError(f'Each term of {self._conjunctions} should be of length {num_qubits}.')
254
255
 
255
- @_compat.cached_property
256
+ @cached_property
256
257
  def is_trivial(self) -> bool:
257
258
  return self._conjunctions == ((1,) * self._num_qubits_(),)
258
259
 
@@ -17,7 +17,7 @@ from typing import Any, Dict, List, Optional, Sequence, TYPE_CHECKING
17
17
  import numpy as np
18
18
 
19
19
  from cirq import protocols
20
- from cirq._compat import proper_repr
20
+ from cirq._compat import proper_repr, cached_method
21
21
  from cirq.qis import quantum_state_representation
22
22
  from cirq.value import big_endian_int_to_digits, linear_dict, random_state
23
23
 
@@ -652,3 +652,7 @@ class CliffordTableau(StabilizerState):
652
652
  self, axes: Sequence[int], seed: 'cirq.RANDOM_STATE_OR_SEED_LIKE' = None
653
653
  ) -> List[int]:
654
654
  return [self._measure(axis, random_state.parse_random_state(seed)) for axis in axes]
655
+
656
+ @cached_method
657
+ def __hash__(self) -> int:
658
+ return hash(self.matrix().tobytes() + self.rs.tobytes())
@@ -324,9 +324,11 @@ def test_clifford_circuit_SHSYSHS():
324
324
  clifford_simulator = cirq.CliffordSimulator()
325
325
  state_vector_simulator = cirq.Simulator()
326
326
 
327
+ # workaround until #6402 is resolved.
328
+ final_state_vector = state_vector_simulator.simulate(circuit).final_state_vector
329
+ final_state_vector /= np.linalg.norm(final_state_vector)
327
330
  np.testing.assert_almost_equal(
328
- clifford_simulator.simulate(circuit).final_state.state_vector(),
329
- state_vector_simulator.simulate(circuit).final_state_vector,
331
+ clifford_simulator.simulate(circuit).final_state.state_vector(), final_state_vector
330
332
  )
331
333
 
332
334
 
@@ -14,6 +14,7 @@
14
14
  """Abstract classes for simulations which keep track of state vector."""
15
15
 
16
16
  import abc
17
+ from functools import cached_property
17
18
  from typing import Any, Dict, Iterator, Sequence, Type, TYPE_CHECKING, Generic, TypeVar
18
19
 
19
20
  import numpy as np
@@ -121,7 +122,7 @@ class StateVectorTrialResult(
121
122
  qubit_map=final_simulator_state.qubit_map,
122
123
  )
123
124
 
124
- @_compat.cached_property
125
+ @cached_property
125
126
  def final_state_vector(self) -> np.ndarray:
126
127
  return self._get_merged_sim_state().target_tensor.reshape(-1)
127
128
 
@@ -226,7 +226,7 @@ def assert_circuits_have_same_unitary_given_final_permutation(
226
226
  expected: circuits.AbstractCircuit,
227
227
  qubit_map: Dict[ops.Qid, ops.Qid],
228
228
  ) -> None:
229
- """Asserts two circuits have the same unitary up to a final permuation of qubits.
229
+ """Asserts two circuits have the same unitary up to a final permutation of qubits.
230
230
 
231
231
  Args:
232
232
  actual: A circuit computed by some code under test.
@@ -71,7 +71,7 @@ def map_clean_and_borrowable_qubits(
71
71
  inserting all mapped operations in a resulting circuit using EARLIEST strategy. The reason
72
72
  is that preserving moment structure forces additional constraints on the qubit allocation
73
73
  strategy (i.e. if two operations `op1` and `op2` are in the same moment, then we cannot
74
- reuse ancilla across `op1` and `op2`). We leave it upto the user to force such constraints
74
+ reuse ancilla across `op1` and `op2`). We leave it up to the user to force such constraints
75
75
  using the qubit manager instead of making it part of the transformer.
76
76
  3. However, for borrowable system qubits managed by the transformer, we do not reuse qubits
77
77
  within the same moment.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cirq-core
3
- Version: 1.4.0.dev20231221183905
3
+ Version: 1.4.0.dev20240111191543
4
4
  Summary: A framework for creating, editing, and invoking Noisy Intermediate Scale Quantum (NISQ) circuits.
5
5
  Home-page: http://github.com/quantumlib/cirq
6
6
  Author: The Cirq Developers
@@ -1,10 +1,10 @@
1
1
  cirq/__init__.py,sha256=GlOnPWDvat-Y203LsbXhkC0UnGm9HHiNx2ywz7Bkc3o,15708
2
- cirq/_compat.py,sha256=wXi3WIiKjfJp5mCB2Kha3LyfJzxCetEPXq5-wg_faq0,29536
3
- cirq/_compat_test.py,sha256=iQJYqIP1uyRe8mNUwi2VKccyUaJDFYH7b3Fg6cqQLQw,35053
2
+ cirq/_compat.py,sha256=ogNbww9v943-ZNZcOx-ad8kGO8-jLBuS8865gQ3QA-c,29350
3
+ cirq/_compat_test.py,sha256=Qq3ZcfgD-Nb81cEppQdJqhAyrVqXKtfXZYGXT0p-Wh0,34718
4
4
  cirq/_doc.py,sha256=yDyWUD_2JDS0gShfGRb-rdqRt9-WeL7DhkqX7np0Nko,2879
5
5
  cirq/_import.py,sha256=p9gMHJscbtDDkfHOaulvd3Aer0pwUF5AXpL89XR8dNw,8402
6
6
  cirq/_import_test.py,sha256=6K_v0riZJXOXUphHNkGA8MY-JcmGlezFaGmvrNhm3OQ,1015
7
- cirq/_version.py,sha256=_fcYtE8htVvnq0jJ7T652Geu1s2hsXFqB3QxzXgTFNo,40
7
+ cirq/_version.py,sha256=JxwaDhKW-S1gML1FzVDlWvWtSpW28zxxzpe48wAK2Og,40
8
8
  cirq/_version_test.py,sha256=yYS6xm5-nuBRQJa9R3n41WdvFtVyY7Lb5Q8bea3VgBI,133
9
9
  cirq/conftest.py,sha256=X7yLFL8GLhg2CjPw0hp5e_dGASfvHx1-QT03aUbhKJw,1168
10
10
  cirq/json_resolver_cache.py,sha256=S0HaPOCUIck-vNSQlS6KxnQtle6w-2dGuSxkUbJQY9Y,13168
@@ -18,10 +18,10 @@ cirq/circuits/_box_drawing_character_data_test.py,sha256=XO94z0piwZRHaNZHTf-5tKH
18
18
  cirq/circuits/_bucket_priority_queue.py,sha256=hxFuii2fKD8G6EKT_aVLEsA7FmSfqFXPwIbA0KsoSC4,6745
19
19
  cirq/circuits/_bucket_priority_queue_test.py,sha256=t6u_hG7K2e2WKWrgCsKxNRtp4ghKwiCrp0_WSY0W25k,5288
20
20
  cirq/circuits/circuit.py,sha256=KP6tYjQ4pb1kz_jW3cfCgtnVvN_MRl0jHeNsOq0CA70,114383
21
- cirq/circuits/circuit_operation.py,sha256=qdJshRvGRFKwin7Ec_RndIb2Fm3sh7-N9SarEZo6AXM,34354
21
+ cirq/circuits/circuit_operation.py,sha256=D4u8jDD4fGOca1xnZPN1obuKTIouXENUfnxOF2JrwgU,34375
22
22
  cirq/circuits/circuit_operation_test.py,sha256=_0iQJ3h_dnQcQmbGRZbc-NqdglJTXantbj72ggqLKNE,44724
23
23
  cirq/circuits/circuit_test.py,sha256=EYIApq2DpZe7HckvySR3JlJdUIfJTSbKHm0lgENP2HA,160111
24
- cirq/circuits/frozen_circuit.py,sha256=GnFZ6kT1hFpxK6sOzqy1hq2SnKbG7OSu0q3bfGwi7b8,9240
24
+ cirq/circuits/frozen_circuit.py,sha256=_0SkmIiQ4UjIug-k_iO00ulDFoFnxmAHvXX2I2HHN8k,9262
25
25
  cirq/circuits/frozen_circuit_test.py,sha256=rHyii8hLhOQ6jdA8dC1OcYPGnyeBC4uY5Q53XspkkCk,4133
26
26
  cirq/circuits/insert_strategy.py,sha256=L0OLXuo24TtBfdJGOAG2PsVDMrbvQl4iN5lUk6IPuyo,2851
27
27
  cirq/circuits/insert_strategy_test.py,sha256=dgz13_ssa_GWqzzx5W4G4sJJw4SUHC3-g3K0_Z4TRiA,686
@@ -169,7 +169,7 @@ cirq/devices/noise_properties.py,sha256=DyaaNl2VlDFX38x4J7Zu5EMJBIj8bCDUYwSjbkBf
169
169
  cirq/devices/noise_properties_test.py,sha256=JTJW8_-rI4awd9jTbCgI5l8MpeDsNlXnO53s8QgJw2A,2341
170
170
  cirq/devices/noise_utils.py,sha256=q7LR7mT__oHYoCmmPln1PnsVa94p0i9ONjqKlcka5_o,6722
171
171
  cirq/devices/noise_utils_test.py,sha256=ha_P9Z_eycH97QIQ27WmwnvGM1CBUVoaJO8oy-VnIWI,4841
172
- cirq/devices/superconducting_qubits_noise_properties.py,sha256=Fg4S23uBPIBZWKdDyJ7AAZ_ajT1Vd6n1WxJ-k-0VUlM,8125
172
+ cirq/devices/superconducting_qubits_noise_properties.py,sha256=1SMeHgfydqYL5iwD9s38yJnOtfXWdJLw069B2DDSn9s,8146
173
173
  cirq/devices/superconducting_qubits_noise_properties_test.py,sha256=u9B1_4uwRdNzeyW9f-CSbYfsNpxiJ0RtmttvaaNzXkk,12207
174
174
  cirq/devices/thermal_noise_model.py,sha256=qdWrN7Kqw5dq1rwVUBLY1DDw1nCPADSaxoLtGHC-zW4,11608
175
175
  cirq/devices/thermal_noise_model_test.py,sha256=ox9b0BoHH6d73CjWWI1fIAGd_o3r-4qy8v2ggUwc-pw,12246
@@ -184,8 +184,8 @@ cirq/experiments/n_qubit_tomography.py,sha256=9M_kf2-1hvFxfZOWND7ACwHYgD9SJU5nYF
184
184
  cirq/experiments/n_qubit_tomography_test.py,sha256=wHfV2OpGYSDXfoyEh-B5dc1Dv8sxKNFbUoHyjIWZoFk,4362
185
185
  cirq/experiments/purity_estimation.py,sha256=6D1UwFlQRzHeajXMTyTUfBYAc0jJQ8Cfz4lteFKeUaM,2467
186
186
  cirq/experiments/purity_estimation_test.py,sha256=xlBGp0NOBYR0IhTy3bckHPgi81FkGSGxKqk9hwXG-I8,923
187
- cirq/experiments/qubit_characterizations.py,sha256=EqoZd3BRnjpFDMGz_NffZnAmuunuSJVybnum6QTYOg0,31359
188
- cirq/experiments/qubit_characterizations_test.py,sha256=l5O--F9LJGn7lZX5LA535zr0O1qmYgasUTZ1JbBQwLI,8382
187
+ cirq/experiments/qubit_characterizations.py,sha256=cyso_zmuU7xT9VBiI_Un5P8c-V8zOEETLuApLJ-QYWc,31792
188
+ cirq/experiments/qubit_characterizations_test.py,sha256=l4wtsezdM6pxB4W4Xq0f7RTCREy-W25jUsE6gssztoY,9032
189
189
  cirq/experiments/random_quantum_circuit_generation.py,sha256=R_w7z35plUHEYBY0-F80bPcWJSSSjNQDaP2GbxVBEZg,28143
190
190
  cirq/experiments/random_quantum_circuit_generation_test.py,sha256=1rvgN8-Ajedn_70FyYKVzjvzR6NVpHj6KQgo6tra-Jc,15995
191
191
  cirq/experiments/readout_confusion_matrix.py,sha256=gsRjGJTDcxRPtY7G63t-nYoJ1BcByC1jl02zHh2B8fQ,17278
@@ -267,7 +267,7 @@ cirq/ops/boolean_hamiltonian.py,sha256=hjmzBvWiZnb18JfdhId-dVxt2VmbyAbqMSFAPWV7s
267
267
  cirq/ops/boolean_hamiltonian_test.py,sha256=1ey5yfYZPKZDsfM3jpCPAOpbPs_y8i4K_WvDK2d5_4Y,8518
268
268
  cirq/ops/classically_controlled_operation.py,sha256=bMqKutwzqbvN2r7mOVOI12HTPDGSJLkhQQgfAcTtbDU,9166
269
269
  cirq/ops/classically_controlled_operation_test.py,sha256=MNU0Adff4kTosqsrQ3PUT3ARcZee_PkchT6u0xDl8Qg,48039
270
- cirq/ops/clifford_gate.py,sha256=B1guFN4YvUzqjBPVZH_stYWdi9MicJYjuoByB6rrK_Q,38139
270
+ cirq/ops/clifford_gate.py,sha256=xTAGYR24u__ctlY2fNsWYTQcJof4euRYMGN8cdERV2E,39235
271
271
  cirq/ops/clifford_gate_test.py,sha256=NF_if1X8LCMA9hy0vBO7lxvVPdumlvMMnI2XRQ-RLpk,37472
272
272
  cirq/ops/common_channels.py,sha256=mVGEta2wnaWOhRCXQO6gUj9Zll3rtXqpY-PRYcJ8m1U,38282
273
273
  cirq/ops/common_channels_test.py,sha256=EL_PxbqD3KPC8ioihiukhmW8bUdclqqigKoFyUQpmIM,29690
@@ -275,7 +275,7 @@ cirq/ops/common_gate_families.py,sha256=e5M8wlDYtdrpWBrhdns6iizIvSqzfxDyIsBdxt8h
275
275
  cirq/ops/common_gate_families_test.py,sha256=Oo3C7BPO3gt3ePuqwsI_lx_lY38et8Ps4AuVydX2Aww,5275
276
276
  cirq/ops/common_gates.py,sha256=YMcadPVRhrvkwYwm6-_TNYM9sz9TY7KSi0g7FvBTeCk,58075
277
277
  cirq/ops/common_gates_test.py,sha256=_5Kifb5k091qyzEVpryyFJV1e6pJ_fjDCag1PmPAQ2g,46227
278
- cirq/ops/control_values.py,sha256=O_ssaNxd50b4cS0hVhnRY0aEMr8J86TIh6iPohPKf_g,13397
278
+ cirq/ops/control_values.py,sha256=nNDN6pgz_aWkUfrpOZ9zHHD42AGFaplWhVQj9rmJwbQ,13410
279
279
  cirq/ops/control_values_test.py,sha256=iDtdQjL39u80MaR16XLp00LRZqWgJqC54cIeADWf0IY,12906
280
280
  cirq/ops/controlled_gate.py,sha256=uVTZk6pA1ZpEwbVggLeXyAFq18_QJ38hWYhk9GbvQnc,14253
281
281
  cirq/ops/controlled_gate_test.py,sha256=5sUUV0xng-GpQOTSiyQqB_LBaTeXXqHehqQuvvw7Cf4,23113
@@ -869,7 +869,7 @@ cirq/protocols/json_test_data/sympy.pi.repr,sha256=ZQS0my0esr3dWTZ3mWlqgR63uorPC
869
869
  cirq/qis/__init__.py,sha256=f5U3udFQirbLPKcHsVO6ViD3uSwe81Bei1wQdSbq2HE,1583
870
870
  cirq/qis/channels.py,sha256=AxKgLUbWLrb1pz9xLtSpYm_stjN-IWOwLFYC9YZSons,12798
871
871
  cirq/qis/channels_test.py,sha256=iqkSyfvx_c2ZpJKAVEsFyZRmKpzNrJsyFjHbaJUMqcQ,14454
872
- cirq/qis/clifford_tableau.py,sha256=yA63laynA1LVDmO7Gy_JFOsb7_gfriaOj6ggrjGRVGo,25174
872
+ cirq/qis/clifford_tableau.py,sha256=Ik1ogTElaB3nJCPCGj1yqxMdpu404AbZjkVOVYZOins,25305
873
873
  cirq/qis/clifford_tableau_test.py,sha256=Z-5YSysJw2H3AfgZxhptvUMr5GUjUFgPcAUdcust9Qk,18441
874
874
  cirq/qis/measures.py,sha256=-e2mStl9882z4mbLwWtbdmmdJilmf6Ex2b_jSXhMX3c,12194
875
875
  cirq/qis/measures_test.py,sha256=3LTTGdvuFfZWmFyWFeUHpg1yGc9z0VE8j7Kd7J7y8i4,10092
@@ -903,12 +903,12 @@ cirq/sim/sparse_simulator_test.py,sha256=3EAeCHUQeKllAAtdw14X592zBsGQY_vwfIYK-gE
903
903
  cirq/sim/state_vector.py,sha256=N6N9EELlW66UaLTBaq62ms0XkfIK7CzN9SBM7t52dXo,13428
904
904
  cirq/sim/state_vector_simulation_state.py,sha256=Ks3nGbIf6rq1Ap7Y5gZkcAJhu_Zr2-KWJhsE_wjwu8k,17624
905
905
  cirq/sim/state_vector_simulation_state_test.py,sha256=UtGMIurlV6N74nX7qoVnGoRhwF35-ghDEIP7Mj5AXmI,9841
906
- cirq/sim/state_vector_simulator.py,sha256=L2S0xyUGqRcVgYdzYef0gVREVZVIDcCXPclVbIJEpPE,7529
906
+ cirq/sim/state_vector_simulator.py,sha256=Q-wCmJdLIoJAssTvrZmGCpnooFHjZNXr_yeyy5R0NFs,7559
907
907
  cirq/sim/state_vector_simulator_test.py,sha256=wJq1OZRzKokeM9cJyaJXi6wHH2qi97h0HmJlYOEBDzU,7864
908
908
  cirq/sim/state_vector_test.py,sha256=OjhAL2tWqJWstHV8RvJYQVqg95zm0PcS9nQKrLOhMmQ,16934
909
909
  cirq/sim/clifford/__init__.py,sha256=lD7l6JuE5n0xwvOYNYH-giCH3qAEVH1SUwDrZM1jKKY,636
910
910
  cirq/sim/clifford/clifford_simulator.py,sha256=V4rExIDeijZ-sjMAyS_dDt5aE-RIrzTWpwF3EnSujto,9732
911
- cirq/sim/clifford/clifford_simulator_test.py,sha256=L13hD6qXwDJ1Mq_gIctnyIZbOq8m6qS1KIce2imon1U,20242
911
+ cirq/sim/clifford/clifford_simulator_test.py,sha256=pgLz8-SSFLBq6kcJ516ufQMJiJI2dG9NM2nkmzwY124,20380
912
912
  cirq/sim/clifford/clifford_tableau_simulation_state.py,sha256=fNkK0gZgfWIvMknGiCr4BjGO0wVYGW1Rc0pnwluerho,2160
913
913
  cirq/sim/clifford/clifford_tableau_simulation_state_test.py,sha256=KTzEoK5HcauVBj5tc8sXLt5vBXbDhxnFyj1bLt09nHo,3184
914
914
  cirq/sim/clifford/stabilizer_ch_form_simulation_state.py,sha256=2ZY_tQIp9J4NjoYkEEz1EdlNUGdyws1T7bl5hJ1VPgw,3028
@@ -931,7 +931,7 @@ cirq/study/sweepable_test.py,sha256=xjUksIurfbh240fEC7Al_TuiHGz7xZGktQUh86XBG9U,
931
931
  cirq/study/sweeps.py,sha256=IzonyU-LgEcMpvQrKZbl14v-BHi01oncp9CmHtLw0J4,19813
932
932
  cirq/study/sweeps_test.py,sha256=IqZp0ywYA430nNE_slBfc4vdKjULttzPl8ytxHLlgWo,11966
933
933
  cirq/testing/__init__.py,sha256=hbGRltgVaFhA6fMG2aVuRY-tXOluRyy4Rh9EQxqhQLg,3816
934
- cirq/testing/circuit_compare.py,sha256=c1uGQDfn2uAPtC-fiAwCrCzY-4NjerVBTm2uAnIceDQ,19175
934
+ cirq/testing/circuit_compare.py,sha256=nBQES45wLVThOqC3WrPrYKLQP7HQ2pH5DjlJ5bHkrtU,19176
935
935
  cirq/testing/circuit_compare_test.py,sha256=AduZCzwBNFCYrjEpyS1DvIR6jU8GaFqQBBgPXyIALoU,19743
936
936
  cirq/testing/consistent_act_on.py,sha256=ofYxdotw7fDfEVaAoM3NJEG2-hTHmi5FlLZkLYfVBWE,7733
937
937
  cirq/testing/consistent_act_on_test.py,sha256=QXQCN76-zzNxZXc5S7XwPSvWWQ6Cl3v_k-1Sak5LCbo,3535
@@ -1028,7 +1028,7 @@ cirq/transformers/merge_single_qubit_gates.py,sha256=NRREV4Z6Ptc3mZnOUgzQePdj4H0
1028
1028
  cirq/transformers/merge_single_qubit_gates_test.py,sha256=0U5oitYfOIka1hUOn1Cv8zVK1Uo34DVaOnGMgqfRg4Q,9966
1029
1029
  cirq/transformers/optimize_for_target_gateset.py,sha256=2f93hEA_9vXbutkoOtzBTk_bjKLfdLWqsuue4-w4Rp0,6005
1030
1030
  cirq/transformers/optimize_for_target_gateset_test.py,sha256=G73RDFhdhXqpXMTEPyl_t5huhcyY1u6XqOToVEFpVJA,13848
1031
- cirq/transformers/qubit_management_transformers.py,sha256=Uk1DcFCRFaFsLTxp_B5AKpSTDjqBKUhOGXD-kmEV0cM,9429
1031
+ cirq/transformers/qubit_management_transformers.py,sha256=A7Mweu9ElLSCsy_atmgFbYlzOFXKhct5gQ5YNTjjaVU,9430
1032
1032
  cirq/transformers/qubit_management_transformers_test.py,sha256=GGuZ4uxtFI59t9diW67_J17XQdBu9NFZjOHeMAHmm8Y,13991
1033
1033
  cirq/transformers/stratify.py,sha256=EEcXD6PEdHTZAoaAfaHnsw3Hf1SftbIl19hZOU_ZnXE,10469
1034
1034
  cirq/transformers/stratify_test.py,sha256=LmQFPB4grvRVvOgV8mA-pXNK3k9UC-banFJgWtDx_cA,15270
@@ -1148,8 +1148,8 @@ cirq/work/sampler.py,sha256=JEAeQQRF3bqlO9AkOf4XbrTATDI5f5JgyM_FAUCNxao,19751
1148
1148
  cirq/work/sampler_test.py,sha256=B2ZsuqGT854gQtBIAh8k0LiG9Vj5wSzcGvkxOUoTcW4,13217
1149
1149
  cirq/work/zeros_sampler.py,sha256=x1C7cup66a43n-3tm8QjhiqJa07qcJW10FxNp9jJ59Q,2356
1150
1150
  cirq/work/zeros_sampler_test.py,sha256=JIkpBBFPJe5Ba4142vzogyWyboG1Q1ZAm0UVGgOoZn8,3279
1151
- cirq_core-1.4.0.dev20231221183905.dist-info/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
1152
- cirq_core-1.4.0.dev20231221183905.dist-info/METADATA,sha256=mrzOuC9yUO4jQmsFxwRgPCJGNh1XpVgDtwKj8C7QQ_w,2075
1153
- cirq_core-1.4.0.dev20231221183905.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
1154
- cirq_core-1.4.0.dev20231221183905.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
1155
- cirq_core-1.4.0.dev20231221183905.dist-info/RECORD,,
1151
+ cirq_core-1.4.0.dev20240111191543.dist-info/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
1152
+ cirq_core-1.4.0.dev20240111191543.dist-info/METADATA,sha256=j0KlVLSwq0qrJhHIHAW8Ic1TmcKCZwJfS6TwRot0CyE,2075
1153
+ cirq_core-1.4.0.dev20240111191543.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
1154
+ cirq_core-1.4.0.dev20240111191543.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
1155
+ cirq_core-1.4.0.dev20240111191543.dist-info/RECORD,,