@@ -26,7 +26,7 @@ def index_tags(
26
26
circuit : 'cirq.AbstractCircuit' ,
27
27
* ,
28
28
context : Optional ['cirq.TransformerContext' ] = None ,
29
- target_tags : Optional [ set [Hashable ]] = None ,
29
+ target_tags : set [Hashable ],
30
30
) -> 'cirq.Circuit' :
31
31
"""Indexes tags in target_tags as tag_0, tag_1, ... per tag.
32
32
@@ -38,7 +38,10 @@ def index_tags(
38
38
Returns:
39
39
Copy of the transformed input circuit.
40
40
"""
41
- target_tags = target_tags or set ()
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
42
45
tag_iter_by_tags = {tag : itertools .count (start = 0 , step = 1 ) for tag in target_tags }
43
46
44
47
def _map_func (op : 'cirq.Operation' , _ ) -> 'cirq.OP_TREE' :
@@ -51,10 +54,7 @@ def _map_func(op: 'cirq.Operation', _) -> 'cirq.OP_TREE':
51
54
return op .untagged .with_tags (* tag_set )
52
55
53
56
return transformer_primitives .map_operations (
54
- circuit ,
55
- _map_func ,
56
- deep = context .deep if context else False ,
57
- tags_to_ignore = context .tags_to_ignore if context else [],
57
+ circuit , _map_func , deep = context .deep if context else False
58
58
).unfreeze (copy = False )
59
59
60
60
@@ -68,8 +68,6 @@ def remove_tags(
68
68
) -> 'cirq.Circuit' :
69
69
"""Removes tags from the operations based on the input args.
70
70
71
- Note: context.tags_to_ignore has higher priority than target_tags and remove_if.
72
-
73
71
Args:
74
72
circuit: Input circuit to apply the transformations on. The input circuit is not mutated.
75
73
context: `cirq.TransformerContext` storing common configurable options for transformers.
@@ -80,6 +78,8 @@ def remove_tags(
80
78
Returns:
81
79
Copy of the transformed input circuit.
82
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
83
target_tags = target_tags or set ()
84
84
85
85
def _map_func (op : 'cirq.Operation' , _ ) -> 'cirq.OP_TREE' :
@@ -91,8 +91,5 @@ def _map_func(op: 'cirq.Operation', _) -> 'cirq.OP_TREE':
91
91
return op .untagged .with_tags (* remaing_tags )
92
92
93
93
return transformer_primitives .map_operations (
94
- circuit ,
95
- _map_func ,
96
- deep = context .deep if context else False ,
97
- tags_to_ignore = context .tags_to_ignore if context else [],
94
+ circuit , _map_func , deep = context .deep if context else False
98
95
).unfreeze (copy = False )
0 commit comments