|
27 | 27 | import cirq
|
28 | 28 |
|
29 | 29 |
|
30 |
| -@value.value_equality |
| 30 | +@value.value_equality(approximate=True) |
31 | 31 | class AsymmetricDepolarizingChannel(raw_types.Gate):
|
32 | 32 | r"""A channel that depolarizes asymmetrically along different directions.
|
33 | 33 |
|
@@ -196,11 +196,6 @@ def error_probabilities(self) -> Dict[str, float]:
|
196 | 196 | def _json_dict_(self) -> Dict[str, Any]:
|
197 | 197 | return protocols.obj_to_dict_helper(self, ['error_probabilities'])
|
198 | 198 |
|
199 |
| - def _approx_eq_(self, other: Any, atol: float) -> bool: |
200 |
| - self_keys, self_values = zip(*sorted(self.error_probabilities.items())) |
201 |
| - other_keys, other_values = zip(*sorted(other.error_probabilities.items())) |
202 |
| - return self_keys == other_keys and protocols.approx_eq(self_values, other_values, atol=atol) |
203 |
| - |
204 | 199 |
|
205 | 200 | def asymmetric_depolarize(
|
206 | 201 | p_x: Optional[float] = None,
|
@@ -246,7 +241,7 @@ def asymmetric_depolarize(
|
246 | 241 | return AsymmetricDepolarizingChannel(p_x, p_y, p_z, error_probabilities, tol)
|
247 | 242 |
|
248 | 243 |
|
249 |
| -@value.value_equality |
| 244 | +@value.value_equality(approximate=True) |
250 | 245 | class DepolarizingChannel(raw_types.Gate):
|
251 | 246 | r"""A channel that depolarizes one or several qubits.
|
252 | 247 |
|
@@ -306,7 +301,7 @@ def _has_mixture_(self) -> bool:
|
306 | 301 | return True
|
307 | 302 |
|
308 | 303 | def _value_equality_values_(self):
|
309 |
| - return self._p |
| 304 | + return self._p, self._n_qubits |
310 | 305 |
|
311 | 306 | def __repr__(self) -> str:
|
312 | 307 | if self._n_qubits == 1:
|
@@ -347,9 +342,6 @@ def _json_dict_(self) -> Dict[str, Any]:
|
347 | 342 | return protocols.obj_to_dict_helper(self, ['p'])
|
348 | 343 | return protocols.obj_to_dict_helper(self, ['p', 'n_qubits'])
|
349 | 344 |
|
350 |
| - def _approx_eq_(self, other: Any, atol: float) -> bool: |
351 |
| - return np.isclose(self.p, other.p, atol=atol).item() and self.n_qubits == other.n_qubits |
352 |
| - |
353 | 345 |
|
354 | 346 | def depolarize(p: float, n_qubits: int = 1) -> DepolarizingChannel:
|
355 | 347 | r"""Returns a DepolarizingChannel with given probability of error.
|
@@ -381,7 +373,7 @@ def depolarize(p: float, n_qubits: int = 1) -> DepolarizingChannel:
|
381 | 373 | return DepolarizingChannel(p, n_qubits)
|
382 | 374 |
|
383 | 375 |
|
384 |
| -@value.value_equality |
| 376 | +@value.value_equality(approximate=True) |
385 | 377 | class GeneralizedAmplitudeDampingChannel(raw_types.Gate):
|
386 | 378 | r"""Dampen qubit amplitudes through non ideal dissipation.
|
387 | 379 |
|
@@ -489,12 +481,6 @@ def gamma(self) -> float:
|
489 | 481 | def _json_dict_(self) -> Dict[str, Any]:
|
490 | 482 | return protocols.obj_to_dict_helper(self, ['p', 'gamma'])
|
491 | 483 |
|
492 |
| - def _approx_eq_(self, other: Any, atol: float) -> bool: |
493 |
| - return ( |
494 |
| - np.isclose(self.gamma, other.gamma, atol=atol).item() |
495 |
| - and np.isclose(self.p, other.p, atol=atol).item() |
496 |
| - ) |
497 |
| - |
498 | 484 |
|
499 | 485 | def generalized_amplitude_damp(p: float, gamma: float) -> GeneralizedAmplitudeDampingChannel:
|
500 | 486 | r"""Returns a GeneralizedAmplitudeDampingChannel with probabilities gamma and p.
|
@@ -542,7 +528,7 @@ def generalized_amplitude_damp(p: float, gamma: float) -> GeneralizedAmplitudeDa
|
542 | 528 | return GeneralizedAmplitudeDampingChannel(p, gamma)
|
543 | 529 |
|
544 | 530 |
|
545 |
| -@value.value_equality |
| 531 | +@value.value_equality(approximate=True) |
546 | 532 | class AmplitudeDampingChannel(raw_types.Gate):
|
547 | 533 | r"""Dampen qubit amplitudes through dissipation.
|
548 | 534 |
|
@@ -619,9 +605,6 @@ def gamma(self) -> float:
|
619 | 605 | def _json_dict_(self) -> Dict[str, Any]:
|
620 | 606 | return protocols.obj_to_dict_helper(self, ['gamma'])
|
621 | 607 |
|
622 |
| - def _approx_eq_(self, other: Any, atol: float) -> bool: |
623 |
| - return np.isclose(self.gamma, other.gamma, atol=atol).item() |
624 |
| - |
625 | 608 |
|
626 | 609 | def amplitude_damp(gamma: float) -> AmplitudeDampingChannel:
|
627 | 610 | r"""Returns an AmplitudeDampingChannel with the given probability gamma.
|
@@ -787,7 +770,7 @@ def reset_each(*qubits: 'cirq.Qid') -> List[raw_types.Operation]:
|
787 | 770 | return [ResetChannel(q.dimension).on(q) for q in qubits]
|
788 | 771 |
|
789 | 772 |
|
790 |
| -@value.value_equality |
| 773 | +@value.value_equality(approximate=True) |
791 | 774 | class PhaseDampingChannel(raw_types.Gate):
|
792 | 775 | r"""Dampen qubit phase.
|
793 | 776 |
|
@@ -881,9 +864,6 @@ def gamma(self) -> float:
|
881 | 864 | def _json_dict_(self) -> Dict[str, Any]:
|
882 | 865 | return protocols.obj_to_dict_helper(self, ['gamma'])
|
883 | 866 |
|
884 |
| - def _approx_eq_(self, other: Any, atol: float) -> bool: |
885 |
| - return np.isclose(self._gamma, other._gamma, atol=atol).item() |
886 |
| - |
887 | 867 |
|
888 | 868 | def phase_damp(gamma: float) -> PhaseDampingChannel:
|
889 | 869 | r"""Creates a PhaseDampingChannel with damping constant gamma.
|
@@ -919,7 +899,7 @@ def phase_damp(gamma: float) -> PhaseDampingChannel:
|
919 | 899 | return PhaseDampingChannel(gamma)
|
920 | 900 |
|
921 | 901 |
|
922 |
| -@value.value_equality |
| 902 | +@value.value_equality(approximate=True) |
923 | 903 | class PhaseFlipChannel(raw_types.Gate):
|
924 | 904 | r"""Probabilistically flip the sign of the phase of a qubit.
|
925 | 905 |
|
@@ -991,9 +971,6 @@ def p(self) -> float:
|
991 | 971 | def _json_dict_(self) -> Dict[str, Any]:
|
992 | 972 | return protocols.obj_to_dict_helper(self, ['p'])
|
993 | 973 |
|
994 |
| - def _approx_eq_(self, other: Any, atol: float) -> bool: |
995 |
| - return np.isclose(self.p, other.p, atol=atol).item() |
996 |
| - |
997 | 974 |
|
998 | 975 | def _phase_flip_Z() -> common_gates.ZPowGate:
|
999 | 976 | """Returns a cirq.Z which corresponds to a guaranteed phase flip."""
|
@@ -1073,7 +1050,7 @@ def phase_flip(p: Optional[float] = None) -> Union[common_gates.ZPowGate, PhaseF
|
1073 | 1050 | return _phase_flip(p)
|
1074 | 1051 |
|
1075 | 1052 |
|
1076 |
| -@value.value_equality |
| 1053 | +@value.value_equality(approximate=True) |
1077 | 1054 | class BitFlipChannel(raw_types.Gate):
|
1078 | 1055 | r"""Probabilistically flip a qubit from 1 to 0 state or vice versa.
|
1079 | 1056 |
|
@@ -1148,9 +1125,6 @@ def p(self) -> float:
|
1148 | 1125 | def _json_dict_(self) -> Dict[str, Any]:
|
1149 | 1126 | return protocols.obj_to_dict_helper(self, ['p'])
|
1150 | 1127 |
|
1151 |
| - def _approx_eq_(self, other: Any, atol: float) -> bool: |
1152 |
| - return np.isclose(self._p, other._p, atol=atol).item() |
1153 |
| - |
1154 | 1128 |
|
1155 | 1129 | def _bit_flip(p: float) -> BitFlipChannel:
|
1156 | 1130 | r"""Construct a BitFlipChannel that flips a qubit state with probability of a flip given by p.
|
|
0 commit comments