general_merger
can_move_before
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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
statement
|
Statement
|
The statement to be moved. |
required |
statement_group
|
list[Statement]
|
The group of statements to move before. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the statement can be moved before the group of statements, otherwise False. |
Source code in opensquirrel/passes/merger/general_merger.py
can_move_statement_before_barrier
Checks whether an instruction can be moved before a group of linked barriers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instruction
|
Instruction
|
The instruction to be moved. |
required |
barriers
|
list[Instruction]
|
The group of linked barriers. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if none of the qubits used by the instruction are part of the linked barriers, otherwise False. |
Source code in opensquirrel/passes/merger/general_merger.py
group_linked_barriers
Groups linked barriers in the input list of statements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
statements
|
list[Statement]
|
The list of statements. |
required |
Returns:
| Type | Description |
|---|---|
list[list[Statement]]
|
A list of 'lists of statements', which are either single instructions or linked barriers. |
Source code in opensquirrel/passes/merger/general_merger.py
rearrange_barriers
Rearrages barriers in the input 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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ir
|
IR
|
The input IR to be modified. |
required |