1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//! High-level 2-site DMRG entry point.
//!
//! [`dmrg_2site`] hides [`BraketEnvs`] construction and canonical-form
//! management from non-expert callers, layered on top of the
//! layout-generic low-level driver [`super::sweep_2site`]. The
//! low-level driver intentionally rejects MPS not in `Right` or
//! `Mixed { center: 0 }` form so that a caller-supplied env is never
//! silently invalidated by an internal canonicalize; this wrapper
//! defensively clones the input MPS, canonicalizes the clone to
//! `Mixed { center: 0 }`, builds a fresh [`BraketEnvs`] against it, and
//! then invokes the driver. The caller's `psi0` is left untouched.
//!
//! Naming convention: `dmrg_2site` is the pure 2-site entry point.
//! The bare name `dmrg` is intentionally reserved for a future
//! mixed-strategy entry point (a single call that varies the number
//! of sites optimized per sweep, mirroring ITensorMPS.jl's `dmrg`
//! with `nsite` keyword). Pure 1-site DMRG with subspace expansion,
//! when it lands, will sit alongside as `dmrg_1site`.
//!
//! # Generic surface
//!
//! `dmrg_2site` is generic over the `Mps<St, L>` chain
//! (`Mps<St, L>: super::DmrgOps<T>` + `Clone`), so the same entry point
//! covers both the Dense and BlockSparse / U(1) paths. The `Clone` bounds
//! (on the storage and layout) are required because the wrapper
//! defensively clones the input `Mps` before canonicalizing it. Both
//! concrete chains satisfy `Clone`, so the bound is met for every concrete
//! chain in the workspace. DMRG is host-pinned in the
//! CPU-only Stage B scope, so the boundary supplies the [`Host`]
//! substrate rather than an arbitrary backend.
//!
//! # Errors
//!
//! See [`DmrgError`] for the full set. Two failure modes are caught
//! by the wrapper itself before the lower layers can panic or repeat
//! the check:
//!
//! - [`DmrgError::EmptyMps`] — `ariadnetor_mps::canonicalize` asserts
//! `center < n` and would panic on an empty chain.
//! - [`DmrgError::LengthMismatch`] — surfaced eagerly so callers see
//! one failure mode for the same bug regardless of whether the
//! build or the sweep would have caught it.
//!
//! Underlying [`BraketEnvError`] (e.g. BlockSparse edge-bond validation)
//! and [`DmrgSweepError`] (param validation, local-eigensolver / SVD
//! failure, `TooFewSites`, etc.) are forwarded as
//! [`DmrgError::Env`] / [`DmrgError::Sweep`] respectively; the
//! `MpsNotRightCanonical` and downstream `LengthMismatch` variants of
//! [`DmrgSweepError`] are unreachable through the wrapper but kept
//! visible as defense-in-depth.
use Scalar;
use ;
use ;
use DmrgOps;
use ;
use ;
/// Errors raised by [`dmrg_2site`].
/// Output of [`dmrg_2site`]: the diagnostic [`DmrgResult`] paired with the
/// optimized MPS, or a [`DmrgError`].
type Dmrg2SiteOutput<R, St, L> = ;
/// Run a 2-site DMRG calculation with caller-friendly defaults for
/// canonical-form management and environment construction.
///
/// The caller's `psi0` is **defensively cloned**; the input MPS is
/// not mutated regardless of outcome. The clone is canonicalized to
/// `Mixed { center: 0 }`, paired with a freshly built [`BraketEnvs`],
/// and handed to [`super::sweep_2site`]. The optimized MPS is
/// returned alongside the diagnostic [`DmrgResult`].
///
/// The returned MPS ends in `CanonicalForm::Mixed { center: 0 }`
/// (the orthogonality center sits at site 0 because the driver runs
/// R→L last); see [`super::sweep_2site`] for details.
///
/// # Errors
///
/// Returns [`DmrgError::EmptyMps`] when `psi0.len() == 0`,
/// [`DmrgError::LengthMismatch`] when MPO and MPS lengths disagree,
/// [`DmrgError::Env`] on environment-build failure, and
/// [`DmrgError::Sweep`] on driver failure.