Ask Your Question
1

Sage on Mac unable to use plot3d due to Java/jmol issues

asked 2017-11-07 17:29:46 +0100

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

Hi,

I am a relative newbie to the Mac and Sage on the Mac. I tried to run the following code from the Sage tutorial on my Mac in the console mode of sage:

sage: x, y = var('x,y')

sage: plot3d(x^2 + y^2, (x,-2,2), (y,-2,2))

The error message I get is

--------------------------------------------------------------------------- RuntimeError
Traceback (most recent call last) <ipython-input-2-878191366deb> in <module>() ----> 1 plot3d(xInteger(2) + yInteger(2), (x,-Integer(2),Integer(2)), (y,-Integer(2),Integer(2)))

/Applications/SageMath/local/lib/python2.7/site-packages/IPython/core/displayhook.pyc in __call__(self, result) 244 self.start_displayhook() 245 self.write_output_prompt() --> 246 format_dict, md_dict = self.compute_format_data(result) 247 self.update_user_ns(result) 248 self.fill_exec_result(result)

/Applications/SageMath/local/lib/python2.7/site-packages/IPython/core/displayhook.pyc in compute_format_data(self, result) 148 149 """ --> 150 return self.shell.display_formatter.format(result) 151 152 # This can be set to True by the write_output_prompt method in a subclass

/Applications/SageMath/local/lib/python2.7/site-packages/sage/repl/display/formatter.pyc in format(self, obj, include, exclude) 158 # First, use Sage rich output if there is any 159 PLAIN_TEXT = u'text/plain' --> 160 sage_format, sage_metadata = self.dm.displayhook(obj) 161 assert PLAIN_TEXT in sage_format, 'plain text is always present' 162 if sage_format.keys() != [PLAIN_TEXT]:

/Applications/SageMath/local/lib/python2.7/site-packages/sage/repl/rich_output/display_manager.pyc in displayhook(self, obj) 806 self._backend.set_underscore_variable(obj) 807 plain_text, rich_output = self._rich_output_formatter(obj, dict()) --> 808 return self._backend.displayhook(plain_text, rich_output) 809 810 def display_immediately(self, obj, **rich_repr_kwds):

/Applications/SageMath/local/lib/python2.7/site-packages/sage/repl/rich_output/backend_ipython.pyc in displayhook(self, plain_text, rich_output) 264 return ({u'text/plain': msg}, {}) 265 elif isinstance(rich_output, OutputSceneJmol): --> 266 msg = self.launch_jmol(rich_output, plain_text.text.get_unicode()) 267 return ({u'text/plain': msg}, {}) 268 elif isinstance(rich_output, OutputSceneWavefront):

/Applications/SageMath/local/lib/python2.7/site-packages/sage/repl/rich_output/backend_ipython.pyc in launch_jmol(self, output_jmol, plain_text) 367 jdata = JmolData() 368 if not jdata.is_jvm_available() and not DOCTEST_MODE: --> 369 raise RuntimeError('jmol cannot run, no suitable java version found') 370 launch_script = output_jmol.launch_script_filename() 371 from sage.env import SAGE_LOCAL

RuntimeError: jmol cannot run, no suitable java version found

I believe I have the latest version of Java installed:

$ java --version java 9.0.1 Java(TM) SE Runtime Environment (build 9.0.1+11) Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)

Sage version

$ sage --version SageMath version 8.0, Release Date: 2017-07-21

I would appreciate any inputs and advice about how to fix this issue. Thanks in advance!

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2017-11-07 20:52:38 +0100

dan_fulea gravatar image

In my case, there is a True returned for

sage: from sage.interfaces.jmoldata import JmolData
sage: jdata = JmolData()
sage: jdata.is_jvm_available()
True

For this to work, the subprocess call (try jdata.is_jvm_available?? to see the problem line of code) has to find java. For me, this also works, it is a cheap linux machine running Manjaro, where i never have to take care about paths:

sage: import subprocess
sage: print subprocess.check_output(['java', '-version'], stderr=subprocess.STDOUT)
....: 
openjdk version "1.8.0_144"
OpenJDK Runtime Environment (build 1.8.0_144-b01)
OpenJDK Server VM (build 25.144-b01, mixed mode)

To fix the problem, one solution would be to make subprocess find the java (version). Try this from the sage interpreter console and/or from some other (iron) python console or IDE. It is rather a mixture of an operating system problem and a java installation & system wide recognition problem, than a sage problem from my point of view.

An other solution would be to use explicitly an other viewer in:

sage: var( 'x,y' );
sage: p = plot3d( x^2 + y^2, (x,-2,2), (y,-2,2) )
sage: p.show( viewer='canvas3d' )    # or 'tachyon' instead

Try p.show? in the command line to see potential viewers. (The chosen one has to be installed and working (also in sage).)

The viewer tachyon will possibly become the new default viewer...

Note: Not in this answer, but somehow in the same issue: During my experience with (plot and) plot3d there were often problems to save a file from the "picture seen in a (jmol) window". Also trying p.save may be frustrating when it saves a black image with a jmol signature in the lower right corner. When tachyon shows some picture (of a plot3d) with a spartan window making the user ask herself / himself "where is my pic?!", then the menu lets us open it with some other viewer, e.g. okular or jmol. Well, jmol opens an interstellar black solid filled rectangle. (Okular does better.) And when opening it via p.show() using the (in my case) working jmol, then there is hard to find the location of the file shown, and there is no menu to save "it" in e.g. ~/temp . The story came at some days, as i was concerned with plotting elliptic curves (to put them in some latex document). My solution was to abandon plotting elliptic curves and to concentrate on maths. Sage makes a wonderful job in this field, and we need more questions and more answers on issues regarding structural mathematics, e.g. elliptic curves.

Note: All this experience is a good one, some day i will understand git and the sage code commit in it, improve the situation e.g. by adding an option verbose=False, which in case of p.show( verbose=True ) should deliver all relevant information about hidden files and applications used to save them and started sub-processes.

edit flag offensive delete link more

Comments

Thanks, Dan. I don't seem to have canvas3d; the graphics quality using tachyon is very poor for some reason: the figure appears dithered.

sage: from sage.interfaces.jmoldata import JmolData

sage: jdata = JmolData()

sage: jdata.is_jvm_available()

False

sage: import subprocess

sage: print subprocess.check_output(['java', '-version'], stderr=subprocess.STDOUT)

java version "9.0.1"

Java(TM) SE Runtime Environment (build 9.0.1+11)

Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)

toricweb gravatar imagetoricweb ( 2017-11-08 00:17:01 +0100 )edit
1

answered 2017-11-07 20:58:45 +0100

eric_g gravatar image

Use the new 3D viewer threejs:

sage: x, y = var('x,y')
sage: plot3d(x^2 + y^2, (x,-2,2), (y,-2,2), viewer='threejs')

It is faster and better than Jmol; it does not rely on Java and hopefully should become Sage's default 3D viewer.

edit flag offensive delete link more

Comments

Thanks eric_g! This worked. But it launches a browser (Safari, in my case). Is there a way to get it to work like jmol would (i.e. without a browser)?

toricweb gravatar imagetoricweb ( 2017-11-08 00:13:40 +0100 )edit

No, threejs always requires a browser, being an interface to WebGL. Note also that, even without any JRE, you can use Jmol if you run Sage in a notebook (either old sagenb or Jupyter), because it involves then Javascript, not Java.

eric_g gravatar imageeric_g ( 2017-11-08 15:45:54 +0100 )edit

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: 2017-11-07 17:29:46 +0100

Seen: 1,065 times

Last updated: Nov 07 '17