Coder Social home page Coder Social logo

cpp2py's Introduction

cpp2py's People

Contributors

algomorph avatar dylex avatar krivenko avatar parcollet avatar phdum avatar tayral avatar wentzell avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cpp2py's Issues

Intra-application dependencies between modules

When cpp2py was a part of triqs, it was possible to define a wrapped type in one Python module, and then use it in another module of the same application. For example, I could have the following description file,

module = module_(full_name = "module4", doc = "My application", app_name = "myapp")

module.use_module('module1', 'myapp')
module.use_module('module2', 'myapp')
module.use_module('module3', 'myapp')

Can I achieve a similar effect with the new cpp2py?
As far as I can see, use_module() is now not a thing...

[gcc installation] Wrapped cxx files produce lots of warnings: "_POSIX_C_SOURCE" redefined

The problem can be traced back to "mako/wrap.cxx". With pure gcc compilation (without clang) #include involves include from "/usr/include/features.h", which conflicts with Python.h.

Also, in its current form "mako/wrap.cxx" does not follow the recommendation for TRIQS users: https://triqs.github.io/triqs/master/reference/utilities/python_include_mess.html

"#include <cpp2py.hpp>" should go first.

================= mako/wrap.cxx ==================
#include
#include
#include //for std::cout...
using dcomplex = std::complex;

// first the basic stuff
#include <cpp2py.hpp>
.......

Wrapping of template member functions

Currently c++2py tries to wrap template member functions.

For the small test-class

#include <iostream>

struct test_class{
  int myint = 2;
  template<typename T> void print_T(T const& t){ std::cout << t << "\n"; }
};

I get a desc file with the following line

c.add_method("""void print_T (T t)""",
             doc = """""")

This will generate an hxx with an unkown type T.

The wrapping of template functions of all kinds should be disabled completely, no?
Only explicit instantiations of the template functions / member functions should be wrapped.

Problem with c++2rst in combination with llvm-5.0

Dear @parcollet ,

I am trying to build the unstable branch of cpp2py/triqs/dft_tools/cthyb/... using clang-5.0 and llvm-5.0 but get into trouble when trying to build the autogenerated docs of triqs. c++2rst crashes with the following:

[ 98%] Generating cpp2rst.log
Traceback (most recent call last):
  File "/Users/hugstr/apps/cpp2py/bin/c++2rst", line 36, in <module>
    libclang_location = args.libclang_location
  File "/Users/hugstr/apps/cpp2py/lib/python2.7/site-packages/cpp2rst/cpp2rst.py", line 60, in __init__
    self.root = CL.parse(filename, compiler_options, includes, libclang_location, parse_all_comments)
  File "/Users/hugstr/apps/cpp2py/lib/python2.7/site-packages/cpp2py/clang_parser.py", line 354, in parse
    raise RuntimeError, s + "\n... Your code must compile before using clang-parser !"
RuntimeError: Clang reports the following errors in parsing
 file /opt/local/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h line 35 col 5
"Python.h requires that stdio.h define NULL." file /opt/local/libexec/llvm-5.0/include/c++/v1/string.h line 95 col 49
unknown type name 'size_t' file /opt/local/libexec/llvm-5.0/include/c++/v1/string.h line 97 col 46
unknown type name 'size_t' file /opt/local/libexec/llvm-5.0/include/c++/v1/string.h line 99 col 46
unknown type name 'size_t' file /opt/local/libexec/llvm-5.0/include/c++/v1/stdlib.h line 116 col 35
unknown type name 'ldiv_t' file /opt/local/libexec/llvm-5.0/include/c++/v1/stdlib.h line 118 col 34
unknown type name 'lldiv_t' file /opt/local/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/pyport.h line 159 col 9
unknown type name 'uintptr_t' file /opt/local/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/object.h line 307 col 38
unknown type name 'FILE' file /opt/local/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/object.h line 459 col 44
unknown type name 'FILE' file /opt/local/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/fileobject.h line 12 col 5
unknown type name 'FILE' file /opt/local/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/fileobject.h line 15 col 20
unknown type name 'FILE' file /opt/local/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/fileobject.h line 44 col 40
unknown type name 'FILE' file /opt/local/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/fileobject.h line 45 col 54
unknown type name 'FILE' file /opt/local/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/fileobject.h line 46 col 1
unknown type name 'FILE' file /opt/local/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/fileobject.h line 65 col 45
unknown type name 'FILE' file /opt/local/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/fileobject.h line 66 col 49
unknown type name 'FILE' file /opt/local/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/pythonrun.h line 35 col 36
unknown type name 'FILE' file /opt/local/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/pythonrun.h line 36 col 38
unknown type name 'FILE' file /opt/local/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/pythonrun.h line 38 col 41
unknown type name 'FILE' file None line 0 col 0
too many errors emitted, stopping now
... Your code must compile before using clang-parser !
make[2]: *** [doc/cpp2rst.log] Error 1
make[2]: *** Deleting file `doc/cpp2rst.log'
make[1]: *** [doc/CMakeFiles/docs_cpp2rst.dir/all] Error 2
make: *** [all] Error 2

it is hard to debug this since the log file is deleted by cmake

make[2]: *** Deleting file `doc/cpp2rst.log'

