self._state.couple_state(state._state, entropy_args) - Python argument types did not match C++ signature

Hello Tiago,

I am sorry that I seem to keep on bugging you with error messages. I have
been playing around with the inference module a bit and tried to replicate a
section of code from your cookbook section. When running
gt.mcmc_equilibrate(state, wait=1000, mcmc_args=dict(niter=10)) I however
get an error message. I have attached the code num_groups_marg_prob.py
<http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/file/n4026975/num_groups_marg_prob.py&gt;
and the screen output screengrab.dat
<http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/file/n4026975/screengrab.dat&gt;
.

It seems to revolve around Python argument types not matching C++
signatures. Having done some searching this seems to come up when using
different compilers for different modules (?). In this case I am however
running the package as downloaded from apt-get (2.19 (commit da041f33, Sat
Nov 12 17:27:48 2016 +0100)) so I was surprised to see it. The same error
also gets thrown if running it on a compiled version of the source code
(2.20dev (commit 01432d60, Sun Jan 15 19:54:52 2017 +0000)).

Do you know what is going wrong here/how I could fix it?

I have copied the error below as it is quite long.

N.B.: This is on a different machine to the one I was posting about earlier
(though it has the same issue with cairomm).

Traceback (most recent call last):
  File "num_groups_marg_prob.py", line 26, in <module>
    gt.mcmc_equilibrate(state, wait=1000, mcmc_args=dict(niter=10))
  File "/usr/lib/python2.7/dist-packages/graph_tool/inference/mcmc.py", line
127, in mcmc_equilibrate
    delta, nmoves = state.mcmc_sweep(**mcmc_args)
  File
"/usr/lib/python2.7/dist-packages/graph_tool/inference/nested_blockmodel.py",
line 576, in mcmc_sweep
    return self._h_sweep(lambda s, **a: s.mcmc_sweep(**a), c=c, **kwargs)
  File
"/usr/lib/python2.7/dist-packages/graph_tool/inference/nested_blockmodel.py",
line 499, in _h_sweep
    get_entropy_args(eargs))
  File
"/usr/lib/python2.7/dist-packages/graph_tool/inference/blockmodel.py", line
616, in _couple_state
    self._state.couple_state(state._state, entropy_args)
Boost.Python.ArgumentError: Python argument types in
    graph_tool::BlockState<boost::adj_list&lt;unsigned long>,
graph_tool::simple_degs_t, std::integral_constant<bool, false>,
std::integral_constant<bool, false>, boost::any, boost::any, boost::any,
boost::unchecked_vector_property_map<int,
boost::adj_edge_index_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >, std::vector<unsigned
long, std::allocator<unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >, std::vector<unsigned
long, std::allocator<unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >, bool, int,
boost::unchecked_vector_property_map<double,
boost::adj_edge_index_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<double,
boost::adj_edge_index_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<double,
boost::adj_edge_index_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<double,
boost::adj_edge_index_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<double,
boost::typed_identity_property_map&lt;unsigned long> >, double, double,
double, double, double, double,
boost::unchecked_vector_property_map<unsigned char,
boost::typed_identity_property_map<unsigned long> >,
boost::unchecked_vector_property_map<unsigned char,
boost::typed_identity_property_map<unsigned long> >,

