quantrs2-sim 0.1.3

Quantum circuit simulators for the QuantRS2 framework
Documentation
//! Auto-generated module
//!
//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)

use scirs2_core::ndarray::{Array1, Array2, Array3, Array4, Axis};
use scirs2_core::Complex64;

use super::topologicalquantumsimulator_type::TopologicalQuantumSimulator;
use super::types::{
    AnyonType, BraidingType, FibonacciAnyons, IsingAnyons, LatticeType, TopologicalConfig,
    TopologicalUtils,
};

/// Trait for anyon model implementations
pub trait AnyonModelImplementation {
    /// Get anyon types for this model
    fn get_anyon_types(&self) -> Vec<AnyonType>;
    /// Compute fusion coefficients
    fn fusion_coefficients(&self, a: &AnyonType, b: &AnyonType, c: &AnyonType) -> Complex64;
    /// Compute braiding matrix
    fn braiding_matrix(&self, a: &AnyonType, b: &AnyonType) -> Array2<Complex64>;
    /// Compute F-matrix
    fn f_matrix(
        &self,
        a: &AnyonType,
        b: &AnyonType,
        c: &AnyonType,
        d: &AnyonType,
    ) -> Array2<Complex64>;
    /// Check if model is Abelian
    fn is_abelian(&self) -> bool;
    /// Get model name
    fn name(&self) -> &str;
}
#[cfg(test)]
#[allow(clippy::field_reassign_with_default)]
mod tests {
    use super::*;
    use approx::assert_abs_diff_eq;
    #[test]
    fn test_topological_config_default() {
        let config = TopologicalConfig::default();
        assert_eq!(config.lattice_type, LatticeType::SquareLattice);
        assert_eq!(config.dimensions, vec![8, 8]);
        assert!(config.topological_protection);
    }
    #[test]
    fn test_anyon_type_creation() {
        let vacuum = AnyonType::vacuum();
        assert_eq!(vacuum.label, "vacuum");
        assert_eq!(vacuum.quantum_dimension, 1.0);
        assert!(vacuum.is_abelian);
        let sigma = AnyonType::sigma();
        assert_eq!(sigma.label, "sigma");
        assert_abs_diff_eq!(sigma.quantum_dimension, 2.0_f64.sqrt(), epsilon = 1e-10);
        assert!(!sigma.is_abelian);
    }
    #[test]
    fn test_topological_simulator_creation() {
        let config = TopologicalConfig::default();
        let simulator = TopologicalQuantumSimulator::new(config);
        assert!(simulator.is_ok());
    }
    #[test]
    fn test_square_lattice_creation() {
        let dimensions = vec![3, 3];
        let lattice = TopologicalQuantumSimulator::create_square_lattice(&dimensions)
            .expect("failed to create square lattice");
        assert_eq!(lattice.sites.len(), 9);
        assert_eq!(lattice.coordination_number, 4);
        assert!(!lattice.bonds.is_empty());
        assert!(!lattice.plaquettes.is_empty());
    }
    #[test]
    fn test_anyon_placement() {
        let config = TopologicalConfig::default();
        let mut simulator =
            TopologicalQuantumSimulator::new(config).expect("failed to create simulator");
        let vacuum = AnyonType::vacuum();
        let anyon_id = simulator
            .place_anyon(vacuum, vec![2, 3])
            .expect("failed to place anyon");
        assert_eq!(anyon_id, 0);
        assert_eq!(simulator.state.anyon_config.anyons.len(), 1);
        assert_eq!(simulator.state.anyon_config.anyons[0].0, vec![2, 3]);
    }
    #[test]
    fn test_braiding_operation() {
        let mut config = TopologicalConfig::default();
        config.enable_braiding = true;
        let mut simulator =
            TopologicalQuantumSimulator::new(config).expect("failed to create simulator");
        let sigma = AnyonType::sigma();
        let anyon_a = simulator
            .place_anyon(sigma.clone(), vec![1, 1])
            .expect("failed to place anyon A");
        let anyon_b = simulator
            .place_anyon(sigma, vec![2, 2])
            .expect("failed to place anyon B");
        let braiding_phase = simulator.braid_anyons(anyon_a, anyon_b, BraidingType::Clockwise);
        assert!(braiding_phase.is_ok());
        assert_eq!(simulator.braiding_history.len(), 1);
        assert_eq!(simulator.stats.braiding_operations, 1);
    }
    #[test]
    fn test_anyon_fusion() {
        let config = TopologicalConfig::default();
        let mut simulator =
            TopologicalQuantumSimulator::new(config).expect("failed to create simulator");
        let sigma = AnyonType::sigma();
        let anyon_a = simulator
            .place_anyon(sigma.clone(), vec![1, 1])
            .expect("failed to place anyon A");
        let anyon_b = simulator
            .place_anyon(sigma, vec![1, 2])
            .expect("failed to place anyon B");
        let fusion_outcomes = simulator.fuse_anyons(anyon_a, anyon_b);
        assert!(fusion_outcomes.is_ok());
    }
    #[test]
    fn test_fibonacci_anyons() {
        let fibonacci_model = FibonacciAnyons::new();
        let anyon_types = fibonacci_model.get_anyon_types();
        assert_eq!(anyon_types.len(), 2);
        assert!(!fibonacci_model.is_abelian());
        assert_eq!(fibonacci_model.name(), "Fibonacci Anyons");
    }
    #[test]
    fn test_ising_anyons() {
        let ising_model = IsingAnyons::new();
        let anyon_types = ising_model.get_anyon_types();
        assert_eq!(anyon_types.len(), 3);
        assert!(!ising_model.is_abelian());
        assert_eq!(ising_model.name(), "Ising Anyons");
    }
    #[test]
    fn test_surface_code_creation() {
        let dimensions = vec![4, 4];
        let surface_code = TopologicalQuantumSimulator::create_toric_surface_code(&dimensions)
            .expect("failed to create surface code");
        assert_eq!(surface_code.distance, 4);
        assert!(!surface_code.data_qubits.is_empty());
        assert!(!surface_code.x_stabilizers.is_empty());
        assert!(!surface_code.z_stabilizers.is_empty());
    }
    #[test]
    fn test_topological_invariants() {
        let config = TopologicalConfig::default();
        let mut simulator =
            TopologicalQuantumSimulator::new(config).expect("failed to create simulator");
        let invariants = simulator.calculate_topological_invariants();
        assert!(invariants.is_ok());
        let inv = invariants.expect("failed to calculate invariants");
        assert!(inv.chern_number.abs() >= 0);
        assert!(inv.hall_conductivity.is_finite());
    }
    #[test]
    fn test_triangular_lattice() {
        let dimensions = vec![3, 3];
        let lattice = TopologicalQuantumSimulator::create_triangular_lattice(&dimensions)
            .expect("failed to create triangular lattice");
        assert_eq!(lattice.lattice_type, LatticeType::TriangularLattice);
        assert_eq!(lattice.sites.len(), 9);
        assert_eq!(lattice.coordination_number, 6);
    }
    #[test]
    fn test_honeycomb_lattice() {
        let dimensions = vec![2, 2];
        let lattice = TopologicalQuantumSimulator::create_honeycomb_lattice(&dimensions)
            .expect("failed to create honeycomb lattice");
        assert_eq!(lattice.lattice_type, LatticeType::HoneycombLattice);
        assert_eq!(lattice.coordination_number, 3);
        assert!(!lattice.bonds.is_empty());
    }
    #[test]
    fn test_error_detection_and_correction() {
        let mut config = TopologicalConfig::default();
        config.topological_protection = true;
        let mut simulator =
            TopologicalQuantumSimulator::new(config).expect("failed to create simulator");
        let syndrome = simulator.detect_and_correct_errors();
        assert!(syndrome.is_ok());
    }
    #[test]
    fn test_predefined_configs() {
        let configs = vec!["toric_code", "fibonacci_system", "majorana_system"];
        for config_type in configs {
            let config = TopologicalUtils::create_predefined_config(config_type, 4);
            let simulator = TopologicalQuantumSimulator::new(config);
            assert!(simulator.is_ok());
        }
    }
}