diff options
| author | hachem <im@hachem.wtf> | 2024-10-12 16:56:12 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2024-10-12 16:56:12 +0200 |
| commit | 483e9e6ce9fbb1440992e916ec743ce0eff0ab5a (patch) | |
| tree | e312bd5be2318c2570d7b42550eaf184deb8c965 /libpsi-core/src/core/component.rs | |
| parent | c643b1535ffb106cf582763804bce655e3fb116c (diff) | |
Simplify and start rework of gate application
Diffstat (limited to 'libpsi-core/src/core/component.rs')
| -rw-r--r-- | libpsi-core/src/core/component.rs | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/libpsi-core/src/core/component.rs b/libpsi-core/src/core/component.rs index be5fbca..d2dc781 100644 --- a/libpsi-core/src/core/component.rs +++ b/libpsi-core/src/core/component.rs @@ -4,7 +4,8 @@ use crate::{complex, ColumnVector, Complex, Matrix, Vector, VectorMatrix}; use core::ops; pub type QuantumBit = ColumnVector<Complex<f64>>; -pub type QuantumGate = (&'static str, Matrix<Complex<f64>>); +pub type QuantumState = Matrix<Complex<f64>>; +pub type QuantumGate = (&'static str, QuantumState); #[macro_export] macro_rules! count { @@ -41,6 +42,7 @@ pub struct ClassicalRegister { bits: Vec<i32>, } +#[derive(Clone)] pub struct QuantumRegister { state: ColumnVector<Complex<f64>>, qubits: Vec<QuantumBit>, @@ -101,6 +103,10 @@ impl QuantumRegister { self.state = ColumnVector::from_matrix(&new_result); } + pub fn new(count: usize) -> QuantumRegister { + QuantumRegister::from(&mut vec![QuantumBit::state_0(); count]) + } + pub fn from(bits: &mut [QuantumBit]) -> QuantumRegister { let mut register = QuantumRegister { qubits: bits.to_vec(), @@ -111,10 +117,6 @@ impl QuantumRegister { register } - pub fn measure(&self, classical_register: &mut ClassicalRegister) { - classical_register.set_bits(self.qubits.iter().map(|qubit| qubit.measure()).collect()); - } - pub fn get_bits(&self) -> Vec<QuantumBit> { self.qubits.clone() } @@ -122,10 +124,6 @@ impl QuantumRegister { pub fn get_state(&self) -> ColumnVector<Complex<f64>> { self.state.clone() } - - pub fn apply(&self, gate: &QuantumGate) -> QuantumBit { - self.state.mul_matrix(&gate.1).unwrap() - } } impl ops::Index<usize> for QuantumRegister { |