Please help.

c++2py with -p (property method) does not wrap return types

Dear Olivier,

I am trying to finish the h5 serialization of the cthyb solver and I think I am hitting a bug in c++2py. When wrapping a class using the -p flag c++2py does not automatically wrap the return types of the methods.

Here is a minimal example:

struct return_struct_t {
  int foo = -1;
};
class class_with_method : return_struct_t{
public:
  class_with_method(int number) {
    foo = number;
  }
  return_struct_t get_data() { return *this; }
};

when wrapping this with c++2py wrap_return.hpp -p --only="class_with_method" one gets

Welcome to C++2py
Parsing the C++ file (may take a few seconds) ...
... done. 

Analysing dependencies
Wrapping classes:
    class_with_method
Generating wrap_return_desc.py
   Class class_with_method : transforming to property : 
        get_data 

i.e. the return_struct_t is not wrapped and this causes a compiler error when trying to compile the wrapper.

Best, H

Wrap instantiation of template class

I tried to wrap to following minimal example to test the wrapping of an instantiated template class

/// Template
template <typename T> class toto {
  public:
  T i;
};

/// Instantiate
template class toto<double>;

/// Normal
class totoro {
  public:
  double i;
};

As expected both classes appear in the desc file. However, for the toto class the members are not wrapped at all.

# The class toto                                                                                                                                                                                                                                                                          
c = class_(                                                                                                                                                                                                                                                                               
        py_type = "Toto",  # name of the python class                                                                                                                                                                                                                                     
        c_type = "toto<double>",   # name of the C++ class                                                                                                                                                                                                                                
        doc = """Instantiate""",   # doc of the C++ class                                                                                                                                                                                                                                 
        hdf5 = False,                                                                                                                                                                                                                                                                     
)                                                                                                                                                                                                                                                                                         
                                                                                                                                                                                                                                                                                          
module.add_class(c)                                                                                                                                                                                                                                                                       
                                                                                                                                                                                                                                                                                          
# The class totoro                                                                                                                                                                                                                                                                        
c = class_(                                                                                                                                                                                                                                                                               
        py_type = "Totoro",  # name of the python class                                                                                                                                                                                                                                   
        c_type = "totoro",   # name of the C++ class                                                                                                                                                                                                                                      
        doc = """Normal""",   # doc of the C++ class                                                                                                                                                                                                                                      
        hdf5 = False,                                                                                                                                                                                                                                                                     
)                                                                                                                                                                                                                                                                                         
                                                                                                                                                                                                                                                                                          
c.add_member(c_name = "i",                                                                                                                                                                                                                                                                
             c_type = "double",                                                                                                                                                                                                                                                           
             read_only= False,                                                                                                                                                                                                                                                            
             doc = """""")                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                          
module.add_class(c)    

I had a brief look at the AST I got from the clang.cindex by iterating recursively over the children of all the nodes and found

   CursorKind.TRANSLATION_UNIT
     CursorKind.CLASS_TEMPLATE
           CursorKind.TEMPLATE_TYPE_PARAMETER
           CursorKind.CXX_ACCESS_SPEC_DECL
           CursorKind.FIELD_DECL
                             CursorKind.TYPE_REF
     CursorKind.CLASS_DECL        # Instantiation of template class toto
     CursorKind.CLASS_DECL        # Non-template class totoro
           CursorKind.CXX_ACCESS_SPEC_DECL
           CursorKind.FIELD_DECL

i.e. the instantiation has no children in the cindex AST. I suppose this is the reason why no members are added by cpp2py?

The strange thing is that the AST using clang -cc1 -ast-dump looks different and does indeed specify all the information necessary

