group_operations(seq, predicate)[source]

Group a set of Operations in a circuit together (if possible).

For the purposes of this method, we call a Operation instance marked iff predicate returns True on it.

This method converts the quantum circuit in seq into an equivalent circuit A+B+C, where the Command instances in sequences A and C do not contain any marked Operations. The sequence B contains all marked Operations in the circuit, and possibly additional unmarked instances that could not be moved into A or C using the available commutation rules. Any of the three returned sequences can be empty (but if B is empty then so is C).

  • seq (Sequence[Command]) – quantum circuit

  • predicate (Callable[[Operation], bool]) – Grouping predicate. Returns True for the Operations to be grouped together, False for the others.


A, B, C such that A+B+C is equivalent to seq,

and A and C do not contain any marked Operation instances.

Return type