TRIQS/TRIQS 4.0.0
Researching Interacting Quantum Systems
Loading...
Searching...
No Matches
Operator utilities

Detailed Description

Helpers to extract coefficient tensors and maps from many-body operators.

This group collects free functions that decompose a many-body operator of a known structure into coefficient dictionaries and dense arrays:

Typedefs

template<typename T>
using triqs::operators::utils::block_matrix_t = array<nda::matrix<T>, 1>
 Type of a block matrix.
template<typename T>
using triqs::operators::utils::dict2_t = std::map<std::tuple<indices_t, indices_t>, T>
 Map from an index pair \( (\alpha_i, \alpha_j) \) to a coefficient of type T.
template<typename T>
using triqs::operators::utils::dict4_t = std::map<std::tuple<indices_t, indices_t, indices_t, indices_t>, T>
 Map from an index quadruple \( (\alpha_i, \alpha_j, \alpha_k, \alpha_l) \) to a coefficient of type T.
template<typename T>
using triqs::operators::utils::op_t = operators::many_body_operator_generic<T>
 Alias for triqs::operators::many_body_operator_generic.
template<int N>
using triqs::operators::utils::real_or_complex_array = std::variant<array<double, N>, array<std::complex<double>, N>>
 Variant of a rank-N array that can hold either real or complex values.

Functions

template<typename T>
block_matrix_t< T > triqs::operators::utils::block_matrix_from_op (op_t< T > const &h, hilbert_space::gf_struct_t const &gf_struct, bool ignore_irrelevant=false)
 Convert a block-diagonal quadratic operator into its block-matrix representation.
template<typename T = double, typename D, std::size_t R = std::tuple_size_v<typename D::key_type>>
array< T, R > triqs::operators::utils::dict_to_matrix (D const &dict, hilbert_space::fundamental_operator_set const &fs)
 Convert a coefficient dictionary into a dense rank-N array indexed by integers from a fundamental operator set.
template<typename D, std::size_t R = std::tuple_size_v<typename D::key_type>>
real_or_complex_array< R > triqs::operators::utils::dict_to_variant_matrix (D const &dict, hilbert_space::fundamental_operator_set const &fs)
 Convert a real or complex valued coefficient dictionary into a real_or_complex_array.
template<typename T>
dict2_t< T > triqs::operators::utils::extract_h_dict (op_t< T > const &h, bool ignore_irrelevant=false)
 Extract the coefficients of a normal-ordered quadratic operator.
template<typename T>
dict2_t< T > triqs::operators::utils::extract_U_dict2 (op_t< T > const &h, bool ignore_irrelevant=false)
 Extract the coefficients of a density-density interaction operator.
template<typename T>
dict4_t< T > triqs::operators::utils::extract_U_dict4 (op_t< T > const &h, bool ignore_irrelevant=false)
 Extract the coefficients of a general two-particle interaction operator.
template<typename T>
op_t< T > triqs::operators::utils::filter_op (op_t< T > const &h, long len)
 Keep only terms of a given length of a many-body operator \( \hat{h} \).
template<typename T>
op_t< T > triqs::operators::utils::op_from_block_matrix (block_matrix_t< T > const &bl_mat, hilbert_space::gf_struct_t const &gf_struct)
 Build a block-diagonal quadratic operator from its block-matrix representation.
template<typename T>
op_t< T > triqs::operators::utils::quadratic_terms (op_t< T > const &h)
 Keep only quadratic terms of a many-body operator \( \hat{h} \).
template<typename T>
op_t< T > triqs::operators::utils::quartic_terms (op_t< T > const &h)
 Keep only quartic terms of a many-body operator \( \hat{h} \).

Function Documentation

◆ block_matrix_from_op()

template<typename T>
block_matrix_t< T > triqs::operators::utils::block_matrix_from_op ( op_t< T > const & h,
hilbert_space::gf_struct_t const & gf_struct,
bool ignore_irrelevant = false )
nodiscard

#include <triqs/operators/util/extractors.hpp>

Convert a block-diagonal quadratic operator into its block-matrix representation.

Assumes that \( \hat{h} \) has the form

\[ \hat{h} = \sum_{\sigma ij} h_{\sigma ij} \hat{c}_{\sigma, i}^\dagger \hat{c}_{\sigma, j} \; , \]

where the first element of each canonical operator's index is interpreted as the block label \( \sigma \) (a string) and the second element as the in-block integer index \( i \).

If a term that is not of this form is encountered, an exception is thrown unless ignore_irrelevant is true, in which case the offending term is silently skipped.

