27 #ifndef ALPS_MPS_OPTIM_RUN_EIGENSTATE_SIM_HPP
28 #define ALPS_MPS_OPTIM_RUN_EIGENSTATE_SIM_HPP
38 #include <alps/parser/xmlstream.h>
44 template <
class Matrix,
class SymmGroup>
54 template <
class Matrix,
class SymmGroup>
57 int neigen = parms[
"NUMBER_EIGENVALUES"];
58 std::vector<std::string> checkpoints(neigen);
59 for (
int eig=0; eig<neigen; ++eig) {
61 std::string resfile = parms[
"resultfile"].str();
62 std::string ckpfile = parms[
"chkpfile"].str();
64 std::string eig_suffix = std::string(
".") + boost::lexical_cast<std::string>(eig);
65 resfile = boost::replace_last_copy(parms[
"resultfile"].str(),
".h5", eig_suffix+
".h5");
66 ckpfile = boost::replace_last_copy(parms[
"chkpfile"].str(),
".chkp", eig_suffix+
".chkp");
67 myparms.
set(
"resultfile", resfile);
68 myparms.
set(
"chkpfile", ckpfile);
70 std::stringstream ortho_states;
71 std::copy(checkpoints.begin(), checkpoints.begin()+eig, std::ostream_iterator<std::string>(ortho_states,
","));
72 myparms.
set(
"n_ortho_states", eig);
73 myparms.
set(
"ortho_states", ortho_states.str());
82 checkpoints[eig] = ckpfile;
97 measurements_type m = (parms.defined(
"nsweeps")) ? overlap_measurements<Matrix, SymmGroup>(parms, parms[
"nsweeps"]-1) : overlap_measurements<Matrix, SymmGroup>(parms);
98 measurements.insert(measurements.end(), m.begin(), m.end());
101 std::string rfile = parms[
"resultfile"].str();
104 ar[
"/parameters"] << parms;
107 alps::oxstream out(boost::replace_last_copy(rfile,
".h5",
".xml"));
108 out << alps::header(
"UTF-8") << alps::stylesheet(alps::xslt_path(
"ALPS.xsl"));
109 out << alps::start_tag(
"SIMULATION") << alps::xml_namespace(
"xsi",
"http://www.w3.org/2001/XMLSchema-instance")
110 << alps::attribute(
"xsi:noNamespaceSchemaLocation",
"http://xml.comp-phys.org/2003/10/ALPS.xsd");
114 out << alps::start_tag(
"EIGENSTATES") << alps::attribute(
"number", neigen);
116 for (
int eig=0; eig<neigen; ++eig) {
118 load(checkpoints[eig], mps);
120 maquis::cout <<
"Measurements." << std::endl;
123 std::vector<int> * measure_es_where = NULL;
125 if (parms.defined(
"entanglement_spectra")) {
127 measure_es_where =
new std::vector<int>();
128 *measure_es_where = parms.template get<std::vector<int> >(
"entanglement_spectra");
130 std::vector<double> entropies, renyi2;
131 if (parms[
"MEASURE[Entropy]"]) {
132 std::cout <<
"Calculating vN entropy." << std::endl;
135 if (parms[
"MEASURE[Renyi2]"]) {
136 std::cout <<
"Calculating n=2 Renyi entropy." << std::endl;
141 std::cout <<
"Energy: " << energy << std::endl;
145 if (entropies.size() > 0)
save_val_at_index(ar,
"/spectrum/results/Entropy/mean/value", entropies, eig);
146 if (renyi2.size() > 0)
save_val_at_index(ar,
"/spectrum/results/Renyi2/mean/value", renyi2, eig);
147 if (spectra != NULL)
save_val_at_index(ar,
"/spectrum/results/Entanglement Spectra/mean/value", *spectra, eig);
150 if (parms[
"MEASURE[EnergyVariance]"]) {
152 mpo2.compress(1e-12);
156 maquis::cout <<
"Energy^2: " << energy2 << std::endl;
157 maquis::cout <<
"Variance: " << energy2 - energy*energy << std::endl;
162 save_val_at_index(ar,
"/spectrum/results/EnergyVariance/mean/value", energy2 - energy*energy, eig);
167 out << alps::start_tag(
"EIGENSTATE") << alps::attribute(
"number", eig);
169 std::for_each(measurements.begin(), measurements.end(),
save_to_xml(out));
171 out << alps::start_tag(
"SCALAR_AVERAGE") << alps::attribute(
"name",
"Energy") << alps::no_linebreak
172 << alps::start_tag(
"MEAN") << alps::no_linebreak << energy << alps::end_tag(
"MEAN")
173 << alps::end_tag(
"SCALAR_AVERAGE");
175 out << alps::end_tag(
"EIGENSTATE");
178 out << alps::end_tag(
"EIGENSTATES");
179 out << alps::end_tag(
"SIMULATION");
void load(alps::hdf5::archive &ar, std::string const &path, TrivialGroup::charge &value, std::vector< std::size_t > chunk=std::vector< std::size_t >(), std::vector< std::size_t > offset=std::vector< std::size_t >())
MPO< Matrix, SymmGroup > make_mpo(Lattice const &lat, Model< Matrix, SymmGroup > const &model, BaseParameters &parms)
double expval(MPS< Matrix, SymmGroup > const &mps, MPO< Matrix, SymmGroup > const &mpo, int d)
measurements_type measurements() const
std::vector< double > calculate_bond_entropies(MPS< Matrix, SymmGroup > &mps)
void set(std::string const &key, T const &value)
void save_val_at_index(Archive &ar, std::string const &archive_path, T const &val, std::size_t eig)
simulation class for ground state optimization
std::vector< std::pair< std::vector< std::string >, std::vector< double > > > entanglement_spectrum_type
void operator()(measurement< Matrix, SymmGroup > const &m)
save_to_xml(alps::oxstream &o)
void write_xml(alps::oxstream &) const
MPO< Matrix, SymmGroup > square_mpo(MPO< Matrix, SymmGroup > const &mpo)
impl_type::measurements_type measurements_type
void run_eigenstate_sim(BaseParameters parms, bool write_xml, run_type rt)
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)
wrapper of eigenstate_sim for symmetry factory
alps::numeric::real_type< T >::type real(T f)