.couple_state(graph_tool::BlockState<boost::adj_list&lt;unsigned long>,

graph_tool::simple_degs_t, std::integral_constant<bool, false>,
std::integral_constant<bool, false>, boost::any, boost::any, boost::any,
boost::unchecked_vector_property_map<int,
boost::adj_edge_index_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >, std::vector<unsigned
long, std::allocator<unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >, std::vector<unsigned
long, std::allocator<unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >, bool, int,
boost::unchecked_vector_property_map<double,
boost::adj_edge_index_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<double,
boost::adj_edge_index_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<double,
boost::adj_edge_index_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<double,
boost::adj_edge_index_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<double,
boost::typed_identity_property_map&lt;unsigned long> >, double, double,
double, double, double, double,
boost::unchecked_vector_property_map<unsigned char,
boost::typed_identity_property_map<unsigned long> >,
boost::unchecked_vector_property_map<unsigned char,
boost::typed_identity_property_map<unsigned long> >, bool>,
graph_tool::BlockState<boost::adj_list&lt;unsigned long>,
graph_tool::simple_degs_t, std::integral_constant<bool, true>,
std::integral_constant<bool, false>, boost::any, boost::any, boost::any,
boost::unchecked_vector_property_map<int,
boost::adj_edge_index_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >, std::vector<unsigned
long, std::allocator<unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >, std::vector<unsigned
long, std::allocator<unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >, bool, int,
boost::unchecked_vector_property_map<double,
boost::adj_edge_index_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<double,
boost::adj_edge_index_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<double,
boost::adj_edge_index_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<double,
boost::adj_edge_index_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<double,
boost::typed_identity_property_map&lt;unsigned long> >, double, double,
double, double, double, double,
boost::unchecked_vector_property_map<unsigned char,
boost::typed_identity_property_map<unsigned long> >,
boost::unchecked_vector_property_map<unsigned char,
boost::typed_identity_property_map<unsigned long> >, bool>, entropy_args)
did not match C++ signature:
    couple_state(graph_tool::BlockState<boost::adj_list&lt;unsigned long>,
graph_tool::simple_degs_t, std::integral_constant<bool, false>,
std::integral_constant<bool, false>, boost::any, boost::any, boost::any,
boost::unchecked_vector_property_map<int,
boost::adj_edge_index_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >, std::vector<unsigned
long, std::allocator<unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >, std::vector<unsigned
long, std::allocator<unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >, bool, int,
boost::unchecked_vector_property_map<double,
boost::adj_edge_index_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<double,
boost::adj_edge_index_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<double,
boost::adj_edge_index_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<double,
boost::adj_edge_index_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<double,
boost::typed_identity_property_map&lt;unsigned long> >, double, double,
double, double, double, double,
boost::unchecked_vector_property_map<unsigned char,
boost::typed_identity_property_map<unsigned long> >,
boost::unchecked_vector_property_map<unsigned char,
boost::typed_identity_property_map<unsigned long> >, bool> {lvalue},
graph_tool::BlockState<boost::adj_list&lt;unsigned long>,
graph_tool::simple_degs_t, std::integral_constant<bool, false>,
std::integral_constant<bool, false>, boost::any, boost::any, boost::any,
boost::unchecked_vector_property_map<int,
boost::adj_edge_index_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >, std::vector<unsigned
long, std::allocator<unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >, std::vector<unsigned
long, std::allocator<unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<int,
boost::typed_identity_property_map&lt;unsigned long> >, bool, int,
boost::unchecked_vector_property_map<double,
boost::adj_edge_index_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<double,
boost::adj_edge_index_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<double,
boost::adj_edge_index_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<double,
boost::adj_edge_index_property_map&lt;unsigned long> >,
boost::unchecked_vector_property_map<double,
boost::typed_identity_property_map&lt;unsigned long> >, double, double,
double, double, double, double,
boost::unchecked_vector_property_map<unsigned char,
boost::typed_identity_property_map<unsigned long> >,
boost::unchecked_vector_property_map<unsigned char,
boost::typed_identity_property_map<unsigned long> >, bool> {lvalue},
graph_tool::entropy_args_t)

Please give us a minimal but complete script that shows the problem.

Hi Tiago,

This should hopefully do it:

    import graph_tool.all as gt

    g = gt.load_graph('graph_no_multi_reac_type.gt')
    gt.remove_parallel_edges(g)

    print 'minimising state'
    state = gt.minimize_nested_blockmodel_dl(g, deg_corr=True)

    print 'equilibrating Markov chain'
    # We will first equilibrate the Markov chain
    gt.mcmc_equilibrate(state, wait=1000, mcmc_args=dict(niter=10))

As explained in the documentation, before doing the mcmc, you have to enable
sampling with:

    state = state.copy(sampling=True)

(The error message is very cryptic and needs to be improved.)

Best,
Tiago

Thank you! I recall reading about that but didn't connect the dots. It seems
to now be working.

Hi Tiago,

I now get another error message:

AttributeError: 'NestedBlockState' object has no attribute 'get_nonempty_B'

Do you know what this is caused by? The MWE is:

    import graph_tool.all as gt
    import cPickle as pickle

    g = gt.load_graph('graph_no_multi_reac_type.gt')
    gt.remove_parallel_edges(g)

    state = gt.minimize_nested_blockmodel_dl(g, deg_corr=True)

    state = state.copy(sampling=True)
    with open('state_mcmc.pkl','wb') as state_pkl:
        pickle.dump(state,state_pkl,-1)

    print 'equilibrating Markov chain'
    gt.mcmc_equilibrate(state, wait=1000, mcmc_args=dict(niter=10))

    h = np.zeros(g.num_vertices() + 1)

    def collect_num_groups(s):
        B = s.get_nonempty_B()
        h[B] += 1

    print 'colleting marginals'
    gt.mcmc_equilibrate(state, force_niter=10000, mcmc_args=dict(niter=10),
                    callback=collect_num_groups)

The traceback I get is:
    Traceback (most recent call last):
      File "num_groups_marg_prob.py", line 42, in <module>
        gt.mcmc_equilibrate(state, force_niter=10000,
mcmc_args=dict(niter=10),
      File "/usr/lib/python2.7/dist-packages/graph_tool/inference/mcmc.py",
line 172, in mcmc_equilibrate
        extra = callback(state)
      File "num_groups_marg_prob.py", line 35, in collect_num_groups
        def collect_num_groups(s):
    AttributeError: 'NestedBlockState' object has no attribute
'get_nonempty_B'

The error message is clear. This attribute belongs to BlockState, not
NestedBlockState. What you wish to do is:

    s.levels[0].get_nonempty_B()

That worked, thank you!