cirq-core 1.6.0.dev20250520234959__py3-none-any.whl → 1.6.0.dev20250521215048__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.

Potentially problematic release.


This version of cirq-core might be problematic. Click here for more details.

Files changed (73) hide show
  1. cirq/_version.py +1 -1
  2. cirq/_version_test.py +1 -1
  3. cirq/circuits/circuit_operation_test.py +1 -2
  4. cirq/contrib/acquaintance/devices.py +2 -2
  5. cirq/contrib/acquaintance/inspection_utils.py +2 -2
  6. cirq/contrib/qasm_import/_lexer.py +1 -2
  7. cirq/contrib/routing/router.py +3 -3
  8. cirq/devices/device.py +4 -4
  9. cirq/experiments/fidelity_estimation.py +4 -4
  10. cirq/experiments/t1_decay_experiment.py +2 -2
  11. cirq/experiments/xeb_fitting.py +1 -1
  12. cirq/interop/quirk/cells/measurement_cells.py +2 -2
  13. cirq/linalg/combinators.py +3 -3
  14. cirq/linalg/predicates.py +2 -2
  15. cirq/linalg/tolerance.py +2 -2
  16. cirq/ops/arithmetic_operation_test.py +2 -4
  17. cirq/ops/common_gate_families.py +7 -7
  18. cirq/ops/controlled_gate.py +11 -0
  19. cirq/ops/controlled_gate_test.py +36 -2
  20. cirq/ops/controlled_operation_test.py +2 -2
  21. cirq/ops/linear_combinations_test.py +8 -9
  22. cirq/ops/qid_util.py +2 -2
  23. cirq/ops/qubit_order_or_list.py +2 -2
  24. cirq/protocols/act_on_protocol.py +4 -4
  25. cirq/protocols/commutes_protocol.py +5 -7
  26. cirq/protocols/control_key_protocol.py +4 -4
  27. cirq/protocols/decompose_protocol_test.py +1 -2
  28. cirq/protocols/has_stabilizer_effect_protocol.py +5 -5
  29. cirq/protocols/has_unitary_protocol.py +5 -5
  30. cirq/protocols/pauli_expansion_protocol.py +3 -3
  31. cirq/protocols/pow_protocol.py +5 -5
  32. cirq/protocols/trace_distance_bound.py +4 -4
  33. cirq/protocols/unitary_protocol.py +7 -7
  34. cirq/protocols/unitary_protocol_test.py +1 -3
  35. cirq/qis/entropy.py +2 -2
  36. cirq/sim/clifford/clifford_tableau_simulation_state.py +4 -4
  37. cirq/sim/clifford/stabilizer_ch_form_simulation_state.py +5 -5
  38. cirq/sim/clifford/stabilizer_simulation_state.py +5 -5
  39. cirq/sim/density_matrix_simulator_test.py +45 -46
  40. cirq/sim/sparse_simulator_test.py +38 -39
  41. cirq/sim/state_vector_simulation_state_test.py +2 -2
  42. cirq/sim/state_vector_test.py +3 -3
  43. cirq/study/sweepable.py +5 -5
  44. cirq/testing/consistent_act_on.py +5 -7
  45. cirq/testing/consistent_controlled_gate_op.py +3 -5
  46. cirq/testing/deprecation.py +2 -2
  47. cirq/testing/lin_alg_utils.py +2 -2
  48. cirq/transformers/align.py +3 -3
  49. cirq/transformers/drop_empty_moments.py +2 -2
  50. cirq/transformers/drop_negligible_operations.py +2 -2
  51. cirq/transformers/expand_composite.py +2 -2
  52. cirq/transformers/heuristic_decompositions/gate_tabulation_math_utils.py +3 -3
  53. cirq/transformers/merge_k_qubit_gates.py +5 -5
  54. cirq/transformers/merge_single_qubit_gates.py +5 -5
  55. cirq/transformers/optimize_for_target_gateset.py +6 -6
  56. cirq/transformers/optimize_for_target_gateset_test.py +3 -3
  57. cirq/transformers/tag_transformers.py +5 -5
  58. cirq/transformers/target_gatesets/cz_gateset_test.py +2 -2
  59. cirq/transformers/target_gatesets/sqrt_iswap_gateset_test.py +1 -3
  60. cirq/transformers/transformer_api_test.py +7 -8
  61. cirq/value/abc_alt.py +2 -2
  62. cirq/value/abc_alt_test.py +3 -3
  63. cirq/value/angle.py +7 -7
  64. cirq/value/type_alias.py +3 -5
  65. cirq/vis/density_matrix.py +2 -4
  66. cirq/vis/histogram.py +6 -6
  67. cirq/vis/state_histogram.py +7 -7
  68. cirq/work/observable_readout_calibration.py +2 -2
  69. {cirq_core-1.6.0.dev20250520234959.dist-info → cirq_core-1.6.0.dev20250521215048.dist-info}/METADATA +1 -1
  70. {cirq_core-1.6.0.dev20250520234959.dist-info → cirq_core-1.6.0.dev20250521215048.dist-info}/RECORD +73 -73
  71. {cirq_core-1.6.0.dev20250520234959.dist-info → cirq_core-1.6.0.dev20250521215048.dist-info}/WHEEL +0 -0
  72. {cirq_core-1.6.0.dev20250520234959.dist-info → cirq_core-1.6.0.dev20250521215048.dist-info}/licenses/LICENSE +0 -0
  73. {cirq_core-1.6.0.dev20250520234959.dist-info → cirq_core-1.6.0.dev20250521215048.dist-info}/top_level.txt +0 -0
