Ejemplo n.º 1
0
int main(int argc, char **argv) {

 try {

  // write
  std::map<std::string, int> m = { {"a",1}, {"b",2} };
  std::map<std::string, std::vector<double>> mv = { {"a",{1.0, 2.0}}, {"b",{2.0, 3.0, 4.0}} };

  {
   h5::file file1("test_map.h5", H5F_ACC_TRUNC);
   h5::group top1(file1);
   h5_write(top1, "map_int", m);
   h5_write(top1, "map_vec", mv);
  }

  // read
  std::map<std::string, int> mm = { {"c",1} };
  std::map<std::string, std::vector<double>> mmv = { {"c",{1.0}} };

  h5::file file2("test_map.h5", H5F_ACC_RDONLY);
  h5::group top2(file2);
  h5_read(top2, "map_int", mm);
  h5_read(top2, "map_vec", mmv);

  for (auto const & val: mm) std::cout << val.first << " " << val.second << std::endl;
  for (auto const & val: mmv) {
    std::cout << val.first << std::endl;
    for (auto const & x: val.second) std::cout << x << std::endl;
  }

 }
 TRIQS_CATCH_AND_ABORT;
}
Ejemplo n.º 2
0
 // -------------- HDF5  --------------------------
 /// Write into HDF5
 friend void h5_write(h5::group fg, std::string subgroup_name, linear_mesh const &m) {
  h5::group gr = fg.create_group(subgroup_name);
  h5_write(gr, "domain", m.domain());
  h5_write(gr, "min", m.xmin);
  h5_write(gr, "max", m.xmax);
  h5_write(gr, "size", long(m.size()));
 }
Ejemplo n.º 3
0
 static void write(h5::group gr, gf_const_view<M, T, S, E> g) {
  gf_h5_write_data<M, T, S, E>::invoke(gr, g); // h5_write(gr, "data", g._data);
  h5_write(gr, "singularity", g._singularity);
  h5_write(gr, "mesh", g._mesh);
  h5_write(gr, "symmetry", g._symmetry);
  h5_write(gr, "indices", g._indices);
 }
Ejemplo n.º 4
0
 static void write(h5::group gr, gf_const_view<block_index2, Target> g) {
  auto const &m0 = std::get<0>(g.mesh());
  auto const &m1 = std::get<1>(g.mesh());
  for (int i = 0; i < m0.size(); ++i)
   for (int j = 0; j < m1.size(); ++j) h5_write(gr, m0.domain().names()[i] + "_" + m1.domain().names()[j], g._data[i][j]);
  h5_write(gr, "block_names", m0.domain().names());
 }
Ejemplo n.º 5
0
 std::c14::enable_if_t<is_amv_value_or_view_class<ArrayType>::value && !has_scalar_or_string_value_type<ArrayType>::value>
 h5_write(h5::group gr, std::string name, ArrayType const& a) {
  if (a.is_empty()) TRIQS_RUNTIME_ERROR << " Cannot save an empty array into hdf5";
  auto gr2 = gr.create_group(name);
  gr2.write_triqs_hdf5_data_scheme(a);
  // save the shape
  array<int, 1> sha(ArrayType::rank);
  for (int u = 0; u < ArrayType::rank; ++u) sha(u) = a.shape()[u];
  h5_write(gr2, "shape", sha);
#ifndef __cpp_generic_lambdas
  foreach(a, h5_impl::_save_lambda<ArrayType>{a, gr2});
#else
  foreach(a, [&](auto... is) { h5_write(gr2, h5_impl::_h5_name(is...), a(is...)); });
#endif
 }
Ejemplo n.º 6
0
 /// HDF5 interface
 friend void h5_write (h5::group g, std::string const & name, mc_generic const & mc){
  auto gr = g.create_group(name);
  h5_write(gr,"moves", mc.AllMoves);
  h5_write(gr,"measures", mc.AllMeasures);
  h5_write(gr,"length_monte_carlo_cycle", mc.Length_MC_Cycle);
  h5_write(gr,"number_cycle_requested", mc.NCycles);
  h5_write(gr,"number_warming_cycle_requested", mc.NWarmIterations);
  h5_write(gr,"number_cycle_done", mc.NC);
  h5_write(gr,"number_measure_done", mc.nmeasures);
  h5_write(gr,"sign", mc.sign);
  h5_write(gr,"sum_sign", mc.sum_sign);
 }
