Skip to content

Commit

Permalink
Change the name convention for G2
Browse files Browse the repository at this point in the history
  • Loading branch information
j-otsuki committed May 7, 2018
1 parent 429ce9c commit 9fb8b76
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 93 deletions.
18 changes: 10 additions & 8 deletions c++/g2_parameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <triqs/hilbert_space/fundamental_operator_set.hpp>
using triqs::hilbert_space::gf_struct_t;
using indices_t = triqs::hilbert_space::fundamental_operator_set::indices_t;
using four_indices_t = std::tuple<indices_t, indices_t, indices_t, indices_t>;
using three_freqs_t = std::vector< std::tuple<int, int, int> >;

namespace pomerol2triqs {
Expand All @@ -12,7 +13,7 @@ namespace pomerol2triqs {

// using g2_blocks_t = std::set<std::pair<std::string, std::string>>;

struct g2_iw_inu_inup_params_t {
struct g2_iw_freq_box_params_t {

/// Block structure of GF
gf_struct_t gf_struct;
Expand All @@ -29,11 +30,11 @@ namespace pomerol2triqs {
/// indices of operators in TRIQS convention: (block_name, inner_index)
indices_t index1, index2, index3, index4;

// g2_iw_inu_inup_params_t() {}
// g2_iw_inu_inup_params_t(gf_struct_t const &gf_struct, double beta) : gf_struct(gf_struct), beta(beta) {}
// g2_iw_freq_box_params_t() {}
// g2_iw_freq_box_params_t(gf_struct_t const &gf_struct, double beta) : gf_struct(gf_struct), beta(beta) {}
};

struct g2_three_freqs_params_t {
struct g2_iw_freq_vec_params_t {

/// Block structure of GF
gf_struct_t gf_struct;
Expand All @@ -47,11 +48,12 @@ namespace pomerol2triqs {
/// three frequencies (wb, wf1, wf2).
three_freqs_t three_freqs;

/// indices of operators in TRIQS convention: (block_name, inner_index)
indices_t index1, index2, index3, index4;
/// set of indices of four operators in TRIQS convention: (block_name, inner_index)*4
// indices_t index1, index2, index3, index4;
std::vector<four_indices_t> vec_four_indices;

// g2_three_freqs_params_t() {}
// g2_three_freqs_params_t(gf_struct_t const &gf_struct, double beta) : gf_struct(gf_struct), beta(beta) {}
// g2_iw_freq_vec_params_t() {}
// g2_iw_freq_vec_params_t(gf_struct_t const &gf_struct, double beta) : gf_struct(gf_struct), beta(beta) {}
};

/*
Expand Down
30 changes: 23 additions & 7 deletions c++/pomerol_ed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ namespace pomerol2triqs {
pom_g2.compute(false, {}, comm);

// compute g2 value using MPI
g2_three_freqs_t g2( three_freqs.size() );
g2_iw_freq_vec_t g2( three_freqs.size() );
for(int i=comm.rank(); i<three_freqs.size(); i+=comm.size()){
int wb = std::get<0>(three_freqs[i]);
int wf1 = std::get<1>(three_freqs[i]);
Expand All @@ -510,8 +510,22 @@ namespace pomerol2triqs {
return g2;
}

std::vector< std::vector<std::complex<double> > > pomerol_ed::compute_g2_indices_loop(gf_struct_t const &gf_struct, double beta, channel_t channel, std::vector<four_indices_t> const &vec_four_indices, three_freqs_t const &three_freqs){

std::vector<g2_iw_freq_vec_t> vec_g2;
// TODO: MPI
for( auto four_indices : vec_four_indices ){
indices_t index1 = std::get<0>(four_indices);
indices_t index2 = std::get<1>(four_indices);
indices_t index3 = std::get<2>(four_indices);
indices_t index4 = std::get<3>(four_indices);
vec_g2.push_back( compute_g2(gf_struct, beta, channel, index1, index2, index3, index4, three_freqs) );
}
return vec_g2;
}

auto pomerol_ed::G2_iw(g2_iw_inu_inup_params_t const &p) -> g2_t {

auto pomerol_ed::G2_iw_freq_box(g2_iw_freq_box_params_t const &p) -> g2_iw_freq_box_t {

// create a list of three frequencies, (wb, wf1, wf2)
three_freqs_t three_freqs;
Expand All @@ -538,11 +552,10 @@ namespace pomerol2triqs {
}

// compute g2 values
// g2_three_freqs_t g2_three_freqs = G2_iw_three_freqs(p_core);
g2_three_freqs_t g2_three_freqs = compute_g2(p.gf_struct, p.beta, p.channel, p.index1, p.index2, p.index3, p.index4, three_freqs);
g2_iw_freq_vec_t g2_three_freqs = compute_g2(p.gf_struct, p.beta, p.channel, p.index1, p.index2, p.index3, p.index4, three_freqs);

// reshape G2
g2_t g2(p.n_b, 2*p.n_f, 2*p.n_f);
g2_iw_freq_box_t g2(p.n_b, 2*p.n_f, 2*p.n_f);
for(int i=0; i<three_indices.size(); i++){
int ib = std::get<0>(three_indices[i]);
int if1 = std::get<1>(three_indices[i]);
Expand All @@ -554,8 +567,11 @@ namespace pomerol2triqs {
}


auto pomerol_ed::G2_iw_three_freqs(g2_three_freqs_params_t const &p) -> g2_three_freqs_t {
return compute_g2(p.gf_struct, p.beta, p.channel, p.index1, p.index2, p.index3, p.index4, p.three_freqs);
// auto pomerol_ed::G2_iw_three_freqs(g2_three_freqs_params_t const &p) -> g2_iw_freq_vec_t {
// return compute_g2(p.gf_struct, p.beta, p.channel, p.index1, p.index2, p.index3, p.index4, p.three_freqs);
// }
auto pomerol_ed::G2_iw_freqs_vec(g2_iw_freq_vec_params_t const &p) -> std::vector<g2_iw_freq_vec_t> {
return compute_g2_indices_loop(p.gf_struct, p.beta, p.channel, p.vec_four_indices, p.three_freqs);
}
/*
auto pomerol_ed::G2_iw_three_freqs(g2_three_freqs_params_t const &p) -> g2_three_freqs_t {
Expand Down
13 changes: 8 additions & 5 deletions c++/pomerol_ed.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,15 @@ namespace pomerol2triqs {

// using w_nu_nup_t = cartesian_product<imfreq, imfreq, imfreq>;
// using w_l_lp_t = cartesian_product<imfreq, legendre, legendre>;
using g2_t = triqs::arrays::array<std::complex<double>, 3>;
using g2_three_freqs_t = std::vector<std::complex<double> >;
using g2_iw_freq_box_t = triqs::arrays::array<std::complex<double>, 3>;
using g2_iw_freq_vec_t = std::vector<std::complex<double> >;
// template <typename Mesh, typename Filler>
// block2_gf<Mesh, tensor_valued<4>> compute_g2(gf_struct_t const &gf_struct, gf_mesh<Mesh> const &mesh, block_order_t block_order,
// g2_blocks_t const &g2_blocks, Filler filler) const;
std::vector<std::complex<double> > compute_g2(gf_struct_t const &gf_struct, double beta, channel_t channel, indices_t index1, indices_t index2, indices_t index3, indices_t index4, three_freqs_t const &three_freqs);
g2_iw_freq_vec_t compute_g2(gf_struct_t const &gf_struct, double beta, channel_t channel, indices_t index1, indices_t index2, indices_t index3, indices_t index4, three_freqs_t const &three_freqs);

// std::vector<g2_iw_freq_vec_t> compute_g2_indices_loop(gf_struct_t const &gf_struct, double beta, channel_t channel, std::vector<four_indices_t> const &vec_four_indices, three_freqs_t const &three_freqs);
std::vector< g2_iw_freq_vec_t > compute_g2_indices_loop(gf_struct_t const &gf_struct, double beta, channel_t channel, std::vector<four_indices_t> const &vec_four_indices, three_freqs_t const &three_freqs);

double density_matrix_cutoff = 1e-15;

Expand Down Expand Up @@ -121,11 +124,11 @@ namespace pomerol2triqs {

/// Two-particle Green's function. Specify frequency cutoff, n_b and n_f.
TRIQS_WRAP_ARG_AS_DICT
g2_t G2_iw(g2_iw_inu_inup_params_t const &p);
g2_iw_freq_box_t G2_iw_freq_box(g2_iw_freq_box_params_t const &p);

/// Two-particle Green's function. Specify three frequencies (wb, wf1, wf2).
TRIQS_WRAP_ARG_AS_DICT
g2_three_freqs_t G2_iw_three_freqs(g2_three_freqs_params_t const &p);
std::vector<g2_iw_freq_vec_t> G2_iw_freqs_vec(g2_iw_freq_vec_params_t const &p);

/// Two-particle Green's function, Matsubara frequencies
// TRIQS_WRAP_ARG_AS_DICT
Expand Down
2 changes: 1 addition & 1 deletion example/2band.atom.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
# G^{(2)}(i\omega;i\nu,i\nu') #
###############################

G2_iw = ed.G2_iw( index1=('up',0), index2=('dn',0), index3=('dn',1), index4=('up',1), **common_g2_params )
G2_iw = ed.G2_iw_freq_box( index1=('up',0), index2=('dn',0), index3=('dn',1), index4=('up',1), **common_g2_params )
print type(G2_iw)
print G2_iw.shape

Expand Down
2 changes: 1 addition & 1 deletion example/slater.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
# G^{(2)}(i\omega;i\nu,i\nu') #
###############################

G2_iw = ed.G2_iw( index1=('up',0), index2=('dn',0), index3=('dn',1), index4=('up',1), **common_g2_params )
G2_iw = ed.G2_iw_freq_box( index1=('up',0), index2=('dn',0), index3=('dn',1), index4=('up',1), **common_g2_params )

if mpi.is_master_node():
print type(G2_iw)
Expand Down
105 changes: 48 additions & 57 deletions python/pomerol2triqs_converters.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,21 @@
// c++2py.py ../c++/pomerol_ed.hpp -I../../../local/pomerol/include -I/usr/include/eigen3 -I../c++ -p -mpytriqs.applications.impurity_solvers.pomerol2triqs -o pomerol2triqs --moduledoc "TRIQS wrapper around Pomerol ED library"


// --- C++ Python converter for g2_iw_inu_inup_params_t
// --- C++ Python converter for g2_iw_freq_vec_params_t
#include <triqs/python_tools/converters/vector.hpp>
#include <triqs/python_tools/converters/string.hpp>
#include <algorithm>

namespace triqs { namespace py_tools {

template <> struct py_converter<g2_iw_inu_inup_params_t> {
static PyObject *c2py(g2_iw_inu_inup_params_t const & x) {
template <> struct py_converter<g2_iw_freq_vec_params_t> {
static PyObject *c2py(g2_iw_freq_vec_params_t const & x) {
PyObject * d = PyDict_New();
PyDict_SetItemString( d, "gf_struct", convert_to_python(x.gf_struct));
PyDict_SetItemString( d, "beta" , convert_to_python(x.beta));
PyDict_SetItemString( d, "channel" , convert_to_python(x.channel));
PyDict_SetItemString( d, "n_b" , convert_to_python(x.n_b));
PyDict_SetItemString( d, "n_f" , convert_to_python(x.n_f));
PyDict_SetItemString( d, "index1" , convert_to_python(x.index1));
PyDict_SetItemString( d, "index2" , convert_to_python(x.index2));
PyDict_SetItemString( d, "index3" , convert_to_python(x.index3));
PyDict_SetItemString( d, "index4" , convert_to_python(x.index4));
PyDict_SetItemString( d, "gf_struct" , convert_to_python(x.gf_struct));
PyDict_SetItemString( d, "beta" , convert_to_python(x.beta));
PyDict_SetItemString( d, "channel" , convert_to_python(x.channel));
PyDict_SetItemString( d, "three_freqs" , convert_to_python(x.three_freqs));
PyDict_SetItemString( d, "vec_four_indices", convert_to_python(x.vec_four_indices));
return d;
}

Expand All @@ -39,17 +35,13 @@ template <> struct py_converter<g2_iw_inu_inup_params_t> {
r = T{};
}

static g2_iw_inu_inup_params_t py2c(PyObject *dic) {
g2_iw_inu_inup_params_t res;
static g2_iw_freq_vec_params_t py2c(PyObject *dic) {
g2_iw_freq_vec_params_t res;
res.gf_struct = convert_from_python<gf_struct_t>(PyDict_GetItemString(dic, "gf_struct"));
res.beta = convert_from_python<double>(PyDict_GetItemString(dic, "beta"));
_get_optional(dic, "channel" , res.channel ,PH);
res.n_b = convert_from_python<int>(PyDict_GetItemString(dic, "n_b"));
res.n_f = convert_from_python<int>(PyDict_GetItemString(dic, "n_f"));
res.index1 = convert_from_python<indices_t>(PyDict_GetItemString(dic, "index1"));
res.index2 = convert_from_python<indices_t>(PyDict_GetItemString(dic, "index2"));
res.index3 = convert_from_python<indices_t>(PyDict_GetItemString(dic, "index3"));
res.index4 = convert_from_python<indices_t>(PyDict_GetItemString(dic, "index4"));
_get_optional(dic, "channel" , res.channel ,PH);
res.three_freqs = convert_from_python<three_freqs_t>(PyDict_GetItemString(dic, "three_freqs"));
res.vec_four_indices = convert_from_python<std::vector<four_indices_t>>(PyDict_GetItemString(dic, "vec_four_indices"));
return res;
}

Expand Down Expand Up @@ -80,7 +72,7 @@ template <> struct py_converter<g2_iw_inu_inup_params_t> {
std::stringstream fs, fs2; int err=0;

#ifndef TRIQS_ALLOW_UNUSED_PARAMETERS
std::vector<std::string> ks, all_keys = {"gf_struct","beta","channel","n_b","n_f","index1","index2","index3","index4"};
std::vector<std::string> ks, all_keys = {"gf_struct","beta","channel","three_freqs","vec_four_indices"};
pyref keys = PyDict_Keys(dic);
if (!convertible_from_python<std::vector<std::string>>(keys, true)) {
fs << "\nThe dict keys are not strings";
Expand All @@ -92,20 +84,16 @@ template <> struct py_converter<g2_iw_inu_inup_params_t> {
fs << "\n"<< ++err << " The parameter '" << k << "' is not recognized.";
#endif

_check_mandatory<gf_struct_t >(dic, fs, err, "gf_struct", "gf_struct_t");
_check_mandatory<double >(dic, fs, err, "beta" , "double");
_check_optional <pomerol2triqs::channel_t>(dic, fs, err, "channel" , "pomerol2triqs::channel_t");
_check_mandatory<int >(dic, fs, err, "n_b" , "int");
_check_mandatory<int >(dic, fs, err, "n_f" , "int");
_check_mandatory<indices_t >(dic, fs, err, "index1" , "indices_t");
_check_mandatory<indices_t >(dic, fs, err, "index2" , "indices_t");
_check_mandatory<indices_t >(dic, fs, err, "index3" , "indices_t");
_check_mandatory<indices_t >(dic, fs, err, "index4" , "indices_t");
_check_mandatory<gf_struct_t >(dic, fs, err, "gf_struct" , "gf_struct_t");
_check_mandatory<double >(dic, fs, err, "beta" , "double");
_check_optional <pomerol2triqs::channel_t >(dic, fs, err, "channel" , "pomerol2triqs::channel_t");
_check_mandatory<three_freqs_t >(dic, fs, err, "three_freqs" , "three_freqs_t");
_check_mandatory<std::vector<four_indices_t>>(dic, fs, err, "vec_four_indices", "std::vector<four_indices_t>");
if (err) goto _error;
return true;

_error:
fs2 << "\n---- There " << (err > 1 ? "are " : "is ") << err<< " error"<<(err >1 ?"s" : "")<< " in Python -> C++ transcription for the class g2_iw_inu_inup_params_t\n" <<fs.str();
fs2 << "\n---- There " << (err > 1 ? "are " : "is ") << err<< " error"<<(err >1 ?"s" : "")<< " in Python -> C++ transcription for the class g2_iw_freq_vec_params_t\n" <<fs.str();
if (raise_exception) PyErr_SetString(PyExc_TypeError, fs2.str().c_str());
return false;
}
Expand All @@ -114,24 +102,25 @@ template <> struct py_converter<g2_iw_inu_inup_params_t> {
}}


// --- C++ Python converter for g2_three_freqs_params_t
// --- C++ Python converter for g2_iw_freq_box_params_t
#include <triqs/python_tools/converters/vector.hpp>
#include <triqs/python_tools/converters/string.hpp>
#include <algorithm>

namespace triqs { namespace py_tools {

template <> struct py_converter<g2_three_freqs_params_t> {
static PyObject *c2py(g2_three_freqs_params_t const & x) {
template <> struct py_converter<g2_iw_freq_box_params_t> {
static PyObject *c2py(g2_iw_freq_box_params_t const & x) {
PyObject * d = PyDict_New();
PyDict_SetItemString( d, "gf_struct" , convert_to_python(x.gf_struct));
PyDict_SetItemString( d, "beta" , convert_to_python(x.beta));
PyDict_SetItemString( d, "channel" , convert_to_python(x.channel));
PyDict_SetItemString( d, "three_freqs", convert_to_python(x.three_freqs));
PyDict_SetItemString( d, "index1" , convert_to_python(x.index1));
PyDict_SetItemString( d, "index2" , convert_to_python(x.index2));
PyDict_SetItemString( d, "index3" , convert_to_python(x.index3));
PyDict_SetItemString( d, "index4" , convert_to_python(x.index4));
PyDict_SetItemString( d, "gf_struct", convert_to_python(x.gf_struct));
PyDict_SetItemString( d, "beta" , convert_to_python(x.beta));
PyDict_SetItemString( d, "channel" , convert_to_python(x.channel));
PyDict_SetItemString( d, "n_b" , convert_to_python(x.n_b));
PyDict_SetItemString( d, "n_f" , convert_to_python(x.n_f));
PyDict_SetItemString( d, "index1" , convert_to_python(x.index1));
PyDict_SetItemString( d, "index2" , convert_to_python(x.index2));
PyDict_SetItemString( d, "index3" , convert_to_python(x.index3));
PyDict_SetItemString( d, "index4" , convert_to_python(x.index4));
return d;
}

Expand All @@ -149,12 +138,13 @@ template <> struct py_converter<g2_three_freqs_params_t> {
r = T{};
}

static g2_three_freqs_params_t py2c(PyObject *dic) {
g2_three_freqs_params_t res;
static g2_iw_freq_box_params_t py2c(PyObject *dic) {
g2_iw_freq_box_params_t res;
res.gf_struct = convert_from_python<gf_struct_t>(PyDict_GetItemString(dic, "gf_struct"));
res.beta = convert_from_python<double>(PyDict_GetItemString(dic, "beta"));
_get_optional(dic, "channel" , res.channel ,PH);
res.three_freqs = convert_from_python<three_freqs_t>(PyDict_GetItemString(dic, "three_freqs"));
_get_optional(dic, "channel" , res.channel ,PH);
res.n_b = convert_from_python<int>(PyDict_GetItemString(dic, "n_b"));
res.n_f = convert_from_python<int>(PyDict_GetItemString(dic, "n_f"));
res.index1 = convert_from_python<indices_t>(PyDict_GetItemString(dic, "index1"));
res.index2 = convert_from_python<indices_t>(PyDict_GetItemString(dic, "index2"));
res.index3 = convert_from_python<indices_t>(PyDict_GetItemString(dic, "index3"));
Expand Down Expand Up @@ -189,7 +179,7 @@ template <> struct py_converter<g2_three_freqs_params_t> {
std::stringstream fs, fs2; int err=0;

#ifndef TRIQS_ALLOW_UNUSED_PARAMETERS
std::vector<std::string> ks, all_keys = {"gf_struct","beta","channel","three_freqs","index1","index2","index3","index4"};
std::vector<std::string> ks, all_keys = {"gf_struct","beta","channel","n_b","n_f","index1","index2","index3","index4"};
pyref keys = PyDict_Keys(dic);
if (!convertible_from_python<std::vector<std::string>>(keys, true)) {
fs << "\nThe dict keys are not strings";
Expand All @@ -201,19 +191,20 @@ template <> struct py_converter<g2_three_freqs_params_t> {
fs << "\n"<< ++err << " The parameter '" << k << "' is not recognized.";
#endif

_check_mandatory<gf_struct_t >(dic, fs, err, "gf_struct" , "gf_struct_t");
_check_mandatory<double >(dic, fs, err, "beta" , "double");
_check_optional <pomerol2triqs::channel_t>(dic, fs, err, "channel" , "pomerol2triqs::channel_t");
_check_mandatory<three_freqs_t >(dic, fs, err, "three_freqs", "three_freqs_t");
_check_mandatory<indices_t >(dic, fs, err, "index1" , "indices_t");
_check_mandatory<indices_t >(dic, fs, err, "index2" , "indices_t");
_check_mandatory<indices_t >(dic, fs, err, "index3" , "indices_t");
_check_mandatory<indices_t >(dic, fs, err, "index4" , "indices_t");
_check_mandatory<gf_struct_t >(dic, fs, err, "gf_struct", "gf_struct_t");
_check_mandatory<double >(dic, fs, err, "beta" , "double");
_check_optional <pomerol2triqs::channel_t>(dic, fs, err, "channel" , "pomerol2triqs::channel_t");
_check_mandatory<int >(dic, fs, err, "n_b" , "int");
_check_mandatory<int >(dic, fs, err, "n_f" , "int");
_check_mandatory<indices_t >(dic, fs, err, "index1" , "indices_t");
_check_mandatory<indices_t >(dic, fs, err, "index2" , "indices_t");
_check_mandatory<indices_t >(dic, fs, err, "index3" , "indices_t");
_check_mandatory<indices_t >(dic, fs, err, "index4" , "indices_t");
if (err) goto _error;
return true;

_error:
fs2 << "\n---- There " << (err > 1 ? "are " : "is ") << err<< " error"<<(err >1 ?"s" : "")<< " in Python -> C++ transcription for the class g2_three_freqs_params_t\n" <<fs.str();
fs2 << "\n---- There " << (err > 1 ? "are " : "is ") << err<< " error"<<(err >1 ?"s" : "")<< " in Python -> C++ transcription for the class g2_iw_freq_box_params_t\n" <<fs.str();
if (raise_exception) PyErr_SetString(PyExc_TypeError, fs2.str().c_str());
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions python/pomerol2triqs_desc.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@
c.add_method("""block_gf<refreq> G_w (gf_struct_t gf_struct, double beta, std::pair<double,double> energy_window, int n_w, double im_shift = 0)""",
doc = r"""Retarded Green's function on real energy axis""")

c.add_method("""triqs::arrays::array<std::complex<double>, 3> G2_iw (**pomerol2triqs::g2_iw_inu_inup_params_t)""",
c.add_method("""triqs::arrays::array<std::complex<double>, 3> G2_iw_freq_box (**pomerol2triqs::g2_iw_freq_box_params_t)""",
doc = r"""Two-particle Green's function. Specify frequency cutoff, n_b and n_f.""")

c.add_method("""std::vector<std::complex<double> > G2_iw_three_freqs (**pomerol2triqs::g2_three_freqs_params_t)""",
c.add_method("""std::vector<std::vector<std::complex<double> > > G2_iw_freqs_vec (**pomerol2triqs::g2_iw_freq_vec_params_t)""",
doc = r"""Two-particle Green's function. Specify three frequencies (wb, wf1, wf2).""")

module.add_class(c)
Expand Down
Loading

0 comments on commit 9fb8b76

Please sign in to comment.