Skip to content

Commit f679efc

Browse files
Expand docs for julia engine
1 parent ef1b666 commit f679efc

File tree

1 file changed

+142
-0
lines changed

1 file changed

+142
-0
lines changed

docs/computations/julia.qmd

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,148 @@ The currently available options are:
318318
- `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/"]`.
319319
- `env`: An array of strings where each string specifies one environment variable that is passed to the worker process. For example, `env: ["SOMEVAR=SOMEVALUE"]`.
320320

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

323465
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).

0 commit comments

Comments
 (0)