Skip to content

Commit febfa2e

Browse files
authored
Merge pull request #1573 from MichaelHatherly/mh/julia-engine-docs-update
Expand docs for `julia` engine
2 parents 1596258 + 0be6327 commit febfa2e

File tree

3 files changed

+158
-2
lines changed

3 files changed

+158
-2
lines changed

docs/computations/julia.qmd

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ Quarto supports executable Julia code blocks within markdown. This allows you to
1212

1313
Quarto has two available engines for executing Julia code. The older one is using the [IJulia](https://github.com/JuliaLang/IJulia.jl) Jupyter kernel and depends on Python to run. The newer engine is using the [QuartoNotebookRunner.jl](https://github.com/PumasAI/QuartoNotebookRunner.jl/) package to render notebooks and does not have any additional dependencies beyond a Julia installation.
1414

15+
Using either of these engines will require manually installing Julia if
16+
you have not done so already. You can download it from
17+
https://julialang.org/downloads/. There are two options for installation: the
18+
Juliaup installation manager, or the "manual" installation approach. Unless
19+
you know that you need to use the "manual" approach, use
20+
Juliaup since it allows you to manage multiple Julia versions on your system.
21+
1522
## Using the `jupyter` engine
1623

1724
Below we'll describe how to [install](#installation) IJulia and related requirements but first we'll cover the basics of creating and rendering documents with Julia code blocks.
@@ -318,6 +325,148 @@ The currently available options are:
318325
- `exeflags`: An array of strings which are appended to the `julia` command that starts the worker process. For example, a notebook is run with `--project=@.` by default (the environment in the directory where the notebook is stored) but this could be overridden by setting `exeflags: ["--project=/some/directory/"]`.
319326
- `env`: An array of strings where each string specifies one environment variable that is passed to the worker process. For example, `env: ["SOMEVAR=SOMEVALUE"]`.
320327

328+
### `juliaup` integration
329+
330+
[`juliaup`](https://github.com/JuliaLang/juliaup) is the recommended way to
331+
install and manage Julia versions. The `julia` engine supports using
332+
`juliaup`'s `+` channel specifier to select the Julia version that a notebook
333+
uses. This allow users to run several notebooks concurrently with different
334+
Julia versions on the same machine without the need for customizing their
335+
`PATH` in any way.
336+
337+
To use this feature, ensure that you have used `juliaup` to install the channels
338+
that you wish to use in your notebooks. Then add the channel specifier to the notebook
339+
frontmatter in the `julia.exeflags` option:
340+
341+
````markdown
342+
---
343+
title: "A Julia 1.11 notebook"
344+
engine: julia
345+
julia:
346+
exeflags: ["+1.11"]
347+
---
348+
349+
```{{julia}}
350+
VERSION
351+
```
352+
````
353+
354+
`QuartoNotebookRunner` currently supports running Julia versions from 1.6
355+
onwards. Support for earlier versions is not planned.
356+
357+
### Revise.jl integration
358+
359+
[Revise](https://github.com/timholy/Revise.jl) allows for automatically
360+
updating function definitions in Julia sessions. It is an essential tool in the
361+
Julia ecosystem for any user that wishes to develop their own packages or large
362+
projects. The `julia` engine supports using `Revise` within notebook processes
363+
by simply importing the package into a cell at the start of a notebook. Once
364+
imported `Revise` will automatically update functions imported from locally
365+
developed packages in the same way as it behaves in a Julia REPL.
366+
367+
Ensure that `Revise` is installed in the project environment that the notebook
368+
is using, since the global environment is not included in the load path
369+
provided to Julia, unlike the behaviour of a Julia REPL session.
370+
371+
### Caching {#caching-julia}
372+
373+
The engine has built-in support for caching notebook results. This feature is disabled by
374+
default but can be enabled by setting the `execute.cache` option to `true` in a notebook's
375+
frontmatter:
376+
377+
````markdown
378+
---
379+
title: "A caching example"
380+
engine: julia
381+
execute:
382+
cache: true
383+
---
384+
385+
```{{julia}}
386+
rand()
387+
```
388+
````
389+
390+
Notebook caches are invalidated based on the following criteria:
391+
392+
- Using a different Julia version to run the notebook.
393+
- Changes to the `Manifest.toml` of the environment the notebook is run in. Adding, removing, or changing package versions will invalidate the cache.
394+
- Changing any contents in the notebook's frontmatter.
395+
- Changing any contents of any executable Julia cells, including cell options.
396+
397+
Changes that do not invalidate a cache:
398+
399+
- Editing markdown content outside of executable Julia cells.
400+
401+
Caches are saved to file in a `.cache` directory alongside the notebook file.
402+
This directory is safe to remove if you want to invalidate all caches. The
403+
contents of the individual cache files is an internal implementation detail and
404+
should not be relied upon.
405+
406+
These caches are safe to save in CI via such tools as GitHub Actions
407+
`action/cache` to help improve the render time of long-running notebooks that
408+
do not often change.
409+
410+
### R and Python support
411+
412+
`{{r}}` and `{{python}}` executable code blocks are supported in the `julia`
413+
engine via integrations with the
414+
[RCall](https://github.com/JuliaInterop/RCall.jl) and
415+
[PythonCall](https://github.com/JuliaPy/PythonCall.jl) packages respectively.
416+
Using this feature requires the notebook author to explicitly `import` those
417+
packages into their notebooks in a `{{julia}}` cell afterwhich they can use
418+
`{{r}}` and `{{python}}` cells.
419+
420+
````markdown
421+
---
422+
title: "Multi-language notebooks"
423+
engine: julia
424+
---
425+
426+
```{{julia}}
427+
import PythonCall
428+
import RCall
429+
```
430+
431+
Create some data in Julia:
432+
433+
```{{julia}}
434+
data = sin.(0:0.1:4pi)
435+
```
436+
437+
Then plot it in R by interpolating the `data` variable from Julia into `R` via
438+
the `$` syntax:
439+
440+
```{{r}}
441+
plot($data)
442+
```
443+
444+
The same `$` syntax can be used to interpolate Julia variables into Python code as well:
445+
446+
```{{python}}
447+
len($data)
448+
```
449+
````
450+
451+
### Engine "extensions"
452+
453+
The implementation of `QuartoNotebookRunner` allows for extending the behaviour
454+
of notebooks via external Julia packages.
455+
456+
One example of this is the
457+
[QuartoTools.jl](https://pumasai.github.io/QuartoTools.jl) package, which
458+
enables fine-grained function call caching, support for serializing data
459+
between notebook processes and normal `julia` processes, and "expandable" cell
460+
outputs that allow for programatic creating of cell inputs and outputs within
461+
notebooks. See the linked documentation for more thorough discussion of that
462+
package's features.
463+
464+
The same approach used by that package can be applied to other third-party
465+
packages that wish to extend the functionality of notebooks in other ways.
466+
Please direct questions and requests regarding this functionality to the
467+
[QuartoNotebookRunner](https://github.com/PumasAI/QuartoNotebookRunner.jl)
468+
repository.
469+
321470
### Limitations
322471

323472
Currently, the `engine: julia` option must be specified in each `.qmd` file. Setting the engine project-wide via `_quarto.yml` [is not yet supported](https://github.com/quarto-dev/quarto-cli/issues/3157).
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
You can view (in-progress) documentation for the next version of Quarto, v1.7, on our pre-release documentation site, [prerelease.quarto.org](https://prerelease.quarto.org), including a list of [highlights](https://prerelease.quarto.org/docs/prerelease/1.7/).
1+
Quarto 1.7 includes the following new features:
2+
3+
- Improvements to the `julia` engine:
4+
- [`juliaup` integration](/docs/computations/julia.qmd#juliaup-integration): Use specific versions of Julia in your notebooks.
5+
- [R and Python support](/docs/computations/julia.qmd#r-and-python-support): Include `{r}` and `{python}` executable code cells via the RCall and PythonCall packages.
6+
- [Caching](/docs/computations/julia.qmd#caching-julia): Save time rendering long-running notebooks by caching results.
7+
- [Revise.jl integration](/docs/computations/julia.qmd#revise.jl-integration): Automatically update function definitions in Julia sessions.
8+

docs/projects/code-execution.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ This sub-directory render won't use the cached `freeze` results but instead will
6868

6969
## Cache
7070

71-
You can use the `cache` option to cache the results of computations (using the [knitr cache](https://yihui.org/knitr/demo/cache/) for R documents, and [Jupyter Cache](https://jupyter-cache.readthedocs.io/en/latest/) for Jupyter documents):
71+
You can use the `cache` option to cache the results of computations (using the [knitr cache](https://yihui.org/knitr/demo/cache/) for R documents, [Jupyter Cache](https://jupyter-cache.readthedocs.io/en/latest/) for Jupyter documents, or [`engine: julia`'s](../computations/julia.qmd#caching-1) built-in support):
7272

7373
``` yaml
7474
execute:

0 commit comments

Comments
 (0)