|
| 1 | +--- |
| 2 | +title: QkDag (dev version) |
| 3 | +description: API reference for QkDag in the dev version of qiskit-c |
| 4 | +in_page_toc_min_heading_level: 2 |
| 5 | +python_api_type: module |
| 6 | +python_api_name: QkDag |
| 7 | +--- |
| 8 | + |
| 9 | +# QkDag |
| 10 | + |
| 11 | +```c |
| 12 | +typedef struct QkDag QkDag |
| 13 | +``` |
| 14 | + |
| 15 | +The `QkDag` struct exposes a low level interface to the Qiskit transpiler’s directed acyclic graph (DAG) representation of a quantum circuit for use in transpiler passes. It exposes only what is defined in the inner data model of Qiskit. Therefore it is missing some functionality that is available in the higher level Python [`DAGCircuit`](/docs/api/qiskit/dev/qiskit.dagcircuit.DAGCircuit#qiskit.dagcircuit.DAGCircuit "qiskit.dagcircuit.DAGCircuit") class. |
| 16 | + |
| 17 | +The C API currently only supports building DAGs that contain operations defined in Qiskit’s internal Rust data model. Generally this includes only gates in the standard gate library, standard non-unitary operations (currently [`Barrier`](/docs/api/qiskit/dev/circuit#qiskit.circuit.Barrier "qiskit.circuit.Barrier"), [`Measure`](/docs/api/qiskit/dev/circuit#qiskit.circuit.Measure "qiskit.circuit.Measure"), [`Reset`](/docs/api/qiskit/dev/circuit#qiskit.circuit.Reset "qiskit.circuit.Reset"), and [`Delay`](/docs/api/qiskit/dev/circuit#qiskit.circuit.Delay "qiskit.circuit.Delay")) and [`UnitaryGate`](/docs/api/qiskit/dev/qiskit.circuit.library.UnitaryGate#qiskit.circuit.library.UnitaryGate "qiskit.circuit.library.UnitaryGate"). This functionality will be expanded over time as the Rust data model is expanded to natively support more functionality. |
| 18 | + |
| 19 | +## Functions |
| 20 | + |
| 21 | +### qk\_dag\_new |
| 22 | + |
| 23 | +<Function id="qk_dag_new" signature="QkDag *qk_dag_new(void)"> |
| 24 | + Construct a new empty DAG. |
| 25 | + |
| 26 | + You must free the returned DAG with qk\_dag\_free when done with it. |
| 27 | + |
| 28 | + <span id="group__QkDag_1autotoc_md50" /> |
| 29 | + |
| 30 | + #### Example |
| 31 | + |
| 32 | + ```c |
| 33 | + QkDag *empty = qk_dag_new(); |
| 34 | + ``` |
| 35 | + |
| 36 | + **Returns** |
| 37 | + |
| 38 | + A pointer to the created DAG. |
| 39 | +</Function> |
| 40 | + |
| 41 | +### qk\_dag\_add\_quantum\_register |
| 42 | + |
| 43 | +<Function id="qk_dag_add_quantum_register" signature="void qk_dag_add_quantum_register(QkDag *dag, const QkQuantumRegister *reg)"> |
| 44 | + Add a quantum register to the DAG. |
| 45 | + |
| 46 | + <span id="group__QkDag_1autotoc_md51" /> |
| 47 | + |
| 48 | + #### Example |
| 49 | + |
| 50 | + ```c |
| 51 | + QkDag *dag = qk_dag_new(); |
| 52 | + QkQuantumRegister *qr = qk_quantum_register_new(1024, "my_register"); |
| 53 | + qk_dag_add_quantum_register(dag, qr); |
| 54 | + qk_quantum_register_free(qr); |
| 55 | + qk_dag_free(dag); |
| 56 | + ``` |
| 57 | +
|
| 58 | + <span id="group__QkDag_1autotoc_md52" /> |
| 59 | +
|
| 60 | + #### Safety |
| 61 | +
|
| 62 | + <span id="group__QkDag_1autotoc_md52" /> |
| 63 | +
|
| 64 | + Behavior is undefined if `dag` is not a valid, non-null pointer to a `QkDag` and if `reg` is not a valid, non-null pointer to a `QkQuantumRegister`. |
| 65 | +
|
| 66 | + **Parameters** |
| 67 | +
|
| 68 | + * **dag** – A pointer to the DAG. |
| 69 | + * **reg** – A pointer to the quantum register. |
| 70 | +</Function> |
| 71 | +
|
| 72 | +### qk\_dag\_add\_classical\_register |
| 73 | +
|
| 74 | +<Function id="qk_dag_add_classical_register" signature="void qk_dag_add_classical_register(QkDag *dag, const QkClassicalRegister *reg)"> |
| 75 | + Add a classical register to the DAG. |
| 76 | +
|
| 77 | + <span id="group__QkDag_1autotoc_md53" /> |
| 78 | +
|
| 79 | + #### Example |
| 80 | +
|
| 81 | + ```c |
| 82 | + QkDag *dag = qk_dag_new(); |
| 83 | + QkClassicalRegister *cr = qk_classical_register_new(24, "my_register"); |
| 84 | + qk_dag_add_classical_register(dag, cr); |
| 85 | + qk_classical_register_free(cr); |
| 86 | + qk_dag_free(dag); |
| 87 | + ``` |
| 88 | + |
| 89 | + <span id="group__QkDag_1autotoc_md54" /> |
| 90 | + |
| 91 | + #### Safety |
| 92 | + |
| 93 | + <span id="group__QkDag_1autotoc_md54" /> |
| 94 | + |
| 95 | + Behavior is undefined if `dag` is not a valid, non-null pointer to a `QkDag` and if `reg` is not a valid, non-null pointer to a `QkClassicalRegister`. |
| 96 | + |
| 97 | + **Parameters** |
| 98 | + |
| 99 | + * **dag** – A pointer to the DAG. |
| 100 | + * **reg** – A pointer to the classical register. |
| 101 | +</Function> |
| 102 | + |
| 103 | +### qk\_dag\_num\_qubits |
| 104 | + |
| 105 | +<Function id="qk_dag_num_qubits" signature="uint32_t qk_dag_num_qubits(const QkDag *dag)"> |
| 106 | + Get the number of qubits the DAG contains. |
| 107 | + |
| 108 | + <span id="group__QkDag_1autotoc_md55" /> |
| 109 | + |
| 110 | + #### Example |
| 111 | + |
| 112 | + ```c |
| 113 | + QkDag *dag = qk_dag_new(); |
| 114 | + QkQuantumRegister *qr = qk_quantum_register_new(24, "my_register"); |
| 115 | + qk_dag_add_quantum_register(dag, qr); |
| 116 | + uint32_t num_qubits = qk_dag_num_qubits(dag); // num_qubits==24 |
| 117 | + qk_quantum_register_free(qr); |
| 118 | + qk_dag_free(dag); |
| 119 | + ``` |
| 120 | +
|
| 121 | + <span id="group__QkDag_1autotoc_md56" /> |
| 122 | +
|
| 123 | + #### Safety |
| 124 | +
|
| 125 | + <span id="group__QkDag_1autotoc_md56" /> |
| 126 | +
|
| 127 | + Behavior is undefined if `dag` is not a valid, non-null pointer to a `QkDag`. |
| 128 | +
|
| 129 | + **Parameters** |
| 130 | +
|
| 131 | + **dag** – A pointer to the DAG. |
| 132 | +
|
| 133 | + **Returns** |
| 134 | +
|
| 135 | + The number of qubits the DAG is defined on. |
| 136 | +</Function> |
| 137 | +
|
| 138 | +### qk\_dag\_num\_clbits |
| 139 | +
|
| 140 | +<Function id="qk_dag_num_clbits" signature="uint32_t qk_dag_num_clbits(const QkDag *dag)"> |
| 141 | + Get the number of clbits the DAG contains. |
| 142 | +
|
| 143 | + <span id="group__QkDag_1autotoc_md57" /> |
| 144 | +
|
| 145 | + #### Example |
| 146 | +
|
| 147 | + ```c |
| 148 | + QkDag *dag = qk_dag_new(); |
| 149 | + QkClassicalRegister *cr = qk_classical_register_new(24, "my_register"); |
| 150 | + qk_dag_add_classical_register(dag, cr); |
| 151 | + uint32_t num_clbits = qk_dag_num_clbits(dag); // num_clbits==24 |
| 152 | + qk_classical_register_free(cr); |
| 153 | + qk_dag_free(dag); |
| 154 | + ``` |
| 155 | + |
| 156 | + <span id="group__QkDag_1autotoc_md58" /> |
| 157 | + |
| 158 | + #### Safety |
| 159 | + |
| 160 | + <span id="group__QkDag_1autotoc_md58" /> |
| 161 | + |
| 162 | + Behavior is undefined if `dag` is not a valid, non-null pointer to a `QkDag`. |
| 163 | + |
| 164 | + **Parameters** |
| 165 | + |
| 166 | + **dag** – A pointer to the DAG. |
| 167 | + |
| 168 | + **Returns** |
| 169 | + |
| 170 | + The number of clbits the DAG is defined on. |
| 171 | +</Function> |
| 172 | + |
| 173 | +### qk\_dag\_free |
| 174 | + |
| 175 | +<Function id="qk_dag_free" signature="void qk_dag_free(QkDag *dag)"> |
| 176 | + Free the DAG. |
| 177 | + |
| 178 | + <span id="group__QkDag_1autotoc_md59" /> |
| 179 | + |
| 180 | + #### Example |
| 181 | + |
| 182 | + ```c |
| 183 | + QkDag *dag = qk_dag_new(); |
| 184 | + qk_dag_free(dag); |
| 185 | + ``` |
| 186 | +
|
| 187 | + <span id="group__QkDag_1autotoc_md60" /> |
| 188 | +
|
| 189 | + #### Safety |
| 190 | +
|
| 191 | + <span id="group__QkDag_1autotoc_md60" /> |
| 192 | +
|
| 193 | + Behavior is undefined if `dag` is not either null or a valid pointer to a `QkDag`. |
| 194 | +
|
| 195 | + **Parameters** |
| 196 | +
|
| 197 | + **dag** – A pointer to the DAG to free. |
| 198 | +</Function> |
| 199 | +
|
0 commit comments