1#ifndef XPED_IPEPS_SOLVER_IMAG_H_
2#define XPED_IPEPS_SOLVER_IMAG_H_
11template <
typename Scalar,
typename Symmetry>
14 template <
typename Sym>
32 imag_opts.
resume ? HighFive::File::ReadWrite : HighFive::File::ReadOnly);
35 if(file.exist(fmt::format(
"/{}/{}", D, chi))) {
36 fmt::print(fg(fmt::color::red),
37 "There already exists data in observable file for D={}, chi={}.\n Filename:{}.\n",
42 std::cout << std::flush;
53 }
catch(
const std::exception& e) {
54 fmt::print(fg(fmt::color::red),
55 "Error while creating the observable file for this simulation:{}.\n",
58 std::cout << std::flush;
68 "{}: Model={}(Bonds: V:{}, H:{}, D1: {}, D2: {})",
69 fmt::styled(
"iPEPSSolverImag", fmt::emphasis::bold),
81 for(
auto iD = 0ul; iD < Es.size(); ++iD) { Es[iD].resize(
imag_opts.
chis[iD].size()); }
83 std::chrono::seconds evol_time{0}, ctm_time{0};
92 std::size_t steps = 0ul;
103 for(
auto i = 0ul; i < conv_h.
size(); ++i) {
104 if(conv_h[i].coupledDomain() != Jim.
spectrum_h[i].coupledDomain() or
105 conv_h[i].coupledCodomain() != Jim.
spectrum_h[i].coupledCodomain()) {
106 diff_h[i] = std::nan(
"1");
108 diff_h[i] = (conv_h[i] - Jim.
spectrum_h[i]).norm();
110 if(conv_v[i].coupledDomain() != Jim.
spectrum_v[i].coupledDomain() or
111 conv_v[i].coupledCodomain() != Jim.
spectrum_v[i].coupledCodomain()) {
112 diff_h[i] = std::nan(
"1");
114 diff_v[i] = (conv_v[i] - Jim.
spectrum_v[i]).norm();
117 diff = std::max(*std::max_element(diff_h.
begin(), diff_h.
end()), *std::max_element(diff_v.
begin(), diff_v.
end()));
124 " ImagSteps(D={}: Nτ={:^4d}, dτ={:.1e}): runtime={}, conv={:2.3g}",
130 Psi->updateAtensors();
131 constexpr std::size_t flags = yas::file | yas::binary;
132 yas::file_ostream ofs(
135 yas::save<flags>(ofs, *
Psi);
139 evol_time += evol_t.
time();
143 Es[iD][ichi] =
Jack.template solve<double, false>(
Psi,
nullptr,
H);
148 std::string e_name = fmt::format(
"/{}/{}/energy", D, chi);
151 HighFive::File::OpenOrCreate);
152 if(not file.exist(e_name)) {
153 HighFive::DataSpace dataspace = HighFive::DataSpace({0, 0}, {HighFive::DataSpace::UNLIMITED, HighFive::DataSpace::UNLIMITED});
156 HighFive::DataSetCreateProps props;
157 props.add(HighFive::Chunking(std::vector<hsize_t>{2, 2}));
160 HighFive::DataSet dataset = file.createDataSet(e_name, dataspace, HighFive::create_datatype<double>(), props);
163 auto d = file.getDataSet(e_name);
164 std::vector<std::vector<double>> data;
165 data.push_back(std::vector<double>(1, Es[iD][ichi]));
166 std::size_t curr_size = d.getDimensions()[0];
167 d.resize({curr_size + 1, data[0].size()});
168 d.select({curr_size, 0}, {1, data[0].size()}).write(data);
170 H.obsToFile(file, fmt::format(
"/{}/{}/", D, chi));
175 ctm_time += ctm_t.
time();
179 "{}(runtime={} [evol={}, ctm={}]) energies:",
180 fmt::styled(
"iPEPSSolverImag", fmt::emphasis::bold),
184 for(
auto i = 0ul; i < Es.size(); ++i) {
185 for(
auto j = 0; j < Es[i].size(); ++j) {
197 case Opts::LoadFormat::MATLAB: {
199 "Load initial iPEPS from matlab file {}.\nScale the quantum numbers from matlab by {}.",
205 case Opts::LoadFormat::NATIVE: {
207 constexpr std::size_t flags = yas::file | yas::binary;
210 yas::load<flags>(load_p.string().c_str(), tmp_Psi);
211 }
catch(
const yas::serialization_exception& se) {
213 "Error while deserializing file ({}) with initial wavefunction.\nThis might be because of incompatible symmetries between this simulation and the loaded wavefunction.",
215 std::cout << std::flush;
217 }
catch(
const yas::io_exception& ie) {
218 fmt::print(
"Error while loading file ({}) with initial wavefunction.\n", load_p.string());
219 std::cout << std::flush;
221 }
catch(
const std::exception& e) {
222 fmt::print(
"Unknown error while loading file ({}) with initial wavefunction.\n", load_p.string());
223 std::cout << std::flush;
226 Psi = std::make_shared<iPEPS<Scalar, Symmetry>>(std::move(tmp_Psi));
230 Psi->initWeightTensors();
231 assert(
Psi->cell().pattern ==
H.data_h.pat);
241 std::vector<std::shared_ptr<iPEPS<Scalar, Symmetry>>> init_Psis(
imag_opts.
init_seeds.size());
242 for(
auto& init_Psi : init_Psis) { init_Psi = std::make_shared<iPEPS<Scalar, Symmetry>>(*Psi); }
246 init_Psis[i]->initWeightTensors();
254 " MultiInit(D={}, seed={}: Nτ={:^4d}, dτ={:.1e}): runtime={}",
261 init_Psis[i]->updateAtensors();
265 init_Es[i] =
Jack.template solve<double, false>(init_Psis[i],
nullptr,
H);
267 std::size_t min_index = std::distance(init_Es.begin(), std::min_element(init_Es.begin(), init_Es.end()));
273 Psi = std::move(init_Psis[min_index]);
277 Psi->initWeightTensors();
284 std::shared_ptr<iPEPS<Scalar, Symmetry>>
Psi;
Definition: CTMSolver.hpp:18
XPED_CONST CTM< Scalar, Symmetry, TRank, false > & getCTM() XPED_CONST
Definition: CTMSolver.hpp:41
Opts::CTM opts
Definition: CTMSolver.hpp:51
Definition: TimePropagator.hpp:25
void t_step(iPEPS< Scalar, Symmetry > &Psi)
Definition: TimePropagator.cpp:8
TMatrix< Tensor< Scalar, 1, 1, Symmetry > > spectrum_h
Definition: TimePropagator.hpp:50
TMatrix< Tensor< Scalar, 1, 1, Symmetry > > spectrum_v
Definition: TimePropagator.hpp:51
Definition: Stopwatch.hpp:42
std::string time_string(TimeUnit u=TimeUnit::NATURAL)
Definition: Stopwatch.hpp:90
std::chrono::seconds time()
Definition: Stopwatch.hpp:113
constexpr void on_exit(Verbosity policy, Args &&... args)
Definition: Logging.hpp:102
constexpr void on_entry(Verbosity policy, Args &&... args)
Definition: Logging.hpp:108
constexpr void per_iteration(Verbosity policy, Args &&... args)
Definition: Logging.hpp:114
std::string format_secs(std::chrono::duration< double, std::ratio< 1, 1 > > dts)
Definition: Stopwatch.hpp:25
Definition: CTMOpts.hpp:28
auto info()
Definition: CTMOpts.hpp:62
std::size_t chi
Definition: CTMOpts.hpp:29
Definition: ImagOpts.hpp:32
std::vector< std::size_t > t_steps
Definition: ImagOpts.hpp:36
bool multi_init
Definition: ImagOpts.hpp:65
std::string load
Definition: ImagOpts.hpp:48
std::filesystem::path obs_directory
Definition: ImagOpts.hpp:62
Verbosity verbosity
Definition: ImagOpts.hpp:56
std::vector< std::size_t > init_t_steps
Definition: ImagOpts.hpp:68
auto info()
Definition: ImagOpts.hpp:105
double tol
Definition: ImagOpts.hpp:44
std::size_t init_chi
Definition: ImagOpts.hpp:70
bool resume
Definition: ImagOpts.hpp:46
std::vector< std::vector< std::size_t > > chis
Definition: ImagOpts.hpp:34
std::size_t seed
Definition: ImagOpts.hpp:52
Update update
Definition: ImagOpts.hpp:39
std::vector< std::size_t > init_Ds
Definition: ImagOpts.hpp:67
std::vector< std::size_t > Ds
Definition: ImagOpts.hpp:33
std::size_t id
Definition: ImagOpts.hpp:54
LoadFormat load_format
Definition: ImagOpts.hpp:49
std::vector< double > init_dts
Definition: ImagOpts.hpp:69
std::size_t min_steps
Definition: ImagOpts.hpp:42
std::filesystem::path working_directory
Definition: ImagOpts.hpp:58
std::vector< double > dts
Definition: ImagOpts.hpp:37
std::vector< std::size_t > init_seeds
Definition: ImagOpts.hpp:66
bool display_obs
Definition: ImagOpts.hpp:63
int qn_scale
Definition: ImagOpts.hpp:50
Definition: TMatrix.hpp:13
std::size_t size() const
Definition: TMatrix.hpp:38
auto end()
Definition: TMatrix.hpp:68
auto begin()
Definition: TMatrix.hpp:67
Definition: TwoSiteObservable.hpp:22
Definition: iPEPSSolverImag.hpp:13
void init_psi()
Definition: iPEPSSolverImag.hpp:191
Opts::Imag imag_opts
Definition: iPEPSSolverImag.hpp:283
CTMSolver< Scalar, Symmetry > Jack
Definition: iPEPSSolverImag.hpp:282
void solve()
Definition: iPEPSSolverImag.hpp:65
iPEPSSolverImag(Opts::Imag imag_opts, Opts::CTM ctm_opts, std::shared_ptr< iPEPS< Scalar, Symmetry > > Psi_in, Hamiltonian< Symmetry > &H_in)
Definition: iPEPSSolverImag.hpp:19
Hamiltonian< Symmetry > & H
Definition: iPEPSSolverImag.hpp:285
std::shared_ptr< iPEPS< Scalar, Symmetry > > Psi
Definition: iPEPSSolverImag.hpp:284