Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returning tuple of Green's functions does not compile if converted to python #755

Closed
Stefan-Dienst opened this issue Nov 12, 2019 · 3 comments
Assignees
Milestone

Comments

@Stefan-Dienst
Copy link

Using TRIQS 2.2.1 with hash 3e0ed62 throws an error at compilation if I try to convert a function that returns a tuple of Green's functions to python.

I have setup an app4triqs skeleton with a minimal example: https://github.com/StefanKaeser/tests_for_triqs.
If I convert the function

std::tuple<g_wk_t, g_wk_t> test_tuple(g_wk_t g_wk) {
  
      return {g_wk, g_wk};
  }

in tests_for_triqs.cpp to python, using cpp2py, I can no longer compile.
Clang version 8.0.1 throws the following error:

In file included from /home/kaeser/my_triqs_installations/tests_for_triqs.build/python/tests_for_triqs/tests_for_triqs_module_wrap.cxx:28:
/home/kaeser/my_triqs_installations/triqs_2.2.x/include/cpp2py/converters/tuple.hpp:15:91: error: 
      conversion function from 'const __tuple_element_t<0UL,                                         
      tuple<triqs::gfs::gf<triqs::gfs::cartesian_product<triqs::gfs::imfreq,                         
      triqs::lattice::brillouin_zone>, triqs::gfs::matrix_valued>,    
      triqs::gfs::gf<triqs::gfs::cartesian_product<triqs::gfs::imfreq,            
      triqs::lattice::brillouin_zone>, triqs::gfs::matrix_valued> > >' (aka 'const
      triqs::gfs::gf<triqs::gfs::cartesian_product<triqs::gfs::imfreq, triqs::lattice::brillouin_zone>, triqs::gfs::matrix_valued>') to
'cpp2py::py_converter<triqs::gfs::gf_view<triqs::gfs::cartesian_product<triqs::gfs::imfreq,                    
      triqs::lattice::brillouin_zone>, triqs::gfs::matrix_valued> >::c_type' (aka                                    
      'gf_view<triqs::gfs::cartesian_product<triqs::gfs::imfreq,                                                     
      triqs::lattice::brillouin_zone>, triqs::gfs::matrix_valued>') invokes a deleted  
      function                                                                             
  ...std::array<pyref, sizeof...(Is)>{pyref(py_converter<Types>::c2py(std::get<Is>(t)))....

Can anyone reproduce this or knows what is going on here?

@Stefan-Dienst Stefan-Dienst changed the title Description Returning tuple of Green's functions does not compile if converted to python Nov 12, 2019
@Wentzell
Copy link
Member

Hi Stefan,

Thank you for pointing out this problem! This is in fact a bug in C++2py

@parcollet
In the tuple converter file c2py will take any tuple by const &, c.f. cpp2py/converters/tuple.hpp:14

template <std::size_t... Is> static PyObject *c2py_impl(tuple_t const &t, std::index_sequence<Is...>) 

The example Stefan gave will thus trigger a conversion of a gf const & at cpp2py/converters/tuple.hpp:14
which will try to construct a gf_view from a gf const & which leads to the problem above.

Shouldn't the tuple converter provide a && overload of c2py

template <std::size_t... Is> static PyObject *c2py_impl(tuple_t &&t, std::index_sequence<Is...>)

This seems to solve the problem above.

@Wentzell
Copy link
Member

This is already fixed on triqs/unstable. TODO Add test

@Wentzell Wentzell added this to the 3.0 milestone Aug 11, 2020
@Wentzell
Copy link
Member

Test was added in 5b0a100

Stefan-Dienst added a commit to TRIQS/tprf that referenced this issue Aug 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants