Python Questions? Ask Me!

497 views
Skip to first unread message

tbei...@googlemail.com

unread,
Jul 7, 2014, 7:15:07 PM7/7/14
to ope...@googlegroups.com
If you have any questions or suggestions to the python wrapper of opengm gm pls post them here!

Greetings Thorsten Beier (aka DerThorsten on Github)

Roman Shapovalov

unread,
Jul 10, 2014, 9:36:43 AM7/10/14
to ope...@googlegroups.com
Hi Thorsten,

I am trying to compile the Python wrapper with Visual Studio to use it from Python 3. There are some issues with that. I fixed several ones (i.e. import_array has different return value in Python3, and some class names needed to be fully-qualified). Now I face the runtime error that occurs while importing the _inference module. I tracked it down the InfSuite::visit() method. Creating most arguments works well, but not the stringvector-typed ones. It seems that the type is not registered for conversion. I am new to boost-python, so not sure if it should be, and how it can be done. Could you help?

Thanks,
Roman

tbei...@googlemail.com

unread,
Jul 10, 2014, 5:20:35 PM7/10/14
to ope...@googlegroups.com
thanks for pointing out that error, and I will have a look in it tomorrow .

Greetings Thorsten

Sam Preston

unread,
Nov 30, 2014, 3:21:30 PM11/30/14
to ope...@googlegroups.com
I've been using the python interface to opengm, and it works quite well.  However I have some additional factor functions I've added, and I'd like to expose them in the python interface.  My initial attempt was, for simplicity, just to add the functions directly to the opengm library and copy how things were done for the TruncatedAbsoluteDifferenceFunction class.  However, this has resulted in editing a lot of the python interface code, and so far I'm still having trouble getting it to work.  I can probably figure this out eventually, but was wondering if there is a suggested way to add custom c++ functions to the python interface.

Thorsten Beier

unread,
Dec 1, 2014, 5:54:46 AM12/1/14
to ope...@googlegroups.com
Hi,
Adding a new FunctionType to the python interface might be a bit painful.

You need to make changes in a lot of headers:
pyFunctionTypes.cxx
pyGm.cxx
include/opengm/opengmpython.hxx

If you need more detailed instructions tell me, and i will write a tiny tutorial .

Greetings Thorsten

Sam Preston

unread,
Dec 2, 2014, 11:16:33 AM12/2/14
to ope...@googlegroups.com
Hi Thorsten,

Thanks, I did eventually get it working.  Modifying include/opengm/opengmpython.hxx was the only part I was missing -- everything else that needed modification was in the src/interfaces/python/opengm/opengmcore/ folder.

Christopher Snyder

unread,
Mar 19, 2015, 8:10:13 PM3/19/15
to ope...@googlegroups.com
Thorsten,

I am trying to install with Python3 wrapper. Using 't' toggle in ccmake I was very careful to make sure only to link Python3 things and not Python2. I remember specifically changing the boost .so file, the numpy related dir/lib, and the python include dir. Of note, I am also using a python3 compiler belonging to a virtual environment and not one in /usr/* I think that's everything, but I have attached the CMakeCache.txt for completeness.

The specific error message I get has to do with the print function in __init__.py

>>> import opengm
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/christopher/.virtualenvs/wormvision3/lib/python3.4/site-packages/opengm/__init__.py", line 37
    print '[%s]' % self.name
               ^
SyntaxError: invalid syntax

I think this is exactly the error that on Nov 14,2013 was fixed (see second to last commit). But I am building using Nov 19,2014 code 2.3.4 from the zipfile on the website, so I do not know why it is not working.

As a sanity check, if you try to to import it with python2, you get an error importing numpy.core.multiarray as expected.

Thanks in advance,
Chris Snyder






CMakeCache.txt

Christopher Snyder

unread,
Mar 19, 2015, 11:31:21 PM3/19/15
to ope...@googlegroups.com
Scratch that I think I was being careless and the Python executable is not what I thought it was.

When I correctly switched to Python3, I got the same message I had been fighting earlier:

In file included from /home/christopher/SourceCode/opengm-master/include/opengm/python/opengmpython.hxx:22:0,
                 from /home/christopher/SourceCode/opengm-master/src/interfaces/python/opengm/hdf5/hdf5.cpp:7:
/home/christopher/SourceCode/opengm-master/include/opengm/python/converter.hxx: In function ‘boost::python::tuple opengm::python::iteratorToTuple(ITERATOR, size_t)’:
/home/christopher/SourceCode/opengm-master/include/opengm/python/converter.hxx:165:64: error: there are no arguments to ‘PyInt_FromLong’ that depend on a template parameter, so a declaration of ‘PyInt_FromLong’ must be available [-fpermissive]
          PyTuple_SetItem(tuple, i, PyInt_FromLong(long(iter[i])));


hdf5 was installed with
sudo apt-get install libhdf5-serial-dev

Include directory for hdf5 is /usr/include ... seems to be right.

Do you know what could be going wrong here? (new cmakecache attached)

Thanks again,
Chris S
CMakeCache.txt

I Am

unread,
Jun 26, 2015, 10:03:57 AM6/26/15
to ope...@googlegroups.com

Hello Thorsten,

I am trying to build a small hierarchical model using the python wrapper. I have the impression that I am doing something wrong.

Say I have two variables A and B and I define a function f=p(A|B). I make a 2d array f where the labels of A index the first dimension and the labels of B index the second dimension.

ID = model.addFunction(f)

=> (1) Is this the correct way to create the function?

Then I want to make a factor F(A,B) like this B ---f--->A.

Then I add the factor F:

model.addFactor(ID,np.array([0,1]))

where A:0, B:1 is the variable names.

=> (2) Is [0,1] the correct order w.r.t. the above?

Thanks

Tobias

Nedialko Dimitrov

unread,
Jul 1, 2015, 2:34:40 PM7/1/15
to ope...@googlegroups.com
Hi Thorsten,

Thanks for the python wrapper in the first place, it looks really useful.

I'm trying to do exact marginal inference on loopy graphs (SumProduct) using the libDai/JunctionTree wrapper.  It looks like that works just fine in C++ (src/unittest/inference/test_libdai.cxx), but the python wrapper for JuncionTreeLibDai raises an error if you pass in a 'multiplier' operator and an 'integrator' accumulator?

It looks like this is perhaps easy to fix?  Maybe just something in (src/interfaces/python/opengm/_inference_interface_generator.py)?

Thank you for the help!

Ned.

Luis Mojica

unread,
Jul 18, 2015, 3:19:39 AM7/18/15
to ope...@googlegroups.com
Hello Nedialko, Thorsten,

I'm having a similar issue with the regular BP. The combination of "adder" with "integrator" gives me an error like the following:

Boost.Python.ArgumentError: Python argument types in
    _BeliefPropagation.__init__(_BeliefPropagation, GraphicalModel, _BeliefPropagation)
did not match C++ signature: ...

Do you guys see a solution for this problem?

Thank you!
BN_02.py

王豪

unread,
Sep 11, 2016, 12:51:05 AM9/11/16
to opengm
Hi, Thorsten:
     After I compile the opengm("cmake, make, make install"), I try to import opengm via python..Always see that "no module named opengm"..Do you know where is the module opengm??
Thx !

Anthony Wang

unread,
Sep 15, 2016, 6:47:35 PM9/15/16
to opengm
Hi Thorsten, when I use opengm python, I see that it do not have  the Gibbs interface..What should I set more in the ccmake procedure? Thx a lot
~~~
inference = opengm.inference.Gibbs(gm)
AttributeError: 'module' object has no attribute 'Gibbs'
~~~

Marco Forte

unread,
Dec 16, 2016, 7:18:58 AM12/16/16
to opengm
Hi Chris, I am getting the same problem. I'm using Ubuntu 16.04, gcc-4.6 and python 3.5. Did you ever resolve the issue?
Thanks,
Marco

Marco Forte

unread,
Jan 18, 2017, 1:58:49 PM1/18/17
to opengm
In case anyone else has the problem, hopefully this helps, I fixed my prev error by using python 2.7.
 Then I got this error 

TypeError: No registered converter was able to produce a C++ rvalue of type std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > from this Python object of type str

which I fixed by updating my version of boost with

conda install -c anaconda boost=1.61.0

I also used cplex not gurobi. 

Ikyo Coyan

unread,
Apr 15, 2018, 11:23:50 AM4/15/18
to opengm
Hi Thorsten,

I was going to install the python-wrapper and qpbo,while there shows link error:
[ 35%] Linking CXX shared module _hdf5.so

 

Undefined symbols for architecture x86_64:

 
"_PyEval_InitThreads", referenced from:

      init_module__hdf5
() in hdf5.cpp.o

 
"_Py_Initialize", referenced from:

      init_module__hdf5
() in hdf5.cpp.o

 
"__Py_NoneStruct", referenced from:

      __GLOBAL__sub_I_hdf5
.cpp in hdf5.cpp.o

      boost
::python::detail::caller_arity<3u>::impl<void (*)(opengm::GraphicalModel<double, opengm::Adder, opengm::meta::TypeList<opengm::ExplicitFunction<double, unsigned long, unsigned long>, opengm::meta::TypeList<opengm::PottsFunction<double, unsigned long, unsigned long>, opengm::meta::TypeList<opengm::PottsNFunction<double, unsigned long, unsigned long>, opengm::meta::TypeList<opengm::PottsGFunction<double, unsigned long, unsigned long>, opengm::meta::TypeList<opengm::TruncatedAbsoluteDifferenceFunction<double, unsigned long, unsigned long>, opengm::meta::TypeList<opengm::TruncatedSquaredDifferenceFunction<double, unsigned long, unsigned long>, opengm::meta::TypeList<opengm::SparseFunction<double, unsigned long, unsigned long, std::__1::map<unsigned long, double, std::__1::less<unsigned long>, std::__1::allocator<std::__1::pair<unsigned long const, double> > > >, opengm::meta::TypeList<opengm::functions::learnable::LPotts<double, unsigned long, unsigned long>, opengm::meta::TypeList<opengm::functions::learnable::LUnary<double, unsigned long, unsigned long>, opengm::meta::ListEnd> > > > > > > > >, opengm::DiscreteSpace<unsigned long, unsigned long> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&), boost::python::default_call_policies, boost::mpl::vector4<void, opengm::GraphicalModel<double, opengm::Adder, opengm::meta::TypeList<opengm::ExplicitFunction<double, unsigned long, unsigned long>, opengm::meta::TypeList<opengm::PottsFunction<double, unsigned long, unsigned long>, opengm::meta::TypeList<opengm::PottsNFunction<double, unsigned long, unsigned long>, opengm::meta::TypeList<opengm::PottsGFunction<double, unsigned long, unsigned long>, opengm::meta::TypeList<opengm::TruncatedAbsoluteDifferenceFunction<double, unsigned long, unsigned long>, opengm::meta::TypeList<opengm::TruncatedSquaredDifferenceFunction<double, unsigned long, unsigned long>, opengm::meta::TypeList<opengm::SparseFunction<double, unsigned long, unsigned long, std::__1::map<unsigned long, double, std::__1::less<unsigned long>, std::__1::allocator<std::__1::pair<unsigned long const, double> > > >, opengm::meta::TypeList<opengm::functions::learnable::LPotts<double, unsigned long, unsigned long>, opengm::meta::TypeList<opengm::functions::learnable::LUnary<double, unsigned long, unsigned long>, opengm::meta::ListEnd> > > > > > > > >, opengm::DiscreteSpace<unsigned long, unsigned long> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&> >::operator()(_object*, _object*) in pyHdf5.cxx.o

      boost
::python::detail::caller_arity<3u>::impl<void (*)(opengm::GraphicalModel<double, opengm::Adder, opengm::meta::TypeList<opengm::ExplicitFunction<double, unsigned long, unsigned long>, opengm::meta::TypeList<opengm::PottsFunction<double, unsigned long, unsigned long>, opengm::meta::TypeList<opengm::PottsNFunction<double, unsigned long, unsigned long>, opengm::meta::TypeList<opengm::PottsGFunction<double, unsigned long, unsigned long>, opengm::meta::TypeList<opengm::TruncatedAbsoluteDifferenceFunction<double, unsigned long, unsigned long>, opengm::meta::TypeList<opengm::TruncatedSquaredDifferenceFunction<double, unsigned long, unsigned long>, opengm::meta::TypeList<opengm::SparseFunction<double, unsigned long, unsigned long, std::__1::map<unsigned long, double, std::__1::less<unsigned long>, std::__1::allocator<std::__1::pair<unsigned long const, double> > > >, opengm::meta::TypeList<opengm::functions::learnable::LPotts<double, unsigned long, unsigned long>, opengm::meta::TypeList<opengm::functions::learnable::LUnary<double, unsigned long, unsigned long>, opengm::meta::ListEnd> > > > > > > > >, opengm::DiscreteSpace<unsigned long, unsigned long> >&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&), boost::python::default_call_policies, boost::mpl::vector4<void, opengm::GraphicalModel<double, opengm::Adder, opengm::meta::TypeList<opengm::ExplicitFunction<double, unsigned long, unsigned long>, opengm::meta::TypeList<opengm::PottsFunction<double, unsigned long, unsigned long>, opengm::meta::TypeList<opengm::PottsNFunction<double, unsigned long, unsigned long>, opengm::meta::TypeList<opengm::PottsGFunction<double, unsigned long, unsigned long>, opengm::meta::TypeList<opengm::TruncatedAbsoluteDifferenceFunction<double, unsigned long, unsigned long>, opengm::meta::TypeList<opengm::TruncatedSquaredDifferenceFunction<double, unsigned long, unsigned long>, opengm::meta::TypeList<opengm::SparseFunction<double, unsigned long, unsigned long, std::__1::map<unsigned long, double, std::__1::less<unsigned long>, std::__1::allocator<std::__1::pair<unsigned long const, double> > > >, opengm::meta::TypeList<opengm::functions::learnable::LPotts<double, unsigned long, unsigned long>, opengm::meta::TypeList<opengm::functions::learnable::LUnary<double, unsigned long, unsigned long>, opengm::meta::ListEnd> > > > > > > > >, opengm::DiscreteSpace<unsigned long, unsigned long> >&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&> >::operator()(_object*, _object*) in pyHdf5.cxx.o

      __GLOBAL__sub_I_pyHdf5
.cxx in pyHdf5.cxx.o

ld
: symbol(s) not found for architecture x86_64

clang
: error: linker command failed with exit code 1 (use -v to see invocation)

make
[2]: *** [src/interfaces/python/opengm/hdf5/_hdf5.so] Error 1

make
[1]: *** [src/interfaces/python/opengm/hdf5/CMakeFiles/_hdf5.dir/all] Error 2

make
: *** [all] Error 2

Could you tell me how to fix this?

Best regards

Reply all
Reply to author
Forward
0 new messages