app.processing.merge ==================== .. py:module:: app.processing.merge .. autoapi-nested-parse:: Merge all nodes from :class:`~app.processing.graph.ProgramGraph` into a single QASM program. Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/app/processing/merge/connections/index /autoapi/app/processing/merge/utils/index Package Contents ---------------- .. py:class:: RemoveAnnotationTransformer(inputs: bool, outputs: bool) Remove leqo annotations of specified types. :param inputs: Whether to remove 'leqo.input' annotations. :param outputs: Whether to remove 'leqo.output' annotations. .. py:method:: visit_Annotation(node: openqasm3.ast.Annotation) -> openqasm3.ast.QASMNode | None Remove or keep annotation. .. py:function:: 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. .. py:function:: 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 :class:`openqasm3.ast.BranchingStatement` from two sub-graphs. There are two known limitations of this implementation: - Classical outputs are not supported. This is because :class:`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. :param if_node: The border node that leads into the if-then-else. This node has to be in both **then_graph** and **else_graph**. :param 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**. :param then_graph: The sub-graph for the **then** case. :param else_graph: The sub-graph for the **else** case. :param condition: The condition to use in the generated :class:`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. :return: merged program and total amount of qubits used (for global/if reg) .. py:function:: merge_nodes(graph: app.processing.graph.ProgramGraph) -> openqasm3.ast.Program Create a unified :class:`openqasm3.ast.Program` from a modeled graph with attached qasm implementation snippets. :param graph: Graph of all nodes representing the program :return: The unified qasm program