aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-08-24 14:48:36 +0200
committerhachem <im@hachem.wtf>2026-08-24 14:48:36 +0200
commit24d639224ca11112025289065d7538851606b56e (patch)
treee7e26c89cd20099f03ff32727ba0af2cf4762088
parent548dc42d9f454cb8c29fddb88ca41f8b1b595882 (diff)
[chore]: unwrap project
-rw-r--r--Cargo.toml27
-rw-r--r--README.md34
-rw-r--r--examples/tester/benchmarks.rs (renamed from tester/src/benchmarks.rs)4
-rw-r--r--examples/tester/clifford.rs (renamed from tester/src/clifford.rs)2
-rw-r--r--examples/tester/common.rs (renamed from tester/src/common.rs)7
-rw-r--r--examples/tester/custom_gates.rs (renamed from tester/src/custom_gates.rs)2
-rw-r--r--examples/tester/kernels.rs (renamed from tester/src/kernels.rs)8
-rw-r--r--examples/tester/main.rs (renamed from tester/src/main.rs)0
-rw-r--r--examples/tester/noise.rs (renamed from tester/src/noise.rs)2
-rw-r--r--examples/tester/non_clifford.rs (renamed from tester/src/non_clifford.rs)2
-rw-r--r--examples/tester/simd.rs (renamed from tester/src/simd.rs)8
-rw-r--r--libpsi-core/Cargo.toml11
-rw-r--r--libpsi-qasm/Cargo.toml7
-rw-r--r--libpsi-qasm/src/lib.rs14
-rw-r--r--libpsi-visualizer/Cargo.toml8
-rw-r--r--libpsi-visualizer/src/lib.rs2
-rw-r--r--src/core/circuit.rs (renamed from libpsi-core/src/core/circuit.rs)12
-rw-r--r--src/core/classical_components.rs (renamed from libpsi-core/src/core/classical_components.rs)4
-rw-r--r--src/core/custom_gate.rs (renamed from libpsi-core/src/core/custom_gate.rs)2
-rw-r--r--src/core/gates.rs (renamed from libpsi-core/src/core/gates.rs)0
-rw-r--r--src/core/kernel.rs (renamed from libpsi-core/src/core/kernel.rs)13
-rw-r--r--src/core/mod.rs (renamed from libpsi-core/src/core/mod.rs)0
-rw-r--r--src/core/noise.rs (renamed from libpsi-core/src/core/noise.rs)11
-rw-r--r--src/core/quantum_components.rs (renamed from libpsi-core/src/core/quantum_components.rs)4
-rw-r--r--src/core/runtime.rs (renamed from libpsi-core/src/core/runtime.rs)8
-rw-r--r--src/lib.rs (renamed from libpsi-core/src/lib.rs)3
-rw-r--r--src/maths/complex.rs (renamed from libpsi-core/src/maths/complex.rs)0
-rw-r--r--src/maths/format.rs (renamed from libpsi-core/src/maths/format.rs)2
-rw-r--r--src/maths/matrix.rs (renamed from libpsi-core/src/maths/matrix.rs)6
-rw-r--r--src/maths/mod.rs (renamed from libpsi-core/src/maths/mod.rs)0
-rw-r--r--src/maths/numeric.rs (renamed from libpsi-core/src/maths/numeric.rs)0
-rw-r--r--src/maths/simd.rs (renamed from libpsi-core/src/maths/simd.rs)0
-rw-r--r--src/maths/vector.rs (renamed from libpsi-core/src/maths/vector.rs)4
-rw-r--r--src/maths/vector_ops.rs (renamed from libpsi-core/src/maths/vector_ops.rs)0
-rw-r--r--src/visualizer/horizontal_cli.rs (renamed from libpsi-visualizer/src/cli/horizontal_cli.rs)4
-rw-r--r--src/visualizer/mod.rs (renamed from libpsi-visualizer/src/cli/mod.rs)4
-rw-r--r--src/visualizer/renderer.rs (renamed from libpsi-visualizer/src/cli/visualizer.rs)0
-rw-r--r--src/visualizer/vertical_cli.rs (renamed from libpsi-visualizer/src/cli/vertical_cli.rs)28
-rw-r--r--tester/Cargo.toml10
39 files changed, 107 insertions, 146 deletions
diff --git a/Cargo.toml b/Cargo.toml
index a95294c..a75e5ef 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,8 +1,19 @@
-[workspace]
-resolver = "2"
-members = [
- "libpsi-core",
- "libpsi-qasm",
- "libpsi-visualizer",
- "tester",
-]
+[package]
+name = "psi"
+version = "0.1.0"
+edition = "2021"
+authors = ["Hachem"]
+
+[lib]
+name = "psi"
+path = "src/lib.rs"
+
+[[example]]
+name = "tester"
+path = "examples/tester/main.rs"
+
+[dependencies]
+lazy_static = "1.5.0"
+libm = "0.2.8"
+rand = "0.9.2"
+rayon = "1.10"
diff --git a/README.md b/README.md
index c5707c8..267b852 100644
--- a/README.md
+++ b/README.md
@@ -75,7 +75,7 @@ Realistic quantum noise simulation using Kraus operators:
| `bit_phase_flip(p)` | $Y$ error with probability $p$ |
```rust
-use libpsi_core::{DensityMatrix, NoiseChannel};
+use psi::{DensityMatrix, NoiseChannel};
// Create density matrix from circuit state
let dm = DensityMatrix::from_state_vector(&state_vec);
@@ -91,16 +91,18 @@ println!("Fidelity: {}", dm.fidelity_with_pure_state(&ideal_state));
## Project Structure
-- **`libpsi-core`**: Core quantum simulation library
- - `core`: Quantum gates, circuits, registers, and runtimes
- - `maths`: Complex numbers, vectors, matrices, SIMD operations
-- **`libpsi-visualizer`**: Circuit visualisation (ASCII horizontal/vertical)
-- **`tester`**: Comprehensive test suite and benchmarks
+`psi` is a single crate. The library lives under `src/`:
+
+- **`core`**: Quantum gates, circuits, registers, and runtimes
+- **`maths`**: Complex numbers, vectors, matrices, SIMD operations
+- **`visualizer`**: Circuit visualisation (ASCII horizontal/vertical)
+
+The comprehensive test suite and benchmarks live in **`examples/tester`**.
## Quick Start
```rust
-use libpsi_core::{QuantumCircuit, Runtime};
+use psi::{QuantumCircuit, Runtime};
fn main() {
let mut circuit = QuantumCircuit::new(3);
@@ -118,7 +120,7 @@ fn main() {
### Composable Runtimes
```rust
-use libpsi_core::{QuantumCircuit, RuntimeConfig};
+use psi::{QuantumCircuit, RuntimeConfig};
let mut circuit = QuantumCircuit::new(8);
// ... add gates ...
@@ -147,7 +149,7 @@ circuit
### Custom Gates
```rust
-use libpsi_core::{CustomGateBuilder, CustomGate, complex, matrix};
+use psi::{CustomGateBuilder, CustomGate, complex, matrix};
// From operations
let bell_gate = CustomGateBuilder::new("BELL", 2)
@@ -166,13 +168,13 @@ let sqrt_x = CustomGate::from_matrix("√X", sqrt_x_matrix);
## Running Tests
```bash
-cargo run --package tester --release # All tests
-cargo run --package tester --release -- clifford
-cargo run --package tester --release -- non-clifford
-cargo run --package tester --release -- kernels
-cargo run --package tester --release -- simd
-cargo run --package tester --release -- bench
-cargo run --package tester --release -- help
+cargo run --release --example tester # All tests
+cargo run --release --example tester -- clifford
+cargo run --release --example tester -- non-clifford
+cargo run --release --example tester -- kernels
+cargo run --release --example tester -- simd
+cargo run --release --example tester -- bench
+cargo run --release --example tester -- help
```
## Disclaimer
diff --git a/tester/src/benchmarks.rs b/examples/tester/benchmarks.rs
index 0a88502..7aea535 100644
--- a/tester/src/benchmarks.rs
+++ b/examples/tester/benchmarks.rs
@@ -1,6 +1,6 @@
use crate::common::{benchmark_circuit, print_section, BenchmarkResult};
-use libpsi_core::QuantumCircuit;
-use libpsi_visualizer::HorizontalRenderer;
+use psi::QuantumCircuit;
+use psi::HorizontalRenderer;
pub fn run_all(results: &mut Vec<BenchmarkResult>) {
println!("═══════════════════════════════════════════════════════════════");
diff --git a/tester/src/clifford.rs b/examples/tester/clifford.rs
index 5c0b453..932a918 100644
--- a/tester/src/clifford.rs
+++ b/examples/tester/clifford.rs
@@ -1,5 +1,5 @@
use crate::common::{benchmark_circuit, print_circuit, print_section, BenchmarkResult};
-use libpsi_core::QuantumCircuit;
+use psi::QuantumCircuit;
pub fn run_all(results: &mut Vec<BenchmarkResult>) {
println!("═══════════════════════════════════════════════════════════════");
diff --git a/tester/src/common.rs b/examples/tester/common.rs
index 63a7c4c..9e576da 100644
--- a/tester/src/common.rs
+++ b/examples/tester/common.rs
@@ -1,7 +1,10 @@
-use libpsi_core::{QuantumCircuit, QuantumState, Runtime, Vector};
-use libpsi_visualizer::{HorizontalRenderer, VerticalRenderer};
+use psi::{QuantumCircuit, QuantumState, Runtime, Vector};
+use psi::{HorizontalRenderer, VerticalRenderer};
use std::time::{Duration, Instant};
+/// A named list of circuit builders used by the benchmark/test suites.
+pub type CircuitCases = Vec<(&'static str, Box<dyn Fn() -> QuantumCircuit>)>;
+
pub struct BenchmarkResult {
pub name: String,
pub basic_time: Duration,
diff --git a/tester/src/custom_gates.rs b/examples/tester/custom_gates.rs
index 0e21614..ffe5c01 100644
--- a/tester/src/custom_gates.rs
+++ b/examples/tester/custom_gates.rs
@@ -1,5 +1,5 @@
use crate::common::{benchmark_circuit, print_circuit, print_section, BenchmarkResult};
-use libpsi_core::{complex, matrix, CustomGate, CustomGateBuilder, QuantumCircuit};
+use psi::{complex, matrix, CustomGate, CustomGateBuilder, QuantumCircuit};
pub fn run_all(results: &mut Vec<BenchmarkResult>) {
println!("═══════════════════════════════════════════════════════════════");
diff --git a/tester/src/kernels.rs b/examples/tester/kernels.rs
index 5ff7c6d..b42b181 100644
--- a/tester/src/kernels.rs
+++ b/examples/tester/kernels.rs
@@ -1,5 +1,5 @@
-use crate::common::{print_section, states_equal, BenchmarkResult};
-use libpsi_core::{QuantumCircuit, Runtime, RuntimeConfig};
+use crate::common::{print_section, states_equal, BenchmarkResult, CircuitCases};
+use psi::{QuantumCircuit, Runtime, RuntimeConfig};
use std::f64::consts::PI;
use std::time::Instant;
@@ -102,7 +102,7 @@ pub fn test_kernel_fusion(results: &mut Vec<BenchmarkResult>) {
pub fn test_batched_vs_basic(results: &mut Vec<BenchmarkResult>) {
print_section("Batched vs Basic Runtime Comparison");
- let test_cases: Vec<(&str, Box<dyn Fn() -> QuantumCircuit>)> = vec![
+ let test_cases: CircuitCases = vec![
(
"Bell State",
Box::new(|| {
@@ -280,7 +280,7 @@ pub fn test_structure_aware(results: &mut Vec<BenchmarkResult>) {
println!();
print_section("Structure-Aware vs Other Runtimes");
- let test_cases: Vec<(&str, Box<dyn Fn() -> QuantumCircuit>)> = vec![
+ let test_cases: CircuitCases = vec![
(
"Diagonal-heavy (5q)",
Box::new(|| {
diff --git a/tester/src/main.rs b/examples/tester/main.rs
index 8a9a41c..8a9a41c 100644
--- a/tester/src/main.rs
+++ b/examples/tester/main.rs
diff --git a/tester/src/noise.rs b/examples/tester/noise.rs
index 54edfe0..02a4ba3 100644
--- a/tester/src/noise.rs
+++ b/examples/tester/noise.rs
@@ -1,5 +1,5 @@
use crate::common::{print_section, BenchmarkResult};
-use libpsi_core::{
+use psi::{
complex, DensityMatrix, NoiseChannel, QuantumCircuit, Runtime, Vector,
};
use std::time::Instant;
diff --git a/tester/src/non_clifford.rs b/examples/tester/non_clifford.rs
index 8545d01..2146fb2 100644
--- a/tester/src/non_clifford.rs
+++ b/examples/tester/non_clifford.rs
@@ -1,5 +1,5 @@
use crate::common::{benchmark_circuit, print_circuit, print_section, BenchmarkResult};
-use libpsi_core::QuantumCircuit;
+use psi::QuantumCircuit;
use std::f64::consts::PI;
pub fn run_all(results: &mut Vec<BenchmarkResult>) {
diff --git a/tester/src/simd.rs b/examples/tester/simd.rs
index 7ab71b6..e91dc6e 100644
--- a/tester/src/simd.rs
+++ b/examples/tester/simd.rs
@@ -1,5 +1,5 @@
-use crate::common::{print_section, states_equal, BenchmarkResult};
-use libpsi_core::{get_simd_info, QuantumCircuit, Runtime};
+use crate::common::{print_section, states_equal, BenchmarkResult, CircuitCases};
+use psi::{get_simd_info, QuantumCircuit, Runtime};
use std::f64::consts::PI;
use std::time::Instant;
@@ -18,7 +18,7 @@ pub fn run_all(results: &mut Vec<BenchmarkResult>) {
pub fn test_simd_correctness(results: &mut Vec<BenchmarkResult>) {
print_section("SIMD Correctness Verification");
- let test_cases: Vec<(&str, Box<dyn Fn() -> QuantumCircuit>)> = vec![
+ let test_cases: CircuitCases = vec![
(
"Bell State",
Box::new(|| {
@@ -89,7 +89,7 @@ pub fn test_simd_correctness(results: &mut Vec<BenchmarkResult>) {
pub fn test_simd_vs_batched(results: &mut Vec<BenchmarkResult>) {
print_section("SIMD vs Batched Runtime Comparison");
- let test_cases: Vec<(&str, Box<dyn Fn() -> QuantumCircuit>)> = vec![
+ let test_cases: CircuitCases = vec![
(
"Single-Qubit Heavy (6q)",
Box::new(|| {
diff --git a/libpsi-core/Cargo.toml b/libpsi-core/Cargo.toml
deleted file mode 100644
index 01b98a5..0000000
--- a/libpsi-core/Cargo.toml
+++ /dev/null
@@ -1,11 +0,0 @@
-[package]
-name = "libpsi-core"
-version = "0.1.0"
-edition = "2021"
-authors = ["Hachem"]
-
-[dependencies]
-lazy_static = "1.5.0"
-libm = "0.2.8"
-rand = "0.9.2"
-rayon = "1.10"
diff --git a/libpsi-qasm/Cargo.toml b/libpsi-qasm/Cargo.toml
deleted file mode 100644
index f0ecc4a..0000000
--- a/libpsi-qasm/Cargo.toml
+++ /dev/null
@@ -1,7 +0,0 @@
-[package]
-name = "libpsi-qasm"
-version = "0.1.0"
-edition = "2021"
-authors = ["Hachem"]
-
-[dependencies]
diff --git a/libpsi-qasm/src/lib.rs b/libpsi-qasm/src/lib.rs
deleted file mode 100644
index 7d12d9a..0000000
--- a/libpsi-qasm/src/lib.rs
+++ /dev/null
@@ -1,14 +0,0 @@
-pub fn add(left: usize, right: usize) -> usize {
- left + right
-}
-
-#[cfg(test)]
-mod tests {
- use super::*;
-
- #[test]
- fn it_works() {
- let result = add(2, 2);
- assert_eq!(result, 4);
- }
-}
diff --git a/libpsi-visualizer/Cargo.toml b/libpsi-visualizer/Cargo.toml
deleted file mode 100644
index c1c9944..0000000
--- a/libpsi-visualizer/Cargo.toml
+++ /dev/null
@@ -1,8 +0,0 @@
-[package]
-name = "libpsi-visualizer"
-version = "0.1.0"
-edition = "2021"
-authors = ["Hachem"]
-
-[dependencies]
-libpsi-core = { path = "../libpsi-core" }
diff --git a/libpsi-visualizer/src/lib.rs b/libpsi-visualizer/src/lib.rs
deleted file mode 100644
index 373ae6d..0000000
--- a/libpsi-visualizer/src/lib.rs
+++ /dev/null
@@ -1,2 +0,0 @@
-pub mod cli;
-pub use cli::*;
diff --git a/libpsi-core/src/core/circuit.rs b/src/core/circuit.rs
index d0e4450..6647f58 100644
--- a/libpsi-core/src/core/circuit.rs
+++ b/src/core/circuit.rs
@@ -185,20 +185,16 @@ impl QuantumCircuit {
}
pub fn compute_with(&mut self, runtime: Runtime) -> &QuantumState {
- if self.computed_state.is_some() {
- return self.computed_state.as_ref().unwrap();
+ if self.computed_state.is_none() {
+ self.computed_state = Some(runtime.compute(self.num_qubits, &self.operations));
}
-
- self.computed_state = Some(runtime.compute(self.num_qubits, &self.operations));
self.computed_state.as_ref().unwrap()
}
pub fn compute_with_config(&mut self, config: RuntimeConfig) -> &QuantumState {
- if self.computed_state.is_some() {
- return self.computed_state.as_ref().unwrap();
+ if self.computed_state.is_none() {
+ self.computed_state = Some(config.compute(self.num_qubits, &self.operations));
}
-
- self.computed_state = Some(config.compute(self.num_qubits, &self.operations));
self.computed_state.as_ref().unwrap()
}
diff --git a/libpsi-core/src/core/classical_components.rs b/src/core/classical_components.rs
index f6565af..b2018d4 100644
--- a/libpsi-core/src/core/classical_components.rs
+++ b/src/core/classical_components.rs
@@ -29,8 +29,8 @@ impl<'a> ClassicalBit<'a> {
impl<'a> ClassicalRegister<'a> {
pub fn new(name: &'a str, names: &'a [&'a str]) -> ClassicalRegister<'a> {
let mut bits: Vec<ClassicalBit<'a>> = Vec::new();
- for i in 0..names.len() {
- bits.push(ClassicalBit::new(names[i], false));
+ for &name in names {
+ bits.push(ClassicalBit::new(name, false));
}
ClassicalRegister { name, bits }
}
diff --git a/libpsi-core/src/core/custom_gate.rs b/src/core/custom_gate.rs
index 9e49ac9..51d3a56 100644
--- a/libpsi-core/src/core/custom_gate.rs
+++ b/src/core/custom_gate.rs
@@ -160,7 +160,7 @@ fn matrix_multiply(a: &Matrix<Complex<f64>>, b: &Matrix<Complex<f64>>) -> Matrix
for j in 0..n {
let mut sum = Complex::new(0.0, 0.0);
for k in 0..n {
- sum = sum + a.data[i * n + k] * b.data[k * n + j];
+ sum += a.data[i * n + k] * b.data[k * n + j];
}
result.data[i * n + j] = sum;
}
diff --git a/libpsi-core/src/core/gates.rs b/src/core/gates.rs
index cee4ebc..cee4ebc 100644
--- a/libpsi-core/src/core/gates.rs
+++ b/src/core/gates.rs
diff --git a/libpsi-core/src/core/kernel.rs b/src/core/kernel.rs
index 7b66eea..7f73458 100644
--- a/libpsi-core/src/core/kernel.rs
+++ b/src/core/kernel.rs
@@ -76,11 +76,10 @@ impl Kernel {
return true;
}
- if self.gate_type == GateType::Diagonal && other.gate_type == GateType::Diagonal {
- if self.targets == other.targets {
+ if self.gate_type == GateType::Diagonal && other.gate_type == GateType::Diagonal
+ && self.targets == other.targets {
return true;
}
- }
false
}
@@ -236,7 +235,7 @@ fn apply_kernel(state: &[Complex<f64>], kernel: &Kernel, num_qubits: usize) -> V
let mut new_state = vec![complex!(0.0, 0.0); dim];
- for i in 0..dim {
+ for (i, new_val) in new_state.iter_mut().enumerate() {
let mut target_idx = 0usize;
for (k, &pos) in target_bits.iter().enumerate() {
if (i >> pos) & 1 == 1 {
@@ -260,10 +259,10 @@ fn apply_kernel(state: &[Complex<f64>], kernel: &Kernel, num_qubits: usize) -> V
}
}
- sum = sum + gate_elem * state[source_idx];
+ sum += gate_elem * state[source_idx];
}
- new_state[i] = sum;
+ *new_val = sum;
}
new_state
@@ -311,7 +310,7 @@ fn apply_kernel_parallel(
}
}
- sum = sum + gate_elem * state[source_idx];
+ sum += gate_elem * state[source_idx];
}
sum
diff --git a/libpsi-core/src/core/mod.rs b/src/core/mod.rs
index c38cf38..c38cf38 100644
--- a/libpsi-core/src/core/mod.rs
+++ b/src/core/mod.rs
diff --git a/libpsi-core/src/core/noise.rs b/src/core/noise.rs
index 6836c00..8d56953 100644
--- a/libpsi-core/src/core/noise.rs
+++ b/src/core/noise.rs
@@ -382,7 +382,7 @@ impl DensityMatrix {
pub fn trace(&self) -> Complex<f64> {
let mut sum = complex!(0.0, 0.0);
for i in 0..self.dim {
- sum = sum + self.get(i, i);
+ sum += self.get(i, i);
}
sum
}
@@ -393,7 +393,7 @@ impl DensityMatrix {
for j in 0..self.dim {
let rho_ij = self.get(i, j);
let rho_ji = self.get(j, i);
- sum = sum + rho_ij * rho_ji;
+ sum += rho_ij * rho_ji;
}
}
sum.real
@@ -456,7 +456,7 @@ impl DensityMatrix {
let u_jl_dag = gate.data[tgt_j * gate_dim + l].get_conjugate();
let rho_kl = self.get(src_i, src_j);
- sum = sum + u_ik * rho_kl * u_jl_dag;
+ sum += u_ik * rho_kl * u_jl_dag;
}
}
@@ -492,8 +492,7 @@ impl DensityMatrix {
let k_dag_elem = k.data[j_target * 2 + kj].get_conjugate();
let rho_elem = self.get(src_i, src_j);
- new_data[i * self.dim + j] =
- new_data[i * self.dim + j] + k_elem * rho_elem * k_dag_elem;
+ new_data[i * self.dim + j] += k_elem * rho_elem * k_dag_elem;
}
}
}
@@ -521,7 +520,7 @@ impl DensityMatrix {
for i in 0..self.dim {
for j in 0..self.dim {
- sum = sum + state[i].get_conjugate() * self.get(i, j) * state[j];
+ sum += state[i].get_conjugate() * self.get(i, j) * state[j];
}
}
diff --git a/libpsi-core/src/core/quantum_components.rs b/src/core/quantum_components.rs
index 75f6325..f07b8ef 100644
--- a/libpsi-core/src/core/quantum_components.rs
+++ b/src/core/quantum_components.rs
@@ -121,8 +121,8 @@ impl<'a> QuantumBit<'a> {
impl<'a> QuantumRegister<'a> {
pub fn new(name: &'a str, names: &[&'a str]) -> QuantumRegister<'a> {
let mut bits: Vec<QuantumBit<'a>> = Vec::new();
- for i in 0..names.len() {
- bits.push(QuantumBit::new(names[i], QuantumState::state_0()))
+ for &name in names {
+ bits.push(QuantumBit::new(name, QuantumState::state_0()))
}
QuantumRegister::from(name, &mut bits)
diff --git a/libpsi-core/src/core/runtime.rs b/src/core/runtime.rs
index 382fa2f..6ea7b76 100644
--- a/libpsi-core/src/core/runtime.rs
+++ b/src/core/runtime.rs
@@ -516,7 +516,7 @@ fn apply_gate_parallel(
}
}
- sum = sum + gate_elem * state[source_idx];
+ sum += gate_elem * state[source_idx];
}
sum
@@ -551,7 +551,7 @@ fn apply_kernel_direct(
let mut new_state = vec![complex!(0.0, 0.0); dim];
- for i in 0..dim {
+ for (i, new_val) in new_state.iter_mut().enumerate() {
let mut target_idx = 0usize;
for (k, &pos) in target_bits.iter().enumerate() {
if (i >> pos) & 1 == 1 {
@@ -575,10 +575,10 @@ fn apply_kernel_direct(
}
}
- sum = sum + gate_elem * state[source_idx];
+ sum += gate_elem * state[source_idx];
}
- new_state[i] = sum;
+ *new_val = sum;
}
new_state
diff --git a/libpsi-core/src/lib.rs b/src/lib.rs
index 5876918..6f54357 100644
--- a/libpsi-core/src/lib.rs
+++ b/src/lib.rs
@@ -1,5 +1,6 @@
pub mod core;
pub mod maths;
+pub mod visualizer;
pub use maths::complex::*;
pub use maths::format::*;
@@ -16,3 +17,5 @@ pub use core::kernel::*;
pub use core::noise::*;
pub use core::quantum_components::*;
pub use core::runtime::*;
+
+pub use visualizer::*;
diff --git a/libpsi-core/src/maths/complex.rs b/src/maths/complex.rs
index 31eae69..31eae69 100644
--- a/libpsi-core/src/maths/complex.rs
+++ b/src/maths/complex.rs
diff --git a/libpsi-core/src/maths/format.rs b/src/maths/format.rs
index 957f1b6..b6b0191 100644
--- a/libpsi-core/src/maths/format.rs
+++ b/src/maths/format.rs
@@ -1,7 +1,7 @@
use crate::Complex;
const EPSILON: f64 = 1e-10;
-const SQRT_2: f64 = 1.4142135623730951;
+const SQRT_2: f64 = std::f64::consts::SQRT_2;
const INV_SQRT_2: f64 = 0.7071067811865475;
const INV_SQRT_8: f64 = 0.3535533905932738;
const INV_SQRT_32: f64 = 0.1767766952966369;
diff --git a/libpsi-core/src/maths/matrix.rs b/src/maths/matrix.rs
index 58492f9..c9d96a4 100644
--- a/libpsi-core/src/maths/matrix.rs
+++ b/src/maths/matrix.rs
@@ -79,7 +79,7 @@ impl<T: Float> Matrix<T> {
for j in 0..other.cols {
let mut sum = T::zero();
for k in 0..self.cols {
- sum = sum + (self.get(i, k) * other.get(k, j));
+ sum += self.get(i, k) * other.get(k, j) ;
}
result.set(i, j, sum);
}
@@ -100,7 +100,7 @@ impl<T: Float> Matrix<T> {
for l in 0..other.cols {
let result_row = i * other.rows + k;
let result_col = j * other.cols + l;
- result.set(result_row, result_col, self_val.clone() * other.get(k, l));
+ result.set(result_row, result_col, self_val * other.get(k, l));
}
}
}
@@ -301,7 +301,7 @@ impl<T: Float + fmt::Display> fmt::Display for Matrix<T> {
}
if i != self.rows - 1 {
- write!(f, "\n")?;
+ writeln!(f)?;
}
}
diff --git a/libpsi-core/src/maths/mod.rs b/src/maths/mod.rs
index 85f4872..85f4872 100644
--- a/libpsi-core/src/maths/mod.rs
+++ b/src/maths/mod.rs
diff --git a/libpsi-core/src/maths/numeric.rs b/src/maths/numeric.rs
index f5a649e..f5a649e 100644
--- a/libpsi-core/src/maths/numeric.rs
+++ b/src/maths/numeric.rs
diff --git a/libpsi-core/src/maths/simd.rs b/src/maths/simd.rs
index de0370c..de0370c 100644
--- a/libpsi-core/src/maths/simd.rs
+++ b/src/maths/simd.rs
diff --git a/libpsi-core/src/maths/vector.rs b/src/maths/vector.rs
index 87b5353..11f3d29 100644
--- a/libpsi-core/src/maths/vector.rs
+++ b/src/maths/vector.rs
@@ -57,7 +57,7 @@ impl<T: Float> ColumnVector<T> {
for i in 0..matrix.rows {
let mut sum = T::zero();
for j in 0..matrix.cols {
- sum = sum + (matrix.get(i, j) * self.get(j));
+ sum += matrix.get(i, j) * self.get(j) ;
}
result.set(i, sum);
}
@@ -81,7 +81,7 @@ impl<T: Float> RowVector<T> {
for j in 0..matrix.cols {
let mut sum = T::zero();
for i in 0..matrix.rows {
- sum = sum + (self.get(i) * matrix.get(i, j));
+ sum += self.get(i) * matrix.get(i, j) ;
}
result.set(j, sum);
}
diff --git a/libpsi-core/src/maths/vector_ops.rs b/src/maths/vector_ops.rs
index 1e7148c..1e7148c 100644
--- a/libpsi-core/src/maths/vector_ops.rs
+++ b/src/maths/vector_ops.rs
diff --git a/libpsi-visualizer/src/cli/horizontal_cli.rs b/src/visualizer/horizontal_cli.rs
index f1a6ba4..28cdb5a 100644
--- a/libpsi-visualizer/src/cli/horizontal_cli.rs
+++ b/src/visualizer/horizontal_cli.rs
@@ -1,6 +1,6 @@
-use super::visualizer::Visualizer;
+use super::renderer::Visualizer;
use core::fmt;
-use libpsi_core::{GateOp, QuantumCircuit};
+use crate::{GateOp, QuantumCircuit};
pub struct HorizontalRenderer<'a> {
circuit: &'a QuantumCircuit,
diff --git a/libpsi-visualizer/src/cli/mod.rs b/src/visualizer/mod.rs
index 213311b..ff53c44 100644
--- a/libpsi-visualizer/src/cli/mod.rs
+++ b/src/visualizer/mod.rs
@@ -1,7 +1,7 @@
pub mod horizontal_cli;
pub mod vertical_cli;
-pub mod visualizer;
+pub mod renderer;
pub use horizontal_cli::*;
pub use vertical_cli::*;
-pub use visualizer::*;
+pub use renderer::*;
diff --git a/libpsi-visualizer/src/cli/visualizer.rs b/src/visualizer/renderer.rs
index 33f730f..33f730f 100644
--- a/libpsi-visualizer/src/cli/visualizer.rs
+++ b/src/visualizer/renderer.rs
diff --git a/libpsi-visualizer/src/cli/vertical_cli.rs b/src/visualizer/vertical_cli.rs
index 6698961..e9322bf 100644
--- a/libpsi-visualizer/src/cli/vertical_cli.rs
+++ b/src/visualizer/vertical_cli.rs
@@ -1,6 +1,6 @@
-use super::visualizer::Visualizer;
+use super::renderer::Visualizer;
use core::fmt;
-use libpsi_core::{GateOp, QuantumCircuit};
+use crate::{GateOp, QuantumCircuit};
pub struct VerticalRenderer<'a> {
circuit: &'a QuantumCircuit,
@@ -207,9 +207,9 @@ impl<'a> fmt::Display for VerticalRenderer<'a> {
let min_center = min_q * (col_width + 1) + col_width / 2;
let max_center = max_q * (col_width + 1) + col_width / 2;
- for pos in (min_center + 1)..max_center {
- if line[pos] == ' ' {
- line[pos] = '─';
+ for cell in &mut line[(min_center + 1)..max_center] {
+ if *cell == ' ' {
+ *cell = '─';
}
}
@@ -246,9 +246,9 @@ impl<'a> fmt::Display for VerticalRenderer<'a> {
let min_center = min_q * (col_width + 1) + col_width / 2;
let max_center = max_q * (col_width + 1) + col_width / 2;
- for pos in (min_center + 1)..max_center {
- if line[pos] == ' ' {
- line[pos] = '─';
+ for cell in &mut line[(min_center + 1)..max_center] {
+ if *cell == ' ' {
+ *cell = '─';
}
}
@@ -281,9 +281,9 @@ impl<'a> fmt::Display for VerticalRenderer<'a> {
let mc_start = q_total + gap_width;
let mc_center = mc_start + *mc * (col_width + 1) + col_width / 2;
- for pos in (mq_center + 2)..=mc_center {
- if line[pos] == ' ' {
- line[pos] = '═';
+ for cell in &mut line[(mq_center + 2)..=mc_center] {
+ if *cell == ' ' {
+ *cell = '═';
}
}
line[mc_center] = '╣';
@@ -339,9 +339,9 @@ impl<'a> fmt::Display for VerticalRenderer<'a> {
let min_center = min_q * (col_width + 1) + col_width / 2;
let max_center = max_q * (col_width + 1) + col_width / 2;
- for pos in (min_center + 1)..max_center {
- if line[pos] == ' ' {
- line[pos] = '─';
+ for cell in &mut line[(min_center + 1)..max_center] {
+ if *cell == ' ' {
+ *cell = '─';
}
}
diff --git a/tester/Cargo.toml b/tester/Cargo.toml
deleted file mode 100644
index e912889..0000000
--- a/tester/Cargo.toml
+++ /dev/null
@@ -1,10 +0,0 @@
-[package]
-name = "tester"
-version = "0.1.0"
-edition = "2021"
-authors = ["Hachem"]
-
-[dependencies]
-libpsi-core ={ path = "../libpsi-core"}
-libpsi-qasm ={ path = "../libpsi-qasm"}
-libpsi-visualizer ={ path = "../libpsi-visualizer"} \ No newline at end of file