Skip to content

Commit

Permalink
Rename context.ignore_tags to context.tags_to_ignore (quantumlib#4931)
Browse files Browse the repository at this point in the history
Co-authored-by: Cirq Bot <craiggidney+github+cirqbot@google.com>
  • Loading branch information
2 people authored and rht committed May 1, 2023
1 parent 37349f5 commit 019e30e
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions cirq-core/cirq/transformers/align.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def align_left(
) -> 'cirq.Circuit':
"""Align gates to the left of the circuit.
Note that tagged operations with tag in `context.ignore_tags` will continue to stay in their
Note that tagged operations with tag in `context.tags_to_ignore` will continue to stay in their
original position and will not be aligned.
Args:
Expand All @@ -45,7 +45,7 @@ def align_left(
for i, moment in enumerate(circuit):
for op in moment:
if isinstance(op, ops.TaggedOperation) and set(op.tags).intersection(
context.ignore_tags
context.tags_to_ignore
):
ret.append([ops.Moment()] * (i + 1 - len(ret)))
ret[i] = ret[i].with_operation(op)
Expand All @@ -60,7 +60,7 @@ def align_right(
) -> 'cirq.Circuit':
"""Align gates to the right of the circuit.
Note that tagged operations with tag in `context.ignore_tags` will continue to stay in their
Note that tagged operations with tag in `context.tags_to_ignore` will continue to stay in their
original position and will not be aligned.
Args:
Expand Down
4 changes: 2 additions & 2 deletions cirq-core/cirq/transformers/align_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_align_left_no_compile_context():
cirq.measure(*[q1, q2], key='a'),
]
),
context=cirq.TransformerContext(ignore_tags=["nocompile"]),
context=cirq.TransformerContext(tags_to_ignore=["nocompile"]),
),
cirq.Circuit(
[
Expand Down Expand Up @@ -85,7 +85,7 @@ def test_align_right_no_compile_context():
cirq.measure(*[q1, q2], key='a'),
]
),
context=cirq.TransformerContext(ignore_tags=["nocompile"]),
context=cirq.TransformerContext(tags_to_ignore=["nocompile"]),
),
cirq.Circuit(
[
Expand Down
2 changes: 1 addition & 1 deletion cirq-core/cirq/transformers/drop_negligible_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def drop_negligible_operations(

def map_func(op: 'cirq.Operation', _: int) -> 'cirq.OP_TREE':
if protocols.is_measurement(op) or (
context and not set(op.tags).isdisjoint(context.ignore_tags)
context and not set(op.tags).isdisjoint(context.tags_to_ignore)
):
return op
return [] if protocols.trace_distance_bound(op) <= atol else op
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_does_not_clear_small_no_compile():
circuit = cirq.Circuit(cirq.Moment((cirq.Z(a) ** 0.000001).with_tags(NO_COMPILE_TAG)))
cirq.testing.assert_same_circuits(
cirq.drop_negligible_operations(
circuit, context=cirq.TransformerContext(ignore_tags=(NO_COMPILE_TAG,)), atol=0.001
circuit, context=cirq.TransformerContext(tags_to_ignore=(NO_COMPILE_TAG,)), atol=0.001
),
circuit,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def synchronize_terminal_measurements(
terminal_measurements = [
(i, op)
for i, op in find_terminal_measurements(circuit)
if set(op.tags).isdisjoint(context.ignore_tags)
if set(op.tags).isdisjoint(context.tags_to_ignore)
]
ret = circuit.unfreeze(copy=True)
if not terminal_measurements:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def assert_optimizes(before, after, measure_only_moment=True, with_context=False
if not with_context
else cirq.synchronize_terminal_measurements(
before,
context=cirq.TransformerContext(ignore_tags=(NO_COMPILE_TAG,)),
context=cirq.TransformerContext(tags_to_ignore=(NO_COMPILE_TAG,)),
after_other_operations=measure_only_moment,
)
)
Expand Down
4 changes: 2 additions & 2 deletions cirq-core/cirq/transformers/transformer_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,14 @@ class TransformerContext:
logger: `cirq.TransformerLogger` instance, which is a stateful logger used for logging
the actions of individual transformer stages. The same logger instance should be
shared across different transformer calls.
ignore_tags: Tuple of tags which should be ignored while applying transformations on a
tags_to_ignore: Tuple of tags which should be ignored while applying transformations on a
circuit. Transformers should not transform any operation marked with a tag that
belongs to this tuple. Note that any instance of a Hashable type (like `str`,
`cirq.VirtualTag` etc.) is a valid tag.
"""

logger: TransformerLogger = NoOpTransformerLogger()
ignore_tags: Tuple[Hashable, ...] = ()
tags_to_ignore: Tuple[Hashable, ...] = ()


class TRANSFORMER(Protocol):
Expand Down
4 changes: 2 additions & 2 deletions cirq-core/cirq/transformers/transformer_api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def mock_tranformer_func(
'context',
[
cirq.TransformerContext(),
cirq.TransformerContext(logger=mock.Mock(), ignore_tags=('tag',)),
cirq.TransformerContext(logger=mock.Mock(), tags_to_ignore=('tag',)),
],
)
@pytest.mark.parametrize(
Expand Down Expand Up @@ -123,7 +123,7 @@ def test_transformer_decorator(context, transformer):
)
def test_transformer_decorator_with_defaults(transformer):
circuit = cirq.Circuit(cirq.X(cirq.NamedQubit("a")))
context = cirq.TransformerContext(ignore_tags=("tags", "to", "ignore"))
context = cirq.TransformerContext(tags_to_ignore=("tags", "to", "ignore"))
transformer(circuit)
transformer.mock.assert_called_with(circuit, cirq.TransformerContext(), 1e-4, CustomArg())
transformer(circuit, context=context, atol=1e-3)
Expand Down

0 comments on commit 019e30e

Please sign in to comment.