Skip to content

Commit

Permalink
added some comments within qc_to_dag to explain the qc_index attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
positr0nium committed Jun 23, 2024
1 parent e9ef66f commit 5d6b4b9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/qrisp/core/compilation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions src/qrisp/uncomputation/unqomp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down

0 comments on commit 5d6b4b9

Please sign in to comment.