graph-tool issueshttps://git.skewed.de/count0/graph-tool/-/issues2023-10-18T14:32:39Zhttps://git.skewed.de/count0/graph-tool/-/issues/770Error when load_graph_from_csv()2023-10-18T14:32:39ZRongbo WuError when load_graph_from_csv()# Bug reports:
## Please follow the general troubleshooting steps first:
- [-] Are you running the latest `graph-tool` version?
- [-] Do you observe the problem with the current git version?
- [ ] Are you using Macports or Homebrew? If...# Bug reports:
## Please follow the general troubleshooting steps first:
- [-] Are you running the latest `graph-tool` version?
- [-] Do you observe the problem with the current git version?
- [ ] Are you using Macports or Homebrew? If yes, please submit an issue there instead: https://github.com/Homebrew/brew/issues and https://trac.macports.org/newticket
- [ ] Did you compile `graph-tool` manually?
- [ ] If you answered yes above, did you use the exact same compiler to build `graph-tool`, `boost-python` and `Python`?
Please replace this section with a brief summary of your issue.
## Do **not** forget to supply the following information:
- [ ] **A _minimal_ and _self-contained_ example that shows the problem.**
- [ ] When use `gt.load_graph_from_csv(f, directed=True, skip_first=True)`:
``` 3657 eprop_names = list(first_line)
3658 del eprop_names[min(ecols)]
-> 3659 del eprop_names[max(ecols)-1]
3661 for i, p in enumerate(eprops):
3662 if eprop_names is not None:
IndexError: list assignment index out of range
```
It seems it dels column 0 twice?
- [ ] Your operating system.
- [ ] CentOS 8
- [ ] The Python version you are using.
- [ ] 3.10.11
- [ ] If you compiled graph-tool manually: Your compiler version, as well as the version of Boost being used.
- [ ] If you are reporting a compilation error, please provide the **entire** `./configure` output, as well as the **entire** contents of the `config.log` file and the **entire** compilation output.
Do not forget to add code snippets and error messages using [Markdown](/help/user/markdown.md), i.e.
```
Insert your code/shell command/error message here.
```
_You can erase any parts of this template not applicable to your Issue._
Please note we may immediately close your issue without comment if you do not fill out the issue template and provide the requested information.https://git.skewed.de/count0/graph-tool/-/issues/769Build issue with boost 1.832023-09-30T20:04:35ZDavid SeifertBuild issue with boost 1.83I'm trying to bump graph-tool in gentoo, and am getting the following error:
```
In file included from src/graph/graph_io.cc:40:
src/graph/gml.hh: In function 'bool graph_tool::read_gml(std::istream&, Graph&, boost::dynamic_properties&, ...I'm trying to bump graph-tool in gentoo, and am getting the following error:
```
In file included from src/graph/graph_io.cc:40:
src/graph/gml.hh: In function 'bool graph_tool::read_gml(std::istream&, Graph&, boost::dynamic_properties&, const std::unordered_set<std::__cxx11::basic_string<char> >&, const std::unordered_set<std::__cxx11::basic_string<char> >&, const std::unordered_set<std::__cxx11::basic_string<char> >&)':
src/graph/gml.hh:367:5: error: 'u8_to_u32_iterator' was not declared in this scope
367 | u8_to_u32_iterator<spirit::istream_iterator> tbegin(begin), tend(end);
| ^~~~~~~~~~~~~~~~~~
src/graph/gml.hh:367:48: error: expected primary-expression before '>' token
367 | u8_to_u32_iterator<spirit::istream_iterator> tbegin(begin), tend(end);
| ^
src/graph/gml.hh:367:50: error: there are no arguments to 'tbegin' that depend on a template parameter, so a declaration of 'tbegin' must be available [-fpermissive]
367 | u8_to_u32_iterator<spirit::istream_iterator> tbegin(begin), tend(end);
| ^~~~~~
src/graph/gml.hh:367:50: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
src/graph/gml.hh:367:65: error: there are no arguments to 'tend' that depend on a template parameter, so a declaration of 'tend' must be available [-fpermissive]
367 | u8_to_u32_iterator<spirit::istream_iterator> tbegin(begin), tend(end);
| ^~~~
src/graph/gml.hh:370:23: error: 'tbegin' was not declared in this scope; did you mean 'begin'?
370 | parse_grammar(tbegin, tend, g, dp,
| ^~~~~~
| begin
src/graph/gml.hh:370:31: error: 'tend' was not declared in this scope; did you mean 'end'?
370 | parse_grammar(tbegin, tend, g, dp,
| ^~~~
| end
```https://git.skewed.de/count0/graph-tool/-/issues/766Copy a graph_tool.Graph into a new one causes an enormously slowdown2023-09-23T20:52:16ZGerion ECopy a graph_tool.Graph into a new one causes an enormously slowdownIn a program, I have this code snipped:
```py
mapping = graph.new_vp("int64_t", vals=numpy.arange(graph.num_vertices()))
g = Graph(graph, prune=True, vorder=mapping)
```
`graph` is a `graph_tool.GraphView` (based on multiple vertex and e...In a program, I have this code snipped:
```py
mapping = graph.new_vp("int64_t", vals=numpy.arange(graph.num_vertices()))
g = Graph(graph, prune=True, vorder=mapping)
```
`graph` is a `graph_tool.GraphView` (based on multiple vertex and edge filters).
The whole code can be found here: https://github.com/luhsra/ara/blob/soso/ara/steps/create_abbs.py#L147
When I run the (whole) program, it needs around 2s to execute. The program consists at minimum of several thousands of LOC. Now, when I run the program in parallel with a very similar input (especially the mentioned `graph` object is equal, I use `meson test --suite ...` to start the program 3 times in parallel), its runtime increases to ~40s.
After debugging and profiling, I found that replacing the above lines with:
```py
mapping = graph.new_vp("int64_t", vals=numpy.arange(graph.num_vertices()))
g = Graph()
```
reduces that runtime to ~8s.
The profiler says, that 60-80% of the runtime of the program belongs to the native copy operation in `graph-tool/__init__.py` line 1789:
```py
# The actual copying of the graph and property maps
self.__graph = libcore.GraphInterface(gv.__graph, False,
vprops,
eprops,
_prop("v", gv, vorder))
```
The profiling indicates that a lot of time is used for spinning in libgomp (a part of pthreads of gcc) at `gomp_team_barrier_wait_end` and `gomp_simple_barrier_wait`, but this happens _only_ when multiple processes are running in parallel.
I have no clue at all, why another process has some interference here (the processes do not communicate!).
Do you have an idea what might be wrong here?https://git.skewed.de/count0/graph-tool/-/issues/761graph-tool 2.57 build fails on macOS Ventura2023-08-17T21:46:12ZStevegraph-tool 2.57 build fails on macOS Ventura# Bug reports:
## Please follow the general troubleshooting steps first:
- [x] Are you running the latest `graph-tool` version?
- [x] Do you observe the problem with the current git version?
- [x] Are you using Macports or Homebrew? If...# Bug reports:
## Please follow the general troubleshooting steps first:
- [x] Are you running the latest `graph-tool` version?
- [x] Do you observe the problem with the current git version?
- [x] Are you using Macports or Homebrew? If yes, please submit an issue there instead: https://github.com/Homebrew/brew/issues and https://trac.macports.org/newticket
- [x] Did you compile `graph-tool` manually?
- [x] If you answered yes above, did you use the exact same compiler to build `graph-tool`, `boost-python` and `Python`?
I'm the `graph-tool` maintainer for MacPorts. `graph-tool` builds fail on macOS Ventura boxes. I tested separately on a Mac Studio with an M2 Ultra, an MBA with an M1, and a Mac Mini x86_64, and see the same issue. The exact same build procedure works for `graph-tool` version 2.46.
The build errors are:
```sh
:info:build In file included from ./src/graph/graph.hh:42:
:info:build ./src/graph/graph_properties.hh:466:19: error: no template named 'unary_function' in namespace 'std'; did you mean '__unary_function'?
:info:build : public std::unary_function<typename IndexMap::key_type, size_t>
:info:build ~~~~~^~~~~~~~~~~~~~
:info:build __unary_function
```
A full log file is attached with `./configure` and other outputs:
[main_py310-graph-tool_x86_64.log.gz](https://git.skewed.de/count0/graph-tool/uploads/48ab835efb1b7d7d9e41d0c547a37382/main_py310-graph-tool_x86_64.log.gz)
Build environment:
macOS 13.4.1 22F770820d arm64
Xcode 14.3.1 14E300c
Python 3.10
The MacPorts build routines are standard based on `graph-tool` build-from-source instructions and have been more-or-less working on `x86_64` boxes for years:
https://github.com/macports/macports-ports/blob/master/python/py-graph-tool/Portfile
## Do **not** forget to supply the following information:
- [x] **A _minimal_ and _self-contained_ example that shows the problem.**
- [x] Your operating system.
- [x] The Python version you are using.
- [x] If you compiled graph-tool manually: Your compiler version, as well as the version of Boost being used.
- [x] If you are reporting a compilation error, please provide the **entire** `./configure` output, as well as the **entire** contents of the `config.log` file and the **entire** compilation output.https://git.skewed.de/count0/graph-tool/-/issues/760Improper quotation encoding in GML files, and other deviations from the spec2023-09-01T13:35:53ZSzabolcs HorvátImproper quotation encoding in GML files, and other deviations from the specgraph-tool's GML writer deviates from the GML spec in several ways, which prevents other software from reading files created by graph-tool. You can download the "technical report" containing the spec here:
https://web.archive.org/web/20...graph-tool's GML writer deviates from the GML spec in several ways, which prevents other software from reading files created by graph-tool. You can download the "technical report" containing the spec here:
https://web.archive.org/web/20190207140002/http://www.fim.uni-passau.de/index.php?id=17297%26L=1
The most problematic behaviour is the escaping of strings. graph-tool uses backslash escaping, but GML requires using `quot;` instead. IPython transcript of an example:
```
In [1]: from graph_tool.all import *
Installed osx event loop hook.
In [2]: g = Graph()
In [3]: g.graph_properties['foo'] = g.new_graph_property('string', 'one "two" three')
In [4]: g.save('test.gml')
```
This results in:
```
graph [
directed 1
foo "one \"two\" three"
]
```
This file won't be read by any of igraph, NetworkX, yEd.
Other issues are visible in the GML version of this graph:
https://networks.skewed.de/net/ceo_club
Namely:
- Property names are not allowed to contain underscores. Both NetworkX and yEd choke on this.
- It is unclear if strings are allowed to contain newlines. NetworkX chokes on this.
igraph doesn't mind either of these two issues. I was the last person to work on igraph's GML reader and my philosophy was to be as lenient during parsing as feasible. So underscores and newlines are no problem. However, interpreting the backslash as an escape character directly conflicts with how other software interprets GML strings, so I decided not to let igraph's parser handle this.https://git.skewed.de/count0/graph-tool/-/issues/759graph_blockmodel_dynamics_cising_glauber_mcmc_h.cc is also missing2023-08-17T21:46:13Zmark-dawngraph_blockmodel_dynamics_cising_glauber_mcmc_h.cc is also missingThank you for the quick fix for [issue#757](https://git.skewed.de/count0/graph-tool/-/issues/757), however I wanted to report that the continous Ising model `CIsingGlauberBlockState` suffers from the same problem, so a `graph_blockmodel_...Thank you for the quick fix for [issue#757](https://git.skewed.de/count0/graph-tool/-/issues/757), however I wanted to report that the continous Ising model `CIsingGlauberBlockState` suffers from the same problem, so a `graph_blockmodel_dynamics_cising_glauber_mcmc_h.cc` file should be added as well.
The minimal example to reproduce is analogous:
```python
# We will first simulate the dynamics with a given network
g = gt.collection.data["dolphins"]
ss = []
for i in range(100):
si_state = gt.CIsingGlauberState(g, beta=.7)
s = [si_state.get_state().copy()]
for j in range(10):
si_state.iterate_sync()
s.append(si_state.get_state().copy())
s = gt.group_vector_property(s)
ss.append(s)
# Prepare the initial state of the reconstruction as an empty graph
u = g.copy()
u.clear_edges()
ss = [u.own_property(s) for s in ss] # time series properties need to be 'owned' by graph u
# Create reconstruction state
rstate = gt.CIsingGlauberBlockState(u, s=ss, beta=.7, nested=False, aE=g.num_edges())
gm = None
bs = []
def collect_marginals(s):
global gm, bs
gm = s.collect_marginal(gm)
bs.append(s.bstate.b.a.copy())
gt.mcmc_equilibrate(rstate, force_niter=1000, mcmc_args=dict(niter=10, xstep=0),
callback=collect_marginals)
```
with error: `AttributeError: module 'graph_tool.inference.libgraph_tool_inference' has no attribute 'mcmc_cising_glauber_sweep_h'`https://git.skewed.de/count0/graph-tool/-/issues/758`minimize_blockmodel_dl` error with numpy 1.25.2023-06-29T14:56:07ZRodrigo Vargas`minimize_blockmodel_dl` error with numpy 1.25.I installed `graph-tool` in a fresh conda environment (python=3.11) via `conda install -c conda-forge graph-tool`. I got an environment with `graph-tool=2.56` and `numpy=1.25.0`. In this environment, execution of
```
from graph_tool.all ...I installed `graph-tool` in a fresh conda environment (python=3.11) via `conda install -c conda-forge graph-tool`. I got an environment with `graph-tool=2.56` and `numpy=1.25.0`. In this environment, execution of
```
from graph_tool.all import *
g = collection.ns["ego_social/facebook_combined"]
state = minimize_blockmodel_dl(g)
```
results in the following error:
```
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/vargonis/miniconda3/envs/langchain/lib/python3.11/site-packages/graph_tool/inference/minimize.py", line 128, in minimize_blockmodel_dl
state = state(g, **state_args)
^^^^^^^^^^^^^^^^^^^^^^
File "/home/vargonis/miniconda3/envs/langchain/lib/python3.11/site-packages/graph_tool/inference/blockmodel.py", line 239, in __init__
B = min(B, self.g.num_vertices())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/vargonis/miniconda3/envs/langchain/lib/python3.11/site-packages/numpy/core/fromnumeric.py", line 2953, in min
return _wrapreduction(a, np.minimum, 'min', axis, None, out,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/vargonis/miniconda3/envs/langchain/lib/python3.11/site-packages/numpy/core/fromnumeric.py", line 88, in _wrapreduction
return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
numpy.exceptions.AxisError: axis 4039 is out of bounds for array of dimension 0
```
The error goes away if one creates the environment like this: `conda create -c conda-forge -n my_env_name python=3.11 numpy=1.24 graph-tool`.https://git.skewed.de/count0/graph-tool/-/issues/757Using IsingGlauberBlockState inference2023-06-30T11:37:08Zmark-dawnUsing IsingGlauberBlockState inference# Bug reports:
## Please follow the general troubleshooting steps first:
- [x] Are you running the latest `graph-tool` version?
- [ ] Do you observe the problem with the current git version? (haven't tried)
OS is arch linux, but every...# Bug reports:
## Please follow the general troubleshooting steps first:
- [x] Are you running the latest `graph-tool` version?
- [ ] Do you observe the problem with the current git version? (haven't tried)
OS is arch linux, but everything is installed in miniconda using the standard conda-forge repo; python 3.10, last version of grap-tool.
I was trying to use the `IsingGlauberBlockState` class on some time series of a neural network. I used as a base the code shown for the [shown for the Epidemic version on the cookbook](https://graph-tool.skewed.de/static/doc/demos/inference/inference.html#reconstruction-from-dynamics) (which works no problem).
However switching the `EpidemicsBlockState` class for either the continuous or discrete Ising, as in this minimal example:
```python
# We will first simulate the dynamics with a given network
g = gt.collection.data["dolphins"]
ss = []
for i in range(100):
si_state = gt.IsingGlauberState(g, beta=.7)
s = [si_state.get_state().copy()]
for j in range(10):
si_state.iterate_sync()
s.append(si_state.get_state().copy())
# Each time series should be represented as a single vector-valued
# vertex property map with the states for each note at each time.
s = gt.group_vector_property(s)
ss.append(s)
# Prepare the initial state of the reconstruction as an empty graph
u = g.copy()
u.clear_edges()
ss = [u.own_property(s) for s in ss] # time series properties need to be 'owned' by graph u
# Create reconstruction state
rstate = gt.IsingGlauberBlockState(u, s=ss, beta=.7,
nested=False, aE=g.num_edges())
# Now we collect the marginals for exactly 10000 sweeps, at
# intervals of 10 sweeps:
gm = None
bs = []
betas = []
def collect_marginals(s):
global gm, bs
gm = s.collect_marginal(gm)
bs.append(s.bstate.b.a.copy())
betas.append(s.params["beta"])
gt.mcmc_equilibrate(rstate, force_niter=1000, mcmc_args=dict(niter=10, xstep=0),
callback=collect_marginals)
```
results in an error:
`AttributeError: module 'graph_tool.inference.libgraph_tool_inference' has no attribute 'mcmc_ising_glauber_sweep_h'`
The stack trace:
```
File "/lib/python3.10/site-packages/graph_tool/inference/mcmc.py", line 123, in mcmc_equilibrate
delta, nattempts, nmoves = state.multiflip_mcmc_sweep(**mcmc_args)
File "/lib/python3.10/site-packages/graph_tool/inference/uncertain_blockmodel.py", line 216, in multiflip_mcmc_sweep
return self.mcmc_sweep(multiflip=True, **kwargs)
File "/lib/python3.10/site-packages/graph_tool/inference/uncertain_blockmodel.py", line 1320, in mcmc_sweep
return super().mcmc_sweep(r=r, p=p, pstep=p, h=h, hstep=hstep,
File "/python3.10/site-packages/graph_tool/inference/base_states.py", line 78, in wrapper
ret = func(self, *args, **kwargs)
File "/lib/python3.10/site-packages/graph_tool/inference/uncertain_blockmodel.py", line 208, in mcmc_sweep
return self._algo_sweep(lambda s, **kw: s.multiflip_mcmc_sweep(**kw),
File "/lib/python3.10/site-packages/graph_tool/inference/uncertain_blockmodel.py", line 1333, in _algo_sweep
return self._mcmc_sweep_h(mcmc_state)
File "/lib/python3.10/site-packages/graph_tool/inference/uncertain_blockmodel.py", line 1367, in _mcmc_sweep_h
return libinference.mcmc_ising_glauber_sweep_h(mcmc_state, self._state,
```
This doesn't happen with the equilibrium Ising model classes (substituting in `PseudoIsingBlockState` works fine), . Indeed it seems, by looking at the source code for the C++ side of the library, that the dynamic models do not have those functions implemented (my c++ is rusty tho), however the equilibrium ones have (for example `graph_blockmodel_dynamics_pseudo_cising_mcmc_h.cc`). Also those functions [are explicitly called from the python code](https://git.skewed.de/count0/graph-tool/-/blob/master/src/graph_tool/inference/uncertain_blockmodel.py#L1387), so it seems they should be existing.
Am i misusing the `IsingGlauberBlockState` model or is this an issue with graph-tool?https://git.skewed.de/count0/graph-tool/-/issues/756Error installing bullseye version of graph tool lib in Docker2023-04-21T18:54:15ZGlebError installing bullseye version of graph tool lib in DockerWe are trying to install this library in our docker image, however we are getting this error:
```
=> [ 2/20] RUN echo "deb [ arch=amd64 ] https://downloads.skewed.de/apt bullseye main" >> /etc/apt/sources.list ...We are trying to install this library in our docker image, however we are getting this error:
```
=> [ 2/20] RUN echo "deb [ arch=amd64 ] https://downloads.skewed.de/apt bullseye main" >> /etc/apt/sources.list 1.5s
=> [ 3/20] RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-key 612DEFB798507F25 1.9s
=> ERROR [ 4/20] RUN apt-get update 3.2s
------
> [ 4/20] RUN apt-get update:
#7 0.487 Get:1 http://security.debian.org/debian-security bullseye-security InRelease [48.4 kB]
#7 0.583 Get:2 http://deb.debian.org/debian bullseye InRelease [116 kB]
#7 0.675 Get:3 http://deb.debian.org/debian bullseye-updates InRelease [44.1 kB]
#7 0.699 Get:4 http://security.debian.org/debian-security bullseye-security/main amd64 Packages [237 kB]
#7 0.873 Get:5 http://deb.debian.org/debian bullseye/main amd64 Packages [8183 kB]
#7 1.353 Get:6 http://deb.debian.org/debian bullseye-updates/main amd64 Packages [14.6 kB]
#7 1.476 Ign:7 https://downloads.skewed.de/apt bullseye InRelease
#7 1.630 Err:8 https://downloads.skewed.de/apt bullseye Release
#7 1.630 404 Not Found [IP: 49.12.93.194 443]
#7 2.475 Reading package lists...
#7 3.169 E: The repository 'https://downloads.skewed.de/apt bullseye Release' does not have a Release file.
------
executor failed running [/bin/sh -c apt-get update]: exit code: 100
```
This is the relevant bit from our Dockerfile:
```
# A dockerfile for running the kgtk-browser
# python 3.9.7 is a KGTK 1.1.0 requirement
# this comes with a debian version 11 (bullseye)
FROM python:3.9.7
# Add graph-tool repository to the list of known apt sources
RUN echo "deb [ arch=amd64 ] https://downloads.skewed.de/apt bullseye main" >> /etc/apt/sources.list
# Fetch the public key in order to verify graph-tool
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-key 612DEFB798507F25
# update the registry
RUN apt-get update
# install graph-tool library for kgtk
RUN apt-get install python3-graph-tool -y
```
This directory seems to be empty as of today (2023-04-21):
[https://downloads.skewed.de/apt/dists/bullseye/](https://downloads.skewed.de/apt/dists/bullseye/)https://git.skewed.de/count0/graph-tool/-/issues/755empty `Graph` evaluates to True2023-03-21T16:37:25ZPaul Brodersenempty `Graph` evaluates to True# Bug reports:
## Please follow the general troubleshooting steps first:
- [ ] Are you running the latest `graph-tool` version? -- Nearly
- [ ] Do you observe the problem with the current git version? -- Presumably
- [ ] Are you using ...# Bug reports:
## Please follow the general troubleshooting steps first:
- [ ] Are you running the latest `graph-tool` version? -- Nearly
- [ ] Do you observe the problem with the current git version? -- Presumably
- [ ] Are you using Macports or Homebrew? If yes, please submit an issue there instead: https://github.com/Homebrew/brew/issues and https://trac.macports.org/newticket -- No
- [ ] Did you compile `graph-tool` manually? -- No
- [ ] If you answered yes above, did you use the exact same compiler to build `graph-tool`, `boost-python` and `Python`?
Please replace this section with a brief summary of your issue.
## Do **not** forget to supply the following information:
- [ ] **A _minimal_ and _self-contained_ example that shows the problem.**
- [ ] Your operating system.
- [ ] The Python version you are using.
graph-tool version 2.44, python 3.9.12, Ubuntu 18.04
In graph-tool, an empty `Graph` instance evaluates to True:
```
from graph_tool import Graph
bool(Graph())
# True
```
This is in contrast to python convention:
```
bool(list())
# False
bool(tuple())
# False
bool(dict())
# False
```
Notably, other network analysis libraries adhere to this convention:
```
from networkx import Graph
bool(Graph())
# False
from igraph import Graph
bool(Graph())
# False
```
I am the author of [netgraph](https://github.com/paulbrodersen/netgraph), a graph drawing library that supports various network analysis libraries, and it would make my life easier if I didn't have to check if the data object is a graph-tool `Graph` each time I defend against empty graphs.https://git.skewed.de/count0/graph-tool/-/issues/754Possible regression: add_edge_list() no longer accepts vertex objects?2023-03-16T16:48:05ZAle AbdoPossible regression: add_edge_list() no longer accepts vertex objects?With graph-tool-2.46 tested in Guix and Debian.
Example:
```python
import graph_tool.all as gt
g = gt.Graph()
v0 = g.add_vertex()
v1 = g.add_vertex()
g.add_edge_list([[v0, v1]])
---------------------------------------------------------...With graph-tool-2.46 tested in Guix and Debian.
Example:
```python
import graph_tool.all as gt
g = gt.Graph()
v0 = g.add_vertex()
v1 = g.add_vertex()
g.add_edge_list([[v0, v1]])
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[41], line 1
----> 1 g.add_edge_list([[v0, v1]])
File ~/.guix-profile/lib/python3.9/site-packages/graph_tool/__init__.py:2603, in Graph.add_edge_list(self, edge_list, hashed, hash_type, eprops)
2601 libcore.add_edge_list(self.__graph, edge_list, eprops)
2602 else:
-> 2603 libcore.add_edge_list_iter(self.__graph, edge_list, eprops)
2604 else:
2605 if isinstance(edge_list, numpy.ndarray):
TypeError: No registered converter was able to produce a C++ rvalue of type double from this Python object of type Vertex
```
Workaround:
```
g.add_edge_list([[int(v0), int(v1)]])
```https://git.skewed.de/count0/graph-tool/-/issues/752Graph edges getting corrupted after vertex deletion2023-03-09T15:42:50ZLuca Pion-TonachiniGraph edges getting corrupted after vertex deletion# Bug reports:
## Please follow the general troubleshooting steps first:
- [x] Are you running the latest `graph-tool` version?
- Yes as I don't see any newer commits that seem relevant so I'm staying with 2.46
I've found that aft...# Bug reports:
## Please follow the general troubleshooting steps first:
- [x] Are you running the latest `graph-tool` version?
- Yes as I don't see any newer commits that seem relevant so I'm staying with 2.46
I've found that after some edge manipulation, namely removal, I'm left with a graph that is likely corrupted. At times it will segfault when I call `graph.edges()` but I've got it down to a _relatively_ minimal example below which starts with a "random" graph and after some alterations ends up with an invalid edge.
```python
import pprint
import graph_tool.all as gt
import numpy as np
# set random seed for repeatability
rng = np.random.default_rng(0)
# build "random" graph with edge distances
num_vertices = 10
graph = gt.random_graph(num_vertices, lambda: rng.integers(2, 5), False, random=False)
graph.edge_properties.dist = graph.new_edge_property(
"double", rng.exponential(size=graph.num_edges())
)
last_node = graph.vertex(num_vertices - 1)
print("Initial edges")
pprint.pprint(list(graph.edges()))
# disconnect last node
for edge in last_node.all_edges():
graph.remove_edge(edge)
print("Edges after deleting all connections to final node")
pprint.pprint(list(graph.edges()))
# shortcut all nodes to last node
for vertex in graph.get_vertices():
edge = graph.add_edge(vertex, last_node)
graph.edge_properties.dist[edge] = 0
print("Edges after adding an edge from final node to all other nodes")
pprint.pprint(list(graph.edges()))
# delete last node
graph.remove_vertex(last_node)
print("Edges after deleting last three node")
pprint.pprint(list(graph.edges()))
```
which results in the following output
```
Initial edges
[<Edge object with source '0' and target '9' at 0x7f70d40d5940>,
<Edge object with source '0' and target '1' at 0x7f70d40d59d0>,
<Edge object with source '0' and target '2' at 0x7f70d40d5a60>,
<Edge object with source '0' and target '3' at 0x7f70d40d5af0>,
<Edge object with source '2' and target '8' at 0x7f70d40d5b80>,
<Edge object with source '4' and target '3' at 0x7f70d40d5c10>,
<Edge object with source '4' and target '5' at 0x7f70d40d5ca0>,
<Edge object with source '6' and target '1' at 0x7f70d40d5d30>,
<Edge object with source '7' and target '6' at 0x7f70d40d5dc0>,
<Edge object with source '7' and target '5' at 0x7f70d40d5e50>,
<Edge object with source '9' and target '8' at 0x7f70d40d5ee0>,
<Edge object with source '9' and target '2' at 0x7f70d40d5f70>,
<Edge object with source '9' and target '1' at 0x7f70d4059040>]
Edges after deleting all connections to final node
[<Edge object with source '0' and target '1' at 0x7f70d40d5940>,
<Edge object with source '0' and target '2' at 0x7f70d40d59d0>,
<Edge object with source '2' and target '8' at 0x7f70d40d5af0>,
<Edge object with source '4' and target '3' at 0x7f70d40d5b80>,
<Edge object with source '4' and target '5' at 0x7f70d40d5c10>,
<Edge object with source '6' and target '1' at 0x7f70d40d5ca0>,
<Edge object with source '7' and target '6' at 0x7f70d40d5d30>,
<Edge object with source '7' and target '5' at 0x7f70d40d5dc0>,
<Edge object with source '9' and target '2' at 0x7f70d40d5e50>]
Edges after adding an edge from final node to all other nodes
[<Edge object with source '0' and target '1' at 0x7f70d40d5940>,
<Edge object with source '0' and target '2' at 0x7f70d40d59d0>,
<Edge object with source '0' and target '9' at 0x7f70d40d5af0>,
<Edge object with source '1' and target '9' at 0x7f70d40d5b80>,
<Edge object with source '2' and target '8' at 0x7f70d40d5c10>,
<Edge object with source '2' and target '9' at 0x7f70d40d5ca0>,
<Edge object with source '3' and target '9' at 0x7f70d40d5d30>,
<Edge object with source '4' and target '3' at 0x7f70d40d5dc0>,
<Edge object with source '4' and target '5' at 0x7f70d40d5e50>,
<Edge object with source '4' and target '9' at 0x7f70d40d5ee0>,
<Edge object with source '5' and target '9' at 0x7f70d40d5f70>,
<Edge object with source '6' and target '1' at 0x7f70d405a040>,
<Edge object with source '6' and target '9' at 0x7f70d405a0d0>,
<Edge object with source '7' and target '6' at 0x7f70d405a160>,
<Edge object with source '7' and target '5' at 0x7f70d405a1f0>,
<Edge object with source '7' and target '9' at 0x7f70d405a280>,
<Edge object with source '8' and target '9' at 0x7f70d405a310>,
<Edge object with source '9' and target '0' at 0x7f70d405a3a0>,
<Edge object with source '9' and target '9' at 0x7f70d405a430>]
Edges after deleting last three node
[<Edge object with source '0' and target '1' at 0x7f70d40d5940>,
<Edge object with source '0' and target '2' at 0x7f70d40d59d0>,
<invalid Edge object at 0x7f70d40d5af0>,
<Edge object with source '2' and target '8' at 0x7f70d40d5b80>,
<Edge object with source '4' and target '3' at 0x7f70d40d5c10>,
<Edge object with source '4' and target '5' at 0x7f70d40d5ca0>,
<Edge object with source '6' and target '1' at 0x7f70d40d5d30>,
<Edge object with source '7' and target '6' at 0x7f70d40d5dc0>,
<Edge object with source '7' and target '5' at 0x7f70d40d5e50>]
Process finished with exit code 0
```
Note the third edge is invalid after all this.
This is running in a docker container with Ubuntu 20.04, python 3.8.10, graph-tool '2.46 (commit ab460df4, Sun Feb 26 16:33:33 2023 +0100)' (from apt).
As an aside, when I import graph-tool I get the following despite having installed `graphviz`, `libcairo2-dev`, and `python-cairo` through `apt`. I don't think it's relevant, but I figure it's worth mentioning in case I'm wrong.
```
/usr/lib/python3/dist-packages/graph_tool/draw/cairo_draw.py:32: RuntimeWarning: Error importing cairo. Graph drawing will not work.
warnings.warn(msg, RuntimeWarning)
/usr/lib/python3/dist-packages/graph_tool/draw/cairo_draw.py:32: RuntimeWarning: Error importing cairo. Graph drawing will not work.
warnings.warn(msg, RuntimeWarning)
/usr/lib/python3/dist-packages/graph_tool/draw/cairo_draw.py:32: RuntimeWarning: Error importing cairo. Graph drawing will not work.
warnings.warn(msg, RuntimeWarning)
/usr/lib/python3/dist-packages/graph_tool/all.py:39: RuntimeWarning: Error importing draw module, proceeding nevertheless: No module named 'cairo'
warnings.warn(msg, RuntimeWarning)
```https://git.skewed.de/count0/graph-tool/-/issues/751Support matplotlib 3.7+2023-03-04T10:13:33ZSilmathoronSupport matplotlib 3.7+In matplotlib 3.7, [ArtistList](https://matplotlib.org/stable/api/axes_api.html#matplotlib.axes.Axes.ArtistList) became immutable, so in graph-tool 2.4.6, ``graph_draw`` is failing as it tries to append to the list.
The following code w...In matplotlib 3.7, [ArtistList](https://matplotlib.org/stable/api/axes_api.html#matplotlib.axes.Axes.ArtistList) became immutable, so in graph-tool 2.4.6, ``graph_draw`` is failing as it tries to append to the list.
The following code works for matplotlib < 3.7 and fails for 3.7:
```python
import graph_tool.all as gt
import matplotlib.pyplot as plt
plt.switch_backend("cairo")
fig, ax = plt.subplots()
g = gt.collection.data["polbooks"]
gt.graph_draw(g, mplfig=ax)
```https://git.skewed.de/count0/graph-tool/-/issues/750Problem in your colab demo2023-02-12T22:48:17ZAndrea VandinProblem in your colab demoThere are problems in installing graph-tool
By running your own Google colab notebook (https://colab.research.google.com/github/count0/colab-gt/blob/master/colab-gt.ipynb), we get this error:
ModuleNotFoundError T...There are problems in installing graph-tool
By running your own Google colab notebook (https://colab.research.google.com/github/count0/colab-gt/blob/master/colab-gt.ipynb), we get this error:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-5-43d339c0c874> in <module>
----> 1 from graph_tool.all import *
2
3 g = collection.data["celegansneural"]
4 state = minimize_nested_blockmodel_dl(g)
ModuleNotFoundError: No module named 'graph_tool'https://git.skewed.de/count0/graph-tool/-/issues/748NestedBlockState.mcmc_sweep can segfault if vertices are specified.2023-02-19T17:16:58ZJames VaughanNestedBlockState.mcmc_sweep can segfault if vertices are specified.SEGFAULT may occur if vertices are specified when using the `mcmc_sweep` method of a NestedBlockState. Example script is provided below, which appears to reliably reproduce the issue on two separate machines and python versions.
Environ...SEGFAULT may occur if vertices are specified when using the `mcmc_sweep` method of a NestedBlockState. Example script is provided below, which appears to reliably reproduce the issue on two separate machines and python versions.
Environment:
- Ubuntu 20.04.4 LTS (64-bit)
- graphtool v2.45, (conda)
- python 3.8.13 and 3.10.5
Example test.py:
```
G = gt.Graph()
v1, v2, v3, v4 = G.add_vertex(4)
G.add_edge(v1, v2)
G.add_edge(v1, v3)
G.add_edge(v2, v3)
G.add_edge(v2, v4)
G.add_edge(v3, v4)
state = gt.minimize_nested_blockmodel_dl(G)
state.mcmc_sweep(vertices = [v2]) # SEGFAULT
# state.mcmc_sweep(vertices = [v1, v3, v4]) # Does not crash
```https://git.skewed.de/count0/graph-tool/-/issues/747BlockState: entropy is `nan` when pclabel is not contiguous or not starting f...2023-02-19T18:56:56ZAle AbdoBlockState: entropy is `nan` when pclabel is not contiguous or not starting from zeroExample:
```python
import graph_tool.all as gt
import numpy as np
g = gt.collection.data["celegansneural"]
N = g.num_vertices()
pclabel_0_2 = np.array([2 * int(i > N / 2) for i in range(N)]) # 0s and 2s
pclabel_1_2 = np.array([1 + in...Example:
```python
import graph_tool.all as gt
import numpy as np
g = gt.collection.data["celegansneural"]
N = g.num_vertices()
pclabel_0_2 = np.array([2 * int(i > N / 2) for i in range(N)]) # 0s and 2s
pclabel_1_2 = np.array([1 + int(i > N / 2) for i in range(N)]) # 1s and 2s
for pclabel in [pclabel_0_2, pclabel_1_2]:
# Case of blockstate constructed with BlockState
b = np.array([int(i > N / 2) for i in range(N)])
bstate = gt.BlockState(g, b, pclabel=pclabel)
assert np.isnan(bstate.entropy())
# Case of blockstate returned by minimize_blockmodel_dl()
bstate = gt.minimize_blockmodel_dl(g, state_args={"pclabel": pclabel})
assert np.isnan(bstate.entropy())
```https://git.skewed.de/count0/graph-tool/-/issues/746multiflip_mcmc_sweep() with pclabel reaches `nan` entropy at top state2023-02-19T18:57:27ZAle Abdomultiflip_mcmc_sweep() with pclabel reaches `nan` entropy at top stateA minimal example:
```python
import graph_tool.all as gt
import numpy as np
g = gt.collection.data["celegansneural"]
N = g.num_vertices()
pclabel = np.array([int(i > N / 2) for i in range(N)])
nbstate = gt.minimize_nested_blockmodel_d...A minimal example:
```python
import graph_tool.all as gt
import numpy as np
g = gt.collection.data["celegansneural"]
N = g.num_vertices()
pclabel = np.array([int(i > N / 2) for i in range(N)])
nbstate = gt.minimize_nested_blockmodel_dl(g, state_args={"pclabel": pclabel})
while not np.isnan(nbstate.entropy()):
nbstate.multiflip_mcmc_sweep(beta=np.inf, niter=10)
level_entropies = {i: nbstate.level_entropy(i) for i in range(len(nbstate.levels))}
print(level_entropies)
```https://git.skewed.de/count0/graph-tool/-/issues/745gt.collection.data: __contains__ returns False until __getitem__2023-02-19T18:24:29ZAle Abdogt.collection.data: __contains__ returns False until __getitem__Example:
```
Python 3.9.9 (main, Jan 1 1970, 00:00:01)
[GCC 10.3.0] on linux
>>> import graph_tool.all as gt
>>> gt.__version__
'2.45 (commit cc4b7c3a, Sun May 22 23:48:12 2022 +0200)'
>>> 'karate' in gt.collection.data
False
>>> _ =...Example:
```
Python 3.9.9 (main, Jan 1 1970, 00:00:01)
[GCC 10.3.0] on linux
>>> import graph_tool.all as gt
>>> gt.__version__
'2.45 (commit cc4b7c3a, Sun May 22 23:48:12 2022 +0200)'
>>> 'karate' in gt.collection.data
False
>>> _ = gt.collection.data['karate']
>>> 'karate' in gt.collection.data
True
>>> 'celegansneural' in gt.collection.data
False
>>> _ = gt.collection.data['celegansneural']
>>> 'celegansneural' in gt.collection.data
True
>>>
```
More generally, `data` actually acts as an empty dict:
```
>>> for name in gt.collection.data:
... print(name)
...
>>> _ = gt.collection.data['karate']
>>> for name in gt.collection.data:
... print(name)
...
karate
>>>
```https://git.skewed.de/count0/graph-tool/-/issues/744Bug with all_shortest_paths() when edges = True all parallel edges have diffe...2023-02-19T19:34:15ZTermeh FaghaniBug with all_shortest_paths() when edges = True all parallel edges have different weightsHello,
I think the function all_shortest_paths is not returning the correct answer when the input parameter edges = True . I created 3 edges between 2 nodes. These edges have different attributes. 2 of them have the weight set to 200 an...Hello,
I think the function all_shortest_paths is not returning the correct answer when the input parameter edges = True . I created 3 edges between 2 nodes. These edges have different attributes. 2 of them have the weight set to 200 and one of the edges weight is 100. As the diagram below shows. However, graph tool return an edge object but the attribute for edge object are not correct. You can see the example in python below.
all_shortest_paths
![all_shortest_paths](/uploads/1d546ce547798d4544337a501e8ecaa4/all_shortest_paths.png)
```
g = gt.Graph()
edge_weight = g.new_edge_property("double")
g.edge_properties["weight"] = edge_weight
edges = [[0,1],[0,1],[0,1]]
weights = [200,200,100]
for i in range(len(edges)):
e = g.add_edge(edges[i][0], edges[i][1])
g.ep.weight[e] = weights[i]
for path in gt.all_shortest_paths(g, 0, 1, weights=g.ep.weight, edges = True):
print(path)
for edge in path:
print(edge,g.ep.weight[edge])
```
It will return:
[<Edge object with source '0' and target '1' at 0x1769584c0>]
(0, 1) 200.0
Which is wrong. I was expecting to see the edge with the weight 100. The good news is that it identifies the shortest path is one edge (not three) but it is not returning it right.https://git.skewed.de/count0/graph-tool/-/issues/743Importing graph_tool.all breaks if Gtk isn't available but GObject is2023-02-19T19:01:39ZAle AbdoImporting graph_tool.all breaks if Gtk isn't available but GObject isThe error:
```python
> import graph_tool.all as gt
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Input In [2], in <cell line: 1>()...The error:
```python
> import graph_tool.all as gt
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Input In [2], in <cell line: 1>()
----> 1 import graph_tool.all as gt
File /gnu/store/dkw4m4ygvh9fkw8jp5wzj2bkb9dhb01d-profile/lib/python3.9/site-packages/graph_tool/all.py:34, in <module>
32 import graph_tool.centrality
33 try:
---> 34 from graph_tool.draw import *
35 import graph_tool.draw
36 except ImportError as e:
37 # Proceed despite errors with cairo, matplotlib, etc.
File /gnu/store/dkw4m4ygvh9fkw8jp5wzj2bkb9dhb01d-profile/lib/python3.9/site-packages/graph_tool/draw/__init__.py:848, in <module>
845 return prop
847 try:
--> 848 from . cairo_draw import graph_draw, cairo_draw, \
849 get_hierarchy_control_points, default_cm, default_clrs, draw_hierarchy
850 __all__ += ["draw_hierarchy"]
851 except ImportError:
File /gnu/store/dkw4m4ygvh9fkw8jp5wzj2bkb9dhb01d-profile/lib/python3.9/site-packages/graph_tool/draw/cairo_draw.py:1494, in <module>
1492 try:
1493 import gi
-> 1494 gi.require_version('Gtk', '3.0')
1495 from gi.repository import Gtk, Gdk, GdkPixbuf
1496 from gi.repository import GObject as gobject
File /gnu/store/da3ki5vd9shsdrpabw022rkf8v4bpkza-python-pygobject-3.40.1/lib/python3.9/site-packages/gi/__init__.py:126, in require_version(namespace, version)
124 available_versions = repository.enumerate_versions(namespace)
125 if not available_versions:
--> 126 raise ValueError('Namespace %s not available' % namespace)
128 if version not in available_versions:
129 raise ValueError('Namespace %s not available for version %s' %
130 (namespace, version))
ValueError: Namespace Gtk not available
```
A simple fix would be to change `cairo_draw.py:1498` to:
```python
except (ImportError, RuntimeError, ValueError) as e:
```