From de571765f161a49129fd9e34150f6a892f388bdc Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Fri, 13 Dec 2019 04:00:31 +0100 Subject: Add fibartion matrices --- src/simulation/mod.rs | 2 + src/simulation/s_5_fibration.rs | 118 +++++++++++++++++++++++++++++++++++++++ src/simulation/time_evolution.rs | 4 +- src/simulation/two_level.rs | 8 ++- src/simulation/twoxtwo_level.rs | 40 +++++++++++++ 5 files changed, 168 insertions(+), 4 deletions(-) create mode 100644 src/simulation/s_5_fibration.rs create mode 100644 src/simulation/twoxtwo_level.rs diff --git a/src/simulation/mod.rs b/src/simulation/mod.rs index 290c3e6..641444e 100644 --- a/src/simulation/mod.rs +++ b/src/simulation/mod.rs @@ -1,5 +1,7 @@ +pub mod s_5_fibration; pub mod time_evolution; pub mod two_level; +pub mod twoxtwo_level; #[allow(non_camel_case_types)] pub(crate) type c64 = num_complex::Complex; diff --git a/src/simulation/s_5_fibration.rs b/src/simulation/s_5_fibration.rs new file mode 100644 index 0000000..76a0350 --- /dev/null +++ b/src/simulation/s_5_fibration.rs @@ -0,0 +1,118 @@ +use super::c64; +use ndarray::prelude::*; + +pub fn X0() -> Array2 { + array![ + [ + c64::new(1.0, 0.0), + c64::new(0.0, 0.0), + c64::new(0.0, 0.0), + c64::new(0.0, 0.0), + ], + [ + c64::new(0.0, 0.0), + c64::new(1.0, 0.0), + c64::new(0.0, 0.0), + c64::new(0.0, 0.0), + ], + [ + c64::new(0.0, 0.0), + c64::new(0.0, 0.0), + c64::new(-1.0, 0.0), + c64::new(0.0, 0.0), + ], + [ + c64::new(0.0, 0.0), + c64::new(0.0, 0.0), + c64::new(0.0, 0.0), + c64::new(-1.0, 0.0), + ] + ] +} + +pub fn X1() -> Array2 { + array![ + [ + c64::new(0.0, 0.0), + c64::new(0.0, 0.0), + c64::new(1.0, 0.0), + c64::new(0.0, 0.0), + ], + [ + c64::new(0.0, 0.0), + c64::new(0.0, 0.0), + c64::new(0.0, 0.0), + c64::new(1.0, 0.0), + ], + [ + c64::new(1.0, 0.0), + c64::new(0.0, 0.0), + c64::new(0.0, 0.0), + c64::new(0.0, 0.0), + ], + [ + c64::new(0.0, 0.0), + c64::new(1.0, 0.0), + c64::new(0.0, 0.0), + c64::new(0.0, 0.0), + ] + ] +} + +pub fn X2() -> Array2 { + array![ + [ + c64::new(0.0, 0.0), + c64::new(0.0, 0.0), + c64::new(0.0, -1.0), + c64::new(0.0, 0.0), + ], + [ + c64::new(0.0, 0.0), + c64::new(0.0, 0.0), + c64::new(0.0, 0.0), + c64::new(0.0, -1.0), + ], + [ + c64::new(0.0, 1.0), + c64::new(0.0, 0.0), + c64::new(0.0, 0.0), + c64::new(0.0, 0.0), + ], + [ + c64::new(0.0, 0.0), + c64::new(0.0, 1.0), + c64::new(0.0, 0.0), + c64::new(0.0, 0.0), + ] + ] +} + +pub fn X3() -> Array2 { + array![ + [ + c64::new(0.0, 0.0), + c64::new(0.0, 0.0), + c64::new(0.0, 0.0), + c64::new(1.0, 0.0), + ], + [ + c64::new(0.0, 0.0), + c64::new(0.0, 0.0), + c64::new(-1.0, 0.0), + c64::new(0.0, 0.0), + ], + [ + c64::new(0.0, 0.0), + c64::new(-1.0, 0.0), + c64::new(0.0, 0.0), + c64::new(0.0, 0.0), + ], + [ + c64::new(1.0, 0.0), + c64::new(0.0, 0.0), + c64::new(0.0, 0.0), + c64::new(0.0, 0.0), + ] + ] +} diff --git a/src/simulation/time_evolution.rs b/src/simulation/time_evolution.rs index 61c609e..31ea4b1 100644 --- a/src/simulation/time_evolution.rs +++ b/src/simulation/time_evolution.rs @@ -1,11 +1,11 @@ use super::c64; -use ndarray::{Array1, Array2}; +use ndarray::Array2; pub trait MatrixGen { fn gen(t: f64) -> Array2; } pub trait State { - fn fibrate(&self) -> Array1; + fn fibrate(&self) -> Vec; fn evolve(self, t: f64) -> Self; } diff --git a/src/simulation/two_level.rs b/src/simulation/two_level.rs index 38a65d9..99336a5 100644 --- a/src/simulation/two_level.rs +++ b/src/simulation/two_level.rs @@ -15,8 +15,12 @@ impl TwoLevel { } impl State for TwoLevel { - fn fibrate(&self) -> Array1 { - self.state.clone() + fn fibrate(&self) -> Vec { + self.state + .iter() + .flat_map(|c| [c.re, c.im]) + .map(|v| *v) + .collect() } fn evolve(mut self, t: f64) -> Self { diff --git a/src/simulation/twoxtwo_level.rs b/src/simulation/twoxtwo_level.rs new file mode 100644 index 0000000..8a34167 --- /dev/null +++ b/src/simulation/twoxtwo_level.rs @@ -0,0 +1,40 @@ +use super::c64; +use super::s_5_fibration::*; +use super::time_evolution::State; +use ndarray::prelude::*; + +pub struct TwoXTwoLevel { + state: Array2, +} + +impl TwoXTwoLevel { + pub fn new(alpha: c64, beta: c64, delta: c64, gamma: c64) -> TwoXTwoLevel { + TwoXTwoLevel { + state: array![[alpha], [beta], [gamma], [delta]], + } + } +} + +impl State for TwoXTwoLevel { + fn fibrate(&self) -> Vec { + let mut conjugate = self + .state + .to_owned() + .into_shape((4, 1)) + .expect("Invalid shape cast during fibartion"); + for val in conjugate.iter_mut() { + *val = val.conj(); + } + + vec![ + conjugate.dot(&X0().dot(&self.state))[(0, 0)].re, + conjugate.dot(&X1().dot(&self.state))[(0, 0)].re, + conjugate.dot(&X2().dot(&self.state))[(0, 0)].re, + ] + } + + fn evolve(mut self, t: f64) -> Self { + self.state = self.state.dot(&G::gen(t)); + self + } +} -- cgit v1.2.3-70-g09d2