pyabc.external.julia

Julia interface via PyJulia

class pyabc.external.julia.Julia(module_name: str, source_file: str = None)[source]

Bases: object

Interface to Julia via PyJulia.

This class provides model, distance, and observable wrappers around Julia objects. It expects the corresponding Julia objects to be defined in a source_file within a module_name.

The Julia model is expected to return a dictionary object compatible with pyABC’s model simulation type, in particular values convertible to numpy.ndarray, pandas.Series, or pandas.DataFrame.

The Julia distance takes two model simulations and returns a single floating value.

We use the PyJulia package to access Julia from inside Python. It can be installed via pip install pyabc[julia], however requires additional Julia dependencies to be installed via:

>>> python -c "import julia; julia.install()"

For further information, see https://pyjulia.readthedocs.io/en/latest/installation.html.

There are some known problems, e.g. with statically linked Python interpreters, see https://pyjulia.readthedocs.io/en/latest/troubleshooting.html for details. Possible solutions are to pass compiled_modules=False to the Julia constructor early in your code:

>>> from julia.api import Julia
>>> jl = Julia(compiled_modules=False)

This however slows down loading and using Julia packages, especially for large ones. An alternative is to use the python-jl command shipped with PyJulia:

>>> python-jl MY_SCRIPT.py

This basically launches a Python interpreter inside Julia. When using Jupyter notebooks, this wrapper can be installed as an additional kernel via:

>>> python -m ipykernel install --name python-jl [--prefix=/path/to/python/env]

And changing the first argument in /path/to/python/env/share/jupyter/kernels/python-jl/kernel.json to python-jl.

Model simulations are eagerly converted to Python objects (specifically, numpy.ndarray and pandas.DataFrame). This can introduce overhead and could be avoided by an alternative lazy implementation.

__init__(module_name: str, source_file: str = None)[source]
display_source_ipython()[source]

Display source code as syntax highlighted HTML within IPython.

distance(name: str = 'distance') Callable[source]

Get the distance function from Julia.

Parameters:

name (Name of the distance function within the Julia module.) –

model(name: str = 'model')[source]

Get a wrapped Julia model callable.

Parameters:

name (Name of the model within the Julia module.) –

observation(name: str = 'observation')[source]

Get the observed data from Julia.

Parameters:

name (Identifier of observed data variable within the Julia module.) –