diff options
| author | hachem <im@hachem.wtf> | 2024-09-28 23:58:13 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2024-09-28 23:58:13 +0200 |
| commit | 2770097e25e7fb5090efe0f85340f0c638f9dd71 (patch) | |
| tree | 591323ea709e14c0b6d8e5d0c396d51b59db5659 /libpsi-core/src | |
| parent | ce0a2aa7fe9fe3a6b638c39078c8b77ac912b860 (diff) | |
Prep for first CLI visualizer
Diffstat (limited to 'libpsi-core/src')
| -rw-r--r-- | libpsi-core/src/core/component.rs | 4 | ||||
| -rw-r--r-- | libpsi-core/src/core/gates.rs | 26 | ||||
| -rw-r--r-- | libpsi-core/src/core/runtime.rs | 4 | ||||
| -rw-r--r-- | libpsi-core/src/runtimes/basic_rt.rs | 12 |
4 files changed, 23 insertions, 23 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>; } diff --git a/libpsi-core/src/runtimes/basic_rt.rs b/libpsi-core/src/runtimes/basic_rt.rs index ed16205..5cc1535 100644 --- a/libpsi-core/src/runtimes/basic_rt.rs +++ b/libpsi-core/src/runtimes/basic_rt.rs @@ -3,17 +3,17 @@ use crate::{ Runtime, RuntimeBase, Vector, }; -pub struct BasicRT { - circuit: QuantumCircuit, +pub struct BasicRT<'a> { + circuit: &'a QuantumCircuit, } -impl RuntimeBase for BasicRT { +impl<'a> RuntimeBase for BasicRT<'a> { fn get_circuit(&self) -> &QuantumCircuit { &self.circuit } } -impl BasicRT { +impl<'a> BasicRT<'a> { fn calculate_state(state: &ColumnVector<Complex<f64>>, n: usize) -> QuantumBit { let num_states = 1 << n; let half_states = num_states >> 1; @@ -52,8 +52,8 @@ impl BasicRT { } } -impl Runtime for BasicRT { - fn new(circuit: QuantumCircuit) -> BasicRT { +impl<'a> Runtime<'a> for BasicRT<'a> { + fn new(circuit: &'a QuantumCircuit) -> BasicRT { BasicRT { circuit } } |
