diff --git a/cirq-core/cirq/transformers/align.py b/cirq-core/cirq/transformers/align.py index 18f967d09b6..9843dcc3417 100644 --- a/cirq-core/cirq/transformers/align.py +++ b/cirq-core/cirq/transformers/align.py @@ -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: @@ -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) @@ -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: diff --git a/cirq-core/cirq/transformers/align_test.py b/cirq-core/cirq/transformers/align_test.py index 5eb93cc82db..4e8a980a6a2 100644 --- a/cirq-core/cirq/transformers/align_test.py +++ b/cirq-core/cirq/transformers/align_test.py @@ -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( [ @@ -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( [ diff --git a/cirq-core/cirq/transformers/drop_negligible_operations.py b/cirq-core/cirq/transformers/drop_negligible_operations.py index 07d8b7dbd49..2237b0cd272 100644 --- a/cirq-core/cirq/transformers/drop_negligible_operations.py +++ b/cirq-core/cirq/transformers/drop_negligible_operations.py @@ -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 diff --git a/cirq-core/cirq/transformers/drop_negligible_operations_test.py b/cirq-core/cirq/transformers/drop_negligible_operations_test.py index b8f221795bf..531d135a7cd 100644 --- a/cirq-core/cirq/transformers/drop_negligible_operations_test.py +++ b/cirq-core/cirq/transformers/drop_negligible_operations_test.py @@ -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, ) diff --git a/cirq-core/cirq/transformers/synchronize_terminal_measurements.py b/cirq-core/cirq/transformers/synchronize_terminal_measurements.py index d182abab107..f65435a85e6 100644 --- a/cirq-core/cirq/transformers/synchronize_terminal_measurements.py +++ b/cirq-core/cirq/transformers/synchronize_terminal_measurements.py @@ -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: diff --git a/cirq-core/cirq/transformers/synchronize_terminal_measurements_test.py b/cirq-core/cirq/transformers/synchronize_terminal_measurements_test.py index ad69aa11050..41097af07ea 100644 --- a/cirq-core/cirq/transformers/synchronize_terminal_measurements_test.py +++ b/cirq-core/cirq/transformers/synchronize_terminal_measurements_test.py @@ -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, ) ) diff --git a/cirq-core/cirq/transformers/transformer_api.py b/cirq-core/cirq/transformers/transformer_api.py index f7aa06b48e7..6983312ab02 100644 --- a/cirq-core/cirq/transformers/transformer_api.py +++ b/cirq-core/cirq/transformers/transformer_api.py @@ -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): diff --git a/cirq-core/cirq/transformers/transformer_api_test.py b/cirq-core/cirq/transformers/transformer_api_test.py index 1b9428b3d67..8b35656fca8 100644 --- a/cirq-core/cirq/transformers/transformer_api_test.py +++ b/cirq-core/cirq/transformers/transformer_api_test.py @@ -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( @@ -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)