cirq-core 1.6.0.dev20250507223949__py3-none-any.whl → 1.6.0.dev20250507225534__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 CHANGED
@@ -363,6 +363,7 @@ from cirq.transformers import (
363
363
  eject_z as eject_z,
364
364
  expand_composite as expand_composite,
365
365
  HardCodedInitialMapper as HardCodedInitialMapper,
366
+ index_tags as index_tags,
366
367
  is_negligible_turn as is_negligible_turn,
367
368
  LineInitialMapper as LineInitialMapper,
368
369
  MappingManager as MappingManager,
@@ -385,6 +386,7 @@ from cirq.transformers import (
385
386
  prepare_two_qubit_state_using_sqrt_iswap as prepare_two_qubit_state_using_sqrt_iswap,
386
387
  quantum_shannon_decomposition as quantum_shannon_decomposition,
387
388
  RouteCQC as RouteCQC,
389
+ remove_tags as remove_tags,
388
390
  routed_circuit_with_mapping as routed_circuit_with_mapping,
389
391
  SqrtIswapTargetGateset as SqrtIswapTargetGateset,
390
392
  single_qubit_matrix_to_gates as single_qubit_matrix_to_gates,
cirq/_version.py CHANGED
@@ -28,4 +28,4 @@ if sys.version_info < (3, 10, 0): # pragma: no cover
28
28
  'of cirq (e.g. "python -m pip install cirq==1.1.*")'
29
29
  )
30
30
 
31
- __version__ = "1.6.0.dev20250507223949"
31
+ __version__ = "1.6.0.dev20250507225534"
cirq/_version_test.py CHANGED
@@ -3,4 +3,4 @@ import cirq
3
3
 
4
4
 
5
5
  def test_version():
6
- assert cirq.__version__ == "1.6.0.dev20250507223949"
6
+ assert cirq.__version__ == "1.6.0.dev20250507225534"
@@ -119,6 +119,8 @@ from cirq.transformers.transformer_api import (
119
119
  transformer as transformer,
120
120
  )
121
121
 
122
+ from cirq.transformers.tag_transformers import index_tags as index_tags, remove_tags as remove_tags
123
+
122
124
  from cirq.transformers.transformer_primitives import (
123
125
  map_moments as map_moments,
124
126
  map_operations as map_operations,
@@ -0,0 +1,95 @@
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 itertools
16
+ from typing import Callable, Hashable, Optional, TYPE_CHECKING
17
+
18
+ from cirq.transformers import transformer_api, transformer_primitives
19
+
20
+ if TYPE_CHECKING:
21
+ import cirq
22
+
23
+
24
+ @transformer_api.transformer
25
+ def index_tags(
26
+ circuit: 'cirq.AbstractCircuit',
27
+ *,
28
+ context: Optional['cirq.TransformerContext'] = None,
29
+ target_tags: Optional[set[Hashable]] = None,
30
+ ) -> 'cirq.Circuit':
31
+ """Indexes tags in target_tags as tag_0, tag_1, ... per tag.
32
+
33
+ Args:
34
+ circuit: Input circuit to apply the transformations on. The input circuit is not mutated.
35
+ context: `cirq.TransformerContext` storing common configurable options for transformers.
36
+ target_tags: Tags to be indexed.
37
+
38
+ Returns:
39
+ Copy of the transformed input circuit.
40
+ """
41
+ if context and context.tags_to_ignore:
42
+ raise ValueError("index_tags doesn't support tags_to_ignore, use function args instead.")
43
+ if not target_tags:
44
+ return circuit.unfreeze(copy=False)
45
+ tag_iter_by_tags = {tag: itertools.count(start=0, step=1) for tag in target_tags}
46
+
47
+ def _map_func(op: 'cirq.Operation', _) -> 'cirq.OP_TREE':
48
+ tag_set = set(op.tags)
49
+ nonlocal tag_iter_by_tags
50
+ for tag in target_tags.intersection(op.tags):
51
+ tag_set.remove(tag)
52
+ tag_set.add(f"{tag}_{next(tag_iter_by_tags[tag])}")
53
+
54
+ return op.untagged.with_tags(*tag_set)
55
+
56
+ return transformer_primitives.map_operations(
57
+ circuit, _map_func, deep=context.deep if context else False
58
+ ).unfreeze(copy=False)
59
+
60
+
61
+ @transformer_api.transformer
62
+ def remove_tags(
63
+ circuit: 'cirq.AbstractCircuit',
64
+ *,
65
+ context: Optional['cirq.TransformerContext'] = None,
66
+ target_tags: Optional[set[Hashable]] = None,
67
+ remove_if: Callable[[Hashable], bool] = lambda _: False,
68
+ ) -> 'cirq.Circuit':
69
+ """Removes tags from the operations based on the input args.
70
+
71
+ Args:
72
+ circuit: Input circuit to apply the transformations on. The input circuit is not mutated.
73
+ context: `cirq.TransformerContext` storing common configurable options for transformers.
74
+ target_tags: Tags to be removed.
75
+ remove_if: A callable(tag) that returns True if the tag should be removed.
76
+ Defaults to False.
77
+
78
+ Returns:
79
+ Copy of the transformed input circuit.
80
+ """
81
+ if context and context.tags_to_ignore:
82
+ raise ValueError("remove_tags doesn't support tags_to_ignore, use function args instead.")
83
+ target_tags = target_tags or set()
84
+
85
+ def _map_func(op: 'cirq.Operation', _) -> 'cirq.OP_TREE':
86
+ remaing_tags = set()
87
+ for tag in op.tags:
88
+ if not remove_if(tag) and tag not in target_tags:
89
+ remaing_tags.add(tag)
90
+
91
+ return op.untagged.with_tags(*remaing_tags)
92
+
93
+ return transformer_primitives.map_operations(
94
+ circuit, _map_func, deep=context.deep if context else False
95
+ ).unfreeze(copy=False)
@@ -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
+ import pytest
16
+
17
+ import cirq
18
+
19
+
20
+ def check_same_circuit_with_same_tag_sets(circuit1, circuit2):
21
+ for op1, op2 in zip(circuit1.all_operations(), circuit2.all_operations()):
22
+ assert set(op1.tags) == set(op2.tags)
23
+ assert op1.untagged == op2.untagged
24
+
25
+
26
+ def test_index_tags():
27
+ q0, q1 = cirq.LineQubit.range(2)
28
+ input_circuit = cirq.Circuit(
29
+ cirq.X(q0).with_tags("tag1", "tag2"),
30
+ cirq.Y(q1).with_tags("tag1"),
31
+ cirq.CZ(q0, q1).with_tags("tag2"),
32
+ )
33
+ expected_circuit = cirq.Circuit(
34
+ cirq.X(q0).with_tags("tag1_0", "tag2_0"),
35
+ cirq.Y(q1).with_tags("tag1_1"),
36
+ cirq.CZ(q0, q1).with_tags("tag2_1"),
37
+ )
38
+ check_same_circuit_with_same_tag_sets(
39
+ cirq.index_tags(input_circuit, target_tags={"tag1", "tag2"}), expected_circuit
40
+ )
41
+
42
+
43
+ def test_index_tags_empty_target_tags():
44
+ q0, q1 = cirq.LineQubit.range(2)
45
+ input_circuit = cirq.Circuit(
46
+ cirq.X(q0).with_tags("tag1", "tag2"),
47
+ cirq.Y(q1).with_tags("tag1"),
48
+ cirq.CZ(q0, q1).with_tags("tag2"),
49
+ )
50
+ check_same_circuit_with_same_tag_sets(
51
+ cirq.index_tags(input_circuit, target_tags={}), input_circuit
52
+ )
53
+
54
+
55
+ def test_remove_tags():
56
+ q0, q1 = cirq.LineQubit.range(2)
57
+ input_circuit = cirq.Circuit(
58
+ cirq.X(q0).with_tags("tag1", "tag2"),
59
+ cirq.Y(q1).with_tags("tag1"),
60
+ cirq.CZ(q0, q1).with_tags("tag2"),
61
+ )
62
+ expected_circuit = cirq.Circuit(
63
+ cirq.X(q0).with_tags("tag2"), cirq.Y(q1), cirq.CZ(q0, q1).with_tags("tag2")
64
+ )
65
+ check_same_circuit_with_same_tag_sets(
66
+ cirq.remove_tags(input_circuit, target_tags={"tag1"}), expected_circuit
67
+ )
68
+
69
+
70
+ def test_remove_tags_via_remove_if():
71
+ q0, q1 = cirq.LineQubit.range(2)
72
+ input_circuit = cirq.Circuit(
73
+ cirq.X(q0).with_tags("tag1", "tag2"),
74
+ cirq.Y(q1).with_tags("not_tag1"),
75
+ cirq.CZ(q0, q1).with_tags("tag2"),
76
+ )
77
+ expected_circuit = cirq.Circuit(cirq.X(q0), cirq.Y(q1).with_tags("not_tag1"), cirq.CZ(q0, q1))
78
+ check_same_circuit_with_same_tag_sets(
79
+ cirq.remove_tags(input_circuit, remove_if=lambda tag: tag.startswith("tag")),
80
+ expected_circuit,
81
+ )
82
+
83
+
84
+ def test_index_tags_with_tags_to_ignore():
85
+ with pytest.raises(
86
+ ValueError, match="index_tags doesn't support tags_to_ignore, use function args instead."
87
+ ):
88
+ cirq.index_tags(
89
+ circuit=cirq.Circuit(),
90
+ target_tags={"tag0"},
91
+ context=cirq.TransformerContext(tags_to_ignore=["tag0"]),
92
+ )
93
+
94
+
95
+ def test_remove_tags_with_tags_to_ignore():
96
+ with pytest.raises(
97
+ ValueError, match="remove_tags doesn't support tags_to_ignore, use function args instead."
98
+ ):
99
+ cirq.remove_tags(
100
+ circuit=cirq.Circuit(), context=cirq.TransformerContext(tags_to_ignore=["tag0"])
101
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cirq-core
3
- Version: 1.6.0.dev20250507223949
3
+ Version: 1.6.0.dev20250507225534
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
@@ -1,11 +1,11 @@
1
- cirq/__init__.py,sha256=rUfvQDtywCak2mJQoihOSyRjGxQahK-YOv909us0w5M,28132
1
+ cirq/__init__.py,sha256=ecDdbOid5m5VpqO4ZPoXQRuWUanrH3Y7lGzzgNPpiyM,28194
2
2
  cirq/_compat.py,sha256=_DknO27XngcjEidNApRsCzLUWDS4QmDk9M12BaqP5Is,29531
3
3
  cirq/_compat_test.py,sha256=t51ZXkEuomg1SMI871Ws-5pk68DGBsAf2TGNjVXtZ8I,34755
4
4
  cirq/_doc.py,sha256=yDyWUD_2JDS0gShfGRb-rdqRt9-WeL7DhkqX7np0Nko,2879
5
5
  cirq/_import.py,sha256=cfocxtT1BJ4HkfZ-VO8YyIhPP-xfqHDkLrzz6eeO5U0,8421
6
6
  cirq/_import_test.py,sha256=6K_v0riZJXOXUphHNkGA8MY-JcmGlezFaGmvrNhm3OQ,1015
7
- cirq/_version.py,sha256=ej5Fg_x84YN77p1cdtLyrTatULWldkQMY3wr9uVW6Ao,1206
8
- cirq/_version_test.py,sha256=SLvxISQ8V1GpwYAJkTGScRjoLHudE0Z08eAlyTEUacU,147
7
+ cirq/_version.py,sha256=hTB6q5KLlQenUB_P9SCUo9H4op-PatyQxgikmCkf8U0,1206
8
+ cirq/_version_test.py,sha256=Yt9Dr26wo6Uhn7hGIoGN0kOoBnN7KUfd5ymMAIBGxCE,147
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
@@ -1046,7 +1046,7 @@ cirq/testing/test_data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3
1046
1046
  cirq/testing/test_data/test_module_missing_json_test_data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
1047
1047
  cirq/testing/test_data/test_module_missing_testspec/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
1048
1048
  cirq/testing/test_data/test_module_missing_testspec/json_test_data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
1049
- cirq/transformers/__init__.py,sha256=QjYovkmQHRi7D6nPHkWrszVBM_1__thvOXG4wcYvX_E,6905
1049
+ cirq/transformers/__init__.py,sha256=8k80MycPGQzZdJztV4eDpDAo6qpV7SA7GbG2vFiBAcg,7006
1050
1050
  cirq/transformers/align.py,sha256=XmARu30-wwsWMB-3z0K8WJ7zyErrdsTtgXgMDm4co6A,3355
1051
1051
  cirq/transformers/align_test.py,sha256=AI26PxERbtJDfjKtoz17xVAKn6TSr-9pyImqfr5LJWc,7686
1052
1052
  cirq/transformers/drop_empty_moments.py,sha256=j7zAoEsPs9JQ_zYpQX2yEvfiViDiYejnaOJ9GsXNbx4,1548
@@ -1081,6 +1081,8 @@ cirq/transformers/stratify.py,sha256=jfZEQuKv1YT8RdtcbGNsUNp4cs0WzZoiet-e5zwfLTc
1081
1081
  cirq/transformers/stratify_test.py,sha256=17ic2VAUPEGuPG2o5j98yDxQ2j2J_PN3EsPsfh5xwUk,15220
1082
1082
  cirq/transformers/synchronize_terminal_measurements.py,sha256=uh3u53xLjQLyZvh6KY-oOk_i6j8VveMeOi_zGdi748I,3856
1083
1083
  cirq/transformers/synchronize_terminal_measurements_test.py,sha256=VTiw5S3s_Y31qR7ME8Mzv50LdJ_6M3DOtgwvtziQzPI,7742
1084
+ cirq/transformers/tag_transformers.py,sha256=7Y5w6sKjT5Ccevwu3EysSMLZ4mZvW9jM2wcAFDqBOnU,3510
1085
+ cirq/transformers/tag_transformers_test.py,sha256=qyA9Z6lVk5lRnml6x63EREMUeyCAnxVfRQeA9KN4a0o,3403
1084
1086
  cirq/transformers/transformer_api.py,sha256=zH4suvb0iLPIJ_znCIpJGag4GSiycdPOk2nbbS14C1w,16961
1085
1087
  cirq/transformers/transformer_api_test.py,sha256=YBkIX-R6vYeQz1Y_sqpzDlvNYszEtfvkegoA8dAVVVc,13286
1086
1088
  cirq/transformers/transformer_primitives.py,sha256=q88fl6KGdJvx5mZqnorZv4oR92JK1k6Jm2JZBbjx4Ms,36642
@@ -1212,8 +1214,8 @@ cirq/work/sampler.py,sha256=b7O3B8bc77KQb8ReLx7qeF8owP1Qwb5_I-RwC6-M_C8,19118
1212
1214
  cirq/work/sampler_test.py,sha256=TBJm3gepuOURwklJTXNdqj0thvdqKUvrZwZqdytJxNY,13313
1213
1215
  cirq/work/zeros_sampler.py,sha256=vHCfqkXmUcPkaDuKHlY-UQ71dUHVroEtm_XW51mZpHs,2390
1214
1216
  cirq/work/zeros_sampler_test.py,sha256=TR3AXYSfg3ETpeaEtrmE-GgZsPtfZkUZ36kyH9JquJk,3313
1215
- cirq_core-1.6.0.dev20250507223949.dist-info/licenses/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
1216
- cirq_core-1.6.0.dev20250507223949.dist-info/METADATA,sha256=N8AvAV22NN2JNnFf298hHfQGPHnVd4I2-Yz1_DamQYk,4908
1217
- cirq_core-1.6.0.dev20250507223949.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
1218
- cirq_core-1.6.0.dev20250507223949.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
1219
- cirq_core-1.6.0.dev20250507223949.dist-info/RECORD,,
1217
+ cirq_core-1.6.0.dev20250507225534.dist-info/licenses/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
1218
+ cirq_core-1.6.0.dev20250507225534.dist-info/METADATA,sha256=t80B3z06_iMsNyOWwLvSh4xNe_TlVBNQ6tOCihY7rkA,4908
1219
+ cirq_core-1.6.0.dev20250507225534.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
1220
+ cirq_core-1.6.0.dev20250507225534.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
1221
+ cirq_core-1.6.0.dev20250507225534.dist-info/RECORD,,