Skip to main content

tensor4all_simplett/mpo/
error.rs

1//! Error types for MPO contraction operations
2
3use thiserror::Error;
4
5/// Result type for MPO operations
6pub type Result<T> = std::result::Result<T, MPOError>;
7
8/// Errors that can occur during MPO operations
9#[derive(Error, Debug)]
10pub enum MPOError {
11    /// Dimension mismatch between tensors
12    #[error("Dimension mismatch: tensor at site {site} has incompatible dimensions")]
13    DimensionMismatch {
14        /// The site index where the mismatch occurred
15        site: usize,
16    },
17
18    /// Bond dimension mismatch between adjacent tensors
19    #[error("Bond dimension mismatch at site {site}: left tensor has right_dim={left_right}, right tensor has left_dim={right_left}")]
20    BondDimensionMismatch {
21        /// The site index where the mismatch occurred
22        site: usize,
23        /// Right dimension of the left tensor
24        left_right: usize,
25        /// Left dimension of the right tensor
26        right_left: usize,
27    },
28
29    /// Shared dimension mismatch between two MPOs
30    #[error("Shared dimension mismatch at site {site}: MPO A has site_dim_2={dim_a}, MPO B has site_dim_1={dim_b}")]
31    SharedDimensionMismatch {
32        /// The site index where the mismatch occurred
33        site: usize,
34        /// Second site dimension of MPO A
35        dim_a: usize,
36        /// First site dimension of MPO B
37        dim_b: usize,
38    },
39
40    /// Length mismatch between two MPOs
41    #[error("MPO length mismatch: expected {expected}, got {got}")]
42    LengthMismatch {
43        /// The expected length
44        expected: usize,
45        /// The actual length provided
46        got: usize,
47    },
48
49    /// Invalid index provided
50    #[error("Index out of bounds: index {index} at site {site} (max: {max})")]
51    IndexOutOfBounds {
52        /// The site index where the error occurred
53        site: usize,
54        /// The invalid index value
55        index: usize,
56        /// The maximum allowed index value
57        max: usize,
58    },
59
60    /// Empty MPO
61    #[error("MPO is empty")]
62    Empty,
63
64    /// Invalid boundary conditions
65    #[error("Invalid boundary conditions: first tensor must have left_dim=1, last tensor must have right_dim=1")]
66    InvalidBoundary,
67
68    /// Invalid orthogonality center
69    #[error("Invalid orthogonality center: {center} is out of range [0, {max})")]
70    InvalidCenter {
71        /// The invalid center value
72        center: usize,
73        /// The maximum allowed center value
74        max: usize,
75    },
76
77    /// Factorization error
78    #[error("Factorization failed: {message}")]
79    FactorizationError {
80        /// Description of the factorization failure
81        message: String,
82    },
83
84    /// Invalid operation
85    #[error("Invalid operation: {message}")]
86    InvalidOperation {
87        /// Description of the invalid operation
88        message: String,
89    },
90
91    /// Matrix CI error
92    #[error("Matrix CI error: {0}")]
93    MatrixCI(#[from] tensor4all_tcicore::MatrixCIError),
94
95    /// Convergence failure
96    #[error("Failed to converge after {sweeps} sweeps (final error: {error})")]
97    ConvergenceFailure {
98        /// The number of sweeps performed before failure
99        sweeps: usize,
100        /// The final error value achieved
101        error: f64,
102    },
103}