ALPS MPS Codes
Reference documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
dmrg_sim< Matrix, SymmGroup > Class Template Reference

#include <dmrg_sim.hpp>

Inheritance diagram for dmrg_sim< Matrix, SymmGroup >:
sim< Matrix, SymmGroup > abstract_sim

Public Member Functions

 dmrg_sim (DmrgParameters &parms_)
 
void run ()
 
 ~dmrg_sim ()
 

Protected Member Functions

virtual std::string results_archive_path (status_type const &) const
 
measurements_type iteration_measurements (int sweep)
 
virtual void measure (std::string archive_path, measurements_type &meas)
 
virtual void checkpoint_simulation (MPS< Matrix, SymmGroup > const &state, status_type const &)
 

Protected Attributes

DmrgParameters parms
 
int init_sweep
 
int init_site
 
bool restore
 
bool dns
 
std::string chkpfile
 
std::string rfile
 
time_stopper stop_callback
 
Lattice lat
 
Model< Matrix, SymmGroup > model
 
MPS< Matrix, SymmGroup > mps
 
MPO< Matrix, SymmGroup > mpo
 
MPO< Matrix, SymmGroup > mpoc
 
measurements_type all_measurements
 
measurements_type sweep_measurements
 

Detailed Description

template<class Matrix, class SymmGroup>
class dmrg_sim< Matrix, SymmGroup >

Definition at line 41 of file dmrg_sim.hpp.

Constructor & Destructor Documentation

template<class Matrix, class SymmGroup>
dmrg_sim< Matrix, SymmGroup >::dmrg_sim ( DmrgParameters parms_)
inline

Definition at line 59 of file dmrg_sim.hpp.

60  : base(parms_)
61  { }
template<class Matrix, class SymmGroup>
dmrg_sim< Matrix, SymmGroup >::~dmrg_sim ( )
inline

Definition at line 132 of file dmrg_sim.hpp.

133  {
135  }
static void sync()
Definition: storage.h:245

Member Function Documentation

template<class Matrix, class SymmGroup>
void sim< Matrix, SymmGroup >::checkpoint_simulation ( MPS< Matrix, SymmGroup > const &  state,
status_type const &  status 
)
protectedvirtualinherited

Definition at line 131 of file sim.hpp.

132 {
133  if (!dns) {
134  /// create chkp dir
135  if (!boost::filesystem::exists(chkpfile))
136  boost::filesystem::create_directory(chkpfile);
137  /// save state to chkp dir
138  save(chkpfile, state);
139 
140  /// save status
141  storage::archive ar(chkpfile+"/props.h5", "w");
142  ar["/status"] << status;
143  }
144 }
std::string chkpfile
Definition: sim.h:94
bool dns
Definition: sim.h:93
void save(alps::hdf5::archive &ar, std::string const &path, TrivialGroup::charge const &value, std::vector< std::size_t > size=std::vector< std::size_t >(), std::vector< std::size_t > chunk=std::vector< std::size_t >(), std::vector< std::size_t > offset=std::vector< std::size_t >())
Definition: none.h:70
template<class Matrix , class SymmGroup >
sim< Matrix, SymmGroup >::measurements_type sim< Matrix, SymmGroup >::iteration_measurements ( int  sweep)
protectedinherited

Definition at line 112 of file sim.hpp.

113 {
115  mymeas << overlap_measurements<Matrix, SymmGroup>(parms, sweep);
116 
118  if (!parms["ALWAYS_MEASURE"].empty())
119  sweep_measurements = meas_sublist(mymeas, parms["ALWAYS_MEASURE"]);
120 
121  return sweep_measurements;
122 }
Model< Matrix, SymmGroup >::measurements_type measurements_type
Definition: sim.h:77
DmrgParameters parms
Definition: sim.h:89
measurements_type sweep_measurements
Definition: sim.h:103
boost::ptr_vector< measurement< Matrix, SymmGroup > > meas_sublist(boost::ptr_vector< measurement< Matrix, SymmGroup > > const &m, std::vector< std::string > const &meas_list)
Definition: measurements.h:97
measurements_type all_measurements
Definition: sim.h:103
template<class Matrix , class SymmGroup >
void sim< Matrix, SymmGroup >::measure ( std::string  archive_path,
measurements_type meas 
)
protectedvirtualinherited

Definition at line 161 of file sim.hpp.