TranslationUnitDecl 0x55c3efbda0e0 <<invalid sloc>> <invalid sloc>
|-TypedefDecl 0x55c3efbda670 <<invalid sloc>> <invalid sloc> implicit __int128_t '__int128'
| `-BuiltinType 0x55c3efbda350 '__int128'
|-TypedefDecl 0x55c3efbda6e0 <<invalid sloc>> <invalid sloc> implicit __uint128_t 'unsigned __int128'
| `-BuiltinType 0x55c3efbda370 'unsigned __int128'
|-TypedefDecl 0x55c3efbdaa28 <<invalid sloc>> <invalid sloc> implicit __NSConstantString 'struct __NSConstantString_tag'
| `-RecordType 0x55c3efbda7d0 'struct __NSConstantString_tag'
|   `-CXXRecord 0x55c3efbda738 '__NSConstantString_tag'
|-TypedefDecl 0x55c3efbdaac0 <<invalid sloc>> <invalid sloc> implicit __builtin_ms_va_list 'char *'
| `-PointerType 0x55c3efbdaa80 'char *'
|   `-BuiltinType 0x55c3efbda170 'char'
|-TypedefDecl 0x55c3efc0fdf0 <<invalid sloc>> <invalid sloc> implicit __builtin_va_list 'struct __va_list_tag [1]'
| `-ConstantArrayType 0x55c3efbdada0 'struct __va_list_tag [1]' 1 
|   `-RecordType 0x55c3efbdabb0 'struct __va_list_tag'
|     `-CXXRecord 0x55c3efbdab18 '__va_list_tag'
|-ClassTemplateDecl 0x55c3efc0ffc8 <test.cpp:2:1, line:5:1> line:2:29 toto
| |-TemplateTypeParmDecl 0x55c3efc0fe78 <col:11, col:20> col:20 referenced typename depth 0 index 0 T
| |-CXXRecordDecl 0x55c3efc0ff30 <col:23, line:5:1> line:2:29 class toto definition
| | |-FullComment 0x55c3efc10a50 <line:1:4, col:12>
| | | `-ParagraphComment 0x55c3efc10a20 <col:4, col:12>
| | |   `-TextComment 0x55c3efc109f0 <col:4, col:12> Text=" Template"
| | |-CXXRecordDecl 0x55c3efc10240 <line:2:23, col:29> col:29 implicit class toto
| | |-AccessSpecDecl 0x55c3efc102d8 <line:3:3, col:9> col:3 public
| | `-FieldDecl 0x55c3efc10310 <line:4:3, col:5> col:5 i 'T'
| |-ClassTemplateSpecialization 0x55c3efc103c0 'toto'
| `-FullComment 0x55c3efc10b20 <line:1:4, col:12>
|   `-ParagraphComment 0x55c3efc10af0 <col:4, col:12>
|     `-TextComment 0x55c3efc10ac0 <col:4, col:12> Text=" Template"
|-ClassTemplateSpecializationDecl 0x55c3efc103c0 <line:8:1, col:27> col:16 class toto definition
| |-TemplateArgument type 'double'
| |-FullComment 0x55c3efc10bf0 <line:7:4, col:15>
| | `-ParagraphComment 0x55c3efc10bc0 <col:4, col:15>
| |   `-TextComment 0x55c3efc10b90 <col:4, col:15> Text=" Instantiate"
| |-CXXRecordDecl 0x55c3efc105c0 prev 0x55c3efc103c0 <line:2:23, col:29> col:29 implicit class toto
| |-AccessSpecDecl 0x55c3efc10658 <line:3:3, col:9> col:3 public
| `-FieldDecl 0x55c3efc106b8 <line:4:3, col:5> col:5 i 'double':'double'
`-CXXRecordDecl 0x55c3efc10748 <line:11:1, line:14:1> line:11:7 class totoro definition
  |-FullComment 0x55c3efc10cc0 <line:10:4, col:10>
  | `-ParagraphComment 0x55c3efc10c90 <col:4, col:10>
  |   `-TextComment 0x55c3efc10c60 <col:4, col:10> Text=" Normal"
  |-CXXRecordDecl 0x55c3efc10868 <line:11:1, col:7> col:7 implicit class totoro
  |-AccessSpecDecl 0x55c3efc10900 <line:12:3, col:9> col:3 public
  `-FieldDecl 0x55c3efc10940 <line:13:3, col:10> col:10 i 'double'

[Doc] standalone example?

Hi,
Is there somewhere a minimal standalone example, ie an example with a simple c++ class and the corresponding CMakeLists.txt?
I started thinking about it but my CMakeLists.txt:

cmake_minimum_required(VERSION 3.5)
if(COMMAND cmake_policy)
   cmake_policy(SET CMP0003 OLD)
endif(COMMAND cmake_policy)

set(CPP2PY_ADD_MODULE_ADDITIONAL_PYTHONPATH "/home/tayral/Work/TRIQS_1.6/install_cpp2py/lib/python2.7/site-packages/")
include(${CPP2PY_PATH}/share/cmake/Cpp2PyConfig.cmake)
include_directories(${CPP2PY_PATH}/include)
include_directories(.)
add_cpp2py_module(myclass) #I have generated a myclass_desc.py file with cpp2py

