sf.program_utils.group_operations¶
-
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
Operationinstance marked iffpredicatereturns True on it.This method converts the quantum circuit in
seqinto an equivalent circuitA+B+C, where theCommandinstances in sequencesAandCdo not contain any marked Operations. The sequenceBcontains all marked Operations in the circuit, and possibly additional unmarked instances that could not be moved intoAorCusing the available commutation rules. Any of the three returned sequences can be empty (but ifBis empty then so isC).- Parameters
seq (Sequence[Command]) – quantum circuit
predicate (Callable[[Operation], bool]) – Grouping predicate. Returns True for the Operations to be grouped together, False for the others.
- Returns
- 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
Tuple[Sequence[Command]]