Ask Your Question
1

An error occurred while reading a graph in Plantri format.

asked 2025-05-07 15:58:32 +0200

licheng gravatar image

I need to read some planar graphs from this website, but when I try to use read_planar in SageMath, it doesn't work when using 5reg_20-32.pc (Plane 5-regular simple connected graphs with order 20). It seems something is missing.

file = open("5reg_20-32.pc")
s=graphs._read_planar_code(file)
l=[]
for line in s:
       l.append(line)

It gives:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/tmp/ipykernel_6268/2127516145.py in ?()
      1 file = open("5reg_20-32.pc")
      2 s=graphs._read_planar_code(file)
      3 l=[]
----> 4 for line in s:
      5        l.append(line)

/usr/lib/python3.13/site-packages/sage/graphs/graph_generators.py in ?(self, code_input, immutable)
   1582             G = graph.Graph(edges_g, loops=has_loops, immutable=immutable)
   1583 
   1584             if not (G.has_multiple_edges() or has_loops):
   1585                 embed_g = {i + 1: di for i, di in enumerate(g)}
-> 1586                 G.set_embedding(embed_g)
   1587             yield G

/usr/lib/python3.13/site-packages/sage/graphs/generic_graph.py in ?(self, embedding)
   3228             ...
   3229             ValueError: This method is not known to work on graphs with multiedges. Perhaps this method can be updated to handle them, but in the meantime if you want to use it please disallow multiedges using allow_multiple_edges().
   3230         """
   3231         self._scream_if_not_simple()
-> 3232         self._check_embedding_validity(embedding, boolean=False)
   3233         self._embedding = embedding

/usr/lib/python3.13/site-packages/sage/graphs/generic_graph.py in ?(self, embedding, boolean)
   3394             for u in embedding[v]:
   3395                 if not connected(v, u):
   3396                     if boolean:
   3397                         return False
-> 3398                     raise ValueError("{} and {} are not neighbors but {} is in "
   3399                                      "the list associated with {}".format(u, v, u, v))
   3400         return True

ValueError: 10 and 6 are not neighbors but 10 is in the list associated with 6
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2025-05-07 19:32:54 +0200

Max Alekseyev gravatar image

updated 2025-05-07 19:54:46 +0200

There are 2 issues here. First, Plantri format is binary and so you should have opened the file in binary mode as open("5reg_20-32.pc", "rb"). However, this won't be sufficient as Sage in this line checks the header as header == '>>planar_code<<', while it should have checked header == b'>>planar_code<<'. If you feel comfortable changing the Sage code, this single addition of letter b should fix things up.

Deep down the error is caused by incorrect treatment of hex code 0A in text file. So, the bug potentially affect any graph with 10 or more vertices.

PS. I've reported the issue at https://github.com/sagemath/sage/issu...

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2025-05-07 15:58:32 +0200

Seen: 170 times

Last updated: May 07