general_merger
can_move_before(statement, statement_group)
Checks whether a statement can be moved before a group of statements, following the logic below: - A barrier cannot be moved up. - A (non-barrier) statement cannot be moved before another (non-barrier) statement. - A (non-barrier) statement may be moved before a group of 'linked' barriers.
Source code in opensquirrel/passes/merger/general_merger.py
can_move_statement_before_barrier(instruction, barriers)
Checks whether an instruction can be moved before a group of 'linked' barriers. Returns True if none of the qubits used by the instruction are part of any barrier, False otherwise.
Source code in opensquirrel/passes/merger/general_merger.py
compose_bloch_sphere_rotations(bsr_a, bsr_b)
Computes the Bloch sphere rotation resulting from the composition of two Bloch sphere rotations. The first rotation (A) is applied and then the second (B):
As separate gates
A q B q
As linear operations
(B * A) q
If the final Bloch sphere rotation is anonymous, we try to match it to a default gate.
Uses Rodrigues' rotation formula (see https://en.wikipedia.org/wiki/Rodrigues%27_rotation_formula).
Source code in opensquirrel/passes/merger/general_merger.py
group_linked_barriers(statements)
Receives a list of statements. Returns a list of lists of statements, where each list of statements is either a single instruction, or a list of 'linked' barriers (consecutive barriers that cannot be split).
Source code in opensquirrel/passes/merger/general_merger.py
rearrange_barriers(ir)
Receives an IR. Builds an enumerated list of lists of statements, where each list of statements is either a single instruction, or a list of 'linked' barriers (consecutive barriers that cannot be split). Then sorts that enumerated list of lists so that instructions can be moved before groups of barriers. And updates the input IR with the flattened list of sorted statements.