23#include <triqs/hilbert_space/hilbert_space.hpp>
24#include <triqs/utility/time_pt.hpp>
25#include <triqs/atom_diag/atom_diag.hpp>
26#include <triqs/atom_diag/functions.hpp>
27#include <triqs/utility/macros.hpp>
33namespace triqs_cthyb {
35 using triqs::utility::time_pt;
36 using triqs::utility::time_segment;
52 friend std::ostream &operator<<(std::ostream &out,
op_desc const &op) {
57 static std::string hdf5_format() {
return "op_desc"; }
59 friend void h5_write(h5::group g, std::string
const &name, op_desc
const &op) {
60 auto gr = g.create_group(name);
61 h5::write_hdf5_format(gr, op);
62 h5::write(gr,
"block", op.block_index);
63 h5::write(gr,
"inner", op.inner_index);
64 h5::write(gr,
"dagger", op.dagger);
65 h5::write(gr,
"linear_index", op.linear_index);
68 friend void h5_read(h5::group g, std::string
const &name, op_desc &op) {
69 h5::group gr = g.open_group(name);
70 h5::assert_hdf5_format(gr, op);
71 h5::read(g,
"block", op.block_index);
72 h5::read(g,
"inner", op.inner_index);
73 h5::read(g,
"dagger", op.dagger);
74 h5::read(g,
"linear_index", op.linear_index);
77 bool operator==(op_desc
const &op)
const =
default;
81 struct configuration {
83 bool operator==(configuration
const &config)
const {
return (beta_ == config.beta_ && oplist_ == config.oplist_); }
86 using oplist_t = std::map<time_pt, op_desc, std::greater<time_pt>>;
89 configuration(
double beta,
long id = 0, oplist_t oplist = {})
90 : beta_(beta), id_(
id), oplist_(oplist), configs_hfile(
"configs.h5", exists(
"configs.h5") ?
'a' :
'w') {
91 if (NUM_CONFIGS_TO_SAVE > 0)
h5_write(configs_hfile,
"c_0", *
this);
93 ~configuration() { configs_hfile.close(); }
95 configuration(
double beta,
long id = 0) : beta_(beta), id_(
id) {}
96 C2PY_IGNORE configuration(
double beta,
long id, oplist_t oplist) : beta_(beta), id_(
id), oplist_(oplist) {}
101 auto size()
const {
return oplist_.size(); }
123 void erase(time_pt
const &t) { oplist_.erase(t); }
128 oplist_t::iterator begin() {
return oplist_.begin(); }
129 oplist_t::iterator end() {
return oplist_.end(); }
130 oplist_t::const_iterator begin()
const {
return oplist_.begin(); }
131 oplist_t::const_iterator end()
const {
return oplist_.end(); }
133 friend std::ostream &operator<<(std::ostream &out, configuration
const &c) {
134 for (
auto const &op : c) out <<
"tau = " << op.first <<
" : " << op.second << std::endl;
139 static std::string
hdf5_format() {
return "CTHYB_Configuration"; }
142 friend void h5_write(h5::group g, std::string
const &name, configuration
const &c) {
143 h5::group gr = g.create_group(name);
144 h5::write_hdf5_format(gr, c);
145 h5::write(gr,
"beta", c.beta_);
146 h5::write(gr,
"id", c.id_);
147 h5::write(gr,
"oplist", c.oplist_);
152 h5::group gr = g.open_group(name);
153 h5::assert_hdf5_format<configuration>(gr);
154 auto beta = h5::read<double>(gr,
"beta");
155 auto id = h5::read<long>(gr,
"id");
156 auto oplist = h5::read<oplist_t>(gr,
"oplist");
157 return configuration(beta,
id, std::move(oplist));
167 if (
id < NUM_CONFIGS_TO_SAVE)
h5_write(configs_hfile,
"c_" + std::to_string(
id), *
this);
178 h5::file configs_hfile;
void finalize()
Finalize the configuration after a Monte Carlo move (increment the ID and save the configuration if n...
long get_id() const
Get the ID of the current configuration (for debug purposes).
static C2PY_IGNORE configuration h5_read_construct(h5::group g, std::string const &name)
Read a configuration from an hdf5 file.
void replace(time_pt tau, op_desc op)
Replace an existing operator at a given imaginary time with a new one.
friend void h5_write(h5::group g, std::string const &name, configuration const &c)
Write a configuration to an hdf5 file.
void erase(time_pt const &t)
Erase the operator at a given imaginary time.
C2PY_PROPERTY_GET(beta) double beta() const
Inverse temperature .
void insert(time_pt tau, op_desc op)
Insert a given operator at a given imaginary time.
void clear()
Clear the configuration (remove all operators).
static std::string hdf5_format()
HDF5 format string for configuration.
Description of a creation/annihilation operator.
long linear_index
Cumulative (linear) index.
bool dagger
Whether the operator is a dagger (creation operator).
int inner_index
Inner index within the block.
int block_index
Block index of the operator.