Template Parameters
TValue type of the coefficients.
Parameters
hMany-body operator \( \hat{h} \).
gf_structBlock structure specifying the block labels and the size of each block.
ignore_irrelevantIf true, terms that do not match the expected form are skipped instead of triggering an exception.
Returns
One matrix per block, packaged as a one-dimensional array of matrices.

Definition at line 313 of file extractors.hpp.

◆ dict_to_matrix()

template<typename T = double, typename D, std::size_t R = std::tuple_size_v<typename D::key_type>>
array< T, R > triqs::operators::utils::dict_to_matrix ( D const & dict,
hilbert_space::fundamental_operator_set const & fs )
nodiscard

#include <triqs/operators/util/extractors.hpp>

Convert a coefficient dictionary into a dense rank-N array indexed by integers from a fundamental operator set.

For a dictionary mapping each key tuple \( (\alpha_{i_1}, \dots, \alpha_{i_N}) \) to a value \( x \), the result is a rank-N array of element type T whose entry at \( (\mathtt{fs}[\alpha_{i_1}], \dots, \mathtt{fs}[\alpha_{i_N}]) \) is set to \( x \). All other entries are value-initialized to T{}.

The dimension along every axis is the size of the fundamental operator set. The function throws if any index from the given dictionary is not present in the fundamental operator set.

Template Parameters
TValue type of the resulting array.
DType of the input dictionary.
RRank of the resulting array (defaults to the arity of D's key tuple).
Parameters
dictCoefficient dictionary to convert.
fsFundamental operator set used to map each index \( \alpha_i \) to an integer.
Returns
Dense rank-N array containing the converted coefficients.

Definition at line 217 of file extractors.hpp.

◆ dict_to_variant_matrix()

template<typename D, std::size_t R = std::tuple_size_v<typename D::key_type>>
real_or_complex_array< R > triqs::operators::utils::dict_to_variant_matrix ( D const & dict,
hilbert_space::fundamental_operator_set const & fs )
nodiscard

#include <triqs/operators/util/extractors.hpp>

Convert a real or complex valued coefficient dictionary into a real_or_complex_array.

If every coefficient in the given dictionary is purely real, the result holds a real array. Otherwise, it holds a complex array. The shape of the array follows the same convention as triqs::operators::utils::dict_to_matrix().

Template Parameters
DType of the input dictionary.
RRank of the resulting array (defaults to the arity of D's key tuple).
Parameters
dictCoefficient dictionary to convert.
fsFundamental operator set used to map each index \( \alpha_i \) to an integer.
Returns
Variant containing either a real or a complex dense array, depending on the coefficients in the input dictionary.

Definition at line 248 of file extractors.hpp.

◆ extract_h_dict()

template<typename T>
dict2_t< T > triqs::operators::utils::extract_h_dict ( op_t< T > const & h,
bool ignore_irrelevant = false )
nodiscard

#include <triqs/operators/util/extractors.hpp>

Extract the coefficients of a normal-ordered quadratic operator.

Assumes that the operator \( \hat{h} \) has the normal-ordered quadratic form

\[ \hat{h} = \sum_{ij} h_{ij} \hat{c}_i^\dagger \hat{c}_j \; . \]

The coefficients \( h_{ij} \) are returned as a map from the index pair \( (\alpha_i, \alpha_j) \) to the value \( h_{ij} \).

If a term that is not of this form is encountered, an exception is thrown unless ignore_irrelevant is true, in which case the offending term is silently skipped.

Template Parameters
TValue type of the coefficients.
Parameters
hMany-body operator \( \hat{h} \).
ignore_irrelevantIf true, terms that do not match the expected form are skipped instead of triggering an exception.
Returns
Dictionary with \( (\alpha_i, \alpha_j) \) as keys and the corresponding non-vanishing coefficients \( h_{ij} \) as values.

Definition at line 87 of file extractors.hpp.

◆ extract_U_dict2()

template<typename T>
dict2_t< T > triqs::operators::utils::extract_U_dict2 ( op_t< T > const & h,
bool ignore_irrelevant = false )
nodiscard

#include <triqs/operators/util/extractors.hpp>

Extract the coefficients of a density-density interaction operator.

Assumes that the operator \( \hat{h} \) has the density-density form

\[ \hat{h} = \frac{1}{2} \sum_{ij} U_{ij} \hat{n}_i \hat{n}_j \; , \]

with \( \hat{n}_i = \hat{c}_i^\dagger \hat{c}_i \). Internally each input term is matched against the canonical normal-ordered pattern \( \hat{c}_i^\dagger \hat{c}_j^\dagger \hat{c}_j \hat{c}_i \) and both \( (i, j) \) and \( (j, i) \) entries are written to the output map, so that the returned dictionary is symmetric in its index pair.

If a term that is not of this form is encountered, an exception is thrown unless ignore_irrelevant is true, in which case the offending term is silently skipped.

Template Parameters
TValue type of the coefficients.
Parameters
hMany-body operator \( \hat{h} \).
ignore_irrelevantIf true, terms that do not match the expected form are skipped instead of triggering an exception.
Returns
Dictionary with \( (\alpha_i, \alpha_j) \) as keys and the corresponding non-vanishing coefficients \( U_{ij} \) as values.

Definition at line 130 of file extractors.hpp.

◆ extract_U_dict4()

template<typename T>
dict4_t< T > triqs::operators::utils::extract_U_dict4 ( op_t< T > const & h,
bool ignore_irrelevant = false )
nodiscard

#include <triqs/operators/util/extractors.hpp>

Extract the coefficients of a general two-particle interaction operator.

Assumes that the operator \( \hat{h} \) has the two-particle form

\[ \hat{h} = \frac{1}{2} \sum_{ijkl} U_{ijkl} \hat{c}_i^\dagger \hat{c}_j^\dagger \hat{c}_l \hat{c}_k \; . \]

Each input term is matched against the canonical normal-ordered pattern \( \hat{c}_i^\dagger \hat{c}_j^\dagger \hat{c}_l \hat{c}_k \) and the four index permutations equivalent under fermionic antisymmetry are written to the output map with the appropriate sign, so that the returned dictionary respects the antisymmetry of \( U_{ijkl} \) in \( (i, j) \) and in \( (k, l) \).

If a term that is not of this form is encountered, an exception is thrown unless ignore_irrelevant is true, in which case the offending term is silently skipped.

Template Parameters
TValue type of the coefficients.
Parameters
hMany-body operator \( \hat{h} \).
ignore_irrelevantIf true, terms that do not match the expected form are skipped instead of triggering an exception.
Returns
Dictionary with \( (\alpha_i, \alpha_j, \alpha_k, \alpha_l) \) as keys and the corresponding non-vanishing coefficients \( U_{ijkl} \) as values (including sign and factor of \( 1/2 \)).

Definition at line 174 of file extractors.hpp.

◆ filter_op()

template<typename T>
op_t< T > triqs::operators::utils::filter_op ( op_t< T > const & h,
long len )
nodiscard

#include <triqs/operators/util/extractors.hpp>

Keep only terms of a given length of a many-body operator \( \hat{h} \).

Returns a copy of \( \hat{h} \) consisting of those monomials whose length (number of canonical operators) is exactly the required length.

Template Parameters
TValue type of the coefficients.
Parameters
hMany-body operator \( \hat{h} \).
lenRequired monomial length.
Returns
Many-body operator containing only the matching terms.

Definition at line 266 of file extractors.hpp.

◆ op_from_block_matrix()

template<typename T>
op_t< T > triqs::operators::utils::op_from_block_matrix ( block_matrix_t< T > const & bl_mat,
hilbert_space::gf_struct_t const & gf_struct )
nodiscard

#include <triqs/operators/util/extractors.hpp>

Build a block-diagonal quadratic operator from its block-matrix representation.

Given the block matrices \( h_{\sigma ij} \) and the block structure, returns

\[ \hat{h} = \sum_{\sigma ij} h_{\sigma ij} \hat{c}_{\sigma, i}^\dagger \hat{c}_{\sigma, j} \; . \]

Template Parameters
TValue type of the matrices and of the coefficients in the operator.
Parameters
bl_matOne matrix \( h_{\sigma ij} \) per block \( \sigma \), packaged as a one-dimensional array of matrices.
gf_structBlock structure specifying the block labels and the size of each block.
Returns
Many-body operator \( \hat{h} \).

Definition at line 361 of file extractors.hpp.

◆ quadratic_terms()

template<typename T>
op_t< T > triqs::operators::utils::quadratic_terms ( op_t< T > const & h)
nodiscard

#include <triqs/operators/util/extractors.hpp>

Keep only quadratic terms of a many-body operator \( \hat{h} \).

Template Parameters
TValue type of the coefficients.
Parameters
hMany-body operator \( \hat{h} \).
Returns
Many-body operator containing only the quadratic terms.

Definition at line 281 of file extractors.hpp.

◆ quartic_terms()

template<typename T>
op_t< T > triqs::operators::utils::quartic_terms ( op_t< T > const & h)
nodiscard

#include <triqs/operators/util/extractors.hpp>

Keep only quartic terms of a many-body operator \( \hat{h} \).

Template Parameters
TValue type of the coefficients.
Parameters
hMany-body operator \( \hat{h} \).
Returns
Many-body operator containing only the quartic terms.

Definition at line 290 of file extractors.hpp.