Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyError raised by GraphLatex.dot2tex_picture when edge_labels=True #13624

Closed
seblabbe opened this issue Oct 19, 2012 · 54 comments
Closed

KeyError raised by GraphLatex.dot2tex_picture when edge_labels=True #13624

seblabbe opened this issue Oct 19, 2012 · 54 comments

Comments

@seblabbe
Copy link
Contributor

The following is ok :

sage: G = DiGraph()
sage: G.add_edge(3333, 88, 'my_label')
sage: G.set_latex_options(format='dot2tex')
sage: view(G)

but with edges_labels=True a KeyError is raised :

sage: G.set_latex_options(edge_labels=True)
sage: view(G)
ERROR    Failed to process input
Traceback (most recent call last):
  File "/Users/slabbe/Applications/sage-5.2/local/lib/python2.7/site-packages/dot2tex/dot2tex.py", line 2939, in main
    s =  conv.convert(dotdata)
  File "/Users/slabbe/Applications/sage-5.2/local/lib/python2.7/site-packages/dot2tex/dot2tex.py", line 794, in convert
    return self.do_preview_preproc()
  File "/Users/slabbe/Applications/sage-5.2/local/lib/python2.7/site-packages/dot2tex/dot2tex.py", line 1167, in do_preview_preproc
    hp,dp,wt = pp.texdims[name]
KeyError: '3333880'

The error is also raised by dot2tex_picture method:

sage: G = DiGraph()
sage: G.add_edge(0, 1, 'p0')
sage: G.latex_options().dot2tex_picture()
'\n\\begin{tikzpicture}[>=latex,line join=bevel,]\n%%\n\\node (1) at (6bp,7bp) [draw,draw=none] {$1$};\n  \\node (0) at (6bp,57bp) [draw,draw=none] {$0$};\n  \\draw [black,->] (0) ..controls (6bp,44.053bp) and (6bp,33.103bp)  .. (1);\n%\n\\end{tikzpicture}\n'
.dot2tex_picture()
sage: G.set_latex_options(edge_labels=True)
sage: G.latex_options().dot2tex_picture()
ERROR    Failed to process input
Traceback (most recent call last):
  File "/Users/slabbe/Applications/sage-5.2/local/lib/python2.7/site-packages/dot2tex/dot2tex.py", line 2939, in main
    s =  conv.convert(dotdata)
  File "/Users/slabbe/Applications/sage-5.2/local/lib/python2.7/site-packages/dot2tex/dot2tex.py", line 794, in convert
    return self.do_preview_preproc()
  File "/Users/slabbe/Applications/sage-5.2/local/lib/python2.7/site-packages/dot2tex/dot2tex.py", line 1167, in do_preview_preproc
    hp,dp,wt = pp.texdims[name]
KeyError: '010'
''

This is due to dot2tex currently not supporting '\verb' properly.

The attached patch works around this by replacing \verb by \text, and stripping out tricky characters like ^ and _.

CC: @stumpc5 @nathanncohen

Component: packages: optional

Keywords: dot2tex, graph drawing

Author: Sébastien Labbé

Branch/Commit: 2634500

Reviewer: Christian Stump

Issue created by migration from https://trac.sagemath.org/ticket/13624

@seblabbe

This comment has been minimized.

@seblabbe
Copy link
Contributor Author

comment:2

I managed to fix the bug with the following hack :

diff --git a/src/dot2tex/dot2tex.py b/src/dot2tex/dot2tex.py
--- a/src/dot2tex/dot2tex.py
+++ b/src/dot2tex/dot2tex.py
@@ -1153,6 +1153,20 @@ To see what happened, run dot2tex with t
         for name,item in usededges.items():
 
             edge = item
+            break
             hp,dp,wt = pp.texdims[name]
             xmargin, ymargin = self.get_margins(edge)
             labelcode = '<<<table border="0" cellborder="0" cellpadding="0">'\

but I still don't know what was this loop for... because the output is OK (with edge labels).

@seblabbe
Copy link
Contributor Author

comment:3

I just created an issue on the dot2tex google code project :

http://code.google.com/p/dot2tex/issues/detail?id=32

@nthiery

This comment has been minimized.

@nthiery
Copy link
Contributor

nthiery commented Mar 11, 2013

comment:5

Hi Sébastien,

I had not noticed this ticket. A quick and dirty workaround has been in the Sage-Combinat queue for some time. I did some further cleanup, but it's still nothing but a workaround. Shall we get it into Sage? If you think the patch could use more work, do you mind taking it over?

Cheers,
Nicolas

@nthiery
Copy link
Contributor

nthiery commented Mar 11, 2013

comment:6

While I was at it, I folded in a couple tests I had put in a later patch in the Sage-Combinat queue.

@nthiery

This comment has been minimized.

@nthiery
Copy link
Contributor

nthiery commented Mar 11, 2013

comment:9

The change verb -> text in sage.misc.latex was breaking quite a few doctests. I made it a separate ticket: #14256. This one should not depend on it.

On the other hand, I added three tiny things that were in a later patch in the queue:

  • shape=plain text whenever there are labels on the vertices (latex or not)
  • trim "." from keys (I guess I must have had a problem with them at some point)
  • a doctest fix.

@jdemeyer
Copy link

comment:10

Please add your name as Author.

@nthiery
Copy link
Contributor

nthiery commented Mar 13, 2013

Author: Nicolas M. Thiéry

@nthiery
Copy link
Contributor

nthiery commented Mar 13, 2013

Changed keywords from dot2tex to dot2tex, graph drawing

@nthiery
Copy link
Contributor

nthiery commented Apr 2, 2013

comment:12

Hi Nathann!

Would you have time to review this one?

Thanks!
Nicolas

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Apr 2, 2013

comment:13

This is what happens when I install graphviz

