WolframResearch / WolframLanguageForJupyter

Wolfram Language kernel for Jupyter notebooks
MIT License
1.05k stars 126 forks source link

WolframLanguageForJupyter`Private`getNames hangs with wolframscript #29

Closed halirutan closed 5 years ago

halirutan commented 5 years ago

I'm on Linux with Mathematica 11.3, 12.0 and the free Wolfram Engine. Let's assume I'm trying to set-up the Jupyter kernel to use the wolframscript as backend than this doesn't work. So a minimal example is

ConfigureJupyter[
  "Add", 
  "WolframEngineBinary" ->
    "/usr/local/Wolfram/Mathematica/11.3/SystemFiles/Kernel/Binaries/Linux-x86-64/wolframscript"
]

However, this hangs Mathematica and the reason is that somehow wolframscript cannot be used to open a link successfully. In particular, the LinkRead here hangs

https://github.com/WolframResearch/WolframLanguageForJupyter/blob/b70e8f5cdc23984d0aeb37729ea8fda30f35cd5b/WolframLanguageForJupyter/WolframLanguageForJupyter.m#L32

Simple example to reproduce:

bin="/usr/local/Wolfram/Mathematica/11.3/SystemFiles/Kernel/Binaries/Linux-x86-64/wolframscript";
RunProcess[{bin,"-code","2+2"},"StandardOutput"]
(* 4 *)

However

link = LinkLaunch[bin <> " -wstp"];
LinkReadyQ[link]
(* False *)

Shouldn't it be possible to use the wolframscript kernel as a backend for Jupyter?

Btw, starting a link from the terminal with wolframscript -wstp, giving the link a name and connection then to it from within Mathematica with LinkConnect does work.

jfultz commented 5 years ago

I don't think so. You're basically asking wolframscript to accept some subset of kernel command-line options and relay them to the kernel, which I think will get very messy. But...what you're trying to do should work with WolframKernel. wolframscript is convenient because it handles activation, is generally on your path, automatically finds the best kernel to run, etc. But if your Wolfram Engine is activated, I think you can just run the kernel from the Wolfram Engine layout directly.

Report back here if you have any problems with that. If that works for you, then I think we should just close this issue.

jfultz commented 5 years ago

I should clarify that this would only work on a properly activated Wolfram Engine. And you'll need to run wolframscript at least once to activate it.

halirutan commented 5 years ago

@jfultz Hey John, thanks for answering. Let me reiterate:

The wolframscript that comes with my Mathematica 11.3 or 12 should already be properly activated because I can use Mathematica with the front end, right? To clarify, on my machine, it doesn't matter if I run in the terminal the wolframscript from the Mathematica release or from the free Wolfram Engine. In both cases, I get a fully functional REPL. As you can see in my comment above, I did run a 2+2 through the wolframscript successfully. However, what doesn't work is creating a WSTP link with LinkLaunch to it. On the other hand, starting wolframscript -wstp from terminal gives a link that can be used:

img

So why doesn't LinkLaunch work when the above works?

And my main question is: The free Wolfram Engine comes (at least on Linux) only with one program: wolframscript. For the usage with Jupyter, we need to be able to get a link to this.

jfultz commented 5 years ago

@halirutan, yes it's fully activated.

And Wolfram Engine comes with lots of programs...it's just a matter of finding them. I don't have this set up on Linux to quote it to you, but I believe you can find what you're looking for in FileNameJoin[{$InstallationDirectory, "Executables/wolfram"}].

cc-wr commented 5 years ago

... In particular, the LinkRead here hangs

https://github.com/WolframResearch/WolframLanguageForJupyter/blob/b70e8f5cdc23984d0aeb37729ea8fda30f35cd5b/WolframLanguageForJupyter/WolframLanguageForJupyter.m#L32

This line has been replaced with the following:

https://github.com/WolframResearch/WolframLanguageForJupyter/blob/e91f036f3715e5e72c621539a99d40a6c5f5657b/configure-jupyter.wls#L47

As such, is this issue okay to close?

halirutan commented 5 years ago

@cc-wr Yes, I've seen your commit and I believe this is OK. My basic misunderstanding seemed to be that you can use the wolframscript executable as option value to "WolframEngineBinary" which doesn't work (at least on my machine).