Skip to content

Commit

Permalink
PointOptimizerSummary option to avoid flattening (#2461)
Browse files Browse the repository at this point in the history
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 #2406
  • Loading branch information
mpharrigan authored and CirqBot committed Nov 5, 2019
1 parent 9c0eb4c commit d7fefa8
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions cirq/circuits/optimization_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@
class PointOptimizationSummary:
"""A description of a local optimization to perform."""

def __init__(self, clear_span: int, clear_qubits: Iterable['cirq.Qid'],
new_operations: 'cirq.OP_TREE') -> None:
def __init__(self,
clear_span: int,
clear_qubits: Iterable['cirq.Qid'],
new_operations: 'cirq.OP_TREE',
preserve_moments: bool = False) -> None:
"""
Args:
clear_span: Defines the range of moments to affect. Specifically,
Expand All @@ -41,8 +44,17 @@ def __init__(self, clear_span: int, clear_qubits: Iterable['cirq.Qid'],
with each affected moment.
new_operations: The operations to replace the cleared out
operations with.
preserve_moments: If set, `cirq.Moment` instances within
`new_operations` will be preserved exactly. Normally the
operations would be repacked to fit better into the
target space, which may move them between moments.
Please be advised that a PointOptimizer consuming this
summary will flatten operations no matter what,
see https://github.com/quantumlib/Cirq/issues/2406.
"""
self.new_operations = tuple(ops.flatten_op_tree(new_operations))
self.new_operations = tuple(
ops.flatten_op_tree(new_operations,
preserve_moments=preserve_moments))
self.clear_span = clear_span
self.clear_qubits = tuple(clear_qubits)

Expand Down

0 comments on commit d7fefa8

Please sign in to comment.