tensor4all_simplett/mpo/
error.rs1use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, MPOError>;
7
8#[derive(Error, Debug)]
10pub enum MPOError {
11 #[error("Dimension mismatch: tensor at site {site} has incompatible dimensions")]
13 DimensionMismatch {
14 site: usize,
16 },
17
18 #[error("Bond dimension mismatch at site {site}: left tensor has right_dim={left_right}, right tensor has left_dim={right_left}")]
20 BondDimensionMismatch {
21 site: usize,
23 left_right: usize,
25 right_left: usize,
27 },
28
29 #[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 site: usize,
34 dim_a: usize,
36 dim_b: usize,
38 },
39
40 #[error("MPO length mismatch: expected {expected}, got {got}")]
42 LengthMismatch {
43 expected: usize,
45 got: usize,
47 },
48
49 #[error("Index out of bounds: index {index} at site {site} (max: {max})")]
51 IndexOutOfBounds {
52 site: usize,
54 index: usize,
56 max: usize,
58 },
59
60 #[error("MPO is empty")]
62 Empty,
63
64 #[error("Invalid boundary conditions: first tensor must have left_dim=1, last tensor must have right_dim=1")]
66 InvalidBoundary,
67
68 #[error("Invalid orthogonality center: {center} is out of range [0, {max})")]
70 InvalidCenter {
71 center: usize,
73 max: usize,
75 },
76
77 #[error("Factorization failed: {message}")]
79 FactorizationError {
80 message: String,
82 },
83
84 #[error("Invalid operation: {message}")]
86 InvalidOperation {
87 message: String,
89 },
90
91 #[error("Matrix CI error: {0}")]
93 MatrixCI(#[from] tensor4all_tcicore::MatrixCIError),
94
95 #[error("Failed to converge after {sweeps} sweeps (final error: {error})")]
97 ConvergenceFailure {
98 sweeps: usize,
100 error: f64,
102 },
103}