Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ members = [
"source/compiler/qsc_project",
"source/compiler/qsc_rir",
"source/fuzz",
"source/index_map",
"source/language_service",
"source/simulators",
"source/pip",
Expand Down Expand Up @@ -82,7 +83,6 @@ wasm-bindgen-futures = "0.4"
rand = "0.8"
serde_json = "1.0"
pyo3 = "0.28"
quantum-sparse-sim = { git = "https://github.com/qir-alliance/qir-runner", rev = "2c130b0e4397c8d82e483b2d18fc3e241a5fa31c" }
async-trait = "0.1"
tokio = { version = "1.50", features = ["macros", "rt"] }
rayon = "1.11.0"
Expand Down
1 change: 1 addition & 0 deletions source/compiler/qsc_data_structures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ license.workspace = true
repository.workspace = true

[dependencies]
index_map = { path = "../../index_map" }
miette = { workspace = true }
serde = { workspace = true }
bitflags = { workspace = true }
Expand Down
3 changes: 2 additions & 1 deletion source/compiler/qsc_data_structures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ pub mod attrs;
pub mod display;
pub mod error;
pub mod functors;
pub mod index_map;
pub mod language_features;
pub mod line_column;
pub mod namespaces;
pub mod source;
pub mod span;
pub mod target;

pub use index_map;
8 changes: 4 additions & 4 deletions source/compiler/qsc_eval/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use ndarray::Array2;
use num_bigint::BigUint;
use num_complex::Complex;
use num_traits::Zero;
use qdk_simulators::QuantumSim;
use qdk_simulators::SparseStateSim;
use qdk_simulators::cpu_full_state_simulator::noise::{Fault, PauliFault};
use qdk_simulators::noise_config::{CumulativeNoiseConfig, CumulativeNoiseTable};
use rand::{Rng, RngCore};
Expand Down Expand Up @@ -503,7 +503,7 @@ impl SequentialAllocator {
/// Default backend used when targeting sparse simulation.
pub struct SparseSim {
/// Noiseless Sparse simulator to be used by this instance.
pub sim: QuantumSim,
pub sim: SparseStateSim,
/// Noise configuration for this simulator instance, which defines the probabilities of different faults occurring during simulation.
pub noise_config: Option<CumulativeNoiseConfig<Fault>>,
/// Pauli noise that is applied after a gate or before a measurement is executed.
Expand All @@ -530,7 +530,7 @@ impl SparseSim {
#[must_use]
pub fn new() -> Self {
Self {
sim: QuantumSim::new(None),
sim: SparseStateSim::new(None),
noise_config: None,
noise: PauliNoise::default(),
loss: f64::zero(),
Expand All @@ -549,7 +549,7 @@ impl SparseSim {
#[must_use]
pub fn new_with_noise_config(noise_config: CumulativeNoiseConfig<Fault>) -> Self {
Self {
sim: QuantumSim::new(None),
sim: SparseStateSim::new(None),
noise_config: Some(noise_config),
noise: PauliNoise::default(),
loss: f64::zero(),
Expand Down
20 changes: 1 addition & 19 deletions source/compiler/qsc_eval/src/intrinsic/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::collections::hash_map::Entry;
use num_bigint::BigUint;
use num_complex::{Complex, Complex64};
use num_traits::Zero;
use qdk_simulators::NearlyZero;
use rustc_hash::{FxHashMap, FxHashSet};

/// Given a state and a set of qubits, split the state into two parts: the qubits to dump and the remaining qubits.
Expand Down Expand Up @@ -152,25 +153,6 @@ fn normalize_and_reorder(
}
}

trait NearlyZero {
fn is_nearly_zero(&self) -> bool;
}

impl NearlyZero for f64 {
fn is_nearly_zero(&self) -> bool {
self.abs() <= 1e-10
}
}

impl<T> NearlyZero for Complex<T>
where
T: NearlyZero,
{
fn is_nearly_zero(&self) -> bool {
self.re.is_nearly_zero() && self.im.is_nearly_zero()
}
}

pub(crate) fn state_to_matrix(
state: Vec<(BigUint, Complex64)>,
qubit_count: usize,
Expand Down
15 changes: 15 additions & 0 deletions source/index_map/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "index_map"

version.workspace = true
authors.workspace = true
edition.workspace = true
homepage.workspace = true
license.workspace = true
repository.workspace = true

[lints]
workspace = true

[lib]
doctest = false
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::{
fmt::{self, Debug, Formatter},
iter::Enumerate,
marker::PhantomData,
ops::{Index, IndexMut},
option::Option,
slice, vec,
};
Expand Down Expand Up @@ -37,6 +38,14 @@ impl<K, V> IndexMap<K, V> {
Self::default()
}

#[must_use]
pub fn with_capacity(capacity: usize) -> Self {
Self {
_keys: PhantomData,
values: Vec::with_capacity(capacity),
}
}

#[must_use]
pub fn is_empty(&self) -> bool {
self.values.iter().all(Option::is_none)
Expand Down Expand Up @@ -314,3 +323,19 @@ impl<'a, V> Iterator for ValuesMut<'a, V> {
}
}
}

impl Index<usize> for IndexMap<usize, usize> {
type Output = usize;

fn index(&self, index: usize) -> &Self::Output {
self.get(index)
.expect("IndexMap::index: index out of bounds")
}
}

impl IndexMut<usize> for IndexMap<usize, usize> {
fn index_mut(&mut self, index: usize) -> &mut Self::Output {
self.get_mut(index)
.expect("IndexMap::index_mut: index out of bounds")
}
}
3 changes: 2 additions & 1 deletion source/simulators/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@ license.workspace = true
repository.workspace = true

[dependencies]
quantum-sparse-sim = { workspace = true }
bytemuck = { workspace = true }
futures = { workspace = true }
wgpu = { workspace = true }
rand = { workspace = true }
nalgebra = { workspace = true }
ndarray = { workspace = true }
num-bigint = { workspace = true }
num-complex = { workspace = true }
num-traits = { workspace = true }
regex-lite = { workspace = true }
rustc-hash = { workspace = true }
paulimer = { path = "../paulimer" }
index_map = { path = "../index_map" }
noisy_simulator = { path = "../noisy_simulator" }

[dev-dependencies]
Expand Down
7 changes: 5 additions & 2 deletions source/simulators/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
// Licensed under the MIT License.

pub mod bytecode;
pub mod noise_config;
pub use quantum_sparse_sim::QuantumSim;
pub mod cpu_full_state_simulator;
mod gpu_full_state_simulator;
pub mod noise_config;
pub mod sparse_state_simulator;
pub mod stabilizer_simulator;

pub use gpu_full_state_simulator::*;
pub use sparse_state_simulator::SparseStateSim;
pub use sparse_state_simulator::nearly_zero::NearlyZero;

/// A qubit ID.
pub type QubitID = usize;
Expand Down
Loading
Loading