Unexpected property map to/from gml behaviour
In the following, I noticed the data type of the property map changes. Any ideas what is going on?
graph_tool.all.__version__ '2.2.31 (commit 245d1e2c, Thu Mar 27 11:28:39 2014 +0100)
# having already built my graph
graph.ep
{'weight': <PropertyMap object with key type 'Edge' and value type 'int32_t', for Graph 0x7f93019b8b90, at 0x7f930058c850>}
graph.ep['weight'].a PropertyArray([28, 18, 32, ..., 7, 8, 8], dtype=int32)
graph.save(graph_file_name)
graph2 = Graph()
graph2.load(graph_file_name)
graph2.ep {'weight': <PropertyMap object with key type 'Edge' and value type 'double', for Graph 0x7f93001b7b10, at 0x7f92fc00b190>}
graph2.ep['weight'].a PropertyArray([ 28., 3., 18., ..., 11., 6., 55.])
Then it gets weirder...
graph.ep['ONE_WAY'] = graph.new_edge_property('string')
for edge in graph.edges(): ... graph.ep['ONE_WAY'][edge] = 'TEST!'
graph.ep
{'ONE_WAY': <PropertyMap object with key type 'Edge' and value type 'string', for Graph 0x7f93019b8b90, at 0x7f9327c0dc10>, 'weight': <PropertyMap object with key type 'Edge' and value type 'int32_t', for Graph 0x7f93019b8b90, at 0x7f930058c850>}
graph.ep['ONE_WAY'][edge] 'TEST!'
graph.save(graph_file_name)
graph2 = Graph()
graph2.load(graph_file_name)
graph2.ep {}
graph.num_edges(),graph.num_vertices() (78147, 29870)
graph2.num_edges(),graph2.num_vertices() (1, 29870)
Here is code that reproduces the issue for me. I ran this from ipython in a virtual env. output: In [2]: run graphbug.py 27000 27000 {'test_str': <PropertyMap object with key type 'Edge' and value type 'string', for Graph 0x7f76db44b5d0, at 0x7f76db44b290>, 'test_int': <PropertyMap object with key type 'Edge' and value type 'int32_t', for Graph 0x7f76db44b5d0, at 0x7f76db44b550>} 27000 1 {} On Thu, Jul 17, 2014 at 6:31 PM, ... <offonoffoffonoff@gmail.com> wrote:
In the following, I noticed the data type of the property map changes. Any ideas what is going on?
graph_tool.all.__version__ '2.2.31 (commit 245d1e2c, Thu Mar 27 11:28:39 2014 +0100)
# having already built my graph
graph.ep
{'weight': <PropertyMap object with key type 'Edge' and value type 'int32_t', for Graph 0x7f93019b8b90, at 0x7f930058c850>}
graph.ep['weight'].a PropertyArray([28, 18, 32, ..., 7, 8, 8], dtype=int32)
graph.save(graph_file_name)
graph2 = Graph()
graph2.load(graph_file_name)
graph2.ep {'weight': <PropertyMap object with key type 'Edge' and value type 'double', for Graph 0x7f93001b7b10, at 0x7f92fc00b190>}
graph2.ep['weight'].a PropertyArray([ 28., 3., 18., ..., 11., 6., 55.])
Then it gets weirder...
graph.ep['ONE_WAY'] = graph.new_edge_property('string')
for edge in graph.edges(): ... graph.ep['ONE_WAY'][edge] = 'TEST!'
graph.ep
{'ONE_WAY': <PropertyMap object with key type 'Edge' and value type 'string', for Graph 0x7f93019b8b90, at 0x7f9327c0dc10>, 'weight': <PropertyMap object with key type 'Edge' and value type 'int32_t', for Graph 0x7f93019b8b90, at 0x7f930058c850>}
graph.ep['ONE_WAY'][edge] 'TEST!'
graph.save(graph_file_name)
graph2 = Graph()
graph2.load(graph_file_name)
graph2.ep {}
graph.num_edges(),graph.num_vertices() (78147, 29870)
graph2.num_edges(),graph2.num_vertices() (1, 29870)
On 07/18/2014 01:31 AM, ... wrote:
In the following, I noticed the data type of the property map changes. Any ideas what is going on?
Yes, if you use the gml format there is no way to fully preserve the property map types since the format does not allow it. If you want to perfectly preserve your properties you should use the graphml format. Best, Tiago -- Tiago de Paula Peixoto <tiago@skewed.de>
How does one save a graph as graphml? Graph.save makes no mention of it, and changing the file extension to graphml causes a ValueError: cannot determine file format. I didn't see anything elsewhere in the docs. Elliot On Jul 18, 2014 9:03 AM, "Tiago de Paula Peixoto" <tiago@skewed.de> wrote:
On 07/18/2014 01:31 AM, ... wrote:
In the following, I noticed the data type of the property map changes. Any ideas what is going on?
Yes, if you use the gml format there is no way to fully preserve the property map types since the format does not allow it. If you want to perfectly preserve your properties you should use the graphml format.
Best, Tiago
-- Tiago de Paula Peixoto <tiago@skewed.de>
_______________________________________________ graph-tool mailing list graph-tool@skewed.de http://lists.skewed.de/mailman/listinfo/graph-tool
On 07/18/2014 06:50 PM, ... wrote:
How does one save a graph as graphml? Graph.save makes no mention of it, and changing the file extension to graphml causes a ValueError: cannot determine file format.
The extension name is "xml".
I didn't see anything elsewhere in the docs.
See http://graph-tool.skewed.de/static/doc/quickstart.html#graph-i-o and http://graph-tool.skewed.de/static/doc/graph_tool.html#graph_tool.Graph.save Best, Tiago -- Tiago de Paula Peixoto <tiago@skewed.de>
Thanks. I was clear from the documentation (and from stackoverflow, etc.) that graphml was the format I needed. However, Graph.save doesn't mention graphml. I see now that there is enough information on those two pages to deduce that graphml== xml (that is, both pages mention "dot" and "gml" and so one might be able to assume that the third terms, which are different in each, are meant to be the same). However, I think it would be helpful to clarify that in the Graph.save docstring. For example, change the doc string to: Save graph to ``file_name`` (which can be either a string or a file-like object). The format is guessed from the ``file_name``, or can be specified by ``fmt``, which can be either "xml", "dot" or "gml". Only "xml", also called graphml, preserves all information in the graph. Graph.load might be changed similarly. But if you don't get many people on the list confused about it, maybe it isn't worth it. Just my 2 cents. Thanks again for the great package and your hard work! -Elliot On Jul 18, 2014 12:03 PM, "Tiago de Paula Peixoto" <tiago@skewed.de> wrote:
On 07/18/2014 06:50 PM, ... wrote:
How does one save a graph as graphml? Graph.save makes no mention of it, and changing the file extension to graphml causes a ValueError: cannot determine file format.
The extension name is "xml".
I didn't see anything elsewhere in the docs.
See
http://graph-tool.skewed.de/static/doc/quickstart.html#graph-i-o
and
http://graph-tool.skewed.de/static/doc/graph_tool.html#graph_tool.Graph.save
Best, Tiago
-- Tiago de Paula Peixoto <tiago@skewed.de>
_______________________________________________ graph-tool mailing list graph-tool@skewed.de http://lists.skewed.de/mailman/listinfo/graph-tool
participants (2)
-
... -
Tiago de Paula Peixoto