Skip to content

Commit 9170f04

Browse files
Update API dev docs (#3738)
An action recently synced the latest dev docs. This PR updates all dev APIs that changed. > [!NOTE] > This pull request was created by a GitHub action. Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 9b5e1ae commit 9170f04

File tree

300 files changed

+2579
-28387
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

300 files changed

+2579
-28387
lines changed

docs/api/qiskit-c/dev/_toc.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
"title": "QkComplex64",
2222
"url": "/docs/api/qiskit-c/dev/qk-complex-64"
2323
},
24+
{
25+
"title": "QkElidePermutationsResult",
26+
"url": "/docs/api/qiskit-c/dev/qk-elide-permutations-result"
27+
},
2428
{
2529
"title": "QkExitCode",
2630
"url": "/docs/api/qiskit-c/dev/qk-exit-code"

docs/api/qiskit-c/dev/index.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ As this interface is still new in Qiskit it should be considered experimental an
3434

3535
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.
3636

37-
* [Transpiler Passes](qk-transpiler-passes)
38-
* [QkVF2LayoutResult](qk-vf-2-layout-result)
3937
* [QkTarget](qk-target)
4038
* [QkTargetEntry](qk-target-entry)
39+
* [Transpiler Passes](qk-transpiler-passes)
40+
* [QkVF2LayoutResult](qk-vf-2-layout-result)
41+
* [QkElidePermutationsResult](qk-elide-permutations-result)
4142

docs/api/qiskit-c/dev/qk-circuit.mdx

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ $$
2626
// Create a circuit with three qubits and 3 classical bits
2727
QkCircuit *qc = qk_circuit_new(3, 0);
2828
// H gate on qubit 0, putting this qubit in a superposition of |0> + |1>.
29-
qk_circuit_gate(qc, QkGate_H, {0}, NULL);
29+
qk_circuit_gate(qc, QkGate_H, (uint32_t[]){0}, NULL);
3030
// A CX (CNOT) gate on control qubit 0 and target qubit 1 generating a Bell state.
31-
qk_circuit_gate(qc, QkGate_CX, {0, 1}, NULL);
31+
qk_circuit_gate(qc, QkGate_CX, (uint32_t[]){0, 1}, NULL);
3232
// A CX (CNOT) gate on control qubit 0 and target qubit 2 generating a GHZ state.
33-
qk_circuit_gate(qc, QkGate_CX, {0, 2}, NULL);
33+
qk_circuit_gate(qc, QkGate_CX, (uint32_t[]){0, 2}, NULL);
3434
// Free the created circuit.
3535
qk_circuit_free(qc);
3636
```
@@ -82,7 +82,7 @@ The circuit C API currently only supports creating circuits that contain operati
8282
8383
This struct represents the data contained in an individual instruction in a `QkCircuit`. It is not a pointer to the underlying object, but contains a copy of the properties of the instruction for inspection.
8484
85-
#### const char \*name
85+
#### char \*name
8686
8787
<Attribute id="name">
8888
The instruction name
@@ -202,7 +202,7 @@ The circuit C API currently only supports creating circuits that contain operati
202202
QkQuantumRegister *qr = qk_quantum_register_new(1024, "my_little_register");
203203
qk_circuit_add_quantum_register(qc, qr);
204204
qk_quantum_register_free(qr);
205-
qk_circuit_free(qc)
205+
qk_circuit_free(qc);
206206
```
207207
208208
<span id="group__QkCircuit_1autotoc_md13" />
@@ -233,7 +233,7 @@ The circuit C API currently only supports creating circuits that contain operati
233233
QkClassicalRegister *cr = qk_classical_register_new(24, "my_big_register");
234234
qk_circuit_add_classical_register(qc, cr);
235235
qk_classical_register_free(cr);
236-
qk_circuit_free(qc)
236+
qk_circuit_free(qc);
237237
```
238238

239239
<span id="group__QkCircuit_1autotoc_md15" />
@@ -391,7 +391,7 @@ The circuit C API currently only supports creating circuits that contain operati
391391

392392
<span id="group__QkCircuit_1autotoc_md25" />
393393

394-
The `qubits` and `params` types are expected to be a pointer to an array of `uint32_t` and `double` respectively where the length is matching the expectations for the standard gate. If the array is insufficently long the behavior of this function is undefined as this will read outside the bounds of the array. It can be a null pointer if there are no qubits or params for a given gate. You can check `qk_gate_num_qubits` and `qk_gate_num_params` to determine how many qubits and params are required for a given gate.
394+
The `qubits` and `params` types are expected to be a pointer to an array of `uint32_t` and `double` respectively where the length is matching the expectations for the standard gate. If the array is insufficiently long the behavior of this function is undefined as this will read outside the bounds of the array. It can be a null pointer if there are no qubits or params for a given gate. You can check `qk_gate_num_qubits` and `qk_gate_num_params` to determine how many qubits and params are required for a given gate.
395395

396396
Behavior is undefined if `circuit` is not a valid, non-null pointer to a `QkCircuit`.
397397

@@ -562,17 +562,16 @@ The circuit C API currently only supports creating circuits that contain operati
562562
#### Example
563563
564564
```c
565-
QkComplex64 c0 = qk_complex64_from_native(0); // 0+0i
566-
QkComplex64 c1 = qk_complex64_from_native(1); // 1+0i
565+
QkComplex64 c0 = {0, 0}; // 0+0i
566+
QkComplex64 c1 = {1, 0}; // 1+0i
567567
568568
const uint32_t num_qubits = 1;
569-
const uint32_t dim = 2;
570-
QkComplex64[dim * dim] unitary = {c0, c1, // row 0
569+
QkComplex64 unitary[2*2] = {c0, c1, // row 0
571570
c1, c0}; // row 1
572571
573572
QkCircuit *circuit = qk_circuit_new(1, 0); // 1 qubit circuit
574-
uint32_t qubit = {0}; // qubit to apply the unitary on
575-
qk_circuit_unitary(circuit, unitary, qubit, num_qubits);
573+
uint32_t qubit[1] = {0}; // qubit to apply the unitary on
574+
qk_circuit_unitary(circuit, unitary, qubit, num_qubits, true);
576575
```
577576

578577
<span id="group__QkCircuit_1autotoc_md35" />
@@ -607,7 +606,7 @@ The circuit C API currently only supports creating circuits that contain operati
607606

608607
```c
609608
QkCircuit *qc = qk_circuit_new(100, 0);
610-
uint32_t qubit[1] = {0};
609+
uint32_t qubits[1] = {0};
611610
qk_circuit_gate(qc, QkGate_H, qubits, NULL);
612611
QkOpCounts counts = qk_circuit_count_ops(qc);
613612
```
@@ -669,16 +668,19 @@ The circuit C API currently only supports creating circuits that contain operati
669668

670669
This function is used to get the instruction details for a given instruction in the circuit.
671670

671+
This function allocates memory internally for the provided `QkCircuitInstruction` and thus you are responsible for calling `qk_circuit_instruction_clear` to free it.
672+
672673
<span id="group__QkCircuit_1autotoc_md40" />
673674

674675
#### Example
675676

676677
```c
677678
QkCircuitInstruction inst;
678-
QkCircuit *qc = qk_circuit_new(100);
679+
QkCircuit *qc = qk_circuit_new(100, 0);
679680
uint32_t qubit[1] = {0};
680681
qk_circuit_gate(qc, QkGate_H, qubit, NULL);
681682
qk_circuit_get_instruction(qc, 0, &inst);
683+
qk_circuit_instruction_clear(&inst);
682684
```
683685
684686
<span id="group__QkCircuit_1autotoc_md41" />
@@ -698,7 +700,7 @@ The circuit C API currently only supports creating circuits that contain operati
698700
699701
### qk\_circuit\_instruction\_clear
700702
701-
<Function id="qk_circuit_instruction_clear" signature="void qk_circuit_instruction_clear(const QkCircuitInstruction *inst)">
703+
<Function id="qk_circuit_instruction_clear" signature="void qk_circuit_instruction_clear(QkCircuitInstruction *inst)">
702704
Clear the data in circuit instruction object.
703705
704706
This function doesn’t free the allocation for the provided `QkCircuitInstruction` pointer, it only frees the internal allocations for the data contained in the instruction. You are responsible for allocating and freeing the actual allocation used to store a `QkCircuitInstruction`.
@@ -709,12 +711,12 @@ The circuit C API currently only supports creating circuits that contain operati
709711
710712
```c
711713
QkCircuitInstruction *inst = malloc(sizeof(QkCircuitInstruction));
712-
QkCircuit *qc = qk_circuit_new(100);
713-
uint32_t q0 = {0};
714+
QkCircuit *qc = qk_circuit_new(100, 0);
715+
uint32_t q0[1] = {0};
714716
qk_circuit_gate(qc, QkGate_H, q0, NULL);
715717
qk_circuit_get_instruction(qc, 0, inst);
716-
qk_circuit_instruction_clear(inst); // free the data
717-
free(inst); // free the pointer
718+
qk_circuit_instruction_clear(inst); // clear internal allocations
719+
free(inst); // free struct
718720
qk_circuit_free(qc); // free the circuit
719721
```
720722

docs/api/qiskit-c/dev/qk-classical-register.mdx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,26 @@ python_api_name: QkClassicalRegister
1212
typedef struct QkClassicalRegister QkClassicalRegister
1313
```
1414

15-
A common way to instantiate several bits at once is to create a register. A register is a named collection of bits. Creating a register enables giving a collection of bits a name which can be use as metadata around specific bits in a circuit. This name will also typically be preseserved when exporting the circuit to interchange languages.
15+
A common way to instantiate several bits at once is to create a register. A register is a named collection of bits. Creating a register enables giving a collection of bits a name which can be use as metadata around specific bits in a circuit. This name will also typically be preserved when exporting the circuit to interchange languages.
1616

1717
You can create a register by calling `qk_classical_register_new()`, for example:
1818

19+
```c
20+
#include <qiskit.h>
21+
22+
QkClassicalRegister *creg = qk_classical_register_new(5, "my_creg");
23+
```
24+
1925
Which creates a new 5 classical bit register named `"my_creg"`.
2026

2127
Then to add the register to a circuit you use the `qk_circuit_add_classical_register()` function:
2228

29+
```c
30+
QkCircuit *qc = qk_circuit_new(0, 0);
31+
qk_circuit_add_classical_register(qc, creg);
32+
uint32_t num_qubits = qk_circuit_num_qubits(qc); // 5
33+
```
34+
2335
While circuits track registers, the registers themselves impart almost no behavioral differences on circuits.
2436
2537
## Functions

docs/api/qiskit-c/dev/qk-complex-64.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ python_api_name: QkComplex64
88

99
# QkComplex64
1010

11-
A complex, double-precision number representation. This data type is used to safely use complex numbers within Qiskit, but is not necessarily designed for easy manipulation on user-side. Instead, we provide functions to convert from compiler-native representation (e.g. `double complex` for GNU or Clang compilers), which allow for ergonomic handling, to Qiskit’s `QkComplex64` representation, which is meant for passing into Qiskit functions and structs.
11+
A complex, double-precision number representation. This data type is used to safely use complex numbers within Qiskit, but is not necessarily designed for easy manipulation on user-side. Instead, we provide functions to convert from compiler-native representation (e.g. `complex double` for GNU or Clang compilers), which allow for ergonomic handling, to Qiskit’s `QkComplex64` representation, which is meant for passing into Qiskit functions and structs.
1212

1313
Explicitly, Qiskit assumes the compiler-native complex number type in C to be `_Dcomplex` for Windows MSVC (if `_MSC_VER` is defined) and `double _Complex` otherwise. In C++ (if `__cplusplus` is defined), the complex number type is always `std::complex<double>`.
1414

@@ -38,11 +38,11 @@ Convert a `QkComplex64` to a compiler-native complex number representation. Note
3838

3939
### Example
4040

41-
Assuming a GNU/clang compiler with `double complex` as native complex number, we have
41+
Assuming a GNU/clang compiler with `complex double` as native complex number, we have
4242

4343
```c
4444
QkComplex64 qk_value = {1, 1}; // represents 1 + i
45-
double complex value = qk_complex64_to_native(&qk_value);
45+
complex double value = qk_complex64_to_native(&qk_value);
4646
```
4747
4848
### Safety
@@ -65,10 +65,10 @@ Convert a compiler-native complex number to a `QkComplex64`. Note that `CMPLX_DO
6565
6666
### Example
6767
68-
Assuming a GNU/clang compiler with `double complex` as native complex number, we have
68+
Assuming a GNU/clang compiler with `complex double` as native complex number, we have
6969
7070
```c
71-
double complex value = 1 + I;
71+
complex double value = 1 + I;
7272
QkComplex64 qk_value = qk_complex64_from_native(&value);
7373
```
7474

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
---
2+
title: QkElidePermutationsResult (dev version)
3+
description: API reference for QkElidePermutationsResult in the dev version of qiskit-c
4+
in_page_toc_min_heading_level: 2
5+
python_api_type: module
6+
python_api_name: QkElidePermutationsResult
7+
---
8+
9+
# QkElidePermutationsResult
10+
11+
```c
12+
typedef struct QkElidePermutationsResult QkElidePermutationsResult
13+
```
14+
15+
When running the `qk_transpiler_pass_standalone_elide_permutations` function it returns a modified circuit and a permutation array as a QkElidePermutationsResult object. This object contains the outcome of the transpiler pass, whether the pass was able to elide any gates or not, and what the results of that elision were.
16+
17+
## Functions
18+
19+
### qk\_elide\_permutations\_result\_elided\_gates
20+
21+
<Function id="qk_elide_permutations_result_elided_gates" signature="bool qk_elide_permutations_result_elided_gates(const QkElidePermutationsResult *result)">
22+
Check whether the elide permutations was able to elide anything
23+
24+
<span id="group__QkElidePermutationsResult_1autotoc_md94" />
25+
26+
#### Safety
27+
28+
<span id="group__QkElidePermutationsResult_1autotoc_md94" />
29+
30+
Behavior is undefined if `result` is not a valid, non-null pointer to a `QkElidePermutationsResult`.
31+
32+
**Parameters**
33+
34+
**result** – a pointer to the result
35+
36+
**Returns**
37+
38+
`true` if the `qk_transpiler_pass_standalone_elide_permutations()` run elided any gates
39+
</Function>
40+
41+
### qk\_elide\_permutations\_result\_circuit
42+
43+
<Function id="qk_elide_permutations_result_circuit" signature="const QkCircuit *qk_elide_permutations_result_circuit(const QkElidePermutationsResult *result)">
44+
Get the circuit from the elide permutations result
45+
46+
<span id="group__QkElidePermutationsResult_1autotoc_md95" />
47+
48+
#### Safety
49+
50+
<span id="group__QkElidePermutationsResult_1autotoc_md95" />
51+
52+
Behavior is undefined if `result` is not a valid, non-null pointer to a `QkElidePermutationsResult`. The pointer to the returned circuit is owned by the result object, it should not be passed to `qk_circuit_free()` as it will be freed by `qk_elide_permutations_result_free()`.
53+
54+
**Parameters**
55+
56+
**result** – a pointer to the result of the pass. It must have elided gates as checked by `qk_elide_permutations_result_elided_gates()`
57+
58+
**Returns**
59+
60+
A pointer to the circuit with the permutation gates elided
61+
</Function>
62+
63+
### qk\_elide\_permutations\_result\_permutation
64+
65+
<Function id="qk_elide_permutations_result_permutation" signature="const uintptr_t *qk_elide_permutations_result_permutation(const QkElidePermutationsResult *result)">
66+
Get the permutation array for the elided gates
67+
68+
<span id="group__QkElidePermutationsResult_1autotoc_md96" />
69+
70+
#### Safety
71+
72+
<span id="group__QkElidePermutationsResult_1autotoc_md96" />
73+
74+
Behavior is undefined if `layout` is not a valid, non-null pointer to a `QkElidePermutationsResult`. Also qubit must be a valid qubit for the circuit and there must be a result found. The pointer to the permutation array is owned by the result object, it should not be passed to `free()` as it will be freed by `qk_elide_permutations_result_free()` when that is called.
75+
76+
**Parameters**
77+
78+
**result** – a pointer to the result of the pass. It must have elided gates as checked by `qk_elide_permutations_result_elided_gates()`
79+
80+
**Returns**
81+
82+
A pointer to the permutation array caused by the swap elision performed by the pass. This array has a length equal to the number of qubits of the circuit returned by `qk_elide_permutations_result_elided_gates()` (or the circuit passed into `qk_transpiler_pass_standalone_elide_permutations()`). The permutation array maps the virtual qubit in the original circuit at each index to its new output position after all the elision performed by the pass. For example, and array of `[2, 1, 0]` means that qubit 0 is now in qubit 2 on the output of the circuit and qubit 2’s is now at 0 (qubit 1 remains unchanged)
83+
</Function>
84+
85+
### qk\_elide\_permutations\_result\_free
86+
87+
<Function id="qk_elide_permutations_result_free" signature="void qk_elide_permutations_result_free(QkElidePermutationsResult *result)">
88+
Free a `QkElidePermutationsResult` object
89+
90+
<span id="group__QkElidePermutationsResult_1autotoc_md97" />
91+
92+
#### Safety
93+
94+
<span id="group__QkElidePermutationsResult_1autotoc_md97" />
95+
96+
Behavior is undefined if `layout` is not a valid, non-null pointer to a `QkElidePermutationsResult`.
97+
98+
**Parameters**
99+
100+
**result** – a pointer to the result object to free
101+
</Function>
102+

0 commit comments

Comments
 (0)