Problems and advices using Julia in Emacs' Org babel

Hi all!

I wanted to embed some Julia code in some notes I’m taking, thus creating a notebook-like document. I am using Emacs with Org-mode, so I went for Org babel. I followed the instructions on Worg, but I still have some problems. I collect them all here, if you think it’s better to open a topic for each one I can do it of course, and I apologize. Anyway:

  • Simple blocks like
#+begin_src julia :results output
  4
#+end_src

actually are good. However, if I change the result type to

#+begin_src julia :results value
  4+4
#+end_src

the execution is way slower, taking roughly 8 seconds and quite a lot of CPU time (even if the result is still produced and correct). Why?

  • How can I produce graphs and pictures? Having
#+begin_src julia :results output
  using Plots;
  t = 0:0.01:4;

  f₀ = 1; #Hz
  Fₛ = 2;
  Tₛ = 1/Fₛ;
  CTsignal = sin.(2π * f₀ * t);

  n = 0:Tₛ:4;
  DTsignal = sin.(2π * f₀ * t);

  graph = plot(t, CTsignal);
  graph = scatter!(n, DTsignal);

   gui(graph);
#+end_src

briefly produces the picture, but then it closes automatically. Can I keep the graph on screen?

  • Starting time is quite slow if I use external packages, like in the previous example where I used using Plots;. In my usual Julia workflow I have a sysimage to speed up this time. Can I do the same in Org mode?

  • Even if I end an instruction with a semicolon, the value of the expression is always printed. This is strange: can I stop it? Moreover, if I process a long array, all of it is printed in the document (possibly thousands of values!), whereas in the usual Julia REPL it’s condensed with a vertical ellipsis (). Can I do the same in Org?

Thanks!

1 Like

Hi,
I think you should also send this message to the Org mailing list. The Julia support in Org is a very complicated (and quite disappointing) story, and it is really far from perfect. I tried myself to maintain another backend, which is now deprecated since Org has an official ob-julia support. However, I’m not sure that it is actively maintained…

1 Like

Thanks. I’ll have a look at it.

I’ve seen that my problems can be partially solved using ob-julia-vterm, available on MELPA. In particular:

  • Evaluation of packages is still slow on the first time (I need to investigate if sysimages can be used). However, session is persisted (optionally it can be disabled), so subsequent runs are fast. Overall, it’s a usual Julia session
  • Images can now be displayed
  • :results value is just as fast as :results output
  • Outputted vectors are abbreviated
  • However, REPL outputs are not printed, unless it’s the last value returned and result type is value (which is the default). I mean a block like this:
#+begin_src julia :results value
  2*4
  1+4
#+end_src

produces

#+RESULTS:
: 5

even if in a usual Julia REPL we expect to see both 8 and 5

3 Likes

Yep, ob-julia-vterm may be the best way to use Julia within Org-mode today!

As concerns your last remark,

However, REPL outputs are not printed, unless it’s the last value returned and result type is value (which is the default).

I think this is really the intended behavior when using the value type, for all languages supported in Org-mode.

2 Likes