162 {
163  maquis::cout << "Measurements." << std::endl;
164  std::for_each(meas.begin(), meas.end(), measure_and_save<Matrix, SymmGroup>(rfile, archive_path, mps));
165 
166  // TODO: move into special measurement
167  std::vector<int> * measure_es_where = NULL;
168  entanglement_spectrum_type * spectra = NULL;
169  if (!parms["entanglement_spectra"].empty()) {
170  spectra = new entanglement_spectrum_type();
171  measure_es_where = new std::vector<int>();
172  *measure_es_where = parms.template get<std::vector<int> >("entanglement_spectra");
173  }
174  std::vector<double> entropies, renyi2;
175  if (parms["MEASURE[Entropy]"]) {
176  maquis::cout << "Calculating vN entropy." << std::endl;
177  entropies = calculate_bond_entropies(mps);
178  }
179  if (parms["MEASURE[Renyi2]"]) {
180  maquis::cout << "Calculating n=2 Renyi entropy." << std::endl;
181  renyi2 = calculate_bond_renyi_entropies(mps, 2, measure_es_where, spectra);
182  }
183 
184  {
185  storage::archive ar(rfile, "w");
186  if (entropies.size() > 0)
187  ar[archive_path + "/Entropy/mean/value"] << entropies;
188  if (renyi2.size() > 0)
189  ar[archive_path + "/Renyi2/mean/value"] << renyi2;
190  if (spectra != NULL)
191  ar[archive_path + "/Entanglement Spectra/mean/value"] << *spectra;
192  }
193 }
DmrgParameters parms
Definition: sim.h:89
std::vector< double > calculate_bond_entropies(MPS< Matrix, SymmGroup > &mps)
Definition: mps_mpo_ops.h:252
MPS< Matrix, SymmGroup > mps
Definition: sim.h:101
std::vector< std::pair< std::vector< std::string >, std::vector< double > > > entanglement_spectrum_type
Definition: mps_mpo_ops.h:183
std::string rfile
Definition: sim.h:95
std::vector< double > calculate_bond_renyi_entropies(MPS< Matrix, SymmGroup > &mps, double n, std::vector< int > *measure_es_where=NULL, entanglement_spectrum_type *spectra=NULL)
Definition: mps_mpo_ops.h:186
template<class Matrix , class SymmGroup >
std::string sim< Matrix, SymmGroup >::results_archive_path ( status_type const &  status) const
protectedvirtualinherited

Definition at line 147 of file sim.hpp.

148 {
149  std::ostringstream oss;
150  oss.str("");
151 #if defined(__xlC__) || defined(__FCC_VERSION)
152  typename status_type::const_iterator match = status.find("sweep");
153  oss << "/spectrum/iteration/" << match->second;
154 #else
155  oss << "/spectrum/iteration/" << status.at("sweep");
156 #endif
157  return oss.str();
158 }
template<class Matrix, class SymmGroup>
void dmrg_sim< Matrix, SymmGroup >::run ( )
inlinevirtual

Implements sim< Matrix, SymmGroup >.

Definition at line 63 of file dmrg_sim.hpp.

