From 483e9e6ce9fbb1440992e916ec743ce0eff0ab5a Mon Sep 17 00:00:00 2001 From: hachem Date: Sat, 12 Oct 2024 16:56:12 +0200 Subject: Simplify and start rework of gate application --- libpsi-core/src/core/component.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'libpsi-core/src/core/component.rs') 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>; -pub type QuantumGate = (&'static str, Matrix>); +pub type QuantumState = Matrix>; +pub type QuantumGate = (&'static str, QuantumState); #[macro_export] macro_rules! count { @@ -41,6 +42,7 @@ pub struct ClassicalRegister { bits: Vec, } +#[derive(Clone)] pub struct QuantumRegister { state: ColumnVector>, qubits: Vec, @@ -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 { self.qubits.clone() } @@ -122,10 +124,6 @@ impl QuantumRegister { pub fn get_state(&self) -> ColumnVector> { self.state.clone() } - - pub fn apply(&self, gate: &QuantumGate) -> QuantumBit { - self.state.mul_matrix(&gate.1).unwrap() - } } impl ops::Index for QuantumRegister { -- cgit v1.3