Skip to content

Add support for deep=True to cirq.synchronize_terminal_measurements transformer #5118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def find_terminal_measurements(
return terminal_measurements


@transformer_api.transformer
@transformer_api.transformer(add_deep_support=True)
def synchronize_terminal_measurements(
circuit: 'cirq.AbstractCircuit',
*,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,35 @@


def assert_optimizes(before, after, measure_only_moment=True, with_context=False):
transformed_circuit = (
cirq.synchronize_terminal_measurements(before, after_other_operations=measure_only_moment)
if not with_context
else cirq.synchronize_terminal_measurements(
before,
context=cirq.TransformerContext(tags_to_ignore=(NO_COMPILE_TAG,)),
after_other_operations=measure_only_moment,
)
context = cirq.TransformerContext(tags_to_ignore=(NO_COMPILE_TAG,)) if with_context else None
transformed_circuit = cirq.synchronize_terminal_measurements(
before, context=context, after_other_operations=measure_only_moment
)
cirq.testing.assert_same_circuits(transformed_circuit, after)

# Test nested circuit ops.
context = cirq.TransformerContext(
tags_to_ignore=("ignore",) + tuple([NO_COMPILE_TAG] if with_context else []), deep=True
)
c_nested = cirq.Circuit(
before,
cirq.CircuitOperation(before.freeze()).repeat(5).with_tags("ignore"),
before,
cirq.CircuitOperation(before.freeze()).repeat(6).with_tags("preserve_tag"),
before,
)
c_expected = cirq.Circuit(
before,
cirq.CircuitOperation(before.freeze()).repeat(5).with_tags("ignore"),
before,
cirq.CircuitOperation(after.freeze()).repeat(6).with_tags("preserve_tag"),
after,
)
transformed_circuit = cirq.synchronize_terminal_measurements(
c_nested, context=context, after_other_operations=measure_only_moment
)
cirq.testing.assert_same_circuits(transformed_circuit, c_expected)


def test_no_move():
q1 = cirq.NamedQubit('q1')
Expand Down