31#include <boost/container/flat_map.hpp>
39namespace triqs::hilbert_space {
87 [[nodiscard]]
auto size()
const {
return dim_; }
110 if (f >= dim_)
TRIQS_RUNTIME_ERROR <<
"Error in hilbert_space::get_state_index: Fock state is not in H: f = " << f;
111 return static_cast<int>(f);
123 if (f >= dim_)
TRIQS_RUNTIME_ERROR <<
"Error in hilbert_space::get_fock_state: Index is >= dim(H): " << f;
137 std::set<fundamental_operator_set::indices_t>
const &alphas)
const {
139 for (
auto const &alpha : alphas) f += 1 << fops[alpha];
144 [[nodiscard]]
static std::string
hdf5_format() {
return "hilbert_space"; }
154 auto gr = g.create_group(name);
155 h5::write(gr,
"dim", hs.dim_);
166 auto gr = g.open_group(name);
167 h5::read(gr,
"dim", hs.dim_);
201#ifdef TRIQS_WORKAROUND_INTEL_COMPILER_BUGS
207 fock_states = x.fock_states;
208 fock_to_index = x.fock_to_index;
226 int const M =
static_cast<int>(fock_states_.size());
227 fock_states_.push_back(f);
228 fock_to_index_.insert(std::make_pair(f, M));
232 [[nodiscard]]
auto size()
const {
return static_cast<int>(fock_states_.size()); }
276 [[nodiscard]]
static std::string
hdf5_format() {
return "sub_hilbert_space"; }
286 auto gr = g.create_group(name);
287 h5::write(gr,
"index", hs.m_);
288 h5::write(gr,
"fock_states", hs.fock_states_);
299 auto gr = g.open_group(name);
300 h5::read(gr,
"index", hs.m_);
301 h5::read(gr,
"fock_states", hs.fock_states_);
302 hs.fock_to_index_.clear();
303 for (
auto f : hs.fock_states_) hs.fock_to_index_.insert(std::make_pair(f,
static_cast<int>(hs.fock_to_index_.size())));
308 std::vector<fock_state_t> fock_states_;
309 boost::container::flat_map<fock_state_t, int> fock_to_index_;
Class representing a fundamental operator set.
fock_state_t get_fock_state(fundamental_operator_set const &fops, std::set< fundamental_operator_set::indices_t > const &alphas) const
Get the Fock state .
static std::string hdf5_format()
Get the HDF5 format tag.
friend void h5_write(h5::group g, std::string const &name, hilbert_space const &hs)
Write a triqs::hilbert_space::hilbert_space to HDF5.
auto size() const
Get the dimension of the Hilbert (Fock) space .
bool operator==(hilbert_space const &hs) const
Equal-to operator compares the dimensions of the two Hilbert (Fock) spaces.
bool has_state(fock_state_t f) const
Check if a given Fock state belongs to the Hilbert (Fock) space.
friend void h5_read(h5::group g, std::string const &name, hilbert_space &hs)
Read a triqs::hilbert_space::hilbert_space from HDF5.
fock_state_t get_fock_state(int f) const
Get the Fock state corresponding to a given integer .
auto get_state_index(fock_state_t f) const
Get the integer corresponding to a given Fock state .
hilbert_space(fundamental_operator_set const &fops)
Construct a Hilbert (Fock) space from a given triqs::hilbert_space::fundamental_operator_set object.
hilbert_space()
Default constructor constructs an empty Hilbert (Fock) space of dimension .
Subspace of a fermionic Hilbert (Fock) space.
static std::string hdf5_format()
Get the HDF5 format tag.
auto const & get_all_fock_states() const
Get , the ordered set of all Fock states in the subspace.
void set_index(int m)
Set the subspace index of this subspace .
auto get_state_index(fock_state_t f) const
Get the index of a given Fock state within this subspace.
auto size() const
Get the dimension of the subspace.
auto get_fock_state(int i) const
Get the Fock state for a given index .
bool operator==(sub_hilbert_space const &hs) const
Equal-to operator compares the subspace index and the ordered set .
friend void h5_read(h5::group g, std::string const &name, sub_hilbert_space &hs)
Read a triqs::hilbert_space::sub_hilbert_space from HDF5.
friend void h5_write(h5::group g, std::string const &name, sub_hilbert_space const &hs)
Write a triqs::hilbert_space::sub_hilbert_space to HDF5.
sub_hilbert_space(int m=-1)
Construct an empty subspace with a given index .
void add_fock_state(fock_state_t f)
Add a Fock state to the subspace and increase its dimension by one.
auto get_index() const
Get the subspace index .
bool has_state(fock_state_t f) const
Check if a given Fock state belongs to this subspace.
TRIQS exception hierarchy and related macros.
uint64_t fock_state_t
Integer type representing a fermionic fock state .
#define TRIQS_RUNTIME_ERROR
Throw a triqs::runtime_error with the current source location.
Provides a fundamental operator set class.