yields errors (one is: there is a TRIQS_RUNTIME_ERROR in the cxx file... but one does not necessarily want to use TRIQS)
Thanks

lib python detected should not allow static library

using libpython.a leads to a crash with numpy (import_array), because
the Python import module function uses a static version of the interpreter in TRIQS,
hence a local table apparently.
The configuration should not allow .a, only the dynamical library.
@Wentzell : to be discussed.
Fix is trivial, just make this case a hard error.

Missing boost includes in cpp2py (when building triqs doc)

I am trying to build the Triqs documentation but c++2rst breaks due to missing include path to boost.

Traceback (most recent call last):
  File "/Users/hugstr/apps/cpp2py/bin/c++2rst", line 36, in <module>
    libclang_location = args.libclang_location
  File "/Users/hugstr/apps/cpp2py/lib/python2.7/site-packages/cpp2rst/cpp2rst.py", line 60, in __init__
    self.root = CL.parse(filename, compiler_options, includes, libclang_location, parse_all_comments)
  File "/Users/hugstr/apps/cpp2py/lib/python2.7/site-packages/cpp2py/clang_parser.py", line 356, in parse
    raise RuntimeError, s + "\n... Your code must compile before using clang-parser !"
RuntimeError: Clang reports the following errors in parsing
 file /Users/hugstr/dev/triqs/triqs/./gfs/../utility/macros.hpp line 25 col 10
