From 5d6b4b9f2dd3f84012be44c86d269367bea6f75a Mon Sep 17 00:00:00 2001 From: positr0nium Date: Sun, 23 Jun 2024 15:21:40 +0200 Subject: [PATCH] added some comments within qc_to_dag to explain the qc_index attribute --- src/qrisp/core/compilation.py | 2 ++ src/qrisp/uncomputation/unqomp.py | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/src/qrisp/core/compilation.py b/src/qrisp/core/compilation.py index b5d93921..3afe319a 100644 --- a/src/qrisp/core/compilation.py +++ b/src/qrisp/core/compilation.py @@ -526,6 +526,8 @@ def reorder_qc(qc): # sub_sort = lambda G : topological_sort(G, prefer = mcx_identifier, delay = nmcx_identifier) # for n in topological_sort(G, prefer = dealloc_identifier, delay = alloc_identifer, sub_sort = sub_sort): + # The sub_sort function takes the indices of the gates in the source qc as + # a sorting index. This induces a valid topological ordering because of [proof] def sub_sort(dag): nodes = list(dag.nodes()) nodes.sort(key = lambda x : x.qc_index) diff --git a/src/qrisp/uncomputation/unqomp.py b/src/qrisp/uncomputation/unqomp.py index 6f392764..703028cf 100644 --- a/src/qrisp/uncomputation/unqomp.py +++ b/src/qrisp/uncomputation/unqomp.py @@ -124,6 +124,13 @@ def dag_from_qc(qc, remove_init_nodes=False): # + str(node_counter[instr.qubits[-1]]), instr) node = UnqompNode(str(node_counter[instr.qubits[-1]]), instr) + # We add the index of the corresponding gate to the node object, + # because this information can be used for stable topological ordering: + # The allocation algorithm performs a topological order based on the ancestors + # of a certain nodes. The algorithm can subsequently use another topological + # ordering to sort the ancestors. To make the sorting algorithm "stable" ie. + # it preserves the previous order where possible, we use the indices of the source + # circuit as sorting index. node.qc_index = i if instr.op.name == "qb_dealloc":