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
Operation
instance marked iffpredicate
returns True on it.This method converts the quantum circuit in
seq
into an equivalent circuitA+B+C
, where theCommand
instances in sequencesA
andC
do not contain any marked Operations. The sequenceB
contains all marked Operations in the circuit, and possibly additional unmarked instances that could not be moved intoA
orC
using the available commutation rules. Any of the three returned sequences can be empty (but ifB
is 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]]