'boost/utility/enable_if.hpp' file not found
... Your code must compile before using clang-parser !
make[2]: *** [doc/cpp2rst.log] Error 1
make[2]: *** Deleting file `doc/cpp2rst.log'
make[1]: *** [doc/CMakeFiles/docs_cpp2rst.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....

I will dig a bit into this. Is cpp2py doing boost detection now?

Best, Hugo

Wrappers for non-void methods fail to compile with `release_GIL_and_enable_signal = True`

When release_GIL_and_enable_signal is switched on, the result object is created inside a nested try block (line 547 of wrap.cxx). Later, it is assumed to be visible in the enclosing scope of that try (line 563).

cpp2py/cpp2py/mako/wrap.cxx

Lines 539 to 570 in a54c236

try {
${overload._get_calling_pattern1()}
%if overload.release_GIL_and_enable_signal :
PyOS_sighandler_t sig = PyOS_getsig(SIGINT);
cpp2py::signal_handler::start(); // start the C++ signal handler
Py_BEGIN_ALLOW_THREADS;
try {
%endif
${overload._get_calling_pattern()}; // the call is here. It sets up "result" : sets up in the python layer.
%if overload.release_GIL_and_enable_signal :
}
catch(...) {
// an error has occurred : clean GIL, handler and rethrow
Py_BLOCK_THREADS; // cf python include, ceval.h, line 72 comments and below.
cpp2py::signal_handler::stop(); // stop the C++ signal handler
PyOS_setsig(SIGINT, sig);
throw; //
}
Py_END_ALLOW_THREADS;
cpp2py::signal_handler::stop();
PyOS_setsig(SIGINT, sig);
%endif
%if not overload.is_constructor :
%if overload.rtype != "void" :
py_result = convert_to_python(std::move(result));
%else:
Py_INCREF(Py_None);
py_result = Py_None;
%endif
%endif
return ${'py_result' if not py_meth.is_constructor else '0'};
}

I wanted to prepare a minimal example based on an existing wrapping unit test, but those seem to have been disabled in both TRIQS unstable and cpp2py.

Qualification in compound return types

Hi,

I ran across a problem where a locally defined type was not fully qualified when it was part of a compound return type.

Here a minimal example test.hpp:

#pragma once

#include <utility>
#include <tuple>
#include <triqs/utility/first_include.hpp>

namespace test_namespace {

class test_class {
 public:
  using return_t = double;
  std::pair<return_t, double> test_function_bad() { return std::make_pair(0.0, 0.0); }
  return_t test_function_good() { return std::make_pair(0.0, 0.0); }
};

} // namespace test_namespace

If we run c++2py on this:

# Generated automatically using the command :
# c++2py tmp.hpp -N test_namespace
from cpp2py.wrap_generator import *

# The module
module = module_(full_name = "tmp", doc = r"", app_name = "tmp")

# Imports

# Add here all includes
module.add_include("tmp.hpp")

# Add here anything to add in the C++ code at the start, e.g. namespace using
module.add_preamble("""
#include <cpp2py/converters/pair.hpp>

using namespace test_namespace;
""")


# The class test_class
c = class_(
        py_type = "TestClass",  # name of the python class
        c_type = "test_namespace::test_class",   # name of the C++ class
        doc = r"""""",   # doc of the C++ class
        hdf5 = False,
)

c.add_method("""std::pair<return_t,double> test_function_bad ()""",
             doc = r"""""")

c.add_method("""test_namespace::test_class::return_t test_function_good ()""",
             doc = r"""""")

module.add_class(c)



module.generate_code()

Here return_t is not correctly qualified as part of the return type in test_function_bad(). This leads to a "use of undeclared identifier" error when compiling. Contrast to the correct behaviour in test_function_good().

I'm guessing that c++2py would need to recursively step into the compound return type to check that everything is fully qualified?

[PS: I'm using the c++2py bundled with TRIQS 2.2.x]

Build fails: error: cannot initialize a parameter of type 'npy_intp *' (aka 'int *') with an rvalue of type 'std::__1::vector<long, std::__1::allocator<long> >::value_type *' (aka 'long *')

/wrkdirs/usr/ports/devel/cpp2py/work/cpp2py-10ab97d2e5e56656227a74118943de02e2265292/c++/cpp2py/numpy_proxy.cpp:35:87: error: cannot initialize a parameter of type 'npy_intp *' (aka 'int *') with an rvalue of type 'std::__1::vector<long, std::__1::allocator<long> >::value_type *' (aka 'long *')
       PyArray_NewFromDescr(&PyArray_Type, PyArray_DescrFromType(element_type), rank, extents.data(), strides.data(), data, flags, NULL);
                                                                                      ^~~~~~~~~~~~~~
1 error generated.

Log: http://beefy10.nyi.freebsd.org/data/113i386-default/549079/logs/cpp2py-1.5.20200812.log

This seems to a i386-only failure.

'unsigned long' transformed into 'unsignedlong'

Hi,

It seems c++2py (compiled from triqs 2.2.x) transforms 'unsigned long' into 'unsignedlong' without space.

For example, applying c++2py to a header file containing:

unsigned long function() { return 1; }

will produce a desc file with this line:

module.add_function ("unsignedlong function ()", doc = r"""""")

which cause an obvious error as unsignedlong is not recognized.

Memory leak when returning numpy arrays

When numpy arrays are returned, a small amount of memory leaks. This amount of memory (I think it is 32 bytes) does not depends on the actual size of the array that is returned, so it is probably related to some object that is created while preparing the numpy array. The following code produces a leak

from triqs.gf import *

g = GfImFreq(indices = [0], beta=10, n_points=1000)
#g = GfImFreq(target_shape = [], beta=10, n_points=1000) ## no memory leak with this
# memory usage here is about 42 Mb

for k in range(10000000): x = g(1)
# memory usage here is about 350 Mb

In the code above, the memory usage is about 300 Mb larger after the loop. Similar behavior is observed calling other functions that return an array. I don't see leaks when the functions return a float.

How does this compare to cppyy

This is not really an issue, more a question, or maybe something that could be pointed out in your README.

How does this compare to what cppyy is doing? It seems to achieve something similar but it's not clear to me what's the difference really. If you know: How does this compare in terms of performance? Does this support all of C++? C++17? How does this deal with overloads and other features that exist in C++ but not in Python?

c++2rst in triqs/tprf application (parse errors in triqs?)

Hi, I am trying to use c++2rst to generate the doc for tprf
https://github.com/HugoStrand/tprf

But the c++2rst function CL.parse encounters problems inside of triqs

[ 67%] Generating c++2rst.log
cd /Users/hugstr/dev/tprf/cbuild/doc && /Users/hugstr/apps/cpp2py/bin/c++2rst --namespace tprf /Users/hugstr/dev/tprf/doc/reference/doc_root.hpp --output_directory=/Users/hugstr/dev/tprf/cbuild/doc/cpp2doc_generated --includes=/Users/hugstr/dev/tprf/ -I /opt/local/include/openmpi-clang40 -I /opt/local/include -I /opt/local/include -I /opt/local/include -I /opt/local/include 2>&1 > c++2rst.log
Traceback (most recent call last):
  File "/Users/hugstr/apps/cpp2py/bin/c++2rst", line 36, in <module>
    libclang_location = args.libclang_location
  File "/Users/hugstr/apps/cpp2py/lib/python2.7/site-packages/cpp2rst/cpp2rst.py", line 60, in __init__
    self.root = CL.parse(filename, compiler_options, includes, libclang_location, parse_all_comments)
  File "/Users/hugstr/apps/cpp2py/lib/python2.7/site-packages/cpp2py/clang_parser.py", line 356, in parse
    raise RuntimeError, s + "\n... Your code must compile before using clang-parser !"
RuntimeError: Clang reports the following errors in parsing
 file /Users/hugstr/apps/triqs_devel/include/triqs/./gfs/../utility/complex_ops.hpp line 5 col 38
expected a type file /Users/hugstr/apps/triqs_devel/include/triqs/./gfs/../utility/complex_ops.hpp line 6 col 38
expected a type file /Users/hugstr/apps/triqs_devel/include/triqs/utility/c14.hpp line 75 col 5
'auto' not allowed in function return type file /Users/hugstr/apps/triqs_devel/include/triqs/utility/c14.hpp line 75 col 41
expected ';' at end of declaration list file /Users/hugstr/apps/triqs_devel/include/triqs/utility/c14.hpp line 82 col 5
'auto' not allowed in function return type file /Users/hugstr/apps/triqs_devel/include/triqs/utility/c14.hpp line 82 col 41
expected ';' at end of declaration list file /Users/hugstr/apps/triqs_devel/include/triqs/utility/c14.hpp line 88 col 5
'auto' not allowed in function return type file /Users/hugstr/apps/triqs_devel/include/triqs/utility/c14.hpp line 88 col 41
expected ';' at end of declaration list file /Users/hugstr/apps/triqs_devel/include/triqs/utility/c14.hpp line 123 col 14
unknown type name 'constexpr' file /Users/hugstr/apps/triqs_devel/include/triqs/utility/c14.hpp line 123 col 30
expected ';' at end of declaration list file /Users/hugstr/apps/triqs_devel/include/triqs/utility/c14.hpp line 131 col 66
a space is required between consecutive right angle brackets (use '> >') file /Users/hugstr/apps/triqs_devel/include/triqs/utility/is_complex.hpp line 27 col 55
a space is required between consecutive right angle brackets (use '> >') file /Users/hugstr/apps/triqs_devel/include/triqs/utility/../mpi/./base.hpp line 32 col 31
expected function body after function declarator file /Users/hugstr/apps/triqs_devel/include/triqs/utility/../mpi/./base.hpp line 118 col 67
expected expression file /Users/hugstr/apps/triqs_devel/include/triqs/utility/../mpi/./base.hpp line 118 col 24
'auto' not allowed in function return type file /Users/hugstr/apps/triqs_devel/include/triqs/utility/../mpi/./base.hpp line 118 col 105
expected ';' at end of declaration file /Users/hugstr/apps/triqs_devel/include/triqs/utility/../mpi/./base.hpp line 118 col 106
cannot use arrow operator on a type file /Users/hugstr/apps/triqs_devel/include/triqs/utility/../mpi/./base.hpp line 119 col 67
expected expression file /Users/hugstr/apps/triqs_devel/include/triqs/utility/../mpi/./base.hpp line 119 col 24
'auto' not allowed in function return type file None line 0 col 0
too many errors emitted, stopping now
... Your code must compile before using clang-parser !
make[2]: *** [doc/c++2rst.log] Error 1
make[2]: *** Deleting file `doc/c++2rst.log'
make[1]: *** [doc/CMakeFiles/doc_cpp2doc.dir/all] Error 2
make: *** [all] Error 2