@@ -14,7 +14,7 @@
14
14
 
15
15
  from __future__ import annotations
16
16
 
17
- from typing import Any, Optional
17
+ from typing import Any
18
18
 
19
19
  import cirq.protocols.decompose_protocol as decompose_protocol
20
20
  import cirq.protocols.has_unitary_protocol as has_unitary_protocol
@@ -52,7 +52,7 @@ def has_stabilizer_effect(val: Any) -> bool:
52
52
  return False
53
53
 
54
54
 
55
- def _strat_has_stabilizer_effect_from_has_stabilizer_effect(val: Any) -> Optional[bool]:
55
+ def _strat_has_stabilizer_effect_from_has_stabilizer_effect(val: Any) -> bool | None:
56
56
  """Infer whether val has stabilizer effect via its `_has_stabilizer_effect_` method."""
57
57
  if hasattr(val, '_has_stabilizer_effect_'):
58
58
  result = val._has_stabilizer_effect_()
@@ -61,14 +61,14 @@ def _strat_has_stabilizer_effect_from_has_stabilizer_effect(val: Any) -> Optiona
61
61
  return None
62
62
 
63
63
 
64
- def _strat_has_stabilizer_effect_from_gate(val: Any) -> Optional[bool]:
64
+ def _strat_has_stabilizer_effect_from_gate(val: Any) -> bool | None:
65
65
  """Infer whether val's gate has stabilizer effect via the _has_stabilizer_effect_ method."""
66
66
  if hasattr(val, 'gate'):
67
67
  return _strat_has_stabilizer_effect_from_has_stabilizer_effect(val.gate)
68
68
  return None
69
69
 
70
70
 
71
- def _strat_has_stabilizer_effect_from_unitary(val: Any) -> Optional[bool]:
71
+ def _strat_has_stabilizer_effect_from_unitary(val: Any) -> bool | None:
72
72
  """Attempts to infer whether val has stabilizer effect from its unitary.
73
73
 
74
74
  Returns whether unitary of `val` normalizes the Pauli group. Works only for
@@ -103,7 +103,7 @@ def _strat_has_stabilizer_effect_from_unitary(val: Any) -> Optional[bool]:
103
103
  return True
104
104
 
105
105
 
106
- def _strat_has_stabilizer_effect_from_decompose(val: Any) -> Optional[bool]:
106
+ def _strat_has_stabilizer_effect_from_decompose(val: Any) -> bool | None:
107
107
  decomposition, _, _ = decompose_protocol._try_decompose_into_operations_and_qubits(val)
108
108
  if decomposition is None:
109
109
  return None
@@ -14,7 +14,7 @@
14
14
 
15
15
  from __future__ import annotations
16
16
 
17
- from typing import Any, Optional, TypeVar
17
+ from typing import Any, TypeVar
18
18
 
19
19
  import numpy as np
20
20
  from typing_extensions import Protocol
@@ -110,7 +110,7 @@ def has_unitary(val: Any, *, allow_decompose: bool = True) -> bool:
110
110
  return False
111
111
 
112
112
 
113
- def _strat_has_unitary_from_has_unitary(val: Any) -> Optional[bool]:
113
+ def _strat_has_unitary_from_has_unitary(val: Any) -> bool | None:
114
114
  """Attempts to infer a value's unitary-ness via its _has_unitary_ method."""
