Skip to content

Commit

Permalink
Add prob_perm() (v0.3.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
WrathfulSpatula committed Feb 23, 2023
1 parent 1540942 commit 9f549ab
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "qook"
version = "0.2.0"
version = "0.3.0"
license = "MIT"
description = "qook - Pure Rust unitaryfund/qrack Wrapper"
documentation = "https://pyqrack.readthedocs.io/en/latest/"
Expand Down
2 changes: 2 additions & 0 deletions include/pinvoke_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ MICROSOFT_QUANTUM_DECL void set_concurrency(_In_ uintq sid, _In_ uintq p);

// pseudo-quantum
MICROSOFT_QUANTUM_DECL double Prob(_In_ uintq sid, _In_ uintq q);
MICROSOFT_QUANTUM_DECL double PermutationProb(
_In_ uintq sid, _In_ uintq n, _In_reads_(n) uintq* q, _In_reads_(n) bool* c);
MICROSOFT_QUANTUM_DECL double PermutationExpectation(_In_ uintq sid, _In_ uintq n, _In_reads_(n) uintq* c);

MICROSOFT_QUANTUM_DECL void DumpIds(_In_ uintq sid, _In_ IdCallback callback);
Expand Down
29 changes: 29 additions & 0 deletions src/qrack_simulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2148,6 +2148,35 @@ impl QrackSimulator {
// self.check_error()
// }

pub fn prob_perm(&self, q: Vec<u64>, c: Vec<bool>) -> Result<f64, QrackError> {
// Probability of permutation
//
// Get the probability that the qubit IDs in "q" have the truth values
// in "c", directly corresponding by vector index.
//
// Args:
// q(Vec<u64>): qubit ids
// c(Vec<bool>): qubit truth values
//
// Raises:
// RuntimeError: QrackSimulator raised an exception.
//
// Returns:
// probability that each qubit in "q[i]" has corresponding truth
// value in "c[i]", at once

let mut _q = q.to_vec();
let mut _c = c.to_vec();
let result:f64;
unsafe {
result = qrack_system::PermutationProb(self.sid, _q.len() as u64, _q.as_mut_ptr(), _c.as_mut_ptr());
}
if self.get_error() != 0 {
return Err(QrackError{});
}
Ok(result)
}

pub fn prob(&self, q: u64) -> Result<f64, QrackError> {
// Probability of `|1>`
//
Expand Down
3 changes: 3 additions & 0 deletions src/qrack_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ extern "C" {
extern "C" {
pub fn Prob(sid: uintq, q: uintq) -> f64;
}
extern "C" {
pub fn PermutationProb(sid: uintq, n: uintq, q: *mut uintq, c: *mut bool) -> f64;
}
extern "C" {
pub fn PermutationExpectation(sid: uintq, n: uintq, c: *mut uintq) -> f64;
}
Expand Down

0 comments on commit 9f549ab

Please sign in to comment.