dag
¤
Tools for converting between directed acyclic graphs (DAGs) and quantum circuits
Functions:
| Name | Description |
|---|---|
draw_dag |
Draws a directed acyclic graph (DAG) representation of a quantum circuit and saves it as an image. |
qc2dag |
Converts a quantum circuit into a directed acyclic graph (DAG). |
dag2qc |
Converts a directed acyclic graph (DAG) back into a QuantumCircuit. |
draw_dag(dag, output='dag_figure.png')
¤
Draws a directed acyclic graph (DAG) representation of a quantum circuit and saves it as an image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dag
|
DiGraph
|
The quantum circuit represented as a directed acyclic graph. |
required |
output
|
str
|
The filename for saving the generated DAG image. Defaults to 'dag_figure.png'. |
'dag_figure.png'
|
Source code in quark/circuit/dag.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
qc2dag(qc: QuantumCircuit, show_qubits: bool = True) -> nx.DiGraph
¤
Converts a quantum circuit into a directed acyclic graph (DAG).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qc
|
QuantumCircuit
|
The quantum circuit to be converted. |
required |
Returns:
| Type | Description |
|---|---|
DiGraph
|
nx.DiGraph: A directed acyclic graph representing the quantum circuit, |
DiGraph
|
with nodes as operations and edges as dependencies. |
Source code in quark/circuit/dag.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
dag2qc(dag: nx.DiGraph, nqubits: int | None = None, ncbits: int | None = None) -> QuantumCircuit
¤
Converts a directed acyclic graph (DAG) back into a QuantumCircuit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dag
|
DiGraph
|
The DAG representation of the quantum circuit. |
required |
nqubits
|
int
|
The number of qubits in the circuit. |
None
|
ncbits
|
int | None
|
The number of classical bits in the circuit. Defaults to the value of |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
QuantumCircuit |
QuantumCircuit
|
The reconstructed quantum circuit based on the DAG structure. |
Source code in quark/circuit/dag.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | |