diff options
author | Dennis Kobert <dennis@kobert.dev> | 2019-12-13 04:00:31 +0100 |
---|---|---|
committer | Dennis Kobert <dennis@kobert.dev> | 2019-12-13 04:00:31 +0100 |
commit | de571765f161a49129fd9e34150f6a892f388bdc (patch) | |
tree | d3f49cb6bbfdeff9378fda2fe901a6796269330c /src/simulation | |
parent | 1daf4f35a5dd2f500d95541797661c518f4e2713 (diff) |
Add fibartion matrices
Diffstat (limited to 'src/simulation')
-rw-r--r-- | src/simulation/mod.rs | 2 | ||||
-rw-r--r-- | src/simulation/s_5_fibration.rs | 118 | ||||
-rw-r--r-- | src/simulation/time_evolution.rs | 4 | ||||
-rw-r--r-- | src/simulation/two_level.rs | 8 | ||||
-rw-r--r-- | src/simulation/twoxtwo_level.rs | 40 |
5 files changed, 168 insertions, 4 deletions
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<f64>; 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<c64> { + 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<c64> { + 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<c64> { + 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<c64> { + 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<c64>; } pub trait State { - fn fibrate(&self) -> Array1<c64>; + fn fibrate(&self) -> Vec<f64>; fn evolve<G: MatrixGen>(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<c64> { - self.state.clone() + fn fibrate(&self) -> Vec<f64> { + self.state + .iter() + .flat_map(|c| [c.re, c.im]) + .map(|v| *v) + .collect() } fn evolve<G: super::time_evolution::MatrixGen>(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<c64>, +} + +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<f64> { + 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<G: super::time_evolution::MatrixGen>(mut self, t: f64) -> Self { + self.state = self.state.dot(&G::gen(t)); + self + } +} |