Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/api/qiskit-c/dev/_toc.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
"title": "QkComplex64",
"url": "/docs/api/qiskit-c/dev/qk-complex-64"
},
{
"title": "QkDag",
"url": "/docs/api/qiskit-c/dev/qk-dag"
},
{
"title": "QkExitCode",
"url": "/docs/api/qiskit-c/dev/qk-exit-code"
Expand Down
1 change: 1 addition & 0 deletions docs/api/qiskit-c/dev/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ As this interface is still new in Qiskit it should be considered experimental an

Using the transpiler from the C API is intended to only cover circuits created solely via the C API. If you are in a hybrid mode where you’re using the C API with Python you should invoke the transpiler via the Python [`qiskit.transpiler`](/docs/api/qiskit/dev/transpiler#module-qiskit.transpiler "qiskit.transpiler") module instead; the functionality is the same Rust internals they just offer different entrypoints. The C API for transpilation makes assumptions about the input only using constructs exposed to the C Quantum Circuit API and you will potentially get incomplete results transpiling circuits from Python via the C API.

* [QkDag](qk-dag)
* [QkTranspiler](qk-transpiler)
* [QkTarget](qk-target)
* [QkTargetEntry](qk-target-entry)
Expand Down
6 changes: 3 additions & 3 deletions docs/api/qiskit-c/dev/qk-bit-term.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ The numeric structure of these is that they are all four-bit values of which the
<Function id="qk_bitterm_label" signature="uint8_t qk_bitterm_label(QkBitTerm bit_term)">
Get the label for a bit term.

<span id="group__QkBitTerm_1autotoc_md144" />
<span id="group__QkBitTerm_1autotoc_md155" />

#### Example

Expand All @@ -101,11 +101,11 @@ The numeric structure of these is that they are all four-bit values of which the
char label = qk_bitterm_label(bit_term);
```

<span id="group__QkBitTerm_1autotoc_md145" />
<span id="group__QkBitTerm_1autotoc_md156" />

#### Safety

<span id="group__QkBitTerm_1autotoc_md145" />
<span id="group__QkBitTerm_1autotoc_md156" />

The behavior is undefined if `bit_term` is not a valid `uint8_t` value of a `QkBitTerm`.

Expand Down
199 changes: 199 additions & 0 deletions docs/api/qiskit-c/dev/qk-dag.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
---
title: QkDag (dev version)
description: API reference for QkDag in the dev version of qiskit-c
in_page_toc_min_heading_level: 2
python_api_type: module
python_api_name: QkDag
---

# QkDag

```c
typedef struct QkDag QkDag
```

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.

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.

## Functions

### qk\_dag\_new

<Function id="qk_dag_new" signature="QkDag *qk_dag_new(void)">
Construct a new empty DAG.

You must free the returned DAG with qk\_dag\_free when done with it.

<span id="group__QkDag_1autotoc_md50" />

#### Example

```c
QkDag *empty = qk_dag_new();
```

**Returns**

A pointer to the created DAG.
</Function>

### qk\_dag\_add\_quantum\_register

<Function id="qk_dag_add_quantum_register" signature="void qk_dag_add_quantum_register(QkDag *dag, const QkQuantumRegister *reg)">
Add a quantum register to the DAG.

<span id="group__QkDag_1autotoc_md51" />

#### Example

```c
QkDag *dag = qk_dag_new();
QkQuantumRegister *qr = qk_quantum_register_new(1024, "my_register");
qk_dag_add_quantum_register(dag, qr);
qk_quantum_register_free(qr);
qk_dag_free(dag);
```

<span id="group__QkDag_1autotoc_md52" />

#### Safety

<span id="group__QkDag_1autotoc_md52" />

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`.

**Parameters**

* **dag** – A pointer to the DAG.
* **reg** – A pointer to the quantum register.
</Function>

### qk\_dag\_add\_classical\_register

<Function id="qk_dag_add_classical_register" signature="void qk_dag_add_classical_register(QkDag *dag, const QkClassicalRegister *reg)">
Add a classical register to the DAG.

<span id="group__QkDag_1autotoc_md53" />

#### Example

```c
QkDag *dag = qk_dag_new();
QkClassicalRegister *cr = qk_classical_register_new(24, "my_register");
qk_dag_add_classical_register(dag, cr);
qk_classical_register_free(cr);
qk_dag_free(dag);
```

<span id="group__QkDag_1autotoc_md54" />

#### Safety

<span id="group__QkDag_1autotoc_md54" />

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`.

**Parameters**

* **dag** – A pointer to the DAG.
* **reg** – A pointer to the classical register.
</Function>

### qk\_dag\_num\_qubits

<Function id="qk_dag_num_qubits" signature="uint32_t qk_dag_num_qubits(const QkDag *dag)">
Get the number of qubits the DAG contains.

<span id="group__QkDag_1autotoc_md55" />

#### Example

```c
QkDag *dag = qk_dag_new();
QkQuantumRegister *qr = qk_quantum_register_new(24, "my_register");
qk_dag_add_quantum_register(dag, qr);
uint32_t num_qubits = qk_dag_num_qubits(dag); // num_qubits==24
qk_quantum_register_free(qr);
qk_dag_free(dag);
```

<span id="group__QkDag_1autotoc_md56" />

#### Safety

<span id="group__QkDag_1autotoc_md56" />

Behavior is undefined if `dag` is not a valid, non-null pointer to a `QkDag`.

**Parameters**

**dag** – A pointer to the DAG.

**Returns**

The number of qubits the DAG is defined on.
</Function>

### qk\_dag\_num\_clbits

<Function id="qk_dag_num_clbits" signature="uint32_t qk_dag_num_clbits(const QkDag *dag)">
Get the number of clbits the DAG contains.

<span id="group__QkDag_1autotoc_md57" />

#### Example

```c
QkDag *dag = qk_dag_new();
QkClassicalRegister *cr = qk_classical_register_new(24, "my_register");
qk_dag_add_classical_register(dag, cr);
uint32_t num_clbits = qk_dag_num_clbits(dag); // num_clbits==24
qk_classical_register_free(cr);
qk_dag_free(dag);
```

<span id="group__QkDag_1autotoc_md58" />

#### Safety

<span id="group__QkDag_1autotoc_md58" />

Behavior is undefined if `dag` is not a valid, non-null pointer to a `QkDag`.

**Parameters**

**dag** – A pointer to the DAG.

**Returns**

The number of clbits the DAG is defined on.
</Function>

### qk\_dag\_free

<Function id="qk_dag_free" signature="void qk_dag_free(QkDag *dag)">
Free the DAG.

<span id="group__QkDag_1autotoc_md59" />

#### Example

```c
QkDag *dag = qk_dag_new();
qk_dag_free(dag);
```

<span id="group__QkDag_1autotoc_md60" />

#### Safety

<span id="group__QkDag_1autotoc_md60" />

Behavior is undefined if `dag` is not either null or a valid pointer to a `QkDag`.

**Parameters**

**dag** – A pointer to the DAG to free.
</Function>

6 changes: 3 additions & 3 deletions docs/api/qiskit-c/dev/qk-obs-term.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ This is a group of functions for interacting with an opaque (Rust-space) SparseT
<Function id="qk_obsterm_str" signature="char *qk_obsterm_str(const QkObsTerm *term)">
Return a string representation of the sparse term.

<span id="group__QkObsTerm_1autotoc_md142" />
<span id="group__QkObsTerm_1autotoc_md153" />

#### Example

Expand All @@ -78,11 +78,11 @@ This is a group of functions for interacting with an opaque (Rust-space) SparseT
qk_str_free(string);
```

<span id="group__QkObsTerm_1autotoc_md143" />
<span id="group__QkObsTerm_1autotoc_md154" />

#### Safety

<span id="group__QkObsTerm_1autotoc_md143" />
<span id="group__QkObsTerm_1autotoc_md154" />

Behavior is undefined `term` is not a valid, non-null pointer to a `QkObsTerm`.

Expand Down
Loading