Skip to content

Commit d7fefa8

Browse files
mpharriganCirqBot
authored andcommitted
PointOptimizerSummary option to avoid flattening (quantumlib#2461)
This isn't actually enough as the point optimizer will flatten it (again). But this *does* make it so I can write my own PointOptimizer replacement that can respect it xref quantumlib#2406
1 parent 9c0eb4c commit d7fefa8

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

cirq/circuits/optimization_pass.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@
3030
class PointOptimizationSummary:
3131
"""A description of a local optimization to perform."""
3232

33-
def __init__(self, clear_span: int, clear_qubits: Iterable['cirq.Qid'],
34-
new_operations: 'cirq.OP_TREE') -> None:
33+
def __init__(self,
34+
clear_span: int,
35+
clear_qubits: Iterable['cirq.Qid'],
36+
new_operations: 'cirq.OP_TREE',
37+
preserve_moments: bool = False) -> None:
3538
"""
3639
Args:
3740
clear_span: Defines the range of moments to affect. Specifically,
@@ -41,8 +44,17 @@ def __init__(self, clear_span: int, clear_qubits: Iterable['cirq.Qid'],
4144
with each affected moment.
4245
new_operations: The operations to replace the cleared out
4346
operations with.
47+
preserve_moments: If set, `cirq.Moment` instances within
48+
`new_operations` will be preserved exactly. Normally the
49+
operations would be repacked to fit better into the
50+
target space, which may move them between moments.
51+
Please be advised that a PointOptimizer consuming this
52+
summary will flatten operations no matter what,
53+
see https://github.com/quantumlib/Cirq/issues/2406.
4454
"""
45-
self.new_operations = tuple(ops.flatten_op_tree(new_operations))
55+
self.new_operations = tuple(
56+
ops.flatten_op_tree(new_operations,
57+
preserve_moments=preserve_moments))
4658
self.clear_span = clear_span
4759
self.clear_qubits = tuple(clear_qubits)
4860

0 commit comments

Comments
 (0)