jupyter icon indicating copy to clipboard operation
jupyter copied to clipboard

Wolfram Repl Fails to Print Results

Open georgewsinger opened this issue 5 years ago • 22 comments

After running jupyter-run-repl and selecting Wolfram Language 12.0:

image

Is this the expected behavior?

georgewsinger avatar Mar 05 '20 15:03 georgewsinger

I don't think so.

Can you copy the following code

(let ((jupyter--debug t))
  (jupyter-repl-replace-cell-code "plt.plot([1, 2, 3])")
  (jupyter-repl-ret)
  (sleep-for 2))

and inside the REPL buffer type M-: C-y RET, then paste what was printed in the *Messages* buffer here. There should be a whole bunch of lines like

SENDING: :execute-request 0acd2760-8549-43fa-9825-5a058017b854 (:code plt.plot([1, 2, 3]) :silent :json-false :store_history t :user_expressions #s(hash-table size 1 test eql rehash-size 1.5 rehash-threshold 0.8125 data ()) :allow_stdin t :stop_on_error :json-false)
SENT: (:shell 0acd2760-8549-43fa-9825-5a058017b854)
MESSAGE: (:iopub :status (:execution_state busy))
RUN-HOOK: jupyter-iopub-message-hook
MESSAGE: (:iopub :execute-input (:code plt.plot([1, 2, 3]) :execution_count 18))
RUN-HOOK: jupyter-iopub-message-hook
MESSAGE: (:iopub :execute-result (:data (:text/plain [<matplotlib.lines.Line2D at 0x7fd9cc2eae10>]) :metadata nil :execution_count 18))
...

nnicandro avatar Mar 05 '20 23:03 nnicandro

Doing so yields

image

and in the *Messages* buffer:

Done.
jupyter-start-kernel: default-directory = /home/george/.dotfiles/
jupyter-start-kernel: Starting process with args "/nix/store/hcs22wc96vmsbqgbz8a2lg8jnjylgwis-wolfram-desktop-12.0.0/libexec/Mathematica/Executables/WolframKernel -script /home/george/.WolframDesktop/Paclets/Repository/WolframLanguageForJupyter-0.9.2/Resources/KernelForWolframLanguageForJupyter.wl /run/user/1000/jupyter/emacs-kernel-Dmje3J.json"
Starting wolframlanguage12 kernel process...done
SENDING: :kernel-info-request e4bc6f98-2017-4c9a-ab2b-5075fbbb5d2f nil
SENT: (:shell e4bc6f98-2017-4c9a-ab2b-5075fbbb5d2f)
MESSAGE: (:iopub :status (:execution_state busy))
MESSAGE: (:shell :kernel-info-reply (:protocol_version 5.3.0 :implementation WolframLanguageForJupyter :implementation_version 0.0.1 :language_info (:name Wolfram Language :version 12.0 :mimetype application/vnd.wolfram.m :file_extension .m :pygments_lexer mathematica :codemirror_mode mathematica) :banner Wolfram Language/Wolfram Engine Copyright 2019))
MESSAGE: (:iopub :status (:execution_state idle))
Requesting kernel info...done
SENDING: :history-request cbb0689b-a416-4e29-9fe5-eb422865fbbd (:output :json-false :raw :json-false :hist_access_type tail :n 100)
SENDING: :execute-request 93342f47-1321-4e1d-8fb9-cd4847efb68f (:code  :silent t :store_history t :user_expressions #s(hash-table size 1 test eql rehash-size 1.5 rehash-threshold 0.8125 data ()) :allow_stdin t :stop_on_error :json-false)
SENT: (:shell cbb0689b-a416-4e29-9fe5-eb422865fbbd)
SENT: (:shell 93342f47-1321-4e1d-8fb9-cd4847efb68f)
MESSAGE: (:iopub :status (:execution_state busy))
MESSAGE: (:shell :execute-reply (:status ok :execution_count 1 :user_expressions [] :payload []))
MESSAGE: (:iopub :status (:execution_state idle))
DROPPING-REQ: e4bc6f98-2017-4c9a-ab2b-5075fbbb5d2f
SENDING: :is-complete-request 84885cb4-3baa-434d-b139-4c945cff11f9 (:code 2)
SENT: (:shell 84885cb4-3baa-434d-b139-4c945cff11f9)
MESSAGE: (:iopub :status (:execution_state busy))
MESSAGE: (:shell :is-complete-reply (:status complete))
RUN-HOOK: jupyter-shell-message-hook
MESSAGE: (:iopub :status (:execution_state idle))
DROPPING-REQ: 93342f47-1321-4e1d-8fb9-cd4847efb68f
SENDING: :execute-request 4dfd124d-b45b-4bd3-a692-072c56e4c606 (:code 2 :silent :json-false :store_history t :user_expressions #s(hash-table size 1 test eql rehash-size 1.5 rehash-threshold 0.8125 data ()) :allow_stdin t :stop_on_error :json-false)
SENT: (:shell 4dfd124d-b45b-4bd3-a692-072c56e4c606)
MESSAGE: (:iopub :status (:execution_state busy))
RUN-HOOK: jupyter-iopub-message-hook
MESSAGE: (:shell :execute-reply (:status ok :execution_count 2 :user_expressions [] :payload []))
RUN-HOOK: jupyter-shell-message-hook
MESSAGE: (:iopub :execute-result (:execution_count 2 :data (:text/html  :text/plain 2) :metadata (:text/html [] :text/plain [])))
RUN-HOOK: jupyter-iopub-message-hook
MESSAGE: (:iopub :status (:execution_state idle))
RUN-HOOK: jupyter-iopub-message-hook
DROPPING-REQ: 84885cb4-3baa-434d-b139-4c945cff11f9
SENDING: :is-complete-request 2401546b-e50c-4c5f-a0cf-445dae1437ae (:code plt.plot([1, 2, 3]))
SENT: (:shell 2401546b-e50c-4c5f-a0cf-445dae1437ae)
MESSAGE: (:iopub :status (:execution_state busy))
MESSAGE: (:shell :is-complete-reply (:status invalid))
RUN-HOOK: jupyter-shell-message-hook
MESSAGE: (:iopub :status (:execution_state idle))
DROPPING-REQ: 4dfd124d-b45b-4bd3-a692-072c56e4c606
SENDING: :execute-request c882b383-c94e-41bb-ad12-26643d675d53 (:code plt.plot([1, 2, 3]) :silent :json-false :store_history t :user_expressions #s(hash-table size 1 test eql rehash-size 1.5 rehash-threshold 0.8125 data ()) :allow_stdin t :stop_on_error :json-false)
SENT: (:shell c882b383-c94e-41bb-ad12-26643d675d53)
MESSAGE: (:iopub :error (:ename ToExpression::sntx :evalue Invalid syntax in or before "plt.plot([1, 2, 3])".
                                       ^ :traceback [[0;31mToExpression::sntx: Invalid syntax in or before "plt.plot([1, 2, 3])".
                                                           ^
[0m]))
RUN-HOOK: jupyter-iopub-message-hook
MESSAGE: (:iopub :status (:execution_state busy))
RUN-HOOK: jupyter-iopub-message-hook
MESSAGE: (:shell :execute-reply (:status ok :execution_count 3 :user_expressions [] :payload []))
RUN-HOOK: jupyter-shell-message-hook
MESSAGE: (:iopub :execute-result (:execution_count 3 :data (:text/html  :text/plain $Failed) :metadata (:text/html [] :text/plain [])))
RUN-HOOK: jupyter-iopub-message-hook
MESSAGE: (:iopub :status (:execution_state idle))
RUN-HOOK: jupyter-iopub-message-hook
DROPPING-REQ: 2401546b-e50c-4c5f-a0cf-445dae1437ae
nil

georgewsinger avatar Mar 06 '20 16:03 georgewsinger

Whoops, I meant to replace plt.plot([1, 2, 3]) with Plot[Sin[x], {x, 0, 1}]. So

(let ((jupyter--debug t))
  (jupyter-repl-replace-cell-code "Plot[Sin[x], {x, 0, 1}]")
  (jupyter-repl-ret)
  (sleep-for 2))

Could you retry with the above code.

nnicandro avatar Mar 06 '20 23:03 nnicandro

Here's the corrected test:

Starting wolframlanguage12 kernel process...done
Requesting kernel info...done
SENDING: :is-complete-request c8767e06-2b36-4dcb-a3ab-0fc0e25c9513 (:code Plot[Sin[x], {x, 0, 1}])
SENT: (:shell c8767e06-2b36-4dcb-a3ab-0fc0e25c9513)
MESSAGE: (:iopub :status (:execution_state busy))
MESSAGE: (:shell :is-complete-reply (:status complete))
RUN-HOOK: jupyter-shell-message-hook
MESSAGE: (:iopub :status (:execution_state idle))
DROPPING-REQ: 02681545-240d-4541-8e0b-647d8f7ca3ab
SENDING: :execute-request ab1f19cd-cca9-447d-8374-c0203c131b12 (:code Plot[Sin[x], {x, 0, 1}] :silent :json-false :store_history t :user_expressions #s(hash-table size 1 test eql rehash-size 1.5 rehash-threshold 0.8125 data ()) :allow_stdin t :stop_on_error :json-false)
SENT: (:shell ab1f19cd-cca9-447d-8374-c0203c131b12)
MESSAGE: (:iopub :status (:execution_state busy))
RUN-HOOK: jupyter-iopub-message-hook
MESSAGE: (:shell :execute-reply (:status ok :execution_count 2 :user_expressions [] :payload []))
RUN-HOOK: jupyter-shell-message-hook
MESSAGE: (:iopub :execute-result (:execution_count 2 :data (:text/html  :text/plain -Graphics-) :metadata (:text/html [] :text/plain [])))
RUN-HOOK: jupyter-iopub-message-hook
MESSAGE: (:iopub :status (:execution_state idle))
RUN-HOOK: jupyter-iopub-message-hook
DROPPING-REQ: c8767e06-2b36-4dcb-a3ab-0fc0e25c9513
nil

georgewsinger avatar Mar 07 '20 01:03 georgewsinger

It doesn't look like the kernel sent the text/html representation of the results

MESSAGE: (:iopub :execute-result (:execution_count 2 :data (:text/html  :text/plain -Graphics-) :metadata (:text/html [] :text/plain [])))

otherwise you should see something as the value of the :text/html field. It looks like the empty string is being returned as the value which is why nothing gets printed.

Does the graph show up when you run the cell in a regular Jupyter notebook?

nnicandro avatar Mar 10 '20 21:03 nnicandro

If I open a console REPL it shows up as -Graphics-. If I open a web browser REPL it shows up as the actual graphic. But note I'm seeing results for any return values (plots or not). As in 2+2 also doesnt print in emacs ( but it does print in the console REPL).

georgewsinger avatar Mar 10 '20 21:03 georgewsinger

I didn't notice the 2+2 case, could you also show what is printed to *Messages* when you replace "Plot[Sin[x], {x, 0, 1}]" with 2+2 in the code that I gave you.

Could you also show the kernelspec being used, e.g. by showing the result of

(cl-prettyprint (jupyter-available-kernelspecs))

nnicandro avatar Mar 10 '20 22:03 nnicandro

For 2+2:

SENDING: :is-complete-request b9b3d5a9-d0f8-4620-bf7e-3f72e319aa02 (:code 2+2)
SENT: (:shell b9b3d5a9-d0f8-4620-bf7e-3f72e319aa02)
MESSAGE: (:iopub :status (:execution_state busy))
MESSAGE: (:shell :is-complete-reply (:status complete))
RUN-HOOK: jupyter-shell-message-hook
MESSAGE: (:iopub :status (:execution_state idle))
DROPPING-REQ: 09c6acda-f35f-4547-b52e-47db1bb5f505
SENDING: :execute-request 2abaeb0d-cff6-4904-b5af-911ecd9ba814 (:code 2+2 :silent :json-false :store_history t :user_expressions #s(hash-table size 1 test eql rehash-size 1.5 rehash-threshold 0.8125 data ()) :allow_stdin t :stop_on_error :json-false)
SENT: (:shell 2abaeb0d-cff6-4904-b5af-911ecd9ba814)
MESSAGE: (:iopub :status (:execution_state busy))
RUN-HOOK: jupyter-iopub-message-hook
MESSAGE: (:shell :execute-reply (:status ok :execution_count 2 :user_expressions [] :payload []))
RUN-HOOK: jupyter-shell-message-hook
MESSAGE: (:iopub :execute-result (:execution_count 2 :data (:text/html  :text/plain 4) :metadata (:text/html [] :text/plain [])))
RUN-HOOK: jupyter-iopub-message-hook
MESSAGE: (:iopub :status (:execution_state idle))
RUN-HOOK: jupyter-iopub-message-hook
DROPPING-REQ: b9b3d5a9-d0f8-4620-bf7e-3f72e319aa02

Kernelspec:

(("jwls" "/home/george/.local/share/jupyter/kernels/jwls"
 :argv
 ["/nix/store/vp7mwr3wx0a8a6bg7ifg9iq1wk6n0w6j-python3-3.6.8/bin/python" "-m" "JWLS_kernel" "-f" "{connection_file}"]
 :env
 (:PS1 "$")
 :display_name
 "JWLS"
 :language
 "mathematica"
 :interrupt_mode
 "signal"
 :metadata
 nil)
 ("wolframlanguage12" "/home/george/.local/share/jupyter/kernels/wolframlanguage12"
 :argv
 ["/nix/store/hcs22wc96vmsbqgbz8a2lg8jnjylgwis-wolfram-desktop-12.0.0/libexec/Mathematica/Executables/WolframKernel" "-script" "/home/george/.WolframDesktop/Paclets/Repository/WolframLanguageForJupyter-0.9.2/Resources/KernelForWolframLanguageForJupyter.wl" "{connection_file}"]
 :env
 nil
 :display_name
 "Wolfram Language 12"
 :language
 "Wolfram Language"
 :interrupt_mode
 "signal"
 :metadata
 nil)
 ("python3" "/nix/store/l3ljb1s9663fymipbz2k4a088w59k1zf-python3-3.6.8-env/share/jupyter/kernels/python3"
 :argv
 ["python" "-m" "ipykernel_launcher" "-f" "{connection_file}"]
 :env
 nil
 :display_name
 "Python 3"
 :language
 "python"
 :interrupt_mode
 "signal"
 :metadata
 nil))

georgewsinger avatar Mar 10 '20 23:03 georgewsinger

OK, thanks. I think I know what the issue is with not displaying anything when you type 2+2 and why -Graphics- doesn't show up either in the plot case.

But I'm still confused why the kernel would return an empty HTML representation for the plot since you said a plot was displayed in the web browser. Just to be clear, your saying that the plot is displayed when you start a notebook using something like the jupyter notebook shell command right?

nnicandro avatar Mar 11 '20 02:03 nnicandro

Also I noticed that you are using Nix, do you have any suggestions for how to solve #196.

nnicandro avatar Mar 11 '20 07:03 nnicandro

@dzop I just replied to #196.

Also, yes, to be clear the plot is displaying in a browser when using jupyter notebook (as are other return values, like 2+2).

georgewsinger avatar Mar 11 '20 14:03 georgewsinger

Can you check if #229 at least allows you to see something when you enter 2+2.

You will have to upgrade emacs-jupyter first.

nnicandro avatar Mar 12 '20 20:03 nnicandro

As far as I can tell this bug is still happening - I've updated to the latest emacs-jupyter and dropped jupyter-wolfram-language.el into my load-path and I'm still not seeing anything when I put 2+2 into the REPL.

Screenshot from 2020-05-05 21-14-24

If theres anything I can do to help you patch this up and test it out, give me a shout! I'd love to help with this issue where I can.

Rizzey avatar May 05 '20 20:05 Rizzey

Has there been any progress on this?

georgewsinger avatar May 28 '20 20:05 georgewsinger

FYI This functionality does work correctly with the emacs-ipython-notebook package (maybe you could get some clue there?)

dalanicolai avatar Sep 10 '20 12:09 dalanicolai

Ah... actually on my system everything works just fine with emacs-jupyter using the wolfram kernel too. image

dalanicolai avatar Sep 10 '20 13:09 dalanicolai

@dalanicolai I am unable to replicate this after installing the latest emacs-jupyter. I just get the same issues as before. Also: emacs-ipython-notebook is unable to display Wolfram graphics, unless I'm mistaken (though it does successfully print the results of operations like 2+2).

georgewsinger avatar Oct 24 '20 01:10 georgewsinger

Ah, okay. So I checked again here (I'm not really using emacs-jupyter at the moment), but everything just works here (see screenshot below). But I am not a developer. So unfortunately I don't know why the image does not show up there. image.

dalanicolai avatar Oct 27 '20 14:10 dalanicolai

But I guess when even emacs-ipython-notebook does not show images, while it shows output for 2+2, then maybe you have two problems. So does any of the ipython/juptyer packages show plots for example created using matplotlib with the python kernel? (Or any other images with any other kernel...?)

dalanicolai avatar Oct 27 '20 15:10 dalanicolai

@dalanicolai I am unable to replicate this after installing the latest emacs-jupyter. I just get the same issues as before. Also: emacs-ipython-notebook is unable to display Wolfram graphics, unless I'm mistaken (though it does successfully print the results of operations like 2+2).

I also encountered the same problem,I found WolframLanguageForJupyter latest release will cause this ,with patch [https://github.com/linux-xhyang/WolframLanguageForJupyter/commit/2a4ed08556a3f87e4b134b48d5b0bc44bc81fb8b] will resolve the problem, but I haven't figured out the root cause,you can try.

linux-xhyang avatar Sep 25 '21 15:09 linux-xhyang

@linux-xhyang That patched worked for me. Excellent work, I could never in a million years got that working. FYI if you want interactive 3D it is possible to for a script as well using: nb = CreateDocument[{TextCell["S1","Section"],ExpressionCell[Plot3D[Sin[x+y^2],{x,-3,3},{y,-2,2}],"Input"]}]; // UsingFrontEnd NotebookSave[nb,"my file.nb"] // UsingFrontEnd

The Wolfram player can rotate, zoom etc the graphic

ddph3dg avatar Mar 30 '22 07:03 ddph3dg

I'm bitten by the same problem (no answer printed in the REPL buffer) with Wolfram language 13.2 and Wolfram's kernel.

(cl-prettyprint (jupyter-available-kernelspecs)) prints :

 ("wolframlanguage13.2" "/home/charpent/.local/share/jupyter/kernels/wolframlanguage13.2"
  :argv
   ["/usr/local/Wolfram/WolframEngine/13.2/Executables/WolframKernel" "-script" "/home/charpent/.WolframEngine/Paclets/Repository/WolframLanguageForJupyter-0.9.3/Resources/KernelForWolframLanguageForJupyter.wl" "{connection_file}"]
   :env
    nil
    :display
     _name
      "Wolfram Language 13.2"
      :language
       "Wolfram Language"
       :interrupt
	_mode
	 "signal"
	 :metadata
	  nil))

in the *jupyter-repl[Wolfram-Language 12.0]* buffer.

Running :

(let ((jupyter--debug t)) (message "------------------------------")
  (jupyter-repl-replace-cell-code "2+2")
  (jupyter-repl-ret) (message "++++++++++++++++++++++++++++++")
  (sleep-for 2))

from the minibuffer (via M-:) prints

------------------------------
SENDING: :is-complete-request 7a22d879-346b-40f6-b484-f5109e739ec0 (:code 2+2)
SENT: (:shell 7a22d879-346b-40f6-b484-f5109e739ec0)
MESSAGE: (:iopub :status (:execution_state busy))
MESSAGE: (:shell :is-complete-reply (:status complete))
RUN-HOOK: jupyter-shell-message-hook
MESSAGE: (:iopub :status (:execution_state idle))
DROPPING-REQ: c2911036-0403-4cc2-9107-319a73299392
SENDING: :execute-request 2a5bb3af-eeab-41e3-a3eb-1350008cfda0 (:code 2+2 :silent :json-false :store_history t :user_expressions #s(hash-table size 1 test eql rehash-size 1.5 rehash-threshold 0.8125 data ()) :allow_stdin t :stop_on_error :json-false)
SENT: (:shell 2a5bb3af-eeab-41e3-a3eb-1350008cfda0)
MESSAGE: (:iopub :status (:execution_state busy))
RUN-HOOK: jupyter-iopub-message-hook
MESSAGE: (:shell :execute-reply (:status ok :execution_count 11 :user_expressions [] :payload []))
RUN-HOOK: jupyter-shell-message-hook
MESSAGE: (:iopub :execute-result (:execution_count 11 :data (:text/html  :text/plain 4) :metadata (:text/html [] :text/plain [])))
RUN-HOOK: jupyter-iopub-message-hook
MESSAGE: (:iopub :status (:execution_state idle))
RUN-HOOK: jupyter-iopub-message-hook
DROPPING-REQ: 7a22d879-346b-40f6-b484-f5109e739ec0
++++++++++++++++++++++++++++++

in the *Messages* buffer.

I do not understand @linux-xhyang patch, which seems to replace some non-printing characters in Wolfram's source for its kernel.

Any hint ?

EmmanuelCharpentier avatar Apr 18 '23 19:04 EmmanuelCharpentier