64  {
65  int meas_each = parms["measure_each"];
66  int chkp_each = parms["chkp_each"];
67 
68  /// MPO creation
70  if (parms["use_compressed"])
71  mpoc.compress(1e-12);
72 
73  /// Optimizer initialization
74  boost::shared_ptr<opt_base_t> optimizer;
75  if (init_sweep < parms["nsweeps"]) {
76  if (parms["optimization"] == "singlesite")
78  (mps, mpoc, parms, stop_callback, init_site) );
79  else if(parms["optimization"] == "twosite")
81  (mps, mpoc, parms, stop_callback, init_site) );
82  else
83  throw std::runtime_error("Don't know this optimizer");
84  }
85 
86  measurements_type always_measurements = this->iteration_measurements(init_sweep);
87 
88  try {
89  bool stopped = false;
90  for (int sweep=init_sweep; sweep < parms["nsweeps"]; ++sweep) {
91  // TODO: introduce some timings
92 
93  optimizer->sweep(sweep, Both);
95 
96  if ((sweep+1) % meas_each == 0 || (sweep+1) == parms["nsweeps"])
97  {
98  /// write iteration results
99  {
100  storage::archive ar(rfile, "w");
101  ar[results_archive_path(sweep) + "/parameters"] << parms;
102  ar[results_archive_path(sweep) + "/results"] << optimizer->iteration_results();
103  // ar[results_archive_path(sweep) + "/results/Runtime/mean/value"] << std::vector<double>(1, elapsed_sweep + elapsed_measure);
104  }
105 
106  /// measure observables specified in 'always_measure'
107  if (always_measurements.size() > 0)
108  this->measure(this->results_archive_path(sweep) + "/results/", always_measurements);
109  }
110 
111  /// write checkpoint
112  stopped = stop_callback();
113  if (stopped || (sweep+1) % chkp_each == 0 || (sweep+1) == parms["nsweeps"])
114  checkpoint_simulation(mps, sweep, -1);
115 
116  if (stopped) break;
117  }
118  } catch (dmrg::time_limit const& e) {
119  maquis::cout << e.what() << " checkpointing partial result." << std::endl;
120  checkpoint_simulation(mps, e.sweep(), e.site());
121 
122  {
123  storage::archive ar(rfile, "w");
124  ar[results_archive_path(e.sweep()) + "/parameters"] << parms;
125  ar[results_archive_path(e.sweep()) + "/results"] << optimizer->iteration_results();
126  // ar[results_archive_path(e.sweep()) + "/results/Runtime/mean/value"] << std::vector<double>(1, elapsed_sweep + elapsed_measure);
127  }
128  throw e;
129  }
130  }
virtual void measure(std::string archive_path, measurements_type &meas)
Definition: sim.hpp:161
DmrgParameters parms
Definition: sim.h:89
MPS< Matrix, SymmGroup > mps
Definition: sim.h:101
Definition: optimize.h:84
measurements_type iteration_measurements(int sweep)
Definition: sim.hpp:112
time_stopper stop_callback
Definition: sim.h:97
Definition: mpo.h:36
std::string rfile
Definition: sim.h:95
int init_sweep
Definition: sim.h:91
static void sync()
Definition: storage.h:245
int init_site
Definition: sim.h:91
MPO< Matrix, SymmGroup > mpo
Definition: sim.h:102
MPO< Matrix, SymmGroup > mpoc
Definition: sim.h:102

Member Data Documentation

template<class Matrix, class SymmGroup>
measurements_type sim< Matrix, SymmGroup >::all_measurements
protectedinherited

Definition at line 103 of file sim.h.

template<class Matrix, class SymmGroup>
std::string sim< Matrix, SymmGroup >::chkpfile
protectedinherited

Definition at line 94 of file sim.h.

template<class Matrix, class SymmGroup>
bool sim< Matrix, SymmGroup >::dns
protectedinherited

Definition at line 93 of file sim.h.

template<class Matrix, class SymmGroup>
int sim< Matrix, SymmGroup >::init_site
protectedinherited

Definition at line 91 of file sim.h.

template<class Matrix, class SymmGroup>
int sim< Matrix, SymmGroup >::init_sweep
protectedinherited

Definition at line 91 of file sim.h.

template<class Matrix, class SymmGroup>
Lattice sim< Matrix, SymmGroup >::lat
protectedinherited

Definition at line 99 of file sim.h.

template<class Matrix, class SymmGroup>
Model<Matrix, SymmGroup> sim< Matrix, SymmGroup >::model
protectedinherited

Definition at line 100 of file sim.h.

template<class Matrix, class SymmGroup>
MPO<Matrix, SymmGroup> sim< Matrix, SymmGroup >::mpo
protectedinherited

Definition at line 102 of file sim.h.

template<class Matrix, class SymmGroup>
MPO<Matrix, SymmGroup> sim< Matrix, SymmGroup >::mpoc
protectedinherited

Definition at line 102 of file sim.h.

template<class Matrix, class SymmGroup>
MPS<Matrix, SymmGroup> sim< Matrix, SymmGroup >::mps
protectedinherited

Definition at line 101 of file sim.h.

template<class Matrix, class SymmGroup>
DmrgParameters sim< Matrix, SymmGroup >::parms
protectedinherited

Definition at line 89 of file sim.h.

template<class Matrix, class SymmGroup>
bool sim< Matrix, SymmGroup >::restore
protectedinherited

Definition at line 92 of file sim.h.

template<class Matrix, class SymmGroup>
std::string sim< Matrix, SymmGroup >::rfile
protectedinherited

Definition at line 95 of file sim.h.

template<class Matrix, class SymmGroup>
time_stopper sim< Matrix, SymmGroup >::stop_callback
protectedinherited

Definition at line 97 of file sim.h.

template<class Matrix, class SymmGroup>
measurements_type sim< Matrix, SymmGroup >::sweep_measurements
protectedinherited

Definition at line 103 of file sim.h.


The documentation for this class was generated from the following file: