Skip to content

Commit 5335357

Browse files
committed
Merge remote-tracking branch 'origin/main' into mimalloc
2 parents b20a183 + 43e9c17 commit 5335357

60 files changed

Lines changed: 1633 additions & 488 deletions

Some content is hidden

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

Cargo.lock

Lines changed: 64 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ qiskit-cext = { path = "crates/cext" }
5959
qiskit-cext-vtable = { path = "crates/cext-vtable" }
6060
qiskit-circuit = { path = "crates/circuit" }
6161
qiskit-circuit-library = { path = "crates/circuit_library" }
62+
qiskit-providers = { path = "crates/providers" }
6263
qiskit-qasm2 = { path = "crates/qasm2" }
6364
qiskit-qasm3 = { path = "crates/qasm3" }
6465
qiskit-qpy = { path = "crates/qpy" }

crates/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ The intention is that (much) longer term, we might be wanting to expose more of
3030
* `qiskit-synthesis` is the crate for synthesis functionality.
3131
* `qiskit-circuit-library` is the crate for circuit library functions. It contains constructors or other
3232
circuit functionality that builds on the core circuit data model defined in `qiskit-circuit`.
33+
* `qiskit-providers` is the crate that defines the providers interface for Qiskit. The providers interface is what defines the concept of a Backend.
34+
The backend models a quantum computer, which is the QPU and the infrastructure around it required to execute circuits on the quantum computer.
3335
* `qiskit-util` is for small utility functions and data structures that are independent of all
3436
Qiskit-specific objects, so it can be depended-on by both `quantum-info` and `circuit`.
3537

crates/bindgen/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ name = "qiskit_bindgen"
1414

1515
[dependencies]
1616
anyhow.workspace = true
17-
cbindgen.workspace = true
17+
cbindgen = { workspace = true, features = ["unstable_ir"] }
18+
hashbrown.workspace = true

crates/bindgen/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
// copyright notice, and modified files need to carry a notice indicating
1111
// that they have been altered from the originals.
1212

13+
pub mod render;
14+
1315
use std::fs;
1416
use std::io::Write;
1517
use std::path::{Path, PathBuf};

crates/bindgen/src/render/c.rs

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// This code is part of Qiskit.
2+
//
3+
// (C) Copyright IBM 2026
4+
//
5+
// This code is licensed under the Apache License, Version 2.0. You may
6+
// obtain a copy of this license in the LICENSE.txt file in the root directory
7+
// of this source tree or at https://www.apache.org/licenses/LICENSE-2.0.
8+
//
9+
// Any modifications or derivative works of this code must retain this
10+
// copyright notice, and modified files need to carry a notice indicating
11+
// that they have been altered from the originals.
12+
13+
use cbindgen::bindgen::ir;
14+
use hashbrown::HashMap;
15+
16+
/// Render a given type object into a string representing it in C.
17+
fn render_type(ty: &ir::Type, config: &cbindgen::Config) -> String {
18+
fn render(ty: &ir::Type, config: &cbindgen::Config, acc: &mut String) {
19+
match ty {
20+
ir::Type::Ptr {
21+
ty,
22+
is_const,
23+
is_nullable: _,
24+
is_ref,
25+
} => {
26+
assert!(!is_ref, "C++ reference-likes not handled");
27+
if *is_const {
28+
acc.push_str("const ");
29+
}
30+
render(ty, config, acc);
31+
acc.push_str(" *");
32+
}
33+
ir::Type::Path(p) => acc.push_str(p.export_name()),
34+
ir::Type::Primitive(ty) => acc.push_str(ty.to_repr_c(config)),
35+
ir::Type::Array(..) => todo!("array types not yet handled"),
36+
ir::Type::FuncPtr {
37+
args,
38+
ret,
39+
is_nullable,
40+
never_return,
41+
} => {
42+
assert!(!is_nullable, "nullability of funcptrs is not handled");
43+
assert!(!never_return, "diverging functions not handled");
44+
render(ret, config, acc);
45+
acc.push_str("(*)(");
46+
let mut args = args.iter();
47+
if let Some((_, first)) = args.next() {
48+
render(first, config, acc);
49+
for (_, arg) in args {
50+
acc.push_str(", ");
51+
render(arg, config, acc)
52+
}
53+
}
54+
acc.push(')');
55+
}
56+
}
57+
}
58+
let mut acc = String::new();
59+
render(ty, config, &mut acc);
60+
acc
61+
}
62+
63+
/// Calculate a mapping of exported function names to C casts to appropriate function-pointer types.
64+
pub fn functions_as_funcptr_casts(bindings: &cbindgen::Bindings) -> HashMap<&str, String> {
65+
let to_funcptr = |func: &ir::Function| {
66+
let to_funcptr_arg = |arg: &ir::FunctionArgument| {
67+
let ir::FunctionArgument {
68+
name: _,
69+
ty,
70+
array_length,
71+
} = arg;
72+
assert!(array_length.is_none(), "array arguments not handled");
73+
(None, ty.clone())
74+
};
75+
ir::Type::FuncPtr {
76+
ret: Box::new(func.ret.clone()),
77+
args: func.args.iter().map(to_funcptr_arg).collect(),
78+
is_nullable: false,
79+
never_return: false,
80+
}
81+
};
82+
let config = &bindings.config;
83+
bindings
84+
.functions
85+
.iter()
86+
.map(|func| {
87+
let funcptr = to_funcptr(func);
88+
(func.path.name(), render_type(&funcptr, config))
89+
})
90+
.collect()
91+
}

crates/bindgen/src/render/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// This code is part of Qiskit.
2+
//
3+
// (C) Copyright IBM 2026
4+
//
5+
// This code is licensed under the Apache License, Version 2.0. You may
6+
// obtain a copy of this license in the LICENSE.txt file in the root directory
7+
// of this source tree or at https://www.apache.org/licenses/LICENSE-2.0.
8+
//
9+
// Any modifications or derivative works of this code must retain this
10+
// copyright notice, and modified files need to carry a notice indicating
11+
// that they have been altered from the originals.
12+
13+
pub mod c;

crates/cext/src/transpiler/transpile_function.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ pub struct TranspileOptions {
171171
/// The seed for the transpiler. If set to a negative number this means no seed will be
172172
/// set and the RNGs used in the transpiler will be seeded from system entropy.
173173
seed: i64,
174-
/// The approximation degree a heurstic dial where 1.0 means no approximation (up to numerical
174+
/// The approximation degree a heuristic dial where 1.0 means no approximation (up to numerical
175175
/// tolerance) and 0.0 means the maximum approximation. A `NAN` value indicates that
176176
/// approximation is allowed up to the reported error rate for an operation in the target.
177177
approximation_degree: f64,

crates/circuit/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ nom-language.workspace = true
3333
crossterm = "0.29.0"
3434
unicode-width = "0.2"
3535
unicode-segmentation = "1.13"
36+
lexical-core = "1.0.6"
37+
lexical-write-float = "1.0.6"
3638

3739
[dependencies.pyo3]
3840
workspace = true

0 commit comments

Comments
 (0)