|
18 | 18 |
|
19 | 19 |
|
20 | 20 | def assert_optimizes(before, after, measure_only_moment=True, with_context=False):
|
21 |
| - transformed_circuit = ( |
22 |
| - cirq.synchronize_terminal_measurements(before, after_other_operations=measure_only_moment) |
23 |
| - if not with_context |
24 |
| - else cirq.synchronize_terminal_measurements( |
25 |
| - before, |
26 |
| - context=cirq.TransformerContext(tags_to_ignore=(NO_COMPILE_TAG,)), |
27 |
| - after_other_operations=measure_only_moment, |
28 |
| - ) |
| 21 | + context = cirq.TransformerContext(tags_to_ignore=(NO_COMPILE_TAG,)) if with_context else None |
| 22 | + transformed_circuit = cirq.synchronize_terminal_measurements( |
| 23 | + before, context=context, after_other_operations=measure_only_moment |
29 | 24 | )
|
30 | 25 | cirq.testing.assert_same_circuits(transformed_circuit, after)
|
31 | 26 |
|
| 27 | + # Test nested circuit ops. |
| 28 | + context = cirq.TransformerContext( |
| 29 | + tags_to_ignore=("ignore",) + tuple([NO_COMPILE_TAG] if with_context else []), deep=True |
| 30 | + ) |
| 31 | + c_nested = cirq.Circuit( |
| 32 | + before, |
| 33 | + cirq.CircuitOperation(before.freeze()).repeat(5).with_tags("ignore"), |
| 34 | + before, |
| 35 | + cirq.CircuitOperation(before.freeze()).repeat(6).with_tags("preserve_tag"), |
| 36 | + before, |
| 37 | + ) |
| 38 | + c_expected = cirq.Circuit( |
| 39 | + before, |
| 40 | + cirq.CircuitOperation(before.freeze()).repeat(5).with_tags("ignore"), |
| 41 | + before, |
| 42 | + cirq.CircuitOperation(after.freeze()).repeat(6).with_tags("preserve_tag"), |
| 43 | + after, |
| 44 | + ) |
| 45 | + transformed_circuit = cirq.synchronize_terminal_measurements( |
| 46 | + c_nested, context=context, after_other_operations=measure_only_moment |
| 47 | + ) |
| 48 | + cirq.testing.assert_same_circuits(transformed_circuit, c_expected) |
| 49 | + |
32 | 50 |
|
33 | 51 | def test_no_move():
|
34 | 52 | q1 = cirq.NamedQubit('q1')
|
|
0 commit comments