Skip to main content

tensor4all_itensorlike/
error.rs

1//! Error types for TensorTrain operations.
2
3use thiserror::Error;
4
5/// Result type for TensorTrain operations.
6pub type Result<T> = std::result::Result<T, TensorTrainError>;
7
8/// Errors that can occur in TensorTrain operations.
9#[derive(Debug, Error)]
10pub enum TensorTrainError {
11    /// Tensor train is empty (has no tensors).
12    #[error("Tensor train is empty")]
13    Empty,
14
15    /// Site index is out of bounds.
16    #[error("Site index {site} is out of bounds (tensor train has {length} sites)")]
17    SiteOutOfBounds {
18        /// The requested site index.
19        site: usize,
20        /// The total number of sites in the tensor train.
21        length: usize,
22    },
23
24    /// Bond dimension mismatch between adjacent tensors.
25    #[error("Bond dimension mismatch at site {site}: left tensor has right dim {left_dim}, right tensor has left dim {right_dim}")]
26    BondDimensionMismatch {
27        /// The site index where the mismatch occurred.
28        site: usize,
29        /// The right bond dimension of the left tensor.
30        left_dim: usize,
31        /// The left bond dimension of the right tensor.
32        right_dim: usize,
33    },
34
35    /// Tensor train does not have a well-defined orthogonality center.
36    #[error("Tensor train does not have a well-defined orthogonality center (ortho_lims = {start}..{end})")]
37    NoOrthogonalityCenter {
38        /// The start of the orthogonality limits range.
39        start: usize,
40        /// The end of the orthogonality limits range.
41        end: usize,
42    },
43
44    /// Invalid tensor structure for tensor train.
45    #[error("Invalid tensor structure: {message}")]
46    InvalidStructure {
47        /// A description of the structural issue.
48        message: String,
49    },
50
51    /// Factorization error.
52    #[error("Factorization error: {0}")]
53    Factorize(#[from] tensor4all_core::FactorizeError),
54
55    /// General operation error.
56    #[error("Operation error: {message}")]
57    OperationError {
58        /// A description of the operation error.
59        message: String,
60    },
61}