-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Presently, the Circuit class provides fairly sophisticated method for inserting operations which is useful for writing optimizers (e.g. insert earliest). I think this is a misplaced responsibility. Circuit should be a simple(*) container for storing and organizing gate operations but without circuit optimization logic. In particular, all insertions should require the client to say where the insertion is to occur. If some gates need to be moved earlier to reduce circuit duration by filling empty moments, then this counts as a circuit optimization and should therefore live in optimizers, not the Circuit class.
One reason for this separation is pure esthetics of the Circuit-as-a-simple-container approach. A more practical reason is that Circuit is a core concept in cirq and as such it should be simple, reliable and very stable over future releases. These properties are easier to obtain when complicated logic like circuit optimizations lives elsewhere. This is inspired by some reflection on #2743.
Concretely, this issue proposes to remove InsertStrategy
from Circuit and instead introduce the functionality as an optimizer. This would be a breaking change that would need careful and gradual introduction. It's one of the things we'd want to complete before v1.0.
Note that another welcome effect of this change would be simplification of Circuit API.
I'm curious what y'all think.
(*) For the purposes of this issue, containers such as priority queues count as complex containers.