cirq-core 1.7.0.dev20250724201755__py3-none-any.whl → 1.7.0.dev20250725224902__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/circuits/moment_test.py +1 -1
- cirq/protocols/kraus_protocol.py +19 -5
- cirq/protocols/kraus_protocol_test.py +9 -1
- {cirq_core-1.7.0.dev20250724201755.dist-info → cirq_core-1.7.0.dev20250725224902.dist-info}/METADATA +1 -1
- {cirq_core-1.7.0.dev20250724201755.dist-info → cirq_core-1.7.0.dev20250725224902.dist-info}/RECORD +10 -10
- {cirq_core-1.7.0.dev20250724201755.dist-info → cirq_core-1.7.0.dev20250725224902.dist-info}/WHEEL +0 -0
- {cirq_core-1.7.0.dev20250724201755.dist-info → cirq_core-1.7.0.dev20250725224902.dist-info}/licenses/LICENSE +0 -0
- {cirq_core-1.7.0.dev20250724201755.dist-info → cirq_core-1.7.0.dev20250725224902.dist-info}/top_level.txt +0 -0
cirq/_version.py
CHANGED
cirq/_version_test.py
CHANGED
cirq/circuits/moment_test.py
CHANGED
|
@@ -885,7 +885,7 @@ def test_kraus() -> None:
|
|
|
885
885
|
|
|
886
886
|
|
|
887
887
|
def test_kraus_too_big() -> None:
|
|
888
|
-
m = cirq.Moment(cirq.IdentityGate(11).on(*cirq.LineQubit.range(11)))
|
|
888
|
+
m = cirq.Moment(cirq.IdentityGate(11).with_probability(0.5).on(*cirq.LineQubit.range(11)))
|
|
889
889
|
assert not cirq.has_kraus(m)
|
|
890
890
|
assert not m._has_superoperator_()
|
|
891
891
|
assert m._kraus_() is NotImplemented
|
cirq/protocols/kraus_protocol.py
CHANGED
|
@@ -26,6 +26,7 @@ from typing_extensions import Protocol
|
|
|
26
26
|
from cirq import protocols, qis
|
|
27
27
|
from cirq._doc import doc_private
|
|
28
28
|
from cirq.protocols.decompose_protocol import _try_decompose_into_operations_and_qubits
|
|
29
|
+
from cirq.protocols.has_unitary_protocol import has_unitary
|
|
29
30
|
from cirq.protocols.mixture_protocol import has_mixture
|
|
30
31
|
from cirq.protocols.unitary_protocol import unitary
|
|
31
32
|
|
|
@@ -95,9 +96,14 @@ class SupportsKraus(Protocol):
|
|
|
95
96
|
"""
|
|
96
97
|
|
|
97
98
|
|
|
98
|
-
def _strat_kraus_from_apply_channel(val: Any) -> tuple[np.ndarray, ...] | None:
|
|
99
|
+
def _strat_kraus_from_apply_channel(val: Any, atol: float) -> tuple[np.ndarray, ...] | None:
|
|
99
100
|
"""Attempts to compute a value's Kraus operators via its _apply_channel_ method.
|
|
100
|
-
This is very expensive (O(16^N)), so only do this as a last resort.
|
|
101
|
+
This is very expensive (O(16^N)), so only do this as a last resort.
|
|
102
|
+
|
|
103
|
+
Args:
|
|
104
|
+
val: value to calculate kraus channels from.
|
|
105
|
+
atol: Absolute tolerance for super-operator calculation.
|
|
106
|
+
Matrices with all entries less than this will be dropped."""
|
|
101
107
|
method = getattr(val, '_apply_channel_', None)
|
|
102
108
|
if method is None:
|
|
103
109
|
return None
|
|
@@ -122,12 +128,15 @@ def _strat_kraus_from_apply_channel(val: Any) -> tuple[np.ndarray, ...] | None:
|
|
|
122
128
|
if superop is None or superop is NotImplemented:
|
|
123
129
|
return None
|
|
124
130
|
n = np.prod(qid_shape) ** 2
|
|
125
|
-
|
|
131
|
+
# Note that super-operator calculations can be numerically unstable
|
|
132
|
+
# and we want to avoid returning kraus channels with "almost zero"
|
|
133
|
+
# components
|
|
134
|
+
kraus_ops = qis.superoperator_to_kraus(superop.reshape((n, n)), atol=atol)
|
|
126
135
|
return tuple(kraus_ops)
|
|
127
136
|
|
|
128
137
|
|
|
129
138
|
def kraus(
|
|
130
|
-
val: Any, default: Any = RaiseTypeErrorIfNotProvided
|
|
139
|
+
val: Any, default: Any = RaiseTypeErrorIfNotProvided, atol: float = 1e-6
|
|
131
140
|
) -> tuple[np.ndarray, ...] | TDefault:
|
|
132
141
|
r"""Returns a list of matrices describing the channel for the given value.
|
|
133
142
|
|
|
@@ -149,6 +158,8 @@ def kraus(
|
|
|
149
158
|
default: Determines the fallback behavior when `val` doesn't have
|
|
150
159
|
a channel. If `default` is not set, a TypeError is raised. If
|
|
151
160
|
default is set to a value, that value is returned.
|
|
161
|
+
atol: If calculating Kraus channels from channels, use this tolerance
|
|
162
|
+
for determining whether a super-operator is all zeros.
|
|
152
163
|
|
|
153
164
|
Returns:
|
|
154
165
|
If `val` has a `_kraus_` method and its result is not NotImplemented,
|
|
@@ -187,6 +198,9 @@ def kraus(
|
|
|
187
198
|
if unitary_result is not NotImplemented and unitary_result is not None:
|
|
188
199
|
return (unitary_result,)
|
|
189
200
|
|
|
201
|
+
if has_unitary(val):
|
|
202
|
+
return (unitary(val),)
|
|
203
|
+
|
|
190
204
|
channel_result = NotImplemented if channel_getter is None else channel_getter()
|
|
191
205
|
if channel_result is not NotImplemented:
|
|
192
206
|
return tuple(channel_result) # pragma: no cover
|
|
@@ -195,7 +209,7 @@ def kraus(
|
|
|
195
209
|
# Note: _apply_channel can lead to kraus being called again, so if default
|
|
196
210
|
# is None, this can trigger an infinite loop.
|
|
197
211
|
if default is not None:
|
|
198
|
-
result = _strat_kraus_from_apply_channel(val)
|
|
212
|
+
result = _strat_kraus_from_apply_channel(val, atol)
|
|
199
213
|
if result is not None:
|
|
200
214
|
return result
|
|
201
215
|
|
|
@@ -167,7 +167,7 @@ def test_has_kraus(cls) -> None:
|
|
|
167
167
|
assert cirq.has_kraus(cls())
|
|
168
168
|
|
|
169
169
|
|
|
170
|
-
@pytest.mark.parametrize('decomposed_cls', [HasKraus, HasMixture
|
|
170
|
+
@pytest.mark.parametrize('decomposed_cls', [HasKraus, HasMixture])
|
|
171
171
|
def test_has_kraus_when_decomposed(decomposed_cls) -> None:
|
|
172
172
|
op = HasKrausWhenDecomposed(decomposed_cls).on(cirq.NamedQubit('test'))
|
|
173
173
|
assert cirq.has_kraus(op)
|
|
@@ -243,3 +243,11 @@ def test_reset_channel_kraus_apply_channel_consistency():
|
|
|
243
243
|
gate_no_kraus = NoKrausReset()
|
|
244
244
|
# Should still match the original superoperator
|
|
245
245
|
np.testing.assert_allclose(cirq.kraus(gate), cirq.kraus(gate_no_kraus), atol=1e-8)
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
def test_kraus_channel_with_has_unitary():
|
|
249
|
+
"""CZSWAP has no unitary dunder method but has_unitary returns True."""
|
|
250
|
+
op = cirq.CZSWAP.on(cirq.q(1), cirq.q(2))
|
|
251
|
+
channels = cirq.kraus(op)
|
|
252
|
+
assert len(channels) == 1
|
|
253
|
+
np.testing.assert_allclose(channels[0], cirq.unitary(op))
|
{cirq_core-1.7.0.dev20250724201755.dist-info → cirq_core-1.7.0.dev20250725224902.dist-info}/METADATA
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cirq-core
|
|
3
|
-
Version: 1.7.0.
|
|
3
|
+
Version: 1.7.0.dev20250725224902
|
|
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
|
{cirq_core-1.7.0.dev20250724201755.dist-info → cirq_core-1.7.0.dev20250725224902.dist-info}/RECORD
RENAMED
|
@@ -4,8 +4,8 @@ cirq/_compat_test.py,sha256=emXpdD5ZvwLRlFAoQB8YatmZyU3b4e9jg6FppMTUhkU,33900
|
|
|
4
4
|
cirq/_doc.py,sha256=BrnoABo1hk5RgB3Cgww4zLHUfiyFny0F1V-tOMCbdaU,2909
|
|
5
5
|
cirq/_import.py,sha256=ixBu4EyGl46Ram2cP3p5eZVEFDW5L2DS-VyTjz4N9iw,8429
|
|
6
6
|
cirq/_import_test.py,sha256=oF4izzOVZLc7NZ0aZHFcGv-r01eiFFt_JORx_x7_D4s,1089
|
|
7
|
-
cirq/_version.py,sha256=
|
|
8
|
-
cirq/_version_test.py,sha256
|
|
7
|
+
cirq/_version.py,sha256=r2eDmtAP2xJC2APkN6aWn6RnWNOsjA2XcuXUC7X1yOg,1206
|
|
8
|
+
cirq/_version_test.py,sha256=-vnO8SJPG1hypDpea4Knu5oCTIqBChxjPoSOEnnJaGY,155
|
|
9
9
|
cirq/conftest.py,sha256=wSDKNdIQRDfLnXvOCWD3erheOw8JHRhdfQ53EyTUIXg,1239
|
|
10
10
|
cirq/json_resolver_cache.py,sha256=A5DIgFAY1hUNt9vai_C3-gGBv24116CJMzQxMcXOax4,13726
|
|
11
11
|
cirq/py.typed,sha256=VFSlmh_lNwnaXzwY-ZuW-C2Ws5PkuDoVgBdNCs0jXJE,63
|
|
@@ -25,7 +25,7 @@ cirq/circuits/frozen_circuit_test.py,sha256=1Uk3g9St_nJFmu3IJ5hAcXWJjLfWFUXTCKQU
|
|
|
25
25
|
cirq/circuits/insert_strategy.py,sha256=3995vK4U6O9RV4BXMoFl9Tf3ekxIiqxv71IuX80JtYo,3237
|
|
26
26
|
cirq/circuits/insert_strategy_test.py,sha256=pBFgsylgRG1CS1h4JyzZQFP-xvh6fSbgpiZgxXfbpr4,1237
|
|
27
27
|
cirq/circuits/moment.py,sha256=MK8H9YUQ44ofLdM1E_zOrJ4Sh5Ayh4ezDtwZkx1O-1E,28363
|
|
28
|
-
cirq/circuits/moment_test.py,sha256
|
|
28
|
+
cirq/circuits/moment_test.py,sha256=wTfFl3yret5d5NTsUW1hAoATEZ0iZJ0tFiXHBKgkMUs,34255
|
|
29
29
|
cirq/circuits/optimization_pass.py,sha256=W_YYo_9uy5h4ijU_In5n7gG3EvCVp1cJbE1pHD9ci74,6481
|
|
30
30
|
cirq/circuits/optimization_pass_test.py,sha256=FvCCOZrqVQLYrf_BUAZ6M-sm6dMv00_xsvpN25Op1BA,5914
|
|
31
31
|
cirq/circuits/qasm_output.py,sha256=qclnyiEnRzkcr0JqzzABuiHD3INkiALmhl1jCW0AYNk,13079
|
|
@@ -424,8 +424,8 @@ cirq/protocols/inverse_protocol.py,sha256=tHaY8-dfd0SD59v3DZ_zpwz7lwFrraPExEnIgn
|
|
|
424
424
|
cirq/protocols/inverse_protocol_test.py,sha256=5RoZfSRzBvpGpLdg1XKYdB6qy-GkDvZsATUvxdFrLJ0,2067
|
|
425
425
|
cirq/protocols/json_serialization.py,sha256=z7Yu2vsNabRkdeYyIuNCoXATHkrOGreTRShNyN0Fjuc,24520
|
|
426
426
|
cirq/protocols/json_serialization_test.py,sha256=An57W8eBWaUF4kKOCos2UlHzNiILnUJvqmZLmwZ_6MA,27872
|
|
427
|
-
cirq/protocols/kraus_protocol.py,sha256=
|
|
428
|
-
cirq/protocols/kraus_protocol_test.py,sha256=
|
|
427
|
+
cirq/protocols/kraus_protocol.py,sha256=WjZDM_31MiOoAXbocrmkdBUTIr4UReRZXiLk2-3FCn8,11406
|
|
428
|
+
cirq/protocols/kraus_protocol_test.py,sha256=NCgkPoGuSki7VGqbnRUDsuhpFlvDJEAcJGzeLpImz6Q,8236
|
|
429
429
|
cirq/protocols/measurement_key_protocol.py,sha256=JU7XbZfR7o6Wcv5qRJisp3ZAWwW9Fx7OHtxNMrWtZoQ,13351
|
|
430
430
|
cirq/protocols/measurement_key_protocol_test.py,sha256=PqSU9uB4t2yvPz9hZBLby2mZnZo-DOLlx3HIicyPeLo,8768
|
|
431
431
|
cirq/protocols/mixture_protocol.py,sha256=A8J-kkwUqiQphw6d3DK3QZ-lP31DTWv475ZzdeqYA0w,6428
|
|
@@ -1234,8 +1234,8 @@ cirq/work/sampler.py,sha256=rxbMWvrhu3gfNSBjZKozw28lLKVvBAS_1EGyPdYe8Xg,19041
|
|
|
1234
1234
|
cirq/work/sampler_test.py,sha256=SsMrRvLDYELyOAWLKISjkdEfrBwLYWRsT6D8WrsLM3Q,13533
|
|
1235
1235
|
cirq/work/zeros_sampler.py,sha256=Fs2JWwq0n9zv7_G5Rm-9vPeHUag7uctcMOHg0JTkZpc,2371
|
|
1236
1236
|
cirq/work/zeros_sampler_test.py,sha256=lQLgQDGBLtfImryys2HzQ2jOSGxHgc7-koVBUhv8qYk,3345
|
|
1237
|
-
cirq_core-1.7.0.
|
|
1238
|
-
cirq_core-1.7.0.
|
|
1239
|
-
cirq_core-1.7.0.
|
|
1240
|
-
cirq_core-1.7.0.
|
|
1241
|
-
cirq_core-1.7.0.
|
|
1237
|
+
cirq_core-1.7.0.dev20250725224902.dist-info/licenses/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
|
|
1238
|
+
cirq_core-1.7.0.dev20250725224902.dist-info/METADATA,sha256=pjLVRz2hk-OGPcFaUZk9Dtmb0_WK2zbygv9eb3i1MI0,4857
|
|
1239
|
+
cirq_core-1.7.0.dev20250725224902.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
1240
|
+
cirq_core-1.7.0.dev20250725224902.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
|
|
1241
|
+
cirq_core-1.7.0.dev20250725224902.dist-info/RECORD,,
|
{cirq_core-1.7.0.dev20250724201755.dist-info → cirq_core-1.7.0.dev20250725224902.dist-info}/WHEEL
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|