ket-lang 0.10.2.dev0__tar.gz → 0.10.2.dev2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {ket_lang-0.10.2.dev0/src/ket_lang.egg-info → ket_lang-0.10.2.dev2}/PKG-INFO +1 -1
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/__init__.py +1 -1
- {ket_lang-0.10.2.dev0/src/ket/clib/libs/libket → ket_lang-0.10.2.dev2/src/ket/clib/libs/kbw}/cbindgen.toml +8 -1
- ket_lang-0.10.2.dev2/src/ket/clib/libs/kbw/kbw.h +68 -0
- ket_lang-0.10.2.dev2/src/ket/clib/libs/libket/cbindgen.toml +14 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/libket.h +43 -1
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/mps.py +4 -1
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/qulib/__init__.py +116 -2
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2/src/ket_lang.egg-info}/PKG-INFO +1 -1
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket_lang.egg-info/SOURCES.txt +2 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/LICENSE +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/MANIFEST.in +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/README.md +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/pyproject.toml +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/setup.cfg +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/setup.py +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/amazon.py +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/base.py +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/__init__.py +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/kbw.py +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libket/__init__.py +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libket/execution.py +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/__init__.py +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/kbw/.git +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/kbw/.gitignore +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/kbw/.gitlab-ci.yml +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/kbw/.pre-commit-config.yaml +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/kbw/CHANGELOG.md +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/kbw/Cargo.toml +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/kbw/LICENSE +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/kbw/LICENSES/Apache-2.0.txt +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/kbw/README.md +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/kbw/REUSE.toml +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/kbw/build.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/kbw/examples/grover_batch.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/kbw/examples/grover_live.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/kbw/examples/grover_live_dv2.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/kbw/src/bitwise.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/kbw/src/block.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/kbw/src/c_api.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/kbw/src/convert.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/kbw/src/dense.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/kbw/src/dense_gpu/kernel.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/kbw/src/dense_gpu/mod.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/kbw/src/dense_v2.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/kbw/src/lib.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/kbw/src/quantum_execution.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/kbw/src/sparse.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/kbw/src/sparse_v2.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/.git +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/.gitignore +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/.gitlab-ci.yml +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/.pre-commit-config.yaml +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/CHANGELOG.md +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/Cargo.toml +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/LICENSE +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/LICENSES/Apache-2.0.txt +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/README.md +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/REUSE.toml +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/build.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/examples/grover.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/examples/qft.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/src/c_api/block.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/src/c_api/execute.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/src/c_api/mod.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/src/c_api/process.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/src/decompose/mod.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/src/decompose/network.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/src/decompose/su2.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/src/decompose/u2.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/src/decompose/util.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/src/decompose/x/c2to4x.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/src/decompose/x/mod.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/src/decompose/x/single_aux.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/src/decompose/x/v_chain.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/src/error.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/src/execution.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/src/ir/block.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/src/ir/gate.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/src/ir/hamiltonian.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/src/ir/mod.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/src/lib.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/src/mapping/allocation.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/src/mapping/dynamic_look_ahead.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/src/mapping/graph.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/src/mapping/mod.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/src/matrix.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/src/process/classical_shadow.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/src/process/mod.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/src/process/qwc.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/src/qasm/ast.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/src/qasm/executor.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/src/qasm/gates.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/src/qasm/mod.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/src/qasm/openqasm.lalrpop +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/src/tests.rs +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/wrapper.py +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/expv.py +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/fermion.py +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/gates.py +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/ibm.py +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/measurement.py +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/npsim.py +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/operations.py +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/qint.py +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/quantumstate.py +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/qulib/gates.py +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/qulib/ham.py +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/qulib/oracle.py +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/qulib/prepare.py +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket_lang.egg-info/dependency_links.txt +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket_lang.egg-info/not-zip-safe +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket_lang.egg-info/requires.txt +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket_lang.egg-info/top_level.txt +0 -0
- {ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/tests/test_fermion.py +0 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* SPDX-FileCopyrightText: 2026 Evandro Chagas Ribeiro da Rosa<evandro@quantuloop.com>
|
|
3
|
+
*
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include <stdarg.h>
|
|
11
|
+
#include <stdbool.h>
|
|
12
|
+
#include <stdint.h>
|
|
13
|
+
#include <stdlib.h>
|
|
14
|
+
|
|
15
|
+
#ifdef __cplusplus
|
|
16
|
+
extern "C" {
|
|
17
|
+
#endif // __cplusplus
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Create a [`QPUConfig`] for the requested simulator and write the heap
|
|
21
|
+
* pointer into `*qpu_config`.
|
|
22
|
+
*
|
|
23
|
+
* # Parameters
|
|
24
|
+
*
|
|
25
|
+
* * `num_qubits`: number of qubits to allocate.
|
|
26
|
+
* * `simulator`: NUL-terminated C string naming the backend. Recognised
|
|
27
|
+
* values (case-insensitive, whitespace ignored): `"dense"`, `"densev2"`,
|
|
28
|
+
* `"densegpu"`, `"sparse"`, `"sparsev2"`.
|
|
29
|
+
* * `use_live`: `true` for live (gate-by-gate) mode; `false` for batch mode.
|
|
30
|
+
* * `gradient`: enable the parameter-shift-rule gradient strategy (batch
|
|
31
|
+
* mode only).
|
|
32
|
+
* * `coupling_graph_json`: JSON-encoded `Vec<[usize; 2]>` describing allowed
|
|
33
|
+
* two-qubit pairs, or a JSON `null` for all-to-all connectivity.
|
|
34
|
+
* * `qpu_config`: out-parameter; set to the newly allocated config on
|
|
35
|
+
* success.
|
|
36
|
+
*
|
|
37
|
+
* # Returns
|
|
38
|
+
*
|
|
39
|
+
* A `KetError` integer code: `0` on success, non-zero on failure.
|
|
40
|
+
*
|
|
41
|
+
* # Safety
|
|
42
|
+
*
|
|
43
|
+
* * `simulator` must be a valid, NUL-terminated C string.
|
|
44
|
+
* * `coupling_graph_json` must be a valid, NUL-terminated C string containing
|
|
45
|
+
* either a JSON array of two-element integer arrays or `null`.
|
|
46
|
+
* * `qpu_config` must be a non-null, aligned, writable pointer.
|
|
47
|
+
*/
|
|
48
|
+
int32_t kbw_make_configuration(uintptr_t num_qubits,
|
|
49
|
+
const char *simulator,
|
|
50
|
+
bool use_live,
|
|
51
|
+
bool decompose,
|
|
52
|
+
bool gradient,
|
|
53
|
+
const char *coupling_graph_json,
|
|
54
|
+
void **qpu_config);
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Return a static string describing the KBW build.
|
|
58
|
+
*
|
|
59
|
+
* Sets `*msg` to the UTF-8 bytes of the build-info string and `*size` to
|
|
60
|
+
* its byte length. The pointer is valid for the lifetime of the process.
|
|
61
|
+
*
|
|
62
|
+
* Returns a `KetError` integer code (always `0` = success).
|
|
63
|
+
*/
|
|
64
|
+
int32_t kbw_build_info(const uint8_t **msg, uintptr_t *size);
|
|
65
|
+
|
|
66
|
+
#ifdef __cplusplus
|
|
67
|
+
} // extern "C"
|
|
68
|
+
#endif // __cplusplus
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
header = """
|
|
2
|
+
/*
|
|
3
|
+
* SPDX-FileCopyrightText: 2026 Evandro Chagas Ribeiro da Rosa<evandro@quantuloop.com>
|
|
4
|
+
*
|
|
5
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
6
|
+
*/
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
language = "C"
|
|
10
|
+
pragma_once = true
|
|
11
|
+
cpp_compat = true
|
|
12
|
+
|
|
13
|
+
[defines]
|
|
14
|
+
"feature = qasm" = "FEATURE_QASM"
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
8
10
|
#include <stdarg.h>
|
|
9
11
|
#include <stdbool.h>
|
|
10
12
|
#include <stdint.h>
|
|
@@ -184,6 +186,10 @@ typedef struct CBatchExecution {
|
|
|
184
186
|
const char **grad_json);
|
|
185
187
|
} CBatchExecution;
|
|
186
188
|
|
|
189
|
+
#ifdef __cplusplus
|
|
190
|
+
extern "C" {
|
|
191
|
+
#endif // __cplusplus
|
|
192
|
+
|
|
187
193
|
/**
|
|
188
194
|
* Retrieves the human-readable error message for a given integer error code.
|
|
189
195
|
*
|
|
@@ -345,7 +351,7 @@ int32_t ket_quantum_execution_batch(uintptr_t num_qubits,
|
|
|
345
351
|
const struct CBatchExecution *batch,
|
|
346
352
|
const struct CNativeGateSet *native_gate_set,
|
|
347
353
|
bool decompose,
|
|
348
|
-
|
|
354
|
+
const char *gradient_strategy_json,
|
|
349
355
|
const char *coupling_graph_json,
|
|
350
356
|
const char *exp_value_strategy_json,
|
|
351
357
|
struct QPUConfig **qpu_config);
|
|
@@ -672,3 +678,39 @@ int32_t ket_process_status(const struct Process *process, const char **status);
|
|
|
672
678
|
* `0` on success, non-zero error code on failure.
|
|
673
679
|
*/
|
|
674
680
|
int32_t ket_process_set_parameter(struct Process *process, double value, uintptr_t *index);
|
|
681
|
+
|
|
682
|
+
#if defined(FEATURE_QASM)
|
|
683
|
+
/**
|
|
684
|
+
* Parses an `OpenQASM` 2.0 source string and returns a heap-allocated
|
|
685
|
+
* [`BasicBlock`] containing the resulting gate sequence.
|
|
686
|
+
*
|
|
687
|
+
* Physical qubit indices are mapped to the `qreg` declarations in the source
|
|
688
|
+
* in order. The total number of entries in `qubits` must be ≥ the sum of all
|
|
689
|
+
* `qreg` sizes declared in `qasm`.
|
|
690
|
+
*
|
|
691
|
+
* `measure` statements are **not** executed. Their qubit-to-cbit mapping is
|
|
692
|
+
* recorded so that subsequent `if` statements are converted to controlled
|
|
693
|
+
* quantum gates instead of classical branches.
|
|
694
|
+
*
|
|
695
|
+
* On success, a newly heap-allocated `BasicBlock` is written to `*block_out`.
|
|
696
|
+
* The caller takes ownership and must eventually free it with
|
|
697
|
+
* [`ket_block_delete`].
|
|
698
|
+
*
|
|
699
|
+
* # Parameters
|
|
700
|
+
* - `qubits` : Pointer to an array of `size_t` physical qubit indices.
|
|
701
|
+
* - `qubits_len` : Number of entries in `qubits`.
|
|
702
|
+
* - `qasm` : Null-terminated C string with the `OpenQASM` 2.0 source.
|
|
703
|
+
* - `block_out` : Output: on success, set to a pointer to the new `BasicBlock`.
|
|
704
|
+
*
|
|
705
|
+
* # Returns
|
|
706
|
+
* `0` on success, non-zero error code on failure.
|
|
707
|
+
*/
|
|
708
|
+
int32_t ket_parse_openqasm(const uintptr_t *qubits,
|
|
709
|
+
uintptr_t qubits_len,
|
|
710
|
+
const char *qasm,
|
|
711
|
+
struct BasicBlock **block_out);
|
|
712
|
+
#endif
|
|
713
|
+
|
|
714
|
+
#ifdef __cplusplus
|
|
715
|
+
} // extern "C"
|
|
716
|
+
#endif // __cplusplus
|
|
@@ -161,6 +161,8 @@ class MPS(BatchExecution):
|
|
|
161
161
|
shapes and disables JAX's ``jit`` compilation, which may result in slower evaluations.
|
|
162
162
|
If ``None``, the network is built in 2D and contracted fully at the end,
|
|
163
163
|
which is JIT-compatible but may scale poorly with depth. Defaults to ``None``.
|
|
164
|
+
double_precision: Whether to enable 64-bit floating point precision (double precision) in
|
|
165
|
+
JAX. Defaults to ``False``. Set to ``True`` for higher accuracy in deep circuits.
|
|
164
166
|
"""
|
|
165
167
|
|
|
166
168
|
def __init__(
|
|
@@ -168,13 +170,14 @@ class MPS(BatchExecution):
|
|
|
168
170
|
num_qubits: int,
|
|
169
171
|
backend: Literal["cpu", "gpu"] = "cpu",
|
|
170
172
|
max_bond: int = None,
|
|
173
|
+
double_precision: bool = False,
|
|
171
174
|
):
|
|
172
175
|
super().__init__()
|
|
173
176
|
self.num_qubits = num_qubits
|
|
174
177
|
self.max_bond = max_bond
|
|
175
178
|
if backend not in ["cpu", "gpu"]:
|
|
176
179
|
raise ValueError("backend must be 'cpu' or 'gpu'")
|
|
177
|
-
jax.config.update("jax_enable_x64",
|
|
180
|
+
jax.config.update("jax_enable_x64", double_precision)
|
|
178
181
|
jax.config.update("jax_platform_name", backend)
|
|
179
182
|
|
|
180
183
|
self.last_grad = None
|
|
@@ -14,9 +14,10 @@ from functools import reduce
|
|
|
14
14
|
from operator import add
|
|
15
15
|
import os
|
|
16
16
|
import random
|
|
17
|
-
from typing import Callable
|
|
17
|
+
from typing import Callable
|
|
18
18
|
from math import sqrt, exp
|
|
19
19
|
from collections.abc import Iterable
|
|
20
|
+
from collections import Counter
|
|
20
21
|
from inspect import signature
|
|
21
22
|
from itertools import starmap
|
|
22
23
|
|
|
@@ -28,7 +29,7 @@ except ImportError:
|
|
|
28
29
|
_MULTIPROCESS_AVAILABLE = False
|
|
29
30
|
|
|
30
31
|
|
|
31
|
-
from ..clib.libket.execution import
|
|
32
|
+
from ..clib.libket.execution import LiveExecution
|
|
32
33
|
from ..base import Process, Quant
|
|
33
34
|
from ..operations import dump, exp_value
|
|
34
35
|
from ..gates import H, CNOT, X, Z, obs
|
|
@@ -678,3 +679,116 @@ def exact_solver(
|
|
|
678
679
|
),
|
|
679
680
|
key=lambda se: se[1],
|
|
680
681
|
)
|
|
682
|
+
|
|
683
|
+
|
|
684
|
+
class GateCount(LiveExecution):
|
|
685
|
+
"""Live Execution simulator that counts the quantum gates and CNOT depth.
|
|
686
|
+
|
|
687
|
+
Example:
|
|
688
|
+
.. code-block:: python
|
|
689
|
+
|
|
690
|
+
|
|
691
|
+
from ket import *
|
|
692
|
+
from ket.qulib import GateCount
|
|
693
|
+
|
|
694
|
+
gc = GateCount(3)
|
|
695
|
+
p = Process(gc)
|
|
696
|
+
q = p.alloc(3)
|
|
697
|
+
H(q[0])
|
|
698
|
+
CNOT(q[0], q[1])
|
|
699
|
+
X(q[2])
|
|
700
|
+
CNOT(q[1], q[2])
|
|
701
|
+
H(q)
|
|
702
|
+
|
|
703
|
+
# Trigger execution
|
|
704
|
+
m = measure(q)
|
|
705
|
+
|
|
706
|
+
print("Gate Counts:", gc.counts)
|
|
707
|
+
print("CNOT Depth:", gc.cnot_depth)
|
|
708
|
+
|
|
709
|
+
|
|
710
|
+
Args:
|
|
711
|
+
num_qubits: number of qubits.
|
|
712
|
+
"""
|
|
713
|
+
|
|
714
|
+
def __init__(self, num_qubits: int):
|
|
715
|
+
super().__init__()
|
|
716
|
+
self.num_qubits = num_qubits
|
|
717
|
+
self.counts = Counter()
|
|
718
|
+
self.depths = [0] * num_qubits
|
|
719
|
+
self.cnot_depth = 0
|
|
720
|
+
|
|
721
|
+
def connect(self):
|
|
722
|
+
return self.configure(self.num_qubits, decompose=True)
|
|
723
|
+
|
|
724
|
+
def _update_cnot_depth(self, control: list[int], target: int):
|
|
725
|
+
new_depth = max(self.depths[target], *(self.depths[c] for c in control)) + 1
|
|
726
|
+
for c in control:
|
|
727
|
+
self.depths[c] = new_depth
|
|
728
|
+
self.depths[target] = new_depth
|
|
729
|
+
self.cnot_depth = max(self.cnot_depth, new_depth)
|
|
730
|
+
|
|
731
|
+
def pauli_x(self, target: int, control: list[int]):
|
|
732
|
+
if control:
|
|
733
|
+
if len(control) == 1:
|
|
734
|
+
self.counts["cnot"] += 1
|
|
735
|
+
else:
|
|
736
|
+
self.counts[f"c{len(control)}x"] += 1
|
|
737
|
+
self._update_cnot_depth(control, target)
|
|
738
|
+
else:
|
|
739
|
+
self.counts["x"] += 1
|
|
740
|
+
|
|
741
|
+
def pauli_y(self, target: int, control: list[int]):
|
|
742
|
+
if control:
|
|
743
|
+
self.counts[f"c{len(control)}y"] += 1
|
|
744
|
+
self._update_cnot_depth(control, target)
|
|
745
|
+
else:
|
|
746
|
+
self.counts["y"] += 1
|
|
747
|
+
|
|
748
|
+
def pauli_z(self, target: int, control: list[int]):
|
|
749
|
+
if control:
|
|
750
|
+
if len(control) == 1:
|
|
751
|
+
self.counts["cz"] += 1
|
|
752
|
+
else:
|
|
753
|
+
self.counts[f"c{len(control)}z"] += 1
|
|
754
|
+
self._update_cnot_depth(control, target)
|
|
755
|
+
else:
|
|
756
|
+
self.counts["z"] += 1
|
|
757
|
+
|
|
758
|
+
def hadamard(self, target: int, control: list[int]):
|
|
759
|
+
if control:
|
|
760
|
+
self.counts[f"c{len(control)}h"] += 1
|
|
761
|
+
self._update_cnot_depth(control, target)
|
|
762
|
+
else:
|
|
763
|
+
self.counts["h"] += 1
|
|
764
|
+
|
|
765
|
+
def rotation_x(self, target: int, control: list[int], angle: float):
|
|
766
|
+
if control:
|
|
767
|
+
self.counts[f"c{len(control)}rx"] += 1
|
|
768
|
+
self._update_cnot_depth(control, target)
|
|
769
|
+
else:
|
|
770
|
+
self.counts["rx"] += 1
|
|
771
|
+
|
|
772
|
+
def rotation_y(self, target: int, control: list[int], angle: float):
|
|
773
|
+
if control:
|
|
774
|
+
self.counts[f"c{len(control)}ry"] += 1
|
|
775
|
+
self._update_cnot_depth(control, target)
|
|
776
|
+
else:
|
|
777
|
+
self.counts["ry"] += 1
|
|
778
|
+
|
|
779
|
+
def rotation_z(self, target: int, control: list[int], angle: float):
|
|
780
|
+
if control:
|
|
781
|
+
self.counts[f"c{len(control)}rz"] += 1
|
|
782
|
+
self._update_cnot_depth(control, target)
|
|
783
|
+
else:
|
|
784
|
+
self.counts["rz"] += 1
|
|
785
|
+
|
|
786
|
+
def phase(self, target: int, control: list[int], angle: float):
|
|
787
|
+
if control:
|
|
788
|
+
self.counts[f"c{len(control)}p"] += 1
|
|
789
|
+
self._update_cnot_depth(control, target)
|
|
790
|
+
else:
|
|
791
|
+
self.counts["p"] += 1
|
|
792
|
+
|
|
793
|
+
def measure(self, qubits: list[int]) -> int:
|
|
794
|
+
return 0
|
|
@@ -33,6 +33,8 @@ src/ket/clib/libs/kbw/LICENSE
|
|
|
33
33
|
src/ket/clib/libs/kbw/README.md
|
|
34
34
|
src/ket/clib/libs/kbw/REUSE.toml
|
|
35
35
|
src/ket/clib/libs/kbw/build.rs
|
|
36
|
+
src/ket/clib/libs/kbw/cbindgen.toml
|
|
37
|
+
src/ket/clib/libs/kbw/kbw.h
|
|
36
38
|
src/ket/clib/libs/kbw/LICENSES/Apache-2.0.txt
|
|
37
39
|
src/ket/clib/libs/kbw/examples/grover_batch.rs
|
|
38
40
|
src/ket/clib/libs/kbw/examples/grover_live.rs
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/kbw/examples/grover_batch.rs
RENAMED
|
File without changes
|
|
File without changes
|
{ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/kbw/examples/grover_live_dv2.rs
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/kbw/src/quantum_execution.rs
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/.pre-commit-config.yaml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/LICENSES/Apache-2.0.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/src/decompose/network.rs
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/src/decompose/util.rs
RENAMED
|
File without changes
|
{ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/src/decompose/x/c2to4x.rs
RENAMED
|
File without changes
|
{ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/src/decompose/x/mod.rs
RENAMED
|
File without changes
|
{ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/src/decompose/x/single_aux.rs
RENAMED
|
File without changes
|
{ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/src/decompose/x/v_chain.rs
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/src/ir/hamiltonian.rs
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/src/mapping/allocation.rs
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ket_lang-0.10.2.dev0 → ket_lang-0.10.2.dev2}/src/ket/clib/libs/libket/src/qasm/openqasm.lalrpop
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|