cirq-core 1.6.0.dev20250516154249__py3-none-any.whl → 1.6.0.dev20250517035446__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/__init__.py +1 -0
- cirq/_version.py +1 -1
- cirq/_version_test.py +1 -1
- cirq/transformers/__init__.py +5 -0
- cirq/transformers/symbolize.py +101 -0
- cirq/transformers/symbolize_test.py +60 -0
- {cirq_core-1.6.0.dev20250516154249.dist-info → cirq_core-1.6.0.dev20250517035446.dist-info}/METADATA +1 -1
- {cirq_core-1.6.0.dev20250516154249.dist-info → cirq_core-1.6.0.dev20250517035446.dist-info}/RECORD +11 -9
- {cirq_core-1.6.0.dev20250516154249.dist-info → cirq_core-1.6.0.dev20250517035446.dist-info}/WHEEL +0 -0
- {cirq_core-1.6.0.dev20250516154249.dist-info → cirq_core-1.6.0.dev20250517035446.dist-info}/licenses/LICENSE +0 -0
- {cirq_core-1.6.0.dev20250516154249.dist-info → cirq_core-1.6.0.dev20250517035446.dist-info}/top_level.txt +0 -0
cirq/__init__.py
CHANGED
|
@@ -397,6 +397,7 @@ from cirq.transformers import (
|
|
|
397
397
|
single_qubit_matrix_to_phxz as single_qubit_matrix_to_phxz,
|
|
398
398
|
single_qubit_op_to_framed_phase_form as single_qubit_op_to_framed_phase_form,
|
|
399
399
|
stratified_circuit as stratified_circuit,
|
|
400
|
+
symbolize_single_qubit_gates_by_indexed_tags as symbolize_single_qubit_gates_by_indexed_tags,
|
|
400
401
|
synchronize_terminal_measurements as synchronize_terminal_measurements,
|
|
401
402
|
TRANSFORMER as TRANSFORMER,
|
|
402
403
|
TransformerContext as TransformerContext,
|
cirq/_version.py
CHANGED
cirq/_version_test.py
CHANGED
cirq/transformers/__init__.py
CHANGED
|
@@ -135,6 +135,11 @@ from cirq.transformers.transformer_primitives import (
|
|
|
135
135
|
unroll_circuit_op_greedy_frontier as unroll_circuit_op_greedy_frontier,
|
|
136
136
|
)
|
|
137
137
|
|
|
138
|
+
from cirq.transformers.symbolize import (
|
|
139
|
+
SymbolizeTag as SymbolizeTag,
|
|
140
|
+
symbolize_single_qubit_gates_by_indexed_tags as symbolize_single_qubit_gates_by_indexed_tags,
|
|
141
|
+
)
|
|
142
|
+
|
|
138
143
|
from cirq.transformers.gauge_compiling import (
|
|
139
144
|
CZGaugeTransformer as CZGaugeTransformer,
|
|
140
145
|
ConstantGauge as ConstantGauge,
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# Copyright 2025 The Cirq Developers
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
"""Transformers that symbolize operations."""
|
|
16
|
+
|
|
17
|
+
import re
|
|
18
|
+
from typing import Hashable, Optional, TYPE_CHECKING
|
|
19
|
+
|
|
20
|
+
import attrs
|
|
21
|
+
import sympy
|
|
22
|
+
from attrs import validators
|
|
23
|
+
|
|
24
|
+
from cirq import ops
|
|
25
|
+
from cirq.transformers import transformer_api, transformer_primitives
|
|
26
|
+
|
|
27
|
+
if TYPE_CHECKING:
|
|
28
|
+
import cirq
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@attrs.frozen
|
|
32
|
+
class SymbolizeTag:
|
|
33
|
+
prefix: str = attrs.field(
|
|
34
|
+
validator=validators.and_(validators.instance_of(str), validators.min_len(1))
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@transformer_api.transformer
|
|
39
|
+
def symbolize_single_qubit_gates_by_indexed_tags(
|
|
40
|
+
circuit: 'cirq.AbstractCircuit',
|
|
41
|
+
*,
|
|
42
|
+
context: Optional['cirq.TransformerContext'] = None,
|
|
43
|
+
symbolize_tag: SymbolizeTag = SymbolizeTag(prefix="TO-PHXZ"),
|
|
44
|
+
) -> 'cirq.Circuit':
|
|
45
|
+
"""Symbolizes single qubit operations by indexed tags prefixed by symbolize_tag.prefix.
|
|
46
|
+
|
|
47
|
+
Example:
|
|
48
|
+
>>> from cirq import transformers
|
|
49
|
+
>>> q0, q1 = cirq.LineQubit.range(2)
|
|
50
|
+
>>> c = cirq.Circuit(
|
|
51
|
+
... cirq.X(q0).with_tags("phxz_0"),
|
|
52
|
+
... cirq.CZ(q0,q1),
|
|
53
|
+
... cirq.Y(q0).with_tags("phxz_1"),
|
|
54
|
+
... cirq.X(q0))
|
|
55
|
+
>>> print(c)
|
|
56
|
+
0: ───X[phxz_0]───@───Y[phxz_1]───X───
|
|
57
|
+
│
|
|
58
|
+
1: ───────────────@───────────────────
|
|
59
|
+
>>> new_circuit = cirq.symbolize_single_qubit_gates_by_indexed_tags(
|
|
60
|
+
... c, symbolize_tag=transformers.SymbolizeTag(prefix="phxz"))
|
|
61
|
+
>>> print(new_circuit)
|
|
62
|
+
0: ───PhXZ(a=a0,x=x0,z=z0)───@───PhXZ(a=a1,x=x1,z=z1)───X───
|
|
63
|
+
│
|
|
64
|
+
1: ──────────────────────────@──────────────────────────────
|
|
65
|
+
|
|
66
|
+
Args:
|
|
67
|
+
circuit: Input circuit to apply the transformations on. The input circuit is not mutated.
|
|
68
|
+
context: `cirq.TransformerContext` storing common configurable options for transformers.
|
|
69
|
+
symbolize_tag: The tag info used to symbolize the phxz gate. Prefix is required.
|
|
70
|
+
|
|
71
|
+
Returns:
|
|
72
|
+
Copy of the transformed input circuit.
|
|
73
|
+
"""
|
|
74
|
+
|
|
75
|
+
def _map_func(op: 'cirq.Operation', _):
|
|
76
|
+
"""Maps an op with tag `{tag_prefix}_i` to a symbolzied `PhasedXZGate(xi,zi,ai)`."""
|
|
77
|
+
tags: set[Hashable] = set(op.tags)
|
|
78
|
+
tag_id: None | int = None
|
|
79
|
+
for tag in tags:
|
|
80
|
+
if re.fullmatch(f"{symbolize_tag.prefix}_\\d+", str(tag)):
|
|
81
|
+
if tag_id is None:
|
|
82
|
+
tag_id = int(str(tag).rsplit("_", maxsplit=-1)[-1])
|
|
83
|
+
else:
|
|
84
|
+
raise ValueError(f"Multiple tags are prefixed with {symbolize_tag.prefix}.")
|
|
85
|
+
if tag_id is None:
|
|
86
|
+
return op
|
|
87
|
+
tags.remove(f"{symbolize_tag.prefix}_{tag_id}")
|
|
88
|
+
phxz_params = {
|
|
89
|
+
"x_exponent": sympy.Symbol(f"x{tag_id}"),
|
|
90
|
+
"z_exponent": sympy.Symbol(f"z{tag_id}"),
|
|
91
|
+
"axis_phase_exponent": sympy.Symbol(f"a{tag_id}"),
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return ops.PhasedXZGate(**phxz_params).on(*op.qubits).with_tags(*tags)
|
|
95
|
+
|
|
96
|
+
return transformer_primitives.map_operations(
|
|
97
|
+
circuit.freeze(),
|
|
98
|
+
_map_func,
|
|
99
|
+
deep=context.deep if context else False,
|
|
100
|
+
tags_to_ignore=context.tags_to_ignore if context else [],
|
|
101
|
+
).unfreeze(copy=False)
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Copyright 2025 The Cirq Developers
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
import pytest
|
|
16
|
+
import sympy
|
|
17
|
+
|
|
18
|
+
import cirq
|
|
19
|
+
from cirq.transformers.symbolize import SymbolizeTag
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def test_symbolize_single_qubit_gates_by_indexed_tags_success():
|
|
23
|
+
q = cirq.NamedQubit("a")
|
|
24
|
+
input_circuit = cirq.Circuit(
|
|
25
|
+
cirq.X(q).with_tags("phxz_1"), cirq.Y(q).with_tags("tag1"), cirq.Z(q).with_tags("phxz_0")
|
|
26
|
+
)
|
|
27
|
+
output_circuit = cirq.symbolize_single_qubit_gates_by_indexed_tags(
|
|
28
|
+
input_circuit, symbolize_tag=SymbolizeTag(prefix="phxz")
|
|
29
|
+
)
|
|
30
|
+
cirq.testing.assert_same_circuits(
|
|
31
|
+
output_circuit,
|
|
32
|
+
cirq.Circuit(
|
|
33
|
+
cirq.PhasedXZGate(
|
|
34
|
+
x_exponent=sympy.Symbol("x1"),
|
|
35
|
+
z_exponent=sympy.Symbol("z1"),
|
|
36
|
+
axis_phase_exponent=sympy.Symbol("a1"),
|
|
37
|
+
).on(q),
|
|
38
|
+
cirq.Y(q).with_tags("tag1"),
|
|
39
|
+
cirq.PhasedXZGate(
|
|
40
|
+
x_exponent=sympy.Symbol("x0"),
|
|
41
|
+
z_exponent=sympy.Symbol("z0"),
|
|
42
|
+
axis_phase_exponent=sympy.Symbol("a0"),
|
|
43
|
+
).on(q),
|
|
44
|
+
),
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def test_symbolize_single_qubit_gates_by_indexed_tags_multiple_tags():
|
|
49
|
+
q = cirq.NamedQubit("a")
|
|
50
|
+
input_circuit = cirq.Circuit(cirq.X(q).with_tags("TO-PHXZ_0", "TO-PHXZ_2"))
|
|
51
|
+
|
|
52
|
+
with pytest.raises(ValueError, match="Multiple tags are prefixed with TO-PHXZ."):
|
|
53
|
+
cirq.symbolize_single_qubit_gates_by_indexed_tags(input_circuit)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def test_symbolize_tag_invalid_prefix():
|
|
57
|
+
with pytest.raises(ValueError, match="Length of 'prefix' must be >= 1: 0"):
|
|
58
|
+
SymbolizeTag(prefix="")
|
|
59
|
+
with pytest.raises(TypeError, match="'prefix' must be <class 'str'>"):
|
|
60
|
+
SymbolizeTag(prefix=[1])
|
{cirq_core-1.6.0.dev20250516154249.dist-info → cirq_core-1.6.0.dev20250517035446.dist-info}/METADATA
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cirq-core
|
|
3
|
-
Version: 1.6.0.
|
|
3
|
+
Version: 1.6.0.dev20250517035446
|
|
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.6.0.dev20250516154249.dist-info → cirq_core-1.6.0.dev20250517035446.dist-info}/RECORD
RENAMED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
cirq/__init__.py,sha256=
|
|
1
|
+
cirq/__init__.py,sha256=ATT0Sbu4iemRSpJ0xGabMJJ85kEeGJZ0TPirye6BWwM,28336
|
|
2
2
|
cirq/_compat.py,sha256=WAe4w7ZvaLlmn5J-YQMoHNwlosFaTUW6XiI1bXhPCrA,29569
|
|
3
3
|
cirq/_compat_test.py,sha256=t51ZXkEuomg1SMI871Ws-5pk68DGBsAf2TGNjVXtZ8I,34755
|
|
4
4
|
cirq/_doc.py,sha256=GlE8YPG5aEuA_TNMQMvqS6Pd8654akVJavUnNngtWUg,2915
|
|
5
5
|
cirq/_import.py,sha256=bXzIRteBSrBl6D5KBIMP0uE8T-jjwMAgoF8yTC03tSc,8457
|
|
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=B7HOiBi-ctY9VPauNqxlXcMTEFqTa8pqwwF2Jx1oFVE,1206
|
|
8
|
+
cirq/_version_test.py,sha256=y-5isrqLLscyfY-qpY172j59EXDUvBkpHMMWOrfBnDw,155
|
|
9
9
|
cirq/conftest.py,sha256=X7yLFL8GLhg2CjPw0hp5e_dGASfvHx1-QT03aUbhKJw,1168
|
|
10
10
|
cirq/json_resolver_cache.py,sha256=-4KqEEYb6aps-seafnFTHTp3SZc0D8mr4O-pCKIajn8,13653
|
|
11
11
|
cirq/py.typed,sha256=VFSlmh_lNwnaXzwY-ZuW-C2Ws5PkuDoVgBdNCs0jXJE,63
|
|
@@ -1050,7 +1050,7 @@ cirq/testing/test_data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3
|
|
|
1050
1050
|
cirq/testing/test_data/test_module_missing_json_test_data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
1051
1051
|
cirq/testing/test_data/test_module_missing_testspec/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
1052
1052
|
cirq/testing/test_data/test_module_missing_testspec/json_test_data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
1053
|
-
cirq/transformers/__init__.py,sha256=
|
|
1053
|
+
cirq/transformers/__init__.py,sha256=XrTXxZxi1jhBjcsAe86xtzE5KGOQ_JIIpsyLKistz-g,7183
|
|
1054
1054
|
cirq/transformers/align.py,sha256=XmARu30-wwsWMB-3z0K8WJ7zyErrdsTtgXgMDm4co6A,3355
|
|
1055
1055
|
cirq/transformers/align_test.py,sha256=AI26PxERbtJDfjKtoz17xVAKn6TSr-9pyImqfr5LJWc,7686
|
|
1056
1056
|
cirq/transformers/drop_empty_moments.py,sha256=j7zAoEsPs9JQ_zYpQX2yEvfiViDiYejnaOJ9GsXNbx4,1548
|
|
@@ -1083,6 +1083,8 @@ cirq/transformers/randomized_measurements.py,sha256=J4c9ZwYRDJ2_X_QzXWds4Qe0t9ZL
|
|
|
1083
1083
|
cirq/transformers/randomized_measurements_test.py,sha256=wQ8YXZv-pifnpKUdazSUvgRd3UNC9vaom08IxSGww9Q,2781
|
|
1084
1084
|
cirq/transformers/stratify.py,sha256=jfZEQuKv1YT8RdtcbGNsUNp4cs0WzZoiet-e5zwfLTc,10483
|
|
1085
1085
|
cirq/transformers/stratify_test.py,sha256=17ic2VAUPEGuPG2o5j98yDxQ2j2J_PN3EsPsfh5xwUk,15220
|
|
1086
|
+
cirq/transformers/symbolize.py,sha256=1YE-SMa6iR_YTGiKll0iZXp5uuBTOpSVF_UQts6DwVA,3977
|
|
1087
|
+
cirq/transformers/symbolize_test.py,sha256=bMQhtvt301uKyQH3tAM_wwVjBmPSZAqGpQH3p-DK5NE,2207
|
|
1086
1088
|
cirq/transformers/synchronize_terminal_measurements.py,sha256=uh3u53xLjQLyZvh6KY-oOk_i6j8VveMeOi_zGdi748I,3856
|
|
1087
1089
|
cirq/transformers/synchronize_terminal_measurements_test.py,sha256=vBO2LosBIDbjSXb61zt9k-AvS1M5u-Z13hqS6WaSZn0,7822
|
|
1088
1090
|
cirq/transformers/tag_transformers.py,sha256=7Y5w6sKjT5Ccevwu3EysSMLZ4mZvW9jM2wcAFDqBOnU,3510
|
|
@@ -1218,8 +1220,8 @@ cirq/work/sampler.py,sha256=b7O3B8bc77KQb8ReLx7qeF8owP1Qwb5_I-RwC6-M_C8,19118
|
|
|
1218
1220
|
cirq/work/sampler_test.py,sha256=SsMrRvLDYELyOAWLKISjkdEfrBwLYWRsT6D8WrsLM3Q,13533
|
|
1219
1221
|
cirq/work/zeros_sampler.py,sha256=vHCfqkXmUcPkaDuKHlY-UQ71dUHVroEtm_XW51mZpHs,2390
|
|
1220
1222
|
cirq/work/zeros_sampler_test.py,sha256=lQLgQDGBLtfImryys2HzQ2jOSGxHgc7-koVBUhv8qYk,3345
|
|
1221
|
-
cirq_core-1.6.0.
|
|
1222
|
-
cirq_core-1.6.0.
|
|
1223
|
-
cirq_core-1.6.0.
|
|
1224
|
-
cirq_core-1.6.0.
|
|
1225
|
-
cirq_core-1.6.0.
|
|
1223
|
+
cirq_core-1.6.0.dev20250517035446.dist-info/licenses/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
|
|
1224
|
+
cirq_core-1.6.0.dev20250517035446.dist-info/METADATA,sha256=-GFKnNhXKa5islgY7AGQunUT821owU4X33r3eBWwjCc,4857
|
|
1225
|
+
cirq_core-1.6.0.dev20250517035446.dist-info/WHEEL,sha256=Nw36Djuh_5VDukK0H78QzOX-_FQEo6V37m3nkm96gtU,91
|
|
1226
|
+
cirq_core-1.6.0.dev20250517035446.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
|
|
1227
|
+
cirq_core-1.6.0.dev20250517035446.dist-info/RECORD,,
|
{cirq_core-1.6.0.dev20250516154249.dist-info → cirq_core-1.6.0.dev20250517035446.dist-info}/WHEEL
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|