Ejemplo n.º 7
0
//------------------------------------------------------------
// MAIN
//------------------------------------------------------------
int main(int argc, char* argv[]) {

  // initialize mpi
  boost::mpi::environment env(argc, argv);
  boost::mpi::communicator world;

  // greeting
  if (world.rank() == 0) std::cout << "Random walk calculation" << std::endl;

  // prepare the MC parameters
  int N_Cycles = 100000;
  int Length_Cycle = 100;
  int N_Warmup_Cycles = 0;
  std::string Random_Name = "";
  int Random_Seed = 374982 + world.rank() * 273894;
  int Verbosity = (world.rank() == 0 ? 3 : 0);
  int xmax=floor(4*sqrt(Length_Cycle) ); //max of the position registered in the histogram
  double pl=1.5, pr=1;  //non normalized probabilities for proposing a left or right move

  h5::file file("params.h5",H5F_ACC_TRUNC);
  h5_write(file,"pr",make_array(pr));
  h5_write(file,"pl",make_array(pl));
  h5_write(file,"xmax",make_array(xmax));
  h5_write(file,"N_Cycles",make_array(N_Cycles));
  h5_write(file,"Length_Cycle",make_array(Length_Cycle));
  
  // construct a Monte Carlo loop
  triqs::mc_tools::mc_generic<double> IntMC(N_Cycles, Length_Cycle, N_Warmup_Cycles, Random_Name, Random_Seed, Verbosity);

  // construct configuration
  configuration config;
  triqs::arrays::array<double,1> H(2*xmax);
  H()=0;

  // add moves and measures
  IntMC.add_move(move_left (config, pl, pr, IntMC.rng()  ), "left move",  pl);
  IntMC.add_move(move_right(config, pl, pr, IntMC.rng()  ), "right move", pr);
  IntMC.add_measure(compute_histo(config, H, xmax), "histogramn measure");

  // Run and collect results
  IntMC.start(1.0, triqs::utility::clock_callback(600));
  IntMC.collect_results(world);

  return 0;

}
Ejemplo n.º 8
0
 /// Write into HDF5
 friend void h5_write(h5::group fg, std::string subgroup_name, matsubara_freq_mesh const &m) {
     h5::group gr = fg.create_group(subgroup_name);
     h5_write(gr, "domain", m.domain());
     h5_write(gr, "size", m.size());
     if (m._positive_only) {
         // kept ONLY for backward compatibility of archives
         auto beta = m.domain().beta;
         h5_write(gr, "min", Fermion ? M_PI / beta : 0);
         h5_write(gr, "max", ((Fermion ? 1 : 0) + 2 * m.size()) * M_PI / beta);
         h5_write(gr, "kind", 2);
     } else { // A strange way : to preserve backward compatibility for old archive.
         h5_write(gr, "start_at_0", m._positive_only);
     }
 }
Ejemplo n.º 9
0
TEST(GfCartesian, H5_RW_EvaluatorM) {
 double beta = 1;
 auto g = gf<cartesian_product<imfreq, imfreq>, matrix_valued>{{{beta, Fermion, 5}, {beta, Boson, 5}}, {1, 1}};
 g() = 2;

 h5::file file("g_nu_nuph5", H5F_ACC_TRUNC);
 h5_write(file, "g", g);
 gf<cartesian_product<imfreq, imfreq>, matrix_valued> g2{};
 h5_read(file, "g", g2);

 EXPECT_ARRAY_NEAR(g.data(), g2.data());
 //EXPECT_GF_NEAR(g, g2);

 auto w0 = matsubara_freq(0, beta, Fermion);
 auto W10 = matsubara_freq(10, beta, Boson);
 auto W0 = matsubara_freq(0, beta, Boson);

 EXPECT_ARRAY_NEAR(g(w0, W0), g2(w0, W0));
 EXPECT_ARRAY_NEAR(g(w0, W10), g2(w0, W10));
}
Ejemplo n.º 10
0
 void write_array(h5::group g, std::string const& name, array_const_view<std::string, 1> V) {
  std::vector<std::string> tmp(first_dim(V));
  std::copy(begin(V), end(V), begin(tmp));
  h5_write(g, name, tmp);
 }
Ejemplo n.º 11
0
 /// Write into HDF5
 friend void h5_write(h5::group fg, std::string subgroup_name, gf_mesh const &m) {
  h5::group gr = fg.create_group(subgroup_name);
  auto l = [gr](int N, auto const &m) { h5_write(gr, "MeshComponent" + std::to_string(N), m); };
  triqs::tuple::for_each_enumerate(m.components(), l);
 }
Ejemplo n.º 12
0
 static void write(h5::group gr, gf_const_view<block_index, Target> g) {
  for (size_t i = 0; i < g.mesh().size(); ++i) h5_write(gr, g.mesh().domain().names()[i], g._data[i]);
  h5_write(gr, "block_names", g.mesh().domain().names());
 }
