app.processing.merge

Merge all nodes from ProgramGraph into a single QASM program.

Submodules

Package Contents

class app.processing.merge.RemoveAnnotationTransformer(inputs: bool, outputs: bool)

Remove leqo annotations of specified types.

Parameters:
  • inputs (bool) – Whether to remove ‘leqo.input’ annotations.

  • outputs (bool) – Whether to remove ‘leqo.output’ annotations.

visit_Annotation(node: openqasm3.ast.Annotation) openqasm3.ast.QASMNode | None

Remove or keep annotation.

Parameters:

node (openqasm3.ast.Annotation)

Return type:

openqasm3.ast.QASMNode | None

app.processing.merge.graph_to_statements(graph: app.processing.graph.ProgramGraph, if_node: app.processing.graph.ProgramNode, endif_node: app.processing.graph.ProgramNode) list[openqasm3.ast.Statement]

Concatenate nodes from the graph via topological_sort and remove annotations.

if_node and endif_node need to be skipped here.

Parameters:
Return type:

list[openqasm3.ast.Statement]

app.processing.merge.merge_if_nodes(if_node_raw: app.processing.graph.ProgramNode, endif_node_raw: app.processing.graph.ProgramNode, then_graph: app.processing.graph.ProgramGraph, else_graph: app.processing.graph.ProgramGraph, condition: openqasm3.ast.Expression) tuple[openqasm3.ast.Program, int]

Construct a single program with a openqasm3.ast.BranchingStatement from two sub-graphs.

There are two known limitations of this implementation:

  • Classical outputs are not supported.

    This is because openqasm3.ast.AliasStatement are scoped inside the if-then-else, meaning they can not pass their value to the endif_node, which is outside. This would be required for classical outputs to work. It might be possible in the future to declare the outputs at the top (in the if-node) and initialize them inside the arms. However, this does not fit into our code very well, and classicals have almost no support in Qiskit anyway.

  • The endif_node from both then_graph and else_graph need to match.

    This is not only true for the size of the outputs but also for the order of the used qubit IDs. The problem is very fundamental, as it comes from using a single big qubit register at the top. So the outputs need to have the same underling reg-index in both arms. A workaround might be to swap the qubits via gates.

Parameters:
Returns:

merged program and total amount of qubits used (for global/if reg)

Return type:

tuple[openqasm3.ast.Program, int]

app.processing.merge.merge_nodes(graph: app.processing.graph.ProgramGraph) openqasm3.ast.Program

Create a unified openqasm3.ast.Program from a modeled graph with attached qasm implementation snippets.

Parameters:

graph (app.processing.graph.ProgramGraph) – Graph of all nodes representing the program

Returns:

The unified qasm program

Return type:

openqasm3.ast.Program