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:
- 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:
if_node (app.processing.graph.ProgramNode)
endif_node (app.processing.graph.ProgramNode)
- Return type:
- 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:
if_node – The border node that leads into the if-then-else. This node has to be in both then_graph and else_graph.
endif_node – The border node that leads out of the if-then-else. This node has to be in both then_graph and else_graph.
then_graph (app.processing.graph.ProgramGraph) – The sub-graph for the then case.
else_graph (app.processing.graph.ProgramGraph) – The sub-graph for the else case.
condition (openqasm3.ast.Expression) –
The condition to use in the generated
openqasm3.ast.BranchingStatement
.- raises NotImplementedError:
If the circuit attempts to return classical output from the if-then-else structure.
If the outputs of the then_graph and else_graph do not match in size or qubit ordering.
if_node_raw (app.processing.graph.ProgramNode)
endif_node_raw (app.processing.graph.ProgramNode)
- Returns:
merged program and total amount of qubits used (for global/if reg)
- Return type:
- 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: