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)

attachment.html (3.12 KB)

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 {}

attachment.html (4.01 KB)

graphbug.py (689 Bytes)

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

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

attachment.html (1.36 KB)

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

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

attachment.html (2.76 KB)