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

plot causes weird error "invalid numeric constant" #13

Open
jtravs opened this issue Aug 13, 2013 · 25 comments
Open

plot causes weird error "invalid numeric constant" #13

jtravs opened this issue Aug 13, 2013 · 25 comments

Comments

@jtravs
Copy link

jtravs commented Aug 13, 2013

I discovered something strange when using plot from PyPlot:

julia> 1.0
1.0
julia> using PyPlot
julia> 1.0
1.0
julia> plot([1,2,3])
1-element Any Array:
 PyObject <matplotlib.lines.Line2D object at 0x62390d0>
julia> 1.0
ERROR: syntax: invalid numeric constant 1.0

Any ideas?

Version info:

Julia Version 0.2.0-prerelease+3183
Commit 8752713 2013-08-12 13:11:09 UTC
Platform Info:
  System: Linux (x86_64-linux-gnu)
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY)
  LAPACK: libopenblas
  LIBM: libopenlibm
@stevengj
Copy link
Member

I can't reproduce your error. Can you try updating your Julia build in case this was some bug briefly in git master?

@jtravs
Copy link
Author

jtravs commented Aug 16, 2013

I already checked it again on this version:

Julia Version 0.2.0-prerelease+3265
Commit 92b03a5 2013-08-15 06:55:56 UTC
Platform Info:
  System: Linux (x86_64-linux-gnu)
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY)
  LAPACK: libopenblas
  LIBM: libopenlibm

I'll check an even newer build too. Is there any other info that would be helpful?

@stevengj
Copy link
Member

@loladiro, do you have any idea how this could happen? It is very mysterious to me, and unfortunately I cannot reproduce the problem.

@jtravs
Copy link
Author

jtravs commented Aug 21, 2013

Some more info. Using the Agg backend doesn't have this problem:

julia> using PyCall
julia> @pyimport matplotlib
julia> matplotlib.use("Agg")
julia> @pyimport pylab as plt
julia> plt.plot([1,2,3])
julia> 1.0
1.0

But using the default backend has the same error:

julia> using PyCall
julia> @pyimport pylab as plt
julia> plt.plot([1,2,3])
julia> 1.0
ERROR: syntax: invalid numeric constant 1.0

Could it be to do with GUI usage? I'm am accesing julia on linux over a ssh connection from a mac. The GUI plots show fine, except for this bug.

@AlexanderFabisch
Copy link

I can confirm this error:

julia> using PyPlot

julia> figure()
Figure(PyObject <matplotlib.figure.Figure object at 0x657c810>)

julia> 3.0
ERROR: syntax: invalid numeric constant 3.0

Julia version Version 0.2.0-prerelease+3627, PyPlot commit 7c59b3e, PyCall commit 4f4f9c3.

Calling a function from PyPlot somehow seems to break all numeric constants that contain a '.'. 1e-1 works perfectly. I am working with linux, too.

@stevengj
Copy link
Member

Still can't reproduce. I tried it on OSX and on Debian GNU/Linux with the latest versions of everything.

Which GUI toolkit are you using? (using PyPlot; pygui()) I'm using Qt (PyQt4)

@AlexanderFabisch
Copy link

I can't reproduce that with Ubuntu 13.04 (Matplotlib 1.2.1) either. I think it is a problem with the version of matplotlib. Are there any known requirements? Tomorrow I could look up which version I was using when the error occured.

@stevengj
Copy link
Member

Both matplotlib 0.99.3 and matplotlib 1.2 work for me.

@AlexanderFabisch
Copy link

I currently have these library versions:

Python: 2.7.3 (default, Apr 10 2013, 06:20:15, GCC 4.6.3)
matplotlib: 1.1.1rc
numpy: 1.6.1
Julia: 0.2.0-prerelease+3627
PyPlot commit 7c59b3e
PyCall commit 4f4f9c3

After upgrading to the current version of matplotlib (from git) this error has been fixed.

@andreasnoack
Copy link

I can confirm this. I also get

julia> using PyPlot

julia> figure()
Figure(PyObject <matplotlib.figure.Figure object at 0x109835950>)

julia> 1.0
ERROR: syntax: invalid numeric constant "1.0"

I have

julia> versioninfo()
Julia Version 0.3.0-prerelease+92
Commit 8879168 (2013-11-21 03:42 UTC)
Platform Info:
  System: Darwin (x86_64-apple-darwin13.0.0)
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY)
  LAPACK: libopenblas
  LIBM: libopenlibm

and python 2.7.6 with matplotlib 1.3.1 and Qt4.

@andreasnoack
Copy link

Please let me know, If I can provide any further information that might
help you to locate the problem. It is really convenient to be able to use
matplotlib from julia.

2013/11/21 Steven G. Johnson notifications@github.com

Unfortunately, I still can't reproduce this.


Reply to this email directly or view it on GitHubhttps://github.com//issues/13#issuecomment-29003497
.

Med venlig hilsen

Andreas Noack Jensen

@stevengj
Copy link
Member

Looks like I need to try matplotlib 1.3.1. (I don't suppose you can run it through valgrind or something? This really sounds like some kind of memory bug where something in the Python C API is stomping on Julia memory.)

@dcarrera
Copy link

For what it's worth, I have the same problem.

julia> using PyPlot
julia> surf( rand(10,10) )
julia> 1.5
ERROR: syntax: invalid numeric constant "1.5"

Julia and PyPlot are brand new from Git. The OS is Ubuntu 13.10, which comes with Matplotlib 1.2.1.

I just installed Matplot 1.3.1 from source to see if that make any difference, but I can't figure out where it is installed or how to get PyPlot to see it. If you happen to know, let me know and I'll test it.

@dcarrera
Copy link

The "TkAgg" backend seems to work.

julia> using PyCall
julia> @pyimport matplotlib
julia> matplotlib.use("TkAgg")
julia> @pyimport pylab as plt
Warning: imported binding for transpose overwritten in module __anon__

julia> plt.plot([1 2 3 4 5],"ro")
5-element Array{Any,1}:
 PyObject <matplotlib.lines.Line2D object at 0xea36c0c>
 PyObject <matplotlib.lines.Line2D object at 0xea3b24c>
 PyObject <matplotlib.lines.Line2D object at 0xea3b3ec>
 PyObject <matplotlib.lines.Line2D object at 0xea3b54c>
 PyObject <matplotlib.lines.Line2D object at 0xea3b6ac>

julia> 1.0
1.0

julia> plt.show()

julia> 1.0
1.0

So, adding support for TkAgg might be a work-around for PyPlot until better information becomes available. I tried to do this myself, but I got stuck when trying to add an event loop for Tkinter in PyCall.jl.

(1) In PyPlot/src/PyPlot.jl

-    const gui2matplotlib = [ :wx=>"WXAgg", :gtk=>"GTKAgg", :qt=>"Qt4Agg" ]
+    const gui2matplotlib = [ :tk => "TkAgg", :wx=>"WXAgg", :gtk=>"GTKAgg", :qt=>"Qt4Agg" ]
...
-            for g in (:qt, :wx, :gtk)
+            for g in (:tk, :qt, :wx, :gtk)

(2) In PyCall/src/gui.jl

pygui_works(gui::Symbol) = gui == :default ||
-    ((gui == :wx && pyexists("wx")) ||
+    ((gui == :tk && pyexists("Tkinter")) ||
+     (gui == :wx && pyexists("wx")) ||
...
+# TK:
+function tk_eventloop(sec::Real=50e-3)
+    tk = pyimport("Tkinter")
+    #
+    #    ... no idea what to put here ...
+    #
+    install_doevent(doevent, sec)
+end
+
 # GTK:
 function gtk_eventloop(sec::Real=50e-3)
     gtk = pyimport("gtk")
...
 function pygui_start(gui::Symbol=pygui(), sec::Real=50e-3)
     pygui(gui)
     if !haskey(eventloops, gui)
-        if gui == :wx
+        if gui == :tk
+            eventloops[gui] = tk_eventloop(sec)
+        elseif gui == :wx
             eventloops[gui] = wx_eventloop(sec)

@dcarrera
Copy link

Incidentally, I tested every GUI backend I could find (Gtk, Wx, Qt) and Tkinter was the only one that did not mess up floating point.

@dcarrera
Copy link

I have a hypothesis: The bug may be restricted to 32-bit systems.

I have tested three computers all running Ubuntu (but not all the same version). Two computers are 64-bit and one computer is 32-bit. The two 64-bit computers work fine. The bug with floats is only observed the 32-bit computer.

Considering the very small sample, it is difficult to make any strong assertions. It would be helpful if other people who experienced this bug could confirm whether they are running 32-bit machines or 64-bit machines. If this is indeed the cause, it would explain why it is so hard to reproduce, as 32-bit computers are now rare. This would also be indicative of a real memory bug in Matplotlib which may still come back later.

This is all speculation, but I think it is worth examining.

@AlexanderFabisch
Copy link

I am 90% sure that I used two Ubuntus with 64 bit to reproduce this error. But it is too long ago to be sure. To verify this, someone who can reproduce this error should try the exact same version of matplotlib, python, julia and pyplot on a 32 bit system and a 64 bit system.

@dcarrera
Copy link

Incidentally, because the problem is restricted to the GUI, you can still use PyPlot with the IJulia notebook.

@stevengj
Copy link
Member

I just found a possible source of this problem. @alanedelman was experiencing segfaults with PyPlot.plot on his machine, and it seemed like the problem was due to:

  • Matplotlib internally calls some BLAS operations (via NumPy) during plot, probably to rescale the data somehow, and these BLAS calls get directed to Julia's OpenBLAS library (since that is already loaded in memory).
  • Julia's OpenBLAS library is compiled with 64-bit indices, which are not the default. Matplotlib apparently passes 32-bit indices. Unpredictable behavior ensues.

Can one of you who is seeing this problem compile Julia with

rm -rf deps/openblas*
make clean
make USE_BLAS64=0

to see if that fixes the problem for you? (It fixed the crash for Alan.)

@stevengj
Copy link
Member

See also JuliaLang/julia#4923

@andreasnoack
Copy link

I have just tried your fix but unfortunately it doesn't help. I still get the same error.

Unfortunately Valgrind from brew doesn't work with newer OS Xs and I don't get the error on my Ubuntu machine.

@dcarrera
Copy link

I just tried it too. The error remains. :-(

@andreasnoack
Copy link

I have switched Linux distribution and now I can reproduce this on Linux. I have posted the output from Valgrind here

@ufechner7
Copy link

Same problem here. Ubuntu 12.04 64 bit. I already deleted openblas, that I used for NumPy before and downgraded numpy to 1.7.1, but the problem persists.

@ufechner7
Copy link

I tried it in a virtual machine (VirtualBox) with the same OS and it works. When I start Julia or load numpy I get the message:
OpenBLAS : Your OS does not support AVX instructions. OpenBLAS is using Nehalem kernels as a fallback, which may give poorer performance.

Can this be related to this bug?

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

No branches or pull requests

6 participants