Skip to content

Commit

Permalink
Merge pull request #36 from Cryoris/c-api
Browse files Browse the repository at this point in the history
Implement term handling & docs
  • Loading branch information
Cryoris authored Dec 20, 2024
2 parents be5b395 + fd62fa8 commit 74e9fda
Show file tree
Hide file tree
Showing 6 changed files with 1,062 additions and 126 deletions.
398 changes: 397 additions & 1 deletion crates/accelerate/src/py_sparse_observable.rs

Large diffs are not rendered by default.

33 changes: 30 additions & 3 deletions crates/accelerate/src/sparse_observable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1427,13 +1427,40 @@ impl SparseTerm {
coeff: Complex64,
bit_terms: Box<[BitTerm]>,
indices: Box<[u32]>,
) -> Self {
Self {
) -> Result<Self, CoherenceError> {
if bit_terms.len() != indices.len() {
return Err(CoherenceError::MismatchedItemCount {
bit_terms: bit_terms.len(),
indices: indices.len(),
});
}

if indices.iter().any(|index| *index >= num_qubits) {
return Err(CoherenceError::BitIndexTooHigh);
}

Ok(Self {
num_qubits,
coeff,
bit_terms,
indices,
}
})
}

pub fn num_qubits(&self) -> u32 {
self.num_qubits
}

pub fn coeff(&self) -> Complex64 {
self.coeff
}

pub fn indices<'a>(&'a self) -> &'a [u32] {
&self.indices
}

pub fn bit_terms<'a>(&'a self) -> &'a [BitTerm] {
&self.bit_terms
}

pub fn view(&self) -> SparseTermView {
Expand Down
3 changes: 3 additions & 0 deletions crates/c_ext/cbindgen.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ typedef double complex Complex64;
[parse]
parse_deps = true
include = ["qiskit-accelerate"]

[enum]
prefix_with_name = true
6 changes: 0 additions & 6 deletions crates/c_ext/src/bit_term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@

use qiskit_accelerate::sparse_observable::BitTerm;

#[no_mangle]
#[cfg(feature = "cbinding")]
pub extern "C" fn hello() {
println!("Sparse observable will go here!");
}

#[no_mangle]
#[cfg(feature = "cbinding")]
pub extern "C" fn bit_term(bit: u8) -> *mut BitTerm {
Expand Down
Loading

0 comments on commit 74e9fda

Please sign in to comment.