11#include <fmt/ranges.h>
32 std::vector<long> sigma_embed_decomp;
35 std::vector<std::vector<long>> imp_decomps;
38 std::vector<std::string> _sigma_names;
41 std::vector<std::string> alpha_names;
60 imp_block_t() =
default;
61 imp_block_t(
long n_imp,
long gamma,
long tau) : imp_idx(n_imp), gamma(gamma), tau(tau) {}
62 friend bool operator==(imp_block_t
const &, imp_block_t
const &) =
default;
65 friend std::ostream &
operator<<(std::ostream &out, imp_block_t
const &x) {
66 return out << fmt::format(
"(imp_idx = {}, γ = {}, τ = {})", x.imp_idx, x.gamma, x.tau);
74 nda::array<imp_block_t, 2> psi;
77 std::vector<nda::array<std::vector<std::array<long, 2>>, 2>> reverse_psi;
90 embedding(std::vector<long> sigma_embed_decomposition, std::vector<std::vector<long>> imp_decompositions, nda::array<imp_block_t, 2> psi,
107 imp_block_t
operator[](
long alpha,
long sigma)
const {
return psi(alpha, sigma); }
111 [[nodiscard]] nda::array<imp_block_t, 2>
get_psi()
const {
return psi; }
114 [[nodiscard]]
long n_alpha()
const {
return psi.extent(0); }
117 [[nodiscard]]
long n_sigma()
const {
return psi.extent(1); }
120 [[nodiscard]]
long n_gamma(
long imp_idx)
const {
return long(imp_decomps[imp_idx].size()); }
123 [[nodiscard]]
long n_impurities()
const {
return long(imp_decomps.size()); }
126 [[nodiscard]] std::vector<std::string>
sigma_names()
const {
return _sigma_names; };
129 [[nodiscard]] std::vector<long>
imp_decomposition(
long imp_idx)
const {
return imp_decomps[imp_idx]; };
138 std::string
description(
bool verbosity =
false)
const;
174 embedding replace(
long imp_idx_to_remove,
long imp_idx_to_replace_with)
const;
214 embedding split(
long imp_idx, std::vector<long>
const &block_list)
const;
225 auto make_block_matrix = [](
auto const &gf_struct) {
226 return gf_struct | stdv::transform([](
auto &x) {
227 auto bl_size = x.second;
228 return nda::zeros<dcomplex>(bl_size, bl_size);
230 | tl::to<std::vector<nda::matrix<dcomplex>>>();
233 auto make_self_energy = [&](
auto const &gf_struct) {
234 auto Sigma_static = make_block_matrix(gf_struct);
235 auto Sigma_dynamic = block_gf<Mesh, matrix_valued>{mesh, gf_struct};
236 return std::make_pair(Sigma_dynamic, Sigma_static);
239 return imp_block_shape() | stdv::transform(make_self_energy) | tl::to<std::vector>();
265 template <
typename Mesh> block2_gf<Mesh, matrix_valued>
embed(std::vector<block_gf<Mesh, matrix_valued>>
const &Sigma_imp_vec)
const {
267 if (not
all_equal(Sigma_imp_vec | stdv::transform([](
auto &&x) ->
decltype(
auto) {
return x[0].mesh(); })))
268 throw std::runtime_error{
"[embedding_desc::embed]: meshes of solvers are not all equal"};
270 auto const &mesh = Sigma_imp_vec[0][0].mesh();
274 for (
auto &&[S, m] : zip(Sigma_embed, psi)) {
275 if (m.imp_idx == -1)
continue;
276 S() = Sigma_imp_vec[m.imp_idx][m.gamma +
n_gamma(m.imp_idx) * m.tau];
291 template <
typename Mesh>
292 std::pair<block2_gf<Mesh, matrix_valued>,
block2_matrix_t>
embed(std::vector<block_gf<Mesh, matrix_valued>>
const &Sigma_imp_vec,
293 std::vector<block_matrix_t>
const &Sigma_imp_static_vec)
const {
294 if (Sigma_imp_vec.size() != Sigma_imp_static_vec.size()) {
295 throw std::runtime_error(fmt::format(
"The lists of self-energies are not equal {} != {}", Sigma_imp_vec.size(), Sigma_imp_static_vec.size()));
297 return {this->
embed(Sigma_imp_vec), this->
embed(Sigma_imp_static_vec)};
312 template <
typename Mesh> std::vector<block_gf<Mesh, matrix_valued>>
extract(block2_gf<Mesh, matrix_valued>
const &g_loc)
const {
314 if (
auto decomp =
get_struct(g_loc).dims(
r_all, 0) | tl::to<std::vector>(); decomp != this->sigma_embed_decomp) {
315 if (decomp.size() != 1)
throw std::runtime_error{
"extract: g should have decomp = sigma_embedding_decomp or [1]"};
321 auto extract_one_imp = [&](
long n_imp) {
322 auto gimp = block_gf{g_loc(0, 0).mesh(), imp_gf_stru_list[n_imp]};
323 auto const &rpsi = reverse_psi[n_imp];
324 for (
auto [gamma, tau] : rpsi.indices()) {
325 auto [alpha, sigma] = rpsi(gamma, tau)[0];
326 gimp[gamma +
n_gamma(n_imp) * tau].data() = g_loc(alpha, sigma).data();
330 return range(
n_impurities()) | stdv::transform(extract_one_imp) | tl::to<std::vector>();
348 std::vector<nda::array<dcomplex, 3>>
embed_1p(std::vector<std::vector<nda::array<dcomplex, 3>>>
const &Sigma_imp_vec)
const;
351 nda::array<dcomplex, 5>
embed_2p(std::vector<nda::array<dcomplex, 5>>
const &pi_imp_vec)
const;
354 nda::array<dcomplex, 4>
embed_tensor(std::vector<nda::array<dcomplex, 4>>
const &U_tensor_vec)
const;
359 std::vector<std::vector<nda::array<dcomplex, 3>>>
extract_1p(nda::array<dcomplex, 4>
const &g_loc)
const;
362 std::vector<nda::array<dcomplex, 5>>
extract_2p(nda::array<dcomplex, 5>
const &Pi_loc)
const;
365 std::vector<nda::array<dcomplex, 4>>
extract_tensor(nda::array<dcomplex, 4>
const &U_tensor)
const;
389 embedding
embedding_builder(std::vector<std::string>
const &spin_names, nda::array<std::vector<long>, 2>
const &block_decomposition,
390 std::vector<long>
const &atom_to_imp);
402 embedding
embedding_builder(std::vector<std::string>
const &spin_names, std::vector<std::vector<long>>
const &block_decomposition,
403 std::vector<long>
const &atom_to_imp);
419 embedding
make_embedding(local_space
const &C_space,
bool use_atom_equivalences =
true,
bool use_atom_decomp =
false);
437 std::vector<std::vector<long>>
const &atom_partition) {
447#define INSTANTIATE(Mesh) \
448 template block2_gf<Mesh, matrix_valued> embedding::embed(std::vector<block_gf<Mesh, matrix_valued>> const &) const; \
449 template std::pair<block2_gf<Mesh, matrix_valued>, block2_matrix_t> embedding::embed(std::vector<block_gf<Mesh, matrix_valued>> const &, \
450 std::vector<block_matrix_t> const &) const; \
451 template std::vector<block_gf<Mesh, matrix_valued>> embedding::extract(block2_gf<Mesh, matrix_valued> const &) const; \
452 template std::vector<std::pair<block_gf<Mesh, matrix_valued>, block_matrix_t>> embedding::make_zero_imp_self_energies(Mesh const &);
std::vector< nda::array< dcomplex, 3 > > embed_1p(std::vector< std::vector< nda::array< dcomplex, 3 > > > const &Sigma_imp_vec) const
Embed single-particle quantities (CoQui).
friend void h5_write(h5::group g, std::string const &name, embedding const &x)
h5 read/write
C2PY_IGNORE gf_struct2_t sigma_embed_block_shape() const
Gf block structure for .
nda::array< dcomplex, 4 > embed_tensor(std::vector< nda::array< dcomplex, 4 > > const &U_tensor_vec) const
Embed tensors (CoQui).
long n_impurities() const
Number of impurities.
long n_gamma(long imp_idx) const
Number of blocks in for the [imp_idx].
long n_sigma() const
Number of blocks in for the .
std::vector< gf_struct_t > imp_block_shape() const
Gf block structure for the impurity solvers.
embedding flip_spin(long alpha) const
Flip the spins ( ) for block .
bool operator==(embedding const &other) const =default
embedding split(long imp_idx, std::initializer_list< const char * > x)=delete
nda::array< imp_block_t, 2 > get_psi() const
The mapping table .
nda::array< dcomplex, 5 > embed_2p(std::vector< nda::array< dcomplex, 5 > > const &pi_imp_vec) const
Embed two-particle quantities (CoQui).
std::vector< std::string > sigma_names() const
The names of the sigma indices.
std::vector< block_gf< Mesh, matrix_valued > > extract(block2_gf< Mesh, matrix_valued > const &g_loc) const
Extract single-particle quantities (TRIQS/ModEST).
long n_alpha() const
Number of blocks in for the .
std::vector< long > imp_decomposition(long imp_idx) const
The impurity decomposition.
std::vector< nda::array< dcomplex, 5 > > extract_2p(nda::array< dcomplex, 5 > const &Pi_loc) const
Extract two-particle quantities (CoQui).
std::vector< std::vector< nda::array< dcomplex, 3 > > > extract_1p(nda::array< dcomplex, 4 > const &g_loc) const
Extract single-particle quantities (CoQui).
std::string description(bool verbosity=false) const
Summarize the embedding object.
embedding drop(long imp_idx) const
Remove an impurity from the embedding table .
friend std::ostream & operator<<(std::ostream &out, embedding const &E)
friend void h5_read(h5::group g, std::string const &name, embedding &x)
std::vector< std::pair< block_gf< Mesh, matrix_valued >, block_matrix_t > > make_zero_imp_self_energies(Mesh const &mesh)
Zero initialize impurity self-energies.
embedding split(long imp_idx, std::function< bool(long)> p) const
Split impurity imp_idx.
embedding replace(long imp_idx_to_remove, long imp_idx_to_replace_with) const
Replaces one impurity in the embedding table .
imp_block_t operator[](long alpha, long sigma) const
Bracket accessor: .
std::vector< nda::array< dcomplex, 4 > > extract_tensor(nda::array< dcomplex, 4 > const &U_tensor) const
Extract tensors (CoQui).
block2_gf< Mesh, matrix_valued > embed(std::vector< block_gf< Mesh, matrix_valued > > const &Sigma_imp_vec) const
Embed single-particle quantities (TRIQS/ModEST).
std::pair< block2_gf< Mesh, matrix_valued >, block2_matrix_t > embed(std::vector< block_gf< Mesh, matrix_valued > > const &Sigma_imp_vec, std::vector< block_matrix_t > const &Sigma_imp_static_vec) const
Embed single-particle quantities (TRIQS/ModEST).
#define INSTANTIATE(Mesh)
std::pair< one_body_elements_on_grid, embedding > make_embedding_with_clusters(one_body_elements_on_grid obe, std::vector< std::vector< long > > const &atom_partition)
Make an embedding for clusters of atoms.
embedding make_embedding(local_space const &C_space, bool use_atom_equivalences, bool use_atom_decomp)
Make an embedding from the local space.
block2_gf< Mesh, matrix_valued > make_block2_gf(Mesh const &mesh, gf_struct2_t const &gf_s)
block2_gf< Mesh > decomposition_view(block2_gf< Mesh > const &g, gf_struct2_t const &stru)
gf_struct_t get_struct(block_gf< Mesh > const &g)
std::ostream & operator<<(std::ostream &out, one_body_elements_on_grid const &)
one_body_elements_on_grid permute_local_space(std::vector< std::vector< long > > const &atom_partition, one_body_elements_on_grid const &obe)
embedding embedding_builder(std::vector< std::string > const &spin_names, nda::array< std::vector< long >, 2 > const &block_decomposition, std::vector< long > const &atom_to_imp)
nda::array< nda::matrix< dcomplex >, 2 > block2_matrix_t
static constexpr auto r_all
bool all_equal(R const &r)
Determines if all elements in the given range are equal.
std::vector< nda::matrix< dcomplex > > block_matrix_t
A one-body elements struct where all of the underlying data exists on a fixed momentum grid.