aboutsummaryrefslogtreecommitdiff
path: root/libpsi-core/src/core
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2024-09-28 23:58:13 +0200
committerhachem <im@hachem.wtf>2024-09-28 23:58:13 +0200
commit2770097e25e7fb5090efe0f85340f0c638f9dd71 (patch)
tree591323ea709e14c0b6d8e5d0c396d51b59db5659 /libpsi-core/src/core
parentce0a2aa7fe9fe3a6b638c39078c8b77ac912b860 (diff)
Prep for first CLI visualizer
Diffstat (limited to 'libpsi-core/src/core')
-rw-r--r--libpsi-core/src/core/component.rs4
-rw-r--r--libpsi-core/src/core/gates.rs26
-rw-r--r--libpsi-core/src/core/runtime.rs4
3 files changed, 17 insertions, 17 deletions
diff --git a/libpsi-core/src/core/component.rs b/libpsi-core/src/core/component.rs
index 09095ec..be5fbca 100644
--- a/libpsi-core/src/core/component.rs
+++ b/libpsi-core/src/core/component.rs
@@ -4,7 +4,7 @@ use crate::{complex, ColumnVector, Complex, Matrix, Vector, VectorMatrix};
use core::ops;
pub type QuantumBit = ColumnVector<Complex<f64>>;
-pub type QuantumGate = Matrix<Complex<f64>>;
+pub type QuantumGate = (&'static str, Matrix<Complex<f64>>);
#[macro_export]
macro_rules! count {
@@ -124,7 +124,7 @@ impl QuantumRegister {
}
pub fn apply(&self, gate: &QuantumGate) -> QuantumBit {
- self.state.mul_matrix(gate).unwrap()
+ self.state.mul_matrix(&gate.1).unwrap()
}
}
diff --git a/libpsi-core/src/core/gates.rs b/libpsi-core/src/core/gates.rs
index e9077ad..094fec9 100644
--- a/libpsi-core/src/core/gates.rs
+++ b/libpsi-core/src/core/gates.rs
@@ -2,21 +2,21 @@ use crate::{complex, matrix, QuantumGate};
#[rustfmt::skip]
lazy_static::lazy_static! {
- pub static ref HADAMARD: QuantumGate = matrix!([complex!(1.0, 0.0), complex!( 1.0, 0.0)];
- [complex!(1.0, 0.0), complex!(-1.0, 0.0)]) *
- complex!(1.0/2.0_f64.sqrt(), 0.0);
+ pub static ref HADAMARD: QuantumGate = ("H", matrix!([complex!(1.0, 0.0), complex!( 1.0, 0.0)];
+ [complex!(1.0, 0.0), complex!(-1.0, 0.0)]) *
+ complex!(1.0/2.0_f64.sqrt(), 0.0));
- pub static ref PAULI_X: QuantumGate = matrix!([complex!(0.0, 0.0), complex!(1.0, 0.0)];
- [complex!(1.0, 0.0), complex!(0.0, 0.0)]);
+ pub static ref PAULI_X: QuantumGate = ("Pauli-X", matrix!([complex!(0.0, 0.0), complex!(1.0, 0.0)];
+ [complex!(1.0, 0.0), complex!(0.0, 0.0)]));
- pub static ref PAULI_Y: QuantumGate = matrix!([complex!(0.0, 0.0), complex!(0.0, -1.0)];
- [complex!(0.0, 1.0), complex!(0.0, 0.0)]);
+ pub static ref PAULI_Y: QuantumGate = ("Pauli-Y", matrix!([complex!(0.0, 0.0), complex!(0.0, -1.0)];
+ [complex!(0.0, 1.0), complex!(0.0, 0.0)]));
- pub static ref PAULI_Z: QuantumGate = matrix!([complex!(1.0, 0.0), complex!( 0.0, 0.0)];
- [complex!(0.0, 0.0), complex!(-1.0, 0.0)]);
+ pub static ref PAULI_Z: QuantumGate = ("Pauli-Z", matrix!([complex!(1.0, 0.0), complex!( 0.0, 0.0)];
+ [complex!(0.0, 0.0), complex!(-1.0, 0.0)]));
- pub static ref CNOT: QuantumGate = matrix!([complex!(1.0, 0.0), complex!(0.0, 0.0), complex!(0.0, 0.0), complex!(0.0, 0.0)];
- [complex!(0.0, 0.0), complex!(1.0, 0.0), complex!(0.0, 0.0), complex!(0.0, 0.0)];
- [complex!(0.0, 0.0), complex!(0.0, 0.0), complex!(0.0, 0.0), complex!(1.0, 0.0)];
- [complex!(0.0, 0.0), complex!(0.0, 0.0), complex!(1.0, 0.0), complex!(0.0, 0.0)]);
+ pub static ref CNOT: QuantumGate = ("CNOT", matrix!([complex!(1.0, 0.0), complex!(0.0, 0.0), complex!(0.0, 0.0), complex!(0.0, 0.0)];
+ [complex!(0.0, 0.0), complex!(1.0, 0.0), complex!(0.0, 0.0), complex!(0.0, 0.0)];
+ [complex!(0.0, 0.0), complex!(0.0, 0.0), complex!(0.0, 0.0), complex!(1.0, 0.0)];
+ [complex!(0.0, 0.0), complex!(0.0, 0.0), complex!(1.0, 0.0), complex!(0.0, 0.0)]));
}
diff --git a/libpsi-core/src/core/runtime.rs b/libpsi-core/src/core/runtime.rs
index 5b0a45f..0937f3c 100644
--- a/libpsi-core/src/core/runtime.rs
+++ b/libpsi-core/src/core/runtime.rs
@@ -19,7 +19,7 @@ pub trait RuntimeBase {
fn get_circuit(&self) -> &QuantumCircuit;
}
-pub trait Runtime<T: RuntimeBase = Self> {
- fn new(circuit: QuantumCircuit) -> Self;
+pub trait Runtime<'a, T: RuntimeBase = Self> {
+ fn new(circuit: &'a QuantumCircuit) -> Self;
fn execute(&self, repeat: usize) -> Vec<ExecutationData>;
}