Ejemplo n.º 13
0
 // overload : special treatment for arrays of strings (one dimension only).
 void write_array(h5::group g, std::string const& name, vector_const_view<std::string> V) {
  std::vector<std::string> tmp(V.size());
  std::copy(begin(V), end(V), begin(tmp));
  h5_write(g, name, tmp);
 }
Ejemplo n.º 14
0
 // given a pointer to an object, synthesize h5_read/write function for this object
 template<typename T> h5_rw_lambda_t make_h5_write_impl(T * p, std::true_type) {
  return [p](h5::group F, std::string const &Name) {h5_write(F,Name, *p);};
 }
Ejemplo n.º 15
0
template <typename... Is> void operator()(Is const&... is) const { h5_write(g, _h5_name(is...), a(is...)); }
Ejemplo n.º 16
0
 /// Write into HDF5
 friend void h5_write(h5::group fg, std::string subgroup_name, matsubara_domain const &d) {
  h5::group gr = fg.create_group(subgroup_name);
  h5_write(gr, "beta", d.beta);
  h5_write(gr, "statistic", (d.statistic == Fermion ? "F" : "B"));
 }
Ejemplo n.º 17
0
 static void write(h5::group gr, gf_const_view<block_index, Target, Opt> g) {
  for (size_t i = 0; i < g.mesh().size(); ++i) h5_write(gr, g.mesh().domain().names()[i], g._data[i]);
  // h5_write(gr,"symmetry",g._symmetry);
 }
Ejemplo n.º 18
0
 /// Write into HDF5
 friend void h5_write(h5::group fg, std::string subgroup_name, gf_mesh const &m) {
  h5::group gr = fg.create_group(subgroup_name);
  h5_write(gr, "domain", m.domain());
  h5_write(gr, "size", long(m.size()));
  h5_write(gr, "positive_freq_only", (m._positive_only?1:0));
 }
Ejemplo n.º 19
0
 template <typename... T> void h5_write(h5::group gr, std::string const &name, std::variant<T...> const &v) {
   visit([&](auto const &x) { h5_write(gr, name, x); }, v);
 }
Ejemplo n.º 20
0
 void h5_write (triqs::h5::group fg, std::string subgroup_name, block_matrix<T> const & c) {
  triqs::h5::group gr = fg.create_group(subgroup_name);
  h5_write(gr,"block_names",c.block_names);
  h5_write(gr,"matrix_vec",c.matrix_vec);
  h5_write_attribute(gr, "TRIQS_HDF5_data_scheme", get_triqs_hdf5_data_scheme(c));
 }
Ejemplo n.º 21
0
 template <typename G> static void invoke(h5::group gr, G const &g) {
  if (!is_gf_real(g))
   h5_write(gr, "data", g.data());
  else
   h5_write(gr, "data", array<double, 3>(real(g.data())));
 }
Ejemplo n.º 22
0
 void collect_results(boost::mpi::communicator const &c) {
  H/=tot;
  h5::file file("histo.h5",H5F_ACC_TRUNC);
  h5_write(file,"H",H);
 }
Ejemplo n.º 23
0
 // HDF5 interface
 friend void h5_write (h5::group g, std::string const & name, measure_set const & ms) {
     auto gr = g.create_group(name);
     for (auto & p : ms.m_map) h5_write(gr,p.first, p.second);
 }
Ejemplo n.º 24
0
 /// Write into HDF5
 friend void h5_write(h5::group fg, std::string subgroup_name, discrete_mesh const &m) {
  h5::group gr = fg.create_group(subgroup_name);
  h5_write(gr, "domain", m.domain());
 }
Ejemplo n.º 25
0
 /// Write into HDF5
 friend void h5_write (tqa::h5::group_or_file fg, std::string subgroup_name, discrete_mesh const & m) {
  tqa::h5::group_or_file gr =  fg.create_group(subgroup_name);
  h5_write(gr,"domain",m.domain());
 }
Ejemplo n.º 26
0
template <typename G> static void invoke(h5::group gr, G const &g) { h5_write(gr, "data", g.data()); }
Ejemplo n.º 27
0
 /// Write into HDF5
 friend void h5_write(h5::group fg, std::string subgroup_name, gf_mesh const& m) {
  h5::group gr = fg.create_group(subgroup_name);
  h5_write(gr, "dims", m.dims.to_vector());
 }
Ejemplo n.º 28
0
 friend void h5_write(h5::group fg, std::string subgroup_name, tail_impl const &t) {
  auto gr = fg.create_group(subgroup_name);
  h5_write(gr, "omin", t.omin);
  h5_write(gr, "mask", t._mask);
  h5_write(gr, "data", t._data);
 }