am I doing something wrong when calling c++2rst in the above?

/Users/hugstr/apps/cpp2py/bin/c++2rst 
--namespace tprf /Users/hugstr/dev/tprf/doc/reference/doc_root.hpp 
--output_directory=/Users/hugstr/dev/tprf/cbuild/doc/cpp2doc_generated 
--includes=/Users/hugstr/dev/tprf/ 
-I /opt/local/include/openmpi-clang40 -I /opt/local/include 
-I /opt/local/include -I /opt/local/include -I /opt/local/include 
2>&1 > c++2rst.log

Overly aggressive namespace skipping

Hi,

I was trying to wrap a file with functions contained a namespace simple_ops. Although I added the -N simple_ops flags when running c++2py, none of the functions in the namespace were wrapped.

The origin of this is that there is a namespace filtering in cpp2desc.py (line 72; I'm using the cpp2py now included in triqs 2.2.x).

    namespaces_to_skip = ['std', 'boost', 'detail', 'impl']

Because "simple_ops" contains "impl" as a substring, this is filtered out. (If I set namespaces_to_skip = [] everything is done correctly.) This is probably not the desired behavior and seems a much to aggressive filtering.

Especially since we manually have to specify which namespaces to wrap via the '-N' command, is this filtering really needed?

In any case, it would be nice to get a message if namespaces are being skipped. It took a while to understand what went wrong.

Thanks!

Philipp

[FindPython.cmake] regression ?

tested under ubuntu 18.04
( same conclusions under 16.04 and with BUILD_SHARED_LIBS ON or OFF )

.
├── build
├── cmake
│   ├── FindPython.cmake -> FindPython.cmake_0b94a77
│   ├── FindPython.cmake_0b94a77
│   └── FindPython.cmake_994731d
└── CMakeLists.txt

CMakeLists.txt :

cmake_minimum_required(VERSION 3.10.0)
project(test C )

# shared library. no option, use shared.
set(BUILD_SHARED_LIBS ON)

# add ./cmake to the path for module
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)

# Detect Python
find_package(Python)

output with FindPython.cmake @dylex 0b94a77

-- -------- Python detection -------------
-- Python interpreter /usr/bin/python
-- Python interpreter and modules are ok : version 2.7.15rc1
-- PYTHON_INCLUDE_DIRS =  /usr/include/python2.7
-- PYTHON_H5PY_HDF5VERSION = 1.10.2
-- PYTHON_NUMPY_INCLUDE_DIR = /usr/lib/python2.7/dist-packages/numpy/core/include
-- PYTHON_NUMPY_VERSION = 1.13.3
-- PYTHON_SITE_PKG = /usr/lib/python2.7/dist-packages
-- PYTHON_LIBRARY = /usr/lib/python2.7/config-x86_64-linux-gnu/libpython2.7.so
-- PYTHON_EXTRA_LIBS =-L/usr/lib -lz -lpthread -ldl  -lutil
-- Python modules will be installed in /usr/local/lib/python2.7/site-packages

ok : PYTHON_LIBRARY = /usr/lib/python2.7/config-x86_64-linux-gnu/libpython2.7.so

output with FindPython.cmake @Wentzell 994731d

-- -------- Python detection -------------
-- Python interpreter /usr/bin/python
-- Python interpreter and modules are ok : version 2.7.15rc1
-- PYTHON_INCLUDE_DIRS =  /usr/include/python2.7
-- PYTHON_H5PY_HDF5VERSION = 1.10.2
-- PYTHON_NUMPY_INCLUDE_DIR = /usr/lib/python2.7/dist-packages/numpy/core/include
-- PYTHON_NUMPY_VERSION = 1.13.3
-- PYTHON_SITE_PKG = /usr/lib/python2.7/dist-packages
-- PYTHON_LIBRARY = PYTHON_LIBRARY-NOTFOUND
-- PYTHON_EXTRA_LIBS =-L/usr/lib -lz -lpthread -ldl  -lutil
-- Python modules will be installed in /usr/local/lib/python2.7/site-packages

ko : PYTHON_LIBRARY = PYTHON_LIBRARY-NOTFOUND

[cmake] python virtual environments are currently ignored

Currently cpp2py uses a custom find_package(python) module that became quite old. Newer features like the configuration variable for virtual environments Python_FIND_VIRTUALENV are missing. Currently that means that triqs / cpp2py will completely ignore virutal environments and instead picks the python interpreter behind the venv. This means that all custom installed pip packages in this venv are not found!

Possible solution: remove custom find python package in cmake/FindPython.cmake.

better dictionary-class converter

Hi,

One of the very nice features of cpp2py is the conversion of python dictionaries into a cpp class (e.g. for passing parameters). As far as I can tell, the only way to specifying that such a converter should be generated is with the keyword CPP2PY_ARG_AS_DICT.

This is somewhat inconvenient, since it is a keyword that applies to a function (rather then the parameter class itself) and that function is only allowed to take one parameter (the paramter class).

Consider an example:

class CPP2PY_IGNORE parameter_list {
 public:
  double param = 1.0;
};

void my_wrapped_function(parameter_list plist, int extra_key);

CPP2PY_ARG_AS_DICT inline void fake(parameter_list const &temp){};

The CPP2PY_IGNORE keyword on the parameter_list class stops cpp2py from directly wrapping the class in python. The my_wrapped_fuction is what we want to use, but it takes two arguments and therefore the CPP2PY_ARG_AS_DICT can't be applied. So we are left with defining the fake function whose only purpose is to trick cpp2py to make a converter.

I propose adding a new keyword that is applied to the data class itself. E.g. CPP2PY_CONVERT_TO_DICT. This seems to be the right place to put it logically (why does it matter which and how many functions in cpp we pass the class to?) and avoids the issues mentioned above.

Thoughts? Concerns?

Error reading module classes that change name between cmake build and installation from hdf5

Dear Olivier,

I am having trouble reading the cthyb solver from hdf5, but only when using it outside the cmake testing environment. In the cmake test phase the newly built cthyb solver is accessible as cthyb.solver_core.SolverCore while when we then install it the module path is triqs_cthyb.solver_core.SolverCore. In the wrapped solver_core_wrap.cxx the first module path is hard coded.

When I store the solver to hdf5 and try to read it again it fails complaining that:

Traceback (most recent call last):
  File "h5_read_write.py", line 41, in <module>
    solver_ref = A['solver']
  File "/mnt/home/hstrand/apps/x86_64/triqs_unstable/lib/python2.7/site-packages/pytriqs/archive/hdf_archive.py", line 228, in __getitem__
    return self.__getitem1__(key,self._reconstruct_python_objects)
  File "/mnt/home/hstrand/apps/x86_64/triqs_unstable/lib/python2.7/site-packages/pytriqs/archive/hdf_archive.py", line 263, in __getitem1__
    exec("from %s import %s as r_class" %(r_module_name,r_class_name)) in globals(), locals()
  File "<string>", line 1, in <module>
ImportError: No module named cthyb.solver_core

How do we make these two things work together, 1. running the cmake test with different module name path and 2. getting the cpp2py wrapping to pick up the correct module path for the actual installation?

Best, Hugo

libc++ inline namespaces

When I run c++2py on a function in a class method that returns a complex array I get:

c.add_method("""triqs::arrays::array<std::__1::complex<double>,2> get_array ()""",
             doc = r"""""")

Here the __1 is an inline namespace that libc++ uses, and compiles correctly. However, the __1 should be removed (to give simply std::complex<double>), otherwise there is an error when compiling using libstdc++.

Questions:

  1. How are inline namespaces treated by c++2py?

  2. Is the stripping of inline namespaces also done for compound return types? (see also #28 ).

Please make a release

The latest tag py2_compat suggests that you are currently Python-2 compatible? But Python-2 is EOLed.

Constraint checking on dictionary-class converter

Hi,

I wanted to run an idea by you to see if it would be interesting thing to implement.

I remember that when you have a convertor from python to cpp (via CPP2PY_ARG_AS_DICT), it does type checking of the input to make sure everything is well defined.

Would it also be possible to specify additional constraints / bounds / traits during this conversion?

For example, it would be nice to specify something that a parameter (e.g. temperature) should be > 0. This is then checked on conversion and gives an error message if it fails.

Or would this cause other problems?

Thanks!

'type' and 'default' tags are not recognized in parameter description

I am looking at the auto-generated solver_core_desc.py from cthyb.
Method solve() has a problem in its docstring.

+-------------------------------+------------------------------------------------+--------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Parameter Name                | Type                                           | Default                                          | Documentation                                                                                                                                                                   |
+===============================+================================================+==================================================+=================================================================================================================================================================================+
| h_int                         | cthyb::many_body_op_t                          |                                                  | Interacting part of the atomic Hamiltonian\n     type: Operator                                                                                                                 |
+-------------------------------+------------------------------------------------+--------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| n_cycles                      | int                                            |                                                  | Number of QMC cycles                                                                                                                                                            |
+-------------------------------+------------------------------------------------+--------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| partition_method              | std::string                                    | "autopartition"                                  | Partition method\n     type: str                                                                                                                                                |
+-------------------------------+------------------------------------------------+--------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| quantum_numbers               | std::vector<many_body_op_t>                    | std::vector<many_body_op_t>{}                    | Quantum numbers\n     type: list(Operator)\n     default: []                                                                                                                    |
+-------------------------------+------------------------------------------------+--------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

Before it was

+------------------------+-------------------------------------+-------------------------------+--------------------------------------------------------------------------------------------------------+
| Parameter Name         | Type                                | Default                       | Documentation                                                                                          |
+========================+=====================================+===============================+========================================================================================================+
| h_int                  | Operator                            |                               | Interacting part of the atomic Hamiltonian                                                             |
+------------------------+-------------------------------------+-------------------------------+--------------------------------------------------------------------------------------------------------+
| n_cycles               | int                                 |                               | Number of QMC cycles                                                                                   |
+------------------------+-------------------------------------+-------------------------------+--------------------------------------------------------------------------------------------------------+
| partition_method       | str                                 | "autopartition"               | Partition method                                                                                       |
+------------------------+-------------------------------------+-------------------------------+--------------------------------------------------------------------------------------------------------+
| quantum_numbers        | list(Operator)                      | []                            | Quantum numbers                                                                                        |
+------------------------+-------------------------------------+-------------------------------+--------------------------------------------------------------------------------------------------------+

As you can see, manually provided type and default fields are not extracted from the description anymore.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.