115
115
  if hasattr(val, '_has_unitary_'):
116
116
  result = val._has_unitary_()
@@ -120,7 +120,7 @@ def _strat_has_unitary_from_has_unitary(val: Any) -> Optional[bool]:
120
120
  return None
121
121
 
122
122
 
123
- def _strat_has_unitary_from_unitary(val: Any) -> Optional[bool]:
123
+ def _strat_has_unitary_from_unitary(val: Any) -> bool | None:
124
124
  """Attempts to infer a value's unitary-ness via its _unitary_ method."""
125
125
  getter = getattr(val, '_unitary_', None)
126
126
  if getter is None:
@@ -129,7 +129,7 @@ def _strat_has_unitary_from_unitary(val: Any) -> Optional[bool]:
129
129
  return result is not NotImplemented and result is not None
130
130
 
131
131
 
132
- def _strat_has_unitary_from_decompose(val: Any) -> Optional[bool]:
132
+ def _strat_has_unitary_from_decompose(val: Any) -> bool | None:
133
133
  """Attempts to infer a value's unitary-ness via its _decompose_ method."""
134
134
  operations, _, _ = _try_decompose_into_operations_and_qubits(val)
135
135
  if operations is None:
@@ -137,7 +137,7 @@ def _strat_has_unitary_from_decompose(val: Any) -> Optional[bool]:
137
137
  return all(has_unitary(op) for op in operations)
138
138
 
139
139
 
140
- def _strat_has_unitary_from_apply_unitary(val: Any) -> Optional[bool]:
140
+ def _strat_has_unitary_from_apply_unitary(val: Any) -> bool | None:
141
141
  """Attempts to infer a value's unitary-ness via its _apply_unitary_ method."""
142
142
  method = getattr(val, '_apply_unitary_', None)
143
143
  if method is None:
@@ -16,7 +16,7 @@
16
16
 
17
17
  from __future__ import annotations
18
18
 
19
- from typing import Any, TypeVar, Union
19
+ from typing import Any, TypeVar
20
20
 
21
21
  from typing_extensions import Protocol
22
22
 
@@ -48,9 +48,9 @@ class SupportsPauliExpansion(Protocol):
48
48
  def pauli_expansion(
49
49
  val: Any,
50
50
  *,
51
- default: Union[value.LinearDict[str], TDefault] = RaiseTypeErrorIfNotProvided,
51
+ default: value.LinearDict[str] | TDefault = RaiseTypeErrorIfNotProvided,
52
52
  atol: float = 1e-9,
53
- ) -> Union[value.LinearDict[str], TDefault]:
53
+ ) -> value.LinearDict[str] | TDefault:
54
54
  """Returns coefficients of the expansion of val in the Pauli basis.
55
55
 
56
56
  Args:
@@ -14,7 +14,7 @@
14
14
 
15
15
  from __future__ import annotations
16
16
 
17
- from typing import Any, Callable, Optional, overload, TYPE_CHECKING, TypeVar, Union
17
+ from typing import Any, Callable, overload, TYPE_CHECKING, TypeVar
18
18
 
19
19
  if TYPE_CHECKING:
20
20
  import cirq
@@ -38,17 +38,17 @@ def pow(val: cirq.Operation, exponent: Any) -> cirq.Operation:
38
38
 
39
39
 
40
40
  @overload
41
- def pow(val: cirq.Gate, exponent: Any, default: TDefault) -> Union[TDefault, cirq.Gate]:
41
+ def pow(val: cirq.Gate, exponent: Any, default: TDefault) -> TDefault | cirq.Gate:
42
42
  pass
43
43
 
44
44
 
45
45
  @overload
46
- def pow(val: cirq.Operation, exponent: Any, default: TDefault) -> Union[TDefault, cirq.Operation]:
46
+ def pow(val: cirq.Operation, exponent: Any, default: TDefault) -> TDefault | cirq.Operation:
47
47
  pass
48
48
 
49
49
 
50
50
  @overload
51
- def pow(val: cirq.Circuit, exponent: int, default: TDefault) -> Union[TDefault, cirq.Circuit]:
51
+ def pow(val: cirq.Circuit, exponent: int, default: TDefault) -> TDefault | cirq.Circuit:
52
52
  pass
53
53
 
54
54
 
@@ -84,7 +84,7 @@ def pow(val: Any, exponent: Any, default: Any = RaiseTypeErrorIfNotProvided) ->
84
84
  TypeError: `val` doesn't have a __pow__ method (or that method returned
85
85
  NotImplemented) and no `default` value was specified.
86
86
  """
87
- raiser: Optional[Callable] = getattr(val, '__pow__', None)
87
+ raiser: Callable | None = getattr(val, '__pow__', None)
88
88
  result = NotImplemented if raiser is None else raiser(exponent)
89
89
  if result is not NotImplemented:
90
90
  return result
@@ -14,7 +14,7 @@
14
14
 
15
15
  from __future__ import annotations
16
16
 
17
- from typing import Any, Optional, Sequence, TypeVar, Union
17
+ from typing import Any, Sequence, TypeVar
18
18
 
19
19
  import numpy as np
20
20
  from typing_extensions import Protocol
@@ -81,7 +81,7 @@ def trace_distance_bound(val: Any) -> float:
81
81
  return 1.0
82
82
 
83
83
 
84
- def _strat_from_trace_distance_bound_method(val: Any) -> Optional[float]:
84
+ def _strat_from_trace_distance_bound_method(val: Any) -> float | None:
85
85
  """Attempts to use a specialized method."""
86
86
  getter = getattr(val, '_trace_distance_bound_', None)
87
87
  result = NotImplemented if getter is None else getter()
@@ -95,7 +95,7 @@ def _strat_from_trace_distance_bound_method(val: Any) -> Optional[float]:
95
95
  return NotImplemented
96
96
 
97
97
 
98
- def _strat_distance_from_unitary(val: Any) -> Optional[float]:
98
+ def _strat_distance_from_unitary(val: Any) -> float | None:
99
99
  """Attempts to compute a value's trace_distance_bound from its unitary."""
100
100
  u = unitary_protocol.unitary(val, default=None)
101
101
 
@@ -111,7 +111,7 @@ def _strat_distance_from_unitary(val: Any) -> Optional[float]:
111
111
  return trace_distance_from_angle_list(np.angle(np.linalg.eigvals(u)))
112
112
 
113
113
 
114
- def trace_distance_from_angle_list(angle_list: Union[Sequence[float], np.ndarray]) -> float:
114
+ def trace_distance_from_angle_list(angle_list: Sequence[float] | np.ndarray) -> float:
115
115
  """Given a list of arguments of the eigenvalues of a unitary matrix,
116
116
  calculates the trace distance bound of the unitary effect.
117
117
 
@@ -15,7 +15,7 @@
15
15
  from __future__ import annotations
16
16
 
17
17
  from types import NotImplementedType
18
- from typing import Any, Optional, TypeVar, Union
18
+ from typing import Any, TypeVar
19
19
 
20
20
  import numpy as np
21
21
  from typing_extensions import Protocol
@@ -39,7 +39,7 @@ class SupportsUnitary(Protocol):
39
39
  """An object that may be describable by a unitary matrix."""
40
40
 
41
41
  @doc_private
42
- def _unitary_(self) -> Union[np.ndarray, NotImplementedType]:
42
+ def _unitary_(self) -> np.ndarray | NotImplementedType:
43
43
  """A unitary matrix describing this value, e.g. the matrix of a gate.
44
44
 
45
45
  This method is used by the global `cirq.unitary` method. If this method
@@ -78,8 +78,8 @@ class SupportsUnitary(Protocol):
78
78
 
79
79
 
80
80
  def unitary(
81
- val: Any, default: Union[np.ndarray, TDefault] = RaiseTypeErrorIfNotProvided
82
- ) -> Union[np.ndarray, TDefault]:
81
+ val: Any, default: np.ndarray | TDefault = RaiseTypeErrorIfNotProvided
82
+ ) -> np.ndarray | TDefault:
83
83
  """Returns a unitary matrix describing the given value.
84
84
 
85
85
  The matrix is determined by any one of the following techniques:
@@ -142,7 +142,7 @@ def unitary(
142
142
  )
143
143
 
144
144
 
145
- def _strat_unitary_from_unitary(val: Any) -> Optional[np.ndarray]:
145
+ def _strat_unitary_from_unitary(val: Any) -> np.ndarray | None:
146
146
  """Attempts to compute a value's unitary via its _unitary_ method."""
147
147
  getter = getattr(val, '_unitary_', None)
148
148
  if getter is None:
@@ -150,7 +150,7 @@ def _strat_unitary_from_unitary(val: Any) -> Optional[np.ndarray]:
150
150
  return getter()
151
151
 
152
152
 
153
- def _strat_unitary_from_apply_unitary(val: Any) -> Optional[np.ndarray]:
153
+ def _strat_unitary_from_apply_unitary(val: Any) -> np.ndarray | None:
154
154
  """Attempts to compute a value's unitary via its _apply_unitary_ method."""
155
155
  # Check for the magic method.
156
156
  method = getattr(val, '_apply_unitary_', None)
@@ -171,7 +171,7 @@ def _strat_unitary_from_apply_unitary(val: Any) -> Optional[np.ndarray]:
171
171
  return result.reshape((state_len, state_len))
172
172
 
173
173
 
174
- def _strat_unitary_from_decompose(val: Any) -> Optional[np.ndarray]:
174
+ def _strat_unitary_from_decompose(val: Any) -> np.ndarray | None:
175
175
  """Attempts to compute a value's unitary via its _decompose_ method."""
176
176
  # Check if there's a decomposition.
177
177
  operations, qubits, val_qid_shape = _try_decompose_into_operations_and_qubits(val)
@@ -14,8 +14,6 @@
14
14
 
15
15
  from __future__ import annotations
16
16
 
17
- from typing import Optional
18
-
19
17
  import numpy as np
20
18
  import pytest
21
19
 
@@ -77,7 +75,7 @@ class FullyImplemented(cirq.Gate):
77
75
  def _has_unitary_(self) -> bool:
78
76
  return self.unitary_value
79
77
 
80
- def _unitary_(self) -> Optional[np.ndarray]:
78
+ def _unitary_(self) -> np.ndarray | None:
81
79
  if not self.unitary_value:
82
80
  return None
83
81
  return m1
cirq/qis/entropy.py CHANGED
@@ -17,7 +17,7 @@ from __future__ import annotations
17
17
  from collections.abc import Sequence
18
18
  from concurrent.futures import ThreadPoolExecutor
19
19
  from itertools import product
20
- from typing import Any, cast, Iterator, Optional
20
+ from typing import Any, cast, Iterator
21
21
 
22
22
  import numpy as np
23
23
  import numpy.typing as npt
@@ -94,7 +94,7 @@ def _compute_bitstrings_contribution_to_purity(bitstrings: npt.NDArray[np.int8])
94
94
  def process_renyi_entropy_from_bitstrings(
95
95
  measured_bitstrings: npt.NDArray[np.int8],
96
96
  subsystem: tuple[int] | None = None,
97
- pool: Optional[ThreadPoolExecutor] = None,
97
+ pool: ThreadPoolExecutor | None = None,
98
98
  ) -> float:
99
99
  """Compute the Rényi entropy of an array of bitstrings.
100
100
  Args:
@@ -17,7 +17,7 @@ for Clifford Simulator."""
17
17
 
18
18
  from __future__ import annotations
19
19
 
20
- from typing import Optional, Sequence, TYPE_CHECKING
20
+ from typing import Sequence, TYPE_CHECKING
21
21
 
22
22
  from cirq.qis import clifford_tableau
23
23
  from cirq.sim.clifford.stabilizer_simulation_state import StabilizerSimulationState
@@ -34,9 +34,9 @@ class CliffordTableauSimulationState(StabilizerSimulationState[clifford_tableau.
34
34
  def __init__(
35
35
  self,
36
36
  tableau: cirq.CliffordTableau,
37
- prng: Optional[np.random.RandomState] = None,
38
- qubits: Optional[Sequence[cirq.Qid]] = None,
39
- classical_data: Optional[cirq.ClassicalDataStore] = None,
37
+ prng: np.random.RandomState | None = None,
38
+ qubits: Sequence[cirq.Qid] | None = None,
39
+ classical_data: cirq.ClassicalDataStore | None = None,
40
40
  ):
41
41
  """Inits CliffordTableauSimulationState.
42
42
 
@@ -14,7 +14,7 @@
14
14
 
15
15
  from __future__ import annotations
16
16
 
17
- from typing import Optional, Sequence, TYPE_CHECKING, Union
17
+ from typing import Sequence, TYPE_CHECKING
18
18
 
19
19
  from cirq._compat import proper_repr
20
20
  from cirq.sim.clifford import stabilizer_state_ch_form
@@ -34,10 +34,10 @@ class StabilizerChFormSimulationState(
34
34
  def __init__(
35
35
  self,
36
36
  *,
37
- prng: Optional[np.random.RandomState] = None,
38
- qubits: Optional[Sequence[cirq.Qid]] = None,
39
- initial_state: Union[int, cirq.StabilizerStateChForm] = 0,
40
- classical_data: Optional[cirq.ClassicalDataStore] = None,
37
+ prng: np.random.RandomState | None = None,
38
+ qubits: Sequence[cirq.Qid] | None = None,
39
+ initial_state: int | cirq.StabilizerStateChForm = 0,
40
+ classical_data: cirq.ClassicalDataStore | None = None,
41
41
  ):
42
42
  """Initializes with the given state and the axes for the operation.
43
43
 
@@ -16,7 +16,7 @@ from __future__ import annotations
16
16
 
17
17
  import abc
18
18
  from types import NotImplementedType
19
- from typing import Any, cast, Generic, Optional, Sequence, TYPE_CHECKING, TypeVar, Union
19
+ from typing import Any, cast, Generic, Sequence, TYPE_CHECKING, TypeVar
20
20
 
21
21
  import sympy
22
22
 
@@ -44,9 +44,9 @@ class StabilizerSimulationState(
44
44
  self,
45
45
  *,
46
46
  state: TStabilizerState,
47
- prng: Optional[np.random.RandomState] = None,
48
- qubits: Optional[Sequence[cirq.Qid]] = None,
49
- classical_data: Optional[cirq.ClassicalDataStore] = None,
47
+ prng: np.random.RandomState | None = None,
48
+ qubits: Sequence[cirq.Qid] | None = None,
49
+ classical_data: cirq.ClassicalDataStore | None = None,
50
50
  ):
51
51
  """Initializes the StabilizerSimulationState.
52
52
 
@@ -69,7 +69,7 @@ class StabilizerSimulationState(
69
69
 
70
70
  def _act_on_fallback_(
71
71
  self, action: Any, qubits: Sequence[cirq.Qid], allow_decompose: bool = True
72
- ) -> Union[bool, NotImplementedType]:
72
+ ) -> bool | NotImplementedType:
73
73
  strats = [self._strat_apply_gate, self._strat_apply_mixture]
74
74
  if allow_decompose:
75
75
  strats.append(self._strat_decompose)