[...]
make[3]: *** No rule to make target `../../plugin/pango/libgvplugin_pango.la', needed by `dot_builtins'.  Stop.
make[3]: *** Waiting for unfinished jobs....
mv -f .deps/no_demand_loading.Tpo .deps/no_demand_loading.Po
mv -f .deps/dot_builtins.Tpo .deps/dot_builtins.Po
mv -f .deps/dot.Tpo .deps/dot.Po
make[3]: Leaving directory `/home/ncohen/.Sage/spkg/build/graphviz-2.16.1.p0/src/cmd/dot'
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/home/ncohen/.Sage/spkg/build/graphviz-2.16.1.p0/src/cmd'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/ncohen/.Sage/spkg/build/graphviz-2.16.1.p0/src'
make: *** [all] Error 2
Error building Graphviz

real	0m53.650s
user	0m45.475s
sys	0m8.313s
************************************************************************
Error installing package graphviz-2.16.1.p0
************************************************************************
Please email sage-devel (http://groups.google.com/group/sage-devel)
explaining the problem and including the relevant part of the log file
  /home/ncohen/.Sage/spkg/logs/graphviz-2.16.1.p0.log
Describe your computer, operating system, etc.
If you want to try to fix the problem yourself, *don't* just cd to
/home/ncohen/.Sage/spkg/build/graphviz-2.16.1.p0 and type 'make' or whatever is appropriate.
Instead, the following commands setup all environment variables
correctly and load a subshell for you to debug the error:
  (cd '/home/ncohen/.Sage/spkg/build/graphviz-2.16.1.p0' && '/home/ncohen/.Sage/sage' -sh)
When you are done debugging, you can type "exit" to leave the subshell.
************************************************************************

Nathann

@nthiery
Copy link
Contributor

nthiery commented Apr 2, 2013

comment:14

Hi!

Yes, the graphviz spkg is broken (and as far as I can remember has always been). But most linux distro have a graphviz package, so that's not too bad. The doc already says to install graphviz out of Sage.

We should probably remove this broken spkg from "experimental" ...

Cheers,
Nicolas

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Apr 2, 2013

comment:15

Yes, the graphviz spkg is broken (and as far as I can remember has always been). But most linux distro have a graphviz package, so that's not too bad. The doc already says to install graphviz out of Sage.

......

who the hell put that in the doc without removing the package ?...

Nathann

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Apr 2, 2013

comment:16

We should probably remove this broken spkg from "experimental" ...

Indeed. The only thing to do is update the doc to remove any mention of this graphviz package, and ask Jeroen in a ticket to remove it from experimental.

And it will be quickly reviewed, I swear.

Nathann

@nthiery
Copy link
Contributor

nthiery commented Apr 2, 2013

comment:17

Replying to @nathanncohen:

We should probably remove this broken spkg from "experimental" ...

Indeed. The only thing to do is update the doc to remove any mention of this graphviz package, and ask Jeroen in a ticket to remove it from experimental.

I was already careful not to mention the spkg in the doc (but if you see how to improve the graphviz installation instructions, please go ahead in a separate ticket; I'll review it).

As for removing the spkg, this is now: #14398.

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Apr 2, 2013

comment:18

I was already careful not to mention the spkg in the doc (but if you see how to improve the graphviz installation instructions, please go ahead in a separate ticket; I'll review it).

Is written explicitly anywhere that there is no spkg and that the users should install it by themselves ?

Nathann

@jdemeyer
Copy link

jdemeyer commented Apr 2, 2013

comment:19
# optional - requires dot2tex and graphviz

should be

# optional - dot2tex graphviz

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Apr 2, 2013

comment:20

(and while you're editing the patch, you included a http link which Sphinx does not understand as one)

Nathann

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Apr 2, 2013

comment:21

5 doctests fail on my machine. The error message do not seem to say that there is something wrong with my install (dot or graphviz which I installed through my distro).

sage -t --long dot2tex_utils.py
**********************************************************************
File "dot2tex_utils.py", line 11, in sage.graphs.dot2tex_utils
Failed example:
    output = dot2tex.dot2tex(graph, format="positions", prog="neato") # optional - requires dot2tex and graphviz
Expected nothing
Got:
    ERROR    Failed to process input
    Traceback (most recent call last):
      File "/home/ncohen/.Sage/local/lib/python2.7/site-packages/dot2tex/dot2tex.py", line 2928, in main
        s =  conv.convert(dotdata)
      File "/home/ncohen/.Sage/local/lib/python2.7/site-packages/dot2tex/dot2tex.py", line 848, in convert
        return self.output()
      File "/home/ncohen/.Sage/local/lib/python2.7/site-packages/dot2tex/dot2tex.py", line 2566, in output
        positions[node.name] = map(int, pos.split(','))
    ValueError: invalid literal for int() with base 10: '87.137'
**********************************************************************

Nathann

@nthiery
Copy link
Contributor

nthiery commented Apr 2, 2013

comment:22

Replying to @nathanncohen:

I was already careful not to mention the spkg in the doc (but if you see how to improve the graphviz installation instructions, please go ahead in a separate ticket; I'll review it).

Is written explicitly anywhere that there is no spkg and that the users should install it by themselves ?

It's written that the soft can be downloaded from the graphviz website. This seems explicit enough to me, but if you want to improve that, go ahead (but I would not speak of spkg at all).

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Apr 2, 2013

comment:23

It's written that the soft can be downloaded from the graphviz website.

Where ?

Nathann

@seblabbe
Copy link
Contributor Author

seblabbe commented Apr 2, 2013

comment:42

Ils sont fous ces romains...

Replying to @nthiery:

Have you installed the new spkg as I pointed out in my previous comment?

I think it is better not to update the old ticket #7004. Here is the link to the new spkg:

sage -f http://sage.math.washington.edu/home/nthiery/dot2tex-2.8.7-dev.spkg

@seblabbe
Copy link
Contributor Author

seblabbe commented Apr 3, 2013

comment:43

I just added a patch which fixes the broken doctests seen by the patchbot. I also added a doctest that make sure the issue of this ticket is solved. I also fixed an # optional - dot2tex, graphviz which was not up to date.

Finally I realize that some optional test are broken. Like this one that we can see in the doc of layout_graphviz. This may be considered in another ticket.

sage: g = digraphs.ButterflyGraph(2)
sage: g.plot(layout = "graphviz", prog = "neato") # optional - dot2tex, graphviz
Traceback (most recent call last): 
...
ValueError: invalid literal for int() with base 10: '67.297'

@nthiery
Copy link
Contributor

nthiery commented Apr 3, 2013

comment:44

Replying to @seblabbe:

I just added a patch which fixes the broken doctests seen by the patchbot. I also added a doctest that make sure the issue of this ticket is solved. I also fixed an # optional - dot2tex, graphviz which was not up to date.

Thanks Sébastien! I looked at your reviewer patch, and it looks good to me. Let's see what the patchbot says. Back to needs review for the first patch.

Finally I realize that some optional test are broken. Like this one that we can see in the doc of layout_graphviz. This may be considered in another ticket.

sage: g = digraphs.ButterflyGraph(2)
sage: g.plot(layout = "graphviz", prog = "neato") # optional - dot2tex, graphviz
Traceback (most recent call last): 
...
ValueError: invalid literal for int() with base 10: '67.297'

+1 since the tests were already failing before this ticket. This is
now #14408 which is about updating the dot2tex spkg.

@novoselt
Copy link
Member

comment:45

For the record, current installation instructions for dot2tex are outdated (I tried the example from the description and it failed at first).

With the current patch at #14382, the example from the description does not give errors.

@seblabbe
Copy link
Contributor Author

seblabbe commented Jun 3, 2013

Adding a doctest to make sure the initial issue is fixed

@seblabbe
Copy link
Contributor Author

seblabbe commented Jun 3, 2013

comment:46

Attachment: trac_13624-review-sl.patch.gz

I just updated my patch which adds a doctest. Even if #14382 finally fix the problem, I think it could be merged anyway.

I removed the part that was fixing dot2tex optional doctests errors. I will move this part in another patch that I am going to post on #14408 where similar issues were discussed.

@novoselt
Copy link
Member

novoselt commented Jun 3, 2013

comment:47

Replying to @seblabbe:

Even if #14382 finally fix the problem,

Feel free to give it a try and set to positive review - it is not big ;-)

@jdemeyer jdemeyer modified the milestones: sage-5.11, sage-5.12 Aug 13, 2013
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.1, sage-6.2 Jan 30, 2014
@tscrim
Copy link
Collaborator

tscrim commented Apr 26, 2014

comment:50

Currently in 6.2.rc0, the example given in the description works (probably from #14382):

sage: G = DiGraph()
sage: G.add_edge(333, 88, "my_label")
sage: G.set_latex_options(format="dot2tex", edge_labels=True)
sage: latex(G)

\begin{tikzpicture}[>=latex,line join=bevel,]
%%
\node (node_1) at (11.000000bp,79.000000bp) [draw,draw=none] {$333$};
  \node (node_0) at (11.000000bp,7.000000bp) [draw,draw=none] {$88$};
  \draw [black,->] (node_1) ..controls (11.000000bp,61.481000bp) and (11.000000bp,39.548000bp)  .. (node_0);
  \definecolor{strokecol}{rgb}{0.0,0.0,0.0};
  \pgfsetstrokecolor{strokecol}
  \draw (38.000000bp,43.000000bp) node {$\text{\texttt{my{\char`\_}label}}$};
%
\end{tikzpicture}

So how much of this ticket should we keep or should we just close as a "works-for-me"?

@seblabbe
Copy link
Contributor Author

comment:51

So how much of this ticket should we keep or should we just close as a "works-for-me"?

As I suggested in a previous comment, I think we could merge the patch trac_13624-review-sl.patch which simply adds a doctest.

Sébastien

@seblabbe
Copy link
Contributor Author

Commit: 2634500

@seblabbe
Copy link
Contributor Author

comment:52

I just converted my old hg patch to a git branch. It should be easy to review as it only adds a doctest since the problem was fixed by #14382.


New commits:

2634500adding a doctest to make sure 13624 is fixed

@seblabbe
Copy link
Contributor Author

Branch: u/slabbe/13624

@seblabbe
Copy link
Contributor Author

Changed author from Nicolas M. Thiéry to Sébastien Labbé

@stumpc5
Copy link
Contributor

stumpc5 commented Apr 30, 2014

Reviewer: Christian Stump

@vbraun
Copy link
Member

vbraun commented May 1, 2014

Changed branch from u/slabbe/13624 to 2634500

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants