Message Boards Message Boards

A minimalist alternative to WolframLanguageForJupyter

I have been following the development of the WolframLanguageForJupyter (WLFJ) since its birth because I was already working on my version of a jupyter kernel for the Wolfram language. It appears that WLFJ has several issues, therefore I would like to share with you my version which is called JWLS and it is very minmal and simple compare to WLFJ. As such, it appears to be pretty flexible and I did not experience bad issues on the systems I tried it on. But I need you to test it to confirm my (very biased) impression! :)

Furthermore, I think the release of the free Wolfram Engine for developers gives very much sense to the disclose of such a project right now.

So, here it is https://github.com/Ludwiggle/JWLS

Thank You.


JWLS - DOCs


A Jupyter notebook for Wolfram(Language)Script.

The goal of JWLS is to extend the wolframscript cli with a HTML-based REPL interface.

Features

  • Autocompletion of WL Symbols
  • WL syntax highlighting
  • "!command" runs Bash commands
  • Vector graphics outputs
  • It works also on older versions of CDFPlayer

Installation

Assuming miniconda (Python 3.7) installed

  1. Copy the kernel folder JWLS_kernel into your python installation folder e.g. `~/miniconda3/lib/python3.7/site-packages/
  2. Run the installation script python install.py (it's in the kernel folder)
  3. Modify the path of Names.wl.txt in kernel.py because it requires the full path instead of ~ . Check also if JWLS.sh points the actual wolframscript executable.

Usage

Run JWLS.sh or copy it in the executables path e.g. cp JWLS.sh /usr/local/bin/JWLS .

In order to use it on a cloud compute virtual machine, modify the nbAddrF function by adding jupyter notebook --no-browser --port=7000 . Then screen a session run JWLS and detach it. Go back to your local machine and ssh -N -f -L localhost:6001:localhost:7000 <IP>". For AWS instances also add the pem. For Google Cloud follow their instructions.

Possible issues and Troubleshooting

If your system is generally slow and JWLS.sh opens more than one jupyter-notebook server, you might want to increase the Pause timing in the nbAddrF function which is reponsible for that.

How it works

JWLS is a slimmed down version of the Jupyter bash_kernel that pipes input cells into a wolframscript Dialog[] through a temporary fifo, and it reads the corresponding outputs from the default wolframscript log file.

The JWLS.sh script reads your jupyter notebook list to save the address of the first notebook found; that is needed by show. If Jupyter is not running, JWLS will start a new notebook.

The custom show function returns the clickable URL of the exported graphical output. In this way, graphics is rendered by the Jupyter file viewer in a new browser tab, not within the notebook. Any epression or graphics that is not an Image is exported as a pdf (quickest export time and very accurate), otherwise it exports a png.

The Out[..] expressions are returned on both the Jupyter notebook and the terminal where JWLS is started. On Wolfram Kernels prior to V12, error messages, Information and progress indicators are printed on terminal only. With the new Wolfram Engine (for developers) errors and Information are given back to the standard ouput but still, progress indicators or incremental ouputs like Do[ Print@"hello"; Pause@1, 3 ] returns only at the end of the execution; keep an eye on the terminal for those.

7 Replies

If you use Mathematica mainly for graphics, Jupyter is not for you. A Jupyter interface is great for remote Kernels and Markdown/LaTeX, things that Mathematica does not support that well.

Regarding the black page, is it a problem of safari ? If the out.pdf is properly exported in the JWLout folder but safari does not open it, maybe safari is not well suited to work with Jupyter. As I mention in the description, JWLS is not much more than a couple of fifo on top of a bash_kernel.

That does not work: clicking the link opens a totally black page in Safari. I guess this needs some more work!

In any case, if it worked this does defeat some of the purpose of a Jupyter front end to the Wolfram Engine, namely, to have all output in the same (Jupyter) notebook as the input, and it is contrary to the expected behavior in Mathematica since many versions, where the output from a Plot, Plot3D, etc. is in effect the graphical display and the graphical display is not a side-effect. (That behavior was one of the great advances in the Mathematica Front End, where one no longer had to use the DisplayFunction option before combining several graphics in a single output.)

POSTED BY: Murray Eisenberg

Dear murray, try the show function. E.g. Plot3D[Sin[x y],{x,-Pi,Pi},{y,-Pi,Pi}] // show It will return the address of the exported output; if you click it, a new browser tab will open. If your browser does not open the exported graphics, browse into the JWLSout folder in your notebook home folder ; that's a temporary folder with out.pdf of out.png in it. You can keep the out.pdf tab open and refresh it everytime you call again show because it will be overwritten.

Posted 5 years ago

Using gsed from MacPorts (not Home Brew) fixed that problem, so that I can now get output from 1+1.

However, the output from Plot3D[Sin[x y],{x,-Pi,Pi},{y,-Pi,Pi}] is simply, literally - Graphics3D -.

How do I get to see the display of the graphical output I expected &mdash: the same kind of display I would see in an .nb with the Mathematica Front End, or that I see if instead of JWLS I use WolframLanguageForJupyter?

POSTED BY: Updating Name

Hi Murray, thanks for your feedback. That is MacOS sed complaining about the use of ~ . A solution is to install gnu-sed: brew install gnu-sed and then replace "sed" with "gsed" at line 164 of kernel.py .

I installed (under macOS). When I run JWLS.sh, which starts jupyter and allows me to open a new jupyter notebook in my browser and then try to evaluate something simple like 1+1, I get error:

sed: 1: "0~1 a\": invalid command code ~

What's wrong? (I did check the path to wolframscript and inserted the full path for Names.wl.txt in kernel.py.

POSTED BY: Murray Eisenberg

enter image description here - Congratulations! This post is now featured in our Staff Pick column as distinguished by a badge on your profile of a Featured Contributor and these will help to promote your work! We copied your .md doc file into your post. Posts in Staff Picks should have detailed presentation, - if you could edit and add anything to the current post (for instance, examples of usage) -- that would be great. Thank you, keep it coming!

POSTED BY: Moderation Team
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract