cirq-core 1.6.0.dev20250416221104__py3-none-any.whl → 1.6.0.dev20250417204649__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.
- cirq/_version.py +1 -1
- cirq/_version_test.py +1 -1
- cirq/devices/noise_model_test.py +3 -1
- cirq/devices/noise_properties.py +6 -4
- cirq/devices/noise_utils.py +8 -6
- cirq/devices/superconducting_qubits_noise_properties.py +10 -9
- cirq/devices/thermal_noise_model.py +12 -12
- cirq/devices/unconstrained_device.py +3 -1
- cirq/experiments/n_qubit_tomography.py +15 -12
- cirq/experiments/qubit_characterizations.py +34 -39
- cirq/experiments/random_quantum_circuit_generation.py +38 -38
- cirq/experiments/random_quantum_circuit_generation_test.py +7 -4
- cirq/experiments/readout_confusion_matrix.py +17 -15
- cirq/experiments/single_qubit_readout_calibration.py +9 -5
- cirq/experiments/single_qubit_readout_calibration_test.py +5 -2
- cirq/experiments/t1_decay_experiment.py +7 -5
- cirq/experiments/t2_decay_experiment.py +10 -7
- cirq/experiments/two_qubit_xeb.py +42 -43
- cirq/experiments/two_qubit_xeb_test.py +1 -1
- cirq/experiments/xeb_fitting.py +25 -21
- cirq/experiments/xeb_sampling.py +18 -14
- cirq/experiments/xeb_simulation.py +11 -7
- cirq/experiments/xeb_simulation_test.py +3 -3
- cirq/experiments/z_phase_calibration.py +27 -24
- cirq/experiments/z_phase_calibration_test.py +1 -4
- cirq/interop/quirk/cells/arithmetic_cells.py +11 -10
- cirq/interop/quirk/cells/cell.py +18 -15
- cirq/interop/quirk/cells/composite_cell.py +8 -8
- cirq/interop/quirk/cells/control_cells.py +14 -14
- cirq/interop/quirk/cells/frequency_space_cells.py +4 -3
- cirq/interop/quirk/cells/input_cells.py +6 -4
- cirq/interop/quirk/cells/input_rotation_cells.py +14 -12
- cirq/interop/quirk/cells/measurement_cells.py +4 -1
- cirq/interop/quirk/cells/qubit_permutation_cells.py +3 -1
- cirq/interop/quirk/cells/scalar_cells.py +4 -1
- cirq/interop/quirk/cells/single_qubit_rotation_cells.py +5 -2
- cirq/interop/quirk/cells/swap_cell.py +7 -5
- cirq/interop/quirk/cells/testing.py +1 -1
- cirq/interop/quirk/url_to_circuit.py +11 -8
- cirq/json_resolver_cache.py +5 -3
- cirq/linalg/decompositions.py +5 -4
- cirq/linalg/decompositions_test.py +1 -1
- cirq/linalg/operator_spaces.py +8 -8
- cirq/ops/arithmetic_operation.py +4 -2
- cirq/ops/boolean_hamiltonian.py +7 -6
- cirq/ops/classically_controlled_operation.py +23 -20
- cirq/ops/clifford_gate.py +43 -47
- cirq/ops/common_channels.py +16 -14
- cirq/ops/common_gates.py +49 -67
- cirq/ops/control_values.py +12 -15
- cirq/ops/controlled_gate.py +15 -17
- cirq/ops/controlled_operation.py +17 -15
- {cirq_core-1.6.0.dev20250416221104.dist-info → cirq_core-1.6.0.dev20250417204649.dist-info}/METADATA +1 -1
- {cirq_core-1.6.0.dev20250416221104.dist-info → cirq_core-1.6.0.dev20250417204649.dist-info}/RECORD +57 -57
- {cirq_core-1.6.0.dev20250416221104.dist-info → cirq_core-1.6.0.dev20250417204649.dist-info}/WHEEL +0 -0
- {cirq_core-1.6.0.dev20250416221104.dist-info → cirq_core-1.6.0.dev20250417204649.dist-info}/licenses/LICENSE +0 -0
- {cirq_core-1.6.0.dev20250416221104.dist-info → cirq_core-1.6.0.dev20250417204649.dist-info}/top_level.txt +0 -0
cirq/ops/clifford_gate.py
CHANGED
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
15
17
|
import functools
|
|
16
18
|
from dataclasses import dataclass
|
|
17
19
|
from types import NotImplementedType
|
|
@@ -136,7 +138,7 @@ class CommonCliffordGateMetaClass(value.ABCMetaImplementAnyOneOf):
|
|
|
136
138
|
# These are class properties so we define them as properties on a metaclass.
|
|
137
139
|
|
|
138
140
|
@property
|
|
139
|
-
def all_single_qubit_cliffords(cls) -> Sequence[
|
|
141
|
+
def all_single_qubit_cliffords(cls) -> Sequence[cirq.SingleQubitCliffordGate]:
|
|
140
142
|
"""All 24 single-qubit Clifford gates."""
|
|
141
143
|
if not hasattr(cls, '_all_single_qubit_cliffords'):
|
|
142
144
|
pX = (pauli_gates.X, False)
|
|
@@ -187,31 +189,31 @@ class CommonCliffordGateMetaClass(value.ABCMetaImplementAnyOneOf):
|
|
|
187
189
|
return cls._all_single_qubit_cliffords
|
|
188
190
|
|
|
189
191
|
@property
|
|
190
|
-
def I(cls) ->
|
|
192
|
+
def I(cls) -> cirq.SingleQubitCliffordGate:
|
|
191
193
|
return cls.all_single_qubit_cliffords[0]
|
|
192
194
|
|
|
193
195
|
@property
|
|
194
|
-
def X(cls) ->
|
|
196
|
+
def X(cls) -> cirq.SingleQubitCliffordGate:
|
|
195
197
|
return cls.all_single_qubit_cliffords[1]
|
|
196
198
|
|
|
197
199
|
@property
|
|
198
|
-
def Y(cls) ->
|
|
200
|
+
def Y(cls) -> cirq.SingleQubitCliffordGate:
|
|
199
201
|
return cls.all_single_qubit_cliffords[2]
|
|
200
202
|
|
|
201
203
|
@property
|
|
202
|
-
def Z(cls) ->
|
|
204
|
+
def Z(cls) -> cirq.SingleQubitCliffordGate:
|
|
203
205
|
return cls.all_single_qubit_cliffords[3]
|
|
204
206
|
|
|
205
207
|
@property
|
|
206
|
-
def H(cls) ->
|
|
208
|
+
def H(cls) -> cirq.SingleQubitCliffordGate:
|
|
207
209
|
return cls.all_single_qubit_cliffords[10]
|
|
208
210
|
|
|
209
211
|
@property
|
|
210
|
-
def S(cls) ->
|
|
212
|
+
def S(cls) -> cirq.SingleQubitCliffordGate:
|
|
211
213
|
return cls.all_single_qubit_cliffords[6]
|
|
212
214
|
|
|
213
215
|
@property
|
|
214
|
-
def CNOT(cls) ->
|
|
216
|
+
def CNOT(cls) -> cirq.CliffordGate:
|
|
215
217
|
if not hasattr(cls, '_CNOT'):
|
|
216
218
|
t = qis.CliffordTableau(num_qubits=2)
|
|
217
219
|
t.xs = np.array([[1, 1], [0, 1], [0, 0], [0, 0]])
|
|
@@ -220,7 +222,7 @@ class CommonCliffordGateMetaClass(value.ABCMetaImplementAnyOneOf):
|
|
|
220
222
|
return cls._CNOT
|
|
221
223
|
|
|
222
224
|
@property
|
|
223
|
-
def CZ(cls) ->
|
|
225
|
+
def CZ(cls) -> cirq.CliffordGate:
|
|
224
226
|
if not hasattr(cls, '_CZ'):
|
|
225
227
|
t = qis.CliffordTableau(num_qubits=2)
|
|
226
228
|
t.xs = np.array([[1, 0], [0, 1], [0, 0], [0, 0]])
|
|
@@ -229,7 +231,7 @@ class CommonCliffordGateMetaClass(value.ABCMetaImplementAnyOneOf):
|
|
|
229
231
|
return cls._CZ
|
|
230
232
|
|
|
231
233
|
@property
|
|
232
|
-
def SWAP(cls) ->
|
|
234
|
+
def SWAP(cls) -> cirq.CliffordGate:
|
|
233
235
|
if not hasattr(cls, '_SWAP'):
|
|
234
236
|
t = qis.CliffordTableau(num_qubits=2)
|
|
235
237
|
t.xs = np.array([[0, 1], [1, 0], [0, 0], [0, 0]])
|
|
@@ -238,33 +240,33 @@ class CommonCliffordGateMetaClass(value.ABCMetaImplementAnyOneOf):
|
|
|
238
240
|
return cls._SWAP
|
|
239
241
|
|
|
240
242
|
@property
|
|
241
|
-
def X_sqrt(cls) ->
|
|
243
|
+
def X_sqrt(cls) -> cirq.SingleQubitCliffordGate:
|
|
242
244
|
return cls.all_single_qubit_cliffords[4]
|
|
243
245
|
|
|
244
246
|
@property
|
|
245
|
-
def X_nsqrt(cls) ->
|
|
247
|
+
def X_nsqrt(cls) -> cirq.SingleQubitCliffordGate:
|
|
246
248
|
return cls.all_single_qubit_cliffords[7]
|
|
247
249
|
|
|
248
250
|
@property
|
|
249
|
-
def Y_sqrt(cls) ->
|
|
251
|
+
def Y_sqrt(cls) -> cirq.SingleQubitCliffordGate:
|
|
250
252
|
return cls.all_single_qubit_cliffords[5]
|
|
251
253
|
|
|
252
254
|
@property
|
|
253
|
-
def Y_nsqrt(cls) ->
|
|
255
|
+
def Y_nsqrt(cls) -> cirq.SingleQubitCliffordGate:
|
|
254
256
|
return cls.all_single_qubit_cliffords[8]
|
|
255
257
|
|
|
256
258
|
@property
|
|
257
|
-
def Z_sqrt(cls) ->
|
|
259
|
+
def Z_sqrt(cls) -> cirq.SingleQubitCliffordGate:
|
|
258
260
|
return cls.all_single_qubit_cliffords[6]
|
|
259
261
|
|
|
260
262
|
@property
|
|
261
|
-
def Z_nsqrt(cls) ->
|
|
263
|
+
def Z_nsqrt(cls) -> cirq.SingleQubitCliffordGate:
|
|
262
264
|
return cls.all_single_qubit_cliffords[9]
|
|
263
265
|
|
|
264
266
|
|
|
265
267
|
class CommonCliffordGates(metaclass=CommonCliffordGateMetaClass):
|
|
266
268
|
@classmethod
|
|
267
|
-
def from_clifford_tableau(cls, tableau: qis.CliffordTableau) ->
|
|
269
|
+
def from_clifford_tableau(cls, tableau: qis.CliffordTableau) -> CliffordGate:
|
|
268
270
|
"""Create the CliffordGate instance from Clifford Tableau.
|
|
269
271
|
|
|
270
272
|
Args:
|
|
@@ -293,7 +295,7 @@ class CommonCliffordGates(metaclass=CommonCliffordGateMetaClass):
|
|
|
293
295
|
@classmethod
|
|
294
296
|
def from_op_list(
|
|
295
297
|
cls, operations: Sequence[raw_types.Operation], qubit_order: Sequence[raw_types.Qid]
|
|
296
|
-
) ->
|
|
298
|
+
) -> CliffordGate:
|
|
297
299
|
"""Construct a new Clifford gates from several known operations.
|
|
298
300
|
|
|
299
301
|
Args:
|
|
@@ -332,9 +334,7 @@ class CommonCliffordGates(metaclass=CommonCliffordGateMetaClass):
|
|
|
332
334
|
return cls(_clifford_tableau=_clifford_tableau)
|
|
333
335
|
|
|
334
336
|
@classmethod
|
|
335
|
-
def _get_sqrt_map(
|
|
336
|
-
cls,
|
|
337
|
-
) -> Dict[float, Dict['SingleQubitCliffordGate', 'SingleQubitCliffordGate']]:
|
|
337
|
+
def _get_sqrt_map(cls) -> Dict[float, Dict[SingleQubitCliffordGate, SingleQubitCliffordGate]]:
|
|
338
338
|
"""Returns a map containing two keys 0.5 and -0.5 for the sqrt mapping of Pauli gates."""
|
|
339
339
|
return {
|
|
340
340
|
0.5: {cls.X: cls.X_sqrt, cls.Y: cls.Y_sqrt, cls.Z: cls.Z_sqrt},
|
|
@@ -391,7 +391,7 @@ class CliffordGate(raw_types.Gate, CommonCliffordGates):
|
|
|
391
391
|
# By definition, Clifford Gate should always return True.
|
|
392
392
|
return True
|
|
393
393
|
|
|
394
|
-
def __pow__(self, exponent: float) ->
|
|
394
|
+
def __pow__(self, exponent: float) -> CliffordGate:
|
|
395
395
|
if exponent != int(exponent):
|
|
396
396
|
return NotImplemented # pragma: no cover
|
|
397
397
|
exponent = int(exponent)
|
|
@@ -438,13 +438,13 @@ class CliffordGate(raw_types.Gate, CommonCliffordGates):
|
|
|
438
438
|
# it is because Clifford tableau ignores the global phase information.
|
|
439
439
|
return NotImplemented # pragma: no cover
|
|
440
440
|
|
|
441
|
-
def _decompose_(self, qubits: Sequence[
|
|
441
|
+
def _decompose_(self, qubits: Sequence[cirq.Qid]) -> cirq.OP_TREE:
|
|
442
442
|
return transformers.analytical_decompositions.decompose_clifford_tableau_to_operations(
|
|
443
443
|
list(qubits), self.clifford_tableau
|
|
444
444
|
)
|
|
445
445
|
|
|
446
446
|
def _act_on_(
|
|
447
|
-
self, sim_state:
|
|
447
|
+
self, sim_state: cirq.SimulationStateBase, qubits: Sequence[cirq.Qid]
|
|
448
448
|
) -> Union[NotImplementedType, bool]:
|
|
449
449
|
# Note the computation complexity difference between _decompose_ and _act_on_.
|
|
450
450
|
# Suppose this Gate has `m` qubits, args has `n` qubits, and the decomposition of
|
|
@@ -481,7 +481,7 @@ class SingleQubitCliffordGate(CliffordGate):
|
|
|
481
481
|
|
|
482
482
|
@staticmethod
|
|
483
483
|
@functools.cache
|
|
484
|
-
def from_clifford_tableau(tableau: qis.CliffordTableau) ->
|
|
484
|
+
def from_clifford_tableau(tableau: qis.CliffordTableau) -> SingleQubitCliffordGate:
|
|
485
485
|
if not isinstance(tableau, qis.CliffordTableau):
|
|
486
486
|
raise ValueError('Input argument has to be a CliffordTableau instance.')
|
|
487
487
|
if not tableau._validate():
|
|
@@ -493,9 +493,7 @@ class SingleQubitCliffordGate(CliffordGate):
|
|
|
493
493
|
return SingleQubitCliffordGate(_clifford_tableau=tableau)
|
|
494
494
|
|
|
495
495
|
@staticmethod
|
|
496
|
-
def from_xz_map(
|
|
497
|
-
x_to: Tuple[Pauli, bool], z_to: Tuple[Pauli, bool]
|
|
498
|
-
) -> 'SingleQubitCliffordGate':
|
|
496
|
+
def from_xz_map(x_to: Tuple[Pauli, bool], z_to: Tuple[Pauli, bool]) -> SingleQubitCliffordGate:
|
|
499
497
|
"""Returns a SingleQubitCliffordGate for the specified transforms.
|
|
500
498
|
The Y transform is derived from the X and Z.
|
|
501
499
|
|
|
@@ -514,7 +512,7 @@ class SingleQubitCliffordGate(CliffordGate):
|
|
|
514
512
|
x_to: Optional[Tuple[Pauli, bool]] = None,
|
|
515
513
|
y_to: Optional[Tuple[Pauli, bool]] = None,
|
|
516
514
|
z_to: Optional[Tuple[Pauli, bool]] = None,
|
|
517
|
-
) ->
|
|
515
|
+
) -> SingleQubitCliffordGate:
|
|
518
516
|
"""Returns a SingleQubitCliffordGate for the
|
|
519
517
|
specified transform with a 90 or 180 degree rotation.
|
|
520
518
|
|
|
@@ -547,7 +545,7 @@ class SingleQubitCliffordGate(CliffordGate):
|
|
|
547
545
|
x_to: Optional[Tuple[Pauli, bool]] = None,
|
|
548
546
|
y_to: Optional[Tuple[Pauli, bool]] = None,
|
|
549
547
|
z_to: Optional[Tuple[Pauli, bool]] = None,
|
|
550
|
-
) ->
|
|
548
|
+
) -> SingleQubitCliffordGate:
|
|
551
549
|
"""Returns a SingleQubitCliffordGate for the
|
|
552
550
|
specified transform with a 90 or 180 degree rotation.
|
|
553
551
|
|
|
@@ -570,7 +568,7 @@ class SingleQubitCliffordGate(CliffordGate):
|
|
|
570
568
|
return SingleQubitCliffordGate.from_clifford_tableau(_to_clifford_tableau(rotation_map))
|
|
571
569
|
|
|
572
570
|
@staticmethod
|
|
573
|
-
def from_pauli(pauli: Pauli, sqrt: bool = False) ->
|
|
571
|
+
def from_pauli(pauli: Pauli, sqrt: bool = False) -> SingleQubitCliffordGate:
|
|
574
572
|
prev_pauli = Pauli.by_relative_index(pauli, -1)
|
|
575
573
|
next_pauli = Pauli.by_relative_index(pauli, 1)
|
|
576
574
|
if sqrt:
|
|
@@ -588,7 +586,7 @@ class SingleQubitCliffordGate(CliffordGate):
|
|
|
588
586
|
return SingleQubitCliffordGate.from_clifford_tableau(_to_clifford_tableau(rotation_map))
|
|
589
587
|
|
|
590
588
|
@staticmethod
|
|
591
|
-
def from_quarter_turns(pauli: Pauli, quarter_turns: int) ->
|
|
589
|
+
def from_quarter_turns(pauli: Pauli, quarter_turns: int) -> SingleQubitCliffordGate:
|
|
592
590
|
quarter_turns = quarter_turns % 4
|
|
593
591
|
if quarter_turns == 0:
|
|
594
592
|
return SingleQubitCliffordGate.I
|
|
@@ -600,7 +598,7 @@ class SingleQubitCliffordGate(CliffordGate):
|
|
|
600
598
|
return SingleQubitCliffordGate.from_pauli(pauli, True) ** -1
|
|
601
599
|
|
|
602
600
|
@staticmethod
|
|
603
|
-
def from_unitary(u: np.ndarray) -> Optional[
|
|
601
|
+
def from_unitary(u: np.ndarray) -> Optional[SingleQubitCliffordGate]:
|
|
604
602
|
"""Creates Clifford gate with given unitary (up to global phase).
|
|
605
603
|
|
|
606
604
|
Args:
|
|
@@ -626,7 +624,7 @@ class SingleQubitCliffordGate(CliffordGate):
|
|
|
626
624
|
@classmethod
|
|
627
625
|
def from_unitary_with_global_phase(
|
|
628
626
|
cls, u: np.ndarray
|
|
629
|
-
) -> Optional[Tuple[
|
|
627
|
+
) -> Optional[Tuple[SingleQubitCliffordGate, complex]]:
|
|
630
628
|
"""Creates Clifford gate with given unitary, including global phase.
|
|
631
629
|
|
|
632
630
|
Args:
|
|
@@ -667,7 +665,7 @@ class SingleQubitCliffordGate(CliffordGate):
|
|
|
667
665
|
to_gate = Pauli._XYZ[to.pauli_mask[0] - 1]
|
|
668
666
|
return (to_gate, bool(to.coefficient != 1.0))
|
|
669
667
|
|
|
670
|
-
def dense_pauli_string(self, pauli: Pauli) ->
|
|
668
|
+
def dense_pauli_string(self, pauli: Pauli) -> cirq.DensePauliString:
|
|
671
669
|
from cirq.ops import dense_pauli_string
|
|
672
670
|
|
|
673
671
|
pauli_tuple = self.pauli_tuple(pauli)
|
|
@@ -733,7 +731,7 @@ class SingleQubitCliffordGate(CliffordGate):
|
|
|
733
731
|
z = -0.5 if x_to_flip else 0.5
|
|
734
732
|
return phased_x_z_gate.PhasedXZGate(x_exponent=x, z_exponent=z, axis_phase_exponent=a)
|
|
735
733
|
|
|
736
|
-
def __pow__(self, exponent: float) ->
|
|
734
|
+
def __pow__(self, exponent: float) -> SingleQubitCliffordGate:
|
|
737
735
|
if int(exponent) == exponent:
|
|
738
736
|
# The single qubit Clifford gates are a group of size 24
|
|
739
737
|
exp = int(exponent) % 24
|
|
@@ -753,14 +751,14 @@ class SingleQubitCliffordGate(CliffordGate):
|
|
|
753
751
|
|
|
754
752
|
def _act_on_(
|
|
755
753
|
self,
|
|
756
|
-
sim_state:
|
|
757
|
-
qubits: Sequence[
|
|
754
|
+
sim_state: cirq.SimulationStateBase, # pylint: disable=unused-argument
|
|
755
|
+
qubits: Sequence[cirq.Qid], # pylint: disable=unused-argument
|
|
758
756
|
):
|
|
759
757
|
# TODO(#5256) Add the implementation of _act_on_ with CliffordTableauSimulationState.
|
|
760
758
|
return NotImplemented
|
|
761
759
|
|
|
762
760
|
# Single Clifford Gate decomposition is more efficient than the general Tableau decomposition.
|
|
763
|
-
def _decompose_(self, qubits: Sequence[
|
|
761
|
+
def _decompose_(self, qubits: Sequence[cirq.Qid]) -> cirq.OP_TREE:
|
|
764
762
|
(qubit,) = qubits
|
|
765
763
|
return tuple(gate.on(qubit) for gate in self.decompose_gate())
|
|
766
764
|
|
|
@@ -773,7 +771,7 @@ class SingleQubitCliffordGate(CliffordGate):
|
|
|
773
771
|
return self.commutes_with_pauli(other)
|
|
774
772
|
return NotImplemented
|
|
775
773
|
|
|
776
|
-
def commutes_with_single_qubit_gate(self, gate:
|
|
774
|
+
def commutes_with_single_qubit_gate(self, gate: SingleQubitCliffordGate) -> bool:
|
|
777
775
|
"""Tests if the two circuits would be equivalent up to global phase:
|
|
778
776
|
--self--gate-- and --gate--self--"""
|
|
779
777
|
self_then_gate = self.clifford_tableau.then(gate.clifford_tableau)
|
|
@@ -785,7 +783,7 @@ class SingleQubitCliffordGate(CliffordGate):
|
|
|
785
783
|
return to == pauli and not flip
|
|
786
784
|
|
|
787
785
|
@cached_method
|
|
788
|
-
def merged_with(self, second:
|
|
786
|
+
def merged_with(self, second: SingleQubitCliffordGate) -> SingleQubitCliffordGate:
|
|
789
787
|
"""Returns a SingleQubitCliffordGate such that the circuits
|
|
790
788
|
--output-- and --self--second--
|
|
791
789
|
are equivalent up to global phase."""
|
|
@@ -807,7 +805,7 @@ class SingleQubitCliffordGate(CliffordGate):
|
|
|
807
805
|
mat = protocols.unitary(op).dot(mat)
|
|
808
806
|
return mat
|
|
809
807
|
|
|
810
|
-
def decompose_gate(self) -> Sequence[
|
|
808
|
+
def decompose_gate(self) -> Sequence[cirq.Gate]:
|
|
811
809
|
"""Decomposes this clifford into a series of H and pauli rotation gates.
|
|
812
810
|
|
|
813
811
|
Returns:
|
|
@@ -818,7 +816,7 @@ class SingleQubitCliffordGate(CliffordGate):
|
|
|
818
816
|
return self._decompose_gate
|
|
819
817
|
|
|
820
818
|
@functools.cached_property
|
|
821
|
-
def _decompose_gate(self) -> Sequence[
|
|
819
|
+
def _decompose_gate(self) -> Sequence[cirq.Gate]:
|
|
822
820
|
if self == SingleQubitCliffordGate.H:
|
|
823
821
|
return [common_gates.H]
|
|
824
822
|
rotations = self.decompose_rotation()
|
|
@@ -887,7 +885,7 @@ class SingleQubitCliffordGate(CliffordGate):
|
|
|
887
885
|
False
|
|
888
886
|
), 'Impossible condition where this gate only rotates one Pauli to a different Pauli.'
|
|
889
887
|
|
|
890
|
-
def equivalent_gate_before(self, after:
|
|
888
|
+
def equivalent_gate_before(self, after: SingleQubitCliffordGate) -> SingleQubitCliffordGate:
|
|
891
889
|
"""Returns a SingleQubitCliffordGate such that the circuits
|
|
892
890
|
--output--self-- and --self--gate--
|
|
893
891
|
are equivalent up to global phase."""
|
|
@@ -901,9 +899,7 @@ class SingleQubitCliffordGate(CliffordGate):
|
|
|
901
899
|
f'zs=np.array({self._clifford_tableau.zs.tolist()!r})))'
|
|
902
900
|
)
|
|
903
901
|
|
|
904
|
-
def _circuit_diagram_info_(
|
|
905
|
-
self, args: 'cirq.CircuitDiagramInfoArgs'
|
|
906
|
-
) -> 'cirq.CircuitDiagramInfo':
|
|
902
|
+
def _circuit_diagram_info_(self, args: cirq.CircuitDiagramInfoArgs) -> cirq.CircuitDiagramInfo:
|
|
907
903
|
well_known_map = {
|
|
908
904
|
SingleQubitCliffordGate.I: 'I',
|
|
909
905
|
SingleQubitCliffordGate.H: 'H',
|
cirq/ops/common_channels.py
CHANGED
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
|
|
15
15
|
"""Quantum channels that are commonly used in the literature."""
|
|
16
16
|
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
17
19
|
import itertools
|
|
18
20
|
from typing import Any, Dict, Iterable, List, Optional, Sequence, Tuple, TYPE_CHECKING, Union
|
|
19
21
|
|
|
@@ -140,7 +142,7 @@ class AsymmetricDepolarizingChannel(raw_types.Gate):
|
|
|
140
142
|
return 'asymmetric_depolarize(' + f"error_probabilities={self._error_probabilities})"
|
|
141
143
|
|
|
142
144
|
def _circuit_diagram_info_(
|
|
143
|
-
self, args:
|
|
145
|
+
self, args: protocols.CircuitDiagramInfoArgs
|
|
144
146
|
) -> Union[str, Iterable[str]]:
|
|
145
147
|
if self._num_qubits == 1:
|
|
146
148
|
if args.precision is not None:
|
|
@@ -313,7 +315,7 @@ class DepolarizingChannel(raw_types.Gate):
|
|
|
313
315
|
return f"depolarize(p={self._p})"
|
|
314
316
|
return f"depolarize(p={self._p},n_qubits={self._n_qubits})"
|
|
315
317
|
|
|
316
|
-
def _circuit_diagram_info_(self, args:
|
|
318
|
+
def _circuit_diagram_info_(self, args: protocols.CircuitDiagramInfoArgs) -> Tuple[str, ...]:
|
|
317
319
|
result: Tuple[str, ...]
|
|
318
320
|
if args.precision is not None:
|
|
319
321
|
result = (f"D({self._p:.{args.precision}g})",)
|
|
@@ -462,7 +464,7 @@ class GeneralizedAmplitudeDampingChannel(raw_types.Gate):
|
|
|
462
464
|
def __str__(self) -> str:
|
|
463
465
|
return f'generalized_amplitude_damp(p={self._p!r},gamma={self._gamma!r})'
|
|
464
466
|
|
|
465
|
-
def _circuit_diagram_info_(self, args:
|
|
467
|
+
def _circuit_diagram_info_(self, args: protocols.CircuitDiagramInfoArgs) -> str:
|
|
466
468
|
if args.precision is not None:
|
|
467
469
|
f = '{:.' + str(args.precision) + 'g}'
|
|
468
470
|
return f'GAD({f},{f})'.format(self._p, self._gamma)
|
|
@@ -591,7 +593,7 @@ class AmplitudeDampingChannel(raw_types.Gate):
|
|
|
591
593
|
def __str__(self) -> str:
|
|
592
594
|
return f'amplitude_damp(gamma={self._gamma!r})'
|
|
593
595
|
|
|
594
|
-
def _circuit_diagram_info_(self, args:
|
|
596
|
+
def _circuit_diagram_info_(self, args: protocols.CircuitDiagramInfoArgs) -> str:
|
|
595
597
|
if args.precision is not None:
|
|
596
598
|
f = '{:.' + str(args.precision) + 'g}'
|
|
597
599
|
return f'AD({f})'.format(self._gamma)
|
|
@@ -684,14 +686,14 @@ class ResetChannel(raw_types.Gate):
|
|
|
684
686
|
def _has_stabilizer_effect_(self) -> Optional[bool]:
|
|
685
687
|
return True
|
|
686
688
|
|
|
687
|
-
def _qasm_(self, args:
|
|
689
|
+
def _qasm_(self, args: cirq.QasmArgs, qubits: Tuple[cirq.Qid, ...]) -> Optional[str]:
|
|
688
690
|
args.validate_version('2.0', '3.0')
|
|
689
691
|
return args.format('reset {0};\n', qubits[0])
|
|
690
692
|
|
|
691
693
|
def _qid_shape_(self):
|
|
692
694
|
return (self._dimension,)
|
|
693
695
|
|
|
694
|
-
def _act_on_(self, sim_state:
|
|
696
|
+
def _act_on_(self, sim_state: cirq.SimulationStateBase, qubits: Sequence[cirq.Qid]):
|
|
695
697
|
if len(qubits) != 1:
|
|
696
698
|
return NotImplemented
|
|
697
699
|
|
|
@@ -714,7 +716,7 @@ class ResetChannel(raw_types.Gate):
|
|
|
714
716
|
channel[:, 0, :] = np.eye(self._dimension)
|
|
715
717
|
return channel
|
|
716
718
|
|
|
717
|
-
def _apply_channel_(self, args:
|
|
719
|
+
def _apply_channel_(self, args: cirq.ApplyChannelArgs):
|
|
718
720
|
configs = []
|
|
719
721
|
for i in range(self._dimension):
|
|
720
722
|
s1 = transformations._SliceConfig(
|
|
@@ -742,7 +744,7 @@ class ResetChannel(raw_types.Gate):
|
|
|
742
744
|
def __str__(self) -> str:
|
|
743
745
|
return 'reset'
|
|
744
746
|
|
|
745
|
-
def _circuit_diagram_info_(self, args:
|
|
747
|
+
def _circuit_diagram_info_(self, args: protocols.CircuitDiagramInfoArgs) -> str:
|
|
746
748
|
return 'R'
|
|
747
749
|
|
|
748
750
|
@property
|
|
@@ -754,7 +756,7 @@ class ResetChannel(raw_types.Gate):
|
|
|
754
756
|
return protocols.obj_to_dict_helper(self, ['dimension'])
|
|
755
757
|
|
|
756
758
|
|
|
757
|
-
def reset(qubit:
|
|
759
|
+
def reset(qubit: cirq.Qid) -> raw_types.Operation:
|
|
758
760
|
"""Returns a `cirq.ResetChannel` on the given qubit.
|
|
759
761
|
|
|
760
762
|
This can also be used with the alias `cirq.R`.
|
|
@@ -765,7 +767,7 @@ def reset(qubit: 'cirq.Qid') -> raw_types.Operation:
|
|
|
765
767
|
R = reset
|
|
766
768
|
|
|
767
769
|
|
|
768
|
-
def reset_each(*qubits:
|
|
770
|
+
def reset_each(*qubits: cirq.Qid) -> List[raw_types.Operation]:
|
|
769
771
|
"""Returns a list of `cirq.ResetChannel` instances on the given qubits."""
|
|
770
772
|
return [ResetChannel(q.dimension).on(q) for q in qubits]
|
|
771
773
|
|
|
@@ -815,7 +817,7 @@ class PhaseDampingChannel(raw_types.Gate):
|
|
|
815
817
|
def _num_qubits_(self) -> int:
|
|
816
818
|
return 1
|
|
817
819
|
|
|
818
|
-
def _apply_channel_(self, args:
|
|
820
|
+
def _apply_channel_(self, args: cirq.ApplyChannelArgs):
|
|
819
821
|
if self._gamma == 0:
|
|
820
822
|
return args.target_tensor
|
|
821
823
|
if self._gamma != 1:
|
|
@@ -850,7 +852,7 @@ class PhaseDampingChannel(raw_types.Gate):
|
|
|
850
852
|
def __str__(self) -> str:
|
|
851
853
|
return f'phase_damp(gamma={self._gamma!r})'
|
|
852
854
|
|
|
853
|
-
def _circuit_diagram_info_(self, args:
|
|
855
|
+
def _circuit_diagram_info_(self, args: protocols.CircuitDiagramInfoArgs) -> str:
|
|
854
856
|
if args.precision is not None:
|
|
855
857
|
f = '{:.' + str(args.precision) + 'g}'
|
|
856
858
|
return f'PD({f})'.format(self._gamma)
|
|
@@ -957,7 +959,7 @@ class PhaseFlipChannel(raw_types.Gate):
|
|
|
957
959
|
def __str__(self) -> str:
|
|
958
960
|
return f'phase_flip(p={self._p!r})'
|
|
959
961
|
|
|
960
|
-
def _circuit_diagram_info_(self, args:
|
|
962
|
+
def _circuit_diagram_info_(self, args: protocols.CircuitDiagramInfoArgs) -> str:
|
|
961
963
|
if args.precision is not None:
|
|
962
964
|
f = '{:.' + str(args.precision) + 'g}'
|
|
963
965
|
return f'PF({f})'.format(self._p)
|
|
@@ -1108,7 +1110,7 @@ class BitFlipChannel(raw_types.Gate):
|
|
|
1108
1110
|
def __str__(self) -> str:
|
|
1109
1111
|
return f'bit_flip(p={self._p!r})'
|
|
1110
1112
|
|
|
1111
|
-
def _circuit_diagram_info_(self, args:
|
|
1113
|
+
def _circuit_diagram_info_(self, args: protocols.CircuitDiagramInfoArgs) -> str:
|
|
1112
1114
|
if args.precision is not None:
|
|
1113
1115
|
f = '{:.' + str(args.precision) + 'g}'
|
|
1114
1116
|
return f'BF({f})'.format(self._p)
|