Skip to main content

quantrs2_sim/topological_quantum_simulation/
isinganyons_traits.rs

1//! # IsingAnyons - Trait Implementations
2//!
3//! This module contains trait implementations for `IsingAnyons`.
4//!
5//! ## Implemented Traits
6//!
7//! - `Default`
8//! - `AnyonModelImplementation`
9//!
10//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)
11
12use scirs2_core::ndarray::{Array1, Array2, Array3, Array4, Axis};
13use scirs2_core::Complex64;
14use std::f64::consts::PI;
15
16use super::functions::AnyonModelImplementation;
17use super::types::{AnyonType, IsingAnyons};
18
19impl Default for IsingAnyons {
20    fn default() -> Self {
21        Self::new()
22    }
23}
24
25impl AnyonModelImplementation for IsingAnyons {
26    fn get_anyon_types(&self) -> Vec<AnyonType> {
27        self.anyon_types.clone()
28    }
29    fn fusion_coefficients(&self, a: &AnyonType, b: &AnyonType, c: &AnyonType) -> Complex64 {
30        match (a.label.as_str(), b.label.as_str(), c.label.as_str()) {
31            ("sigma", "sigma", "vacuum" | "psi") => Complex64::new(1.0, 0.0),
32            ("psi", "psi", "vacuum") => Complex64::new(1.0, 0.0),
33            ("sigma", "psi", "sigma") | ("psi", "sigma", "sigma") => Complex64::new(1.0, 0.0),
34            ("vacuum", _, label) | (_, "vacuum", label) if label == a.label || label == b.label => {
35                Complex64::new(1.0, 0.0)
36            }
37            _ => Complex64::new(0.0, 0.0),
38        }
39    }
40    fn braiding_matrix(&self, a: &AnyonType, b: &AnyonType) -> Array2<Complex64> {
41        let phase = a.r_matrix * b.r_matrix.conj();
42        if a.label == "sigma" && b.label == "sigma" {
43            Array2::from_shape_vec(
44                (2, 2),
45                vec![
46                    Complex64::new(0.0, 1.0) * (PI / 8.0).exp(),
47                    Complex64::new(0.0, 0.0),
48                    Complex64::new(0.0, 0.0),
49                    Complex64::new(0.0, -1.0) * (PI / 8.0).exp(),
50                ],
51            )
52            .expect("IsingAnyons::braiding_matrix: 2x2 matrix shape is always valid")
53        } else {
54            Array2::from_shape_vec((1, 1), vec![phase])
55                .expect("IsingAnyons::braiding_matrix: 1x1 matrix shape is always valid")
56        }
57    }
58    fn f_matrix(
59        &self,
60        _a: &AnyonType,
61        _b: &AnyonType,
62        _c: &AnyonType,
63        _d: &AnyonType,
64    ) -> Array2<Complex64> {
65        let sqrt_2_inv = 1.0 / 2.0_f64.sqrt();
66        Array2::from_shape_vec(
67            (2, 2),
68            vec![
69                Complex64::new(sqrt_2_inv, 0.0),
70                Complex64::new(sqrt_2_inv, 0.0),
71                Complex64::new(sqrt_2_inv, 0.0),
72                Complex64::new(-sqrt_2_inv, 0.0),
73            ],
74        )
75        .expect("IsingAnyons::f_matrix: 2x2 matrix shape is always valid")
76    }
77    fn is_abelian(&self) -> bool {
78        false
79    }
80    fn name(&self) -> &'static str {
81        "Ising Anyons"
82    }
83}