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
tevol_sim< Matrix, SymmGroup, TimeEvolver > Class Template Reference

#include <tevol_sim.hpp>

Inheritance diagram for tevol_sim< Matrix, SymmGroup, TimeEvolver >:
sim< Matrix, SymmGroup > abstract_sim

Public Member Functions

 tevol_sim (DmrgParameters const &parms_, bool write_xml_)
 
void run ()
 

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 TimeEvolver>
class tevol_sim< Matrix, SymmGroup, TimeEvolver >

Definition at line 39 of file tevol_sim.hpp.

Constructor & Destructor Documentation

template<class Matrix , class SymmGroup , class TimeEvolver >
tevol_sim< Matrix, SymmGroup, TimeEvolver >::tevol_sim ( DmrgParameters const &  parms_,
bool  write_xml_ 
)
inline

Definition at line 56 of file tevol_sim.hpp.

57  : base(parms_)
58  , write_xml(write_xml_)
59  {
60  alps::oxstream out(boost::replace_last_copy(rfile, ".h5", ".xml"));
61  out << alps::header("UTF-8") << alps::stylesheet(alps::xslt_path("ALPS.xsl"));
62  out << alps::start_tag("SIMULATION") << alps::xml_namespace("xsi","http://www.w3.org/2001/XMLSchema-instance")
63  << alps::attribute("xsi:noNamespaceSchemaLocation","http://xml.comp-phys.org/2003/10/ALPS.xsd");
64  out << parms;
65  out << alps::end_tag("SIMULATION");
66  }
DmrgParameters parms
Definition: sim.h:89
std::string rfile
Definition: sim.h:95

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 , class TimeEvolver >
void tevol_sim< Matrix, SymmGroup, TimeEvolver >::run ( )
inlinevirtual

Implements sim< Matrix, SymmGroup >.

Definition at line 68 of file tevol_sim.hpp.

69  {
70  int meas_each = parms["measure_each"];
71  int chkp_each = parms["chkp_each"];
72  int update_each = parms["update_each"];
73  int nsweeps = parms["nsweeps"];
74  int nsweeps_img = parms["nsweeps_img"];
75 
77 
78  /// compute nsteps as the min of the three above
79  int nsteps = parms["nsweeps"];
80  if (meas_each > -1)
81  nsteps = std::min(nsteps, meas_each);
82  if (chkp_each > -1)
83  nsteps = std::min(nsteps, chkp_each);
84  if (update_each > -1)
85  nsteps = std::min(nsteps, update_each);
86 
87  #define CHECK_MULTIPLICITY(var) \
88  if (var > 0 && var % nsteps != 0) \
89  throw std::runtime_error("var must be a multiple of 'nsteps'.");
90  CHECK_MULTIPLICITY(nsweeps)
91  CHECK_MULTIPLICITY(nsweeps_img)
92  CHECK_MULTIPLICITY(meas_each)
93  CHECK_MULTIPLICITY(chkp_each)
94  CHECK_MULTIPLICITY(update_each)
95  #undef CHECK_MULTIPLICITY
96 
97  TimeEvolver evolver(&parms, &mps, lat, model, init_sweep);
98 
99  int n = nsweeps / nsteps;
100  for (int i=init_sweep/nsteps; i < n; ++i) {
101  // TODO: introduce some timings
102 
103  int sweep = i*nsteps;
104  BaseParameters iteration_params = parms.iteration_params("Time", sweep);
105  if (update_each > -1 && (sweep % update_each) == 0)
106  {
107  if (iteration_params.size() > 1) { // Time will always be set
108  parms << iteration_params;
109  meas_each = parms["measure_each"];
110  chkp_each = parms["chkp_each"];
111  update_each = parms["update_each"];
112  model.update(parms);
113  mpo = make_mpo(lat, model, parms);
114  evolver = TimeEvolver(&parms, &mps, lat, model, sweep);
115  }
116  } else if (sweep == nsweeps_img) {
117  // since this is just a change in the time step, there is
118  // no need to split the hamiltonian in non-overlapping terms.
119  evolver.prepare_te_terms(sweep);
120  }
121 
122  /// time evolution
123  evolver(sweep, nsteps);
124  sweep = (i+1)*nsteps - 1;
125  iteration_params.set("Time", sweep);
126 
127  /// measurements
128  if ((sweep+1) % meas_each == 0 || (sweep+1) == parms["nsweeps"])
129  {
130  /// measure energy
131  double energy = maquis::real(expval(mps, mpo));
132  maquis::cout << "Energy " << energy << std::endl;
133 
134  /// measure observables specified in 'always_measure'
135  measurements_type always_measure = this->iteration_measurements(sweep); // todo: make measure() using const&
136  if (!parms["ALWAYS_MEASURE"].empty())
137  this->measure(this->results_archive_path(sweep) + "/results/", always_measure);
138 
139  /// write iteration results
140  {
141  storage::archive ar(rfile, "w");
142  ar[this->results_archive_path(sweep) + "/parameters"] << iteration_params;
143  ar[this->results_archive_path(sweep) + "/results"] << evolver.iteration_results();
144  ar[this->results_archive_path(sweep) + "/results/Energy/mean/value"] << std::vector<double>(1, energy);
145  // ar[this->results_archive_path(sweep) + "/results/Runtime/mean/value"] << std::vector<double>(1, elapsed_sweep + elapsed_measure);
146  }
147  }
148 
149  /// write checkpoint
150  bool stopped = stop_callback();
151  if (stopped || (sweep+1) % chkp_each == 0 || (sweep+1) == parms["nsweeps"])
152  checkpoint_simulation(mps, sweep);
153 
154  if (stopped) break;
155  }
156  }
virtual void measure(std::string archive_path, measurements_type &meas)
Definition: sim.hpp:161
MPO< Matrix, SymmGroup > make_mpo(Lattice const &lat, Model< Matrix, SymmGroup > const &model, BaseParameters &parms)
DmrgParameters parms
Definition: sim.h:89
double expval(MPS< Matrix, SymmGroup > const &mps, MPO< Matrix, SymmGroup > const &mpo, int d)
Definition: mps_mpo_ops.h:72
MPS< Matrix, SymmGroup > mps
Definition: sim.h:101
measurements_type iteration_measurements(int sweep)
Definition: sim.hpp:112
void set(std::string const &key, T const &value)
Model< Matrix, SymmGroup > model
Definition: sim.h:100
time_stopper stop_callback
Definition: sim.h:97
BaseParameters iteration_params(std::string const &var, std::size_t val)
std::string rfile
Definition: sim.h:95
int init_sweep
Definition: sim.h:91
#define CHECK_MULTIPLICITY(var)
Lattice lat
Definition: sim.h:99
MPO< Matrix, SymmGroup > mpo
Definition: sim.h:102
alps::numeric::real_type< T >::type real(T f)
Definition: bindings.hpp:38

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: