Skip to content

Commit

Permalink
Add get_unitary_fidelity() method
Browse files Browse the repository at this point in the history
  • Loading branch information
WrathfulSpatula committed Mar 30, 2023
1 parent a50cd2c commit 35d9ad9
Show file tree
Hide file tree
Showing 4 changed files with 56 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.3.0"
version = "0.4.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 @@ -228,6 +228,8 @@ MICROSOFT_QUANTUM_DECL void Hash(_In_ uintq sid, _In_ uintq n, _In_reads_(n) uin
MICROSOFT_QUANTUM_DECL bool TrySeparate1Qb(_In_ uintq sid, _In_ uintq qi1);
MICROSOFT_QUANTUM_DECL bool TrySeparate2Qb(_In_ uintq sid, _In_ uintq qi1, _In_ uintq qi2);
MICROSOFT_QUANTUM_DECL bool TrySeparateTol(_In_ uintq sid, _In_ uintq n, _In_reads_(n) uintq* q, _In_ double tol);
MICROSOFT_QUANTUM_DECL double GetUnitaryFidelity(_In_ uintq sid);
MICROSOFT_QUANTUM_DECL void ResetUnitaryFidelity(_In_ uintq sid);
MICROSOFT_QUANTUM_DECL void SetReactiveSeparate(_In_ uintq sid, _In_ bool irs);
MICROSOFT_QUANTUM_DECL void SetTInjection(_In_ uintq sid, _In_ bool iti);

Expand Down
47 changes: 47 additions & 0 deletions src/qrack_simulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2357,6 +2357,53 @@ impl QrackSimulator {
Ok(result)
}

pub fn get_unitary_fidelity(&self) -> Result<f64, QrackError> {
// Get fidelity estimate
//
// When using "Schmidt decomposition rounding parameter" ("SDRP")
// approximate simulation, QrackSimulator() can make an excellent
// estimate of its overall fidelity at any time, tested against a
// nearest-neighbor variant of quantum volume circuits.
//
// Resetting the fidelity calculation to 1.0 happens automatically
// when calling `mall` are can be done manually with
// `reset_unitary_fidelity()`.
//
// Raises:
// RuntimeError: QrackSimulator raised an exception.
//
// Returns:
// Fidelity estimate
let result:f64;
unsafe {
result = qrack_system::GetUnitaryFidelity(self.sid);
}
if self.get_error() != 0 {
return Err(QrackError{});
}
Ok(result)
}

pub fn reset_unitary_fidelity(&self) -> Result<(), QrackError> {
// Reset fidelity estimate
//
// When using "Schmidt decomposition rounding parameter" ("SDRP")
// approximate simulation, QrackSimulator() can make an excellent
// estimate of its overall fidelity at any time, tested against a
// nearest-neighbor variant of quantum volume circuits.
//
// Resetting the fidelity calculation to 1.0 happens automatically
// when calling `mall` are can be done manually with
// `reset_unitary_fidelity()`.
//
// Raises:
// RuntimeError: QrackSimulator raised an exception.
unsafe {
qrack_system::ResetUnitaryFidelity(self.sid);
}
self.check_error()
}

pub fn set_reactive_separate(&self, irs: bool) -> Result<(), QrackError> {
// Set reactive separation option
//
Expand Down
6 changes: 6 additions & 0 deletions src/qrack_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,12 @@ extern "C" {
extern "C" {
pub fn TrySeparateTol(sid: uintq, n: uintq, q: *mut uintq, tol: f64) -> bool;
}
extern "C" {
pub fn GetUnitaryFidelity(sid: uintq) -> f64;
}
extern "C" {
pub fn ResetUnitaryFidelity(sid: uintq);
}
extern "C" {
pub fn SetReactiveSeparate(sid: uintq, irs: bool);
}
Expand Down

0 comments on commit 35d9ad9

Please sign in to comment.