pypesto.objective.julia

Julia objective

class pypesto.objective.julia.JuliaObjective[source]

Bases: Objective

Wrapper around an objective defined in Julia.

This class provides objective function wrappers around Julia objects. It expects the corresponding Julia objects to be defined in a source_file within a module.

We use the PyJulia package to access Julia from inside Python. It can be installed via pip install pypesto[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.

Parameters:
  • module (str) – Julia module name.

  • source_file (str) – Julia source file name. Defaults to {module}.jl.

  • fun (str) – Names of callables within the Julia code of the corresponding objective functions and derivatives.

  • grad (str) – Names of callables within the Julia code of the corresponding objective functions and derivatives.

  • hess (str) – Names of callables within the Julia code of the corresponding objective functions and derivatives.

  • res (str) – Names of callables within the Julia code of the corresponding objective functions and derivatives.

  • sres (str) – Names of callables within the Julia code of the corresponding objective functions and derivatives.

__init__(module, source_file=None, fun=None, grad=None, hess=None, res=None, sres=None)[source]
Parameters:
  • module (str) –

  • source_file (str) –

  • fun (str) –

  • grad (str) –

  • hess (str) –

  • res (str) –

  • sres (str) –

get(name, as_array=False)[source]

Get variable from Julia module.

Use this function to access any variable from the Julia module.

Return type:

Optional[Callable]

Parameters:
  • name (str) –

  • as_array (bool) –

class pypesto.objective.julia.PEtabJlObjective[source]

Bases: JuliaObjective

Wrapper around an objective defined in PEtab.jl.

Parameters:
  • module (str) – Name of the julia module containing the objective.

  • source_file (str) – Julia source file. Defaults to “{module}.jl”.

  • petab_problem_name (str) – Name of the petab problem variable in the julia module.

__init__(module, source_file=None, petab_problem_name='petabProblem', precompile=True, force_compile=False)[source]

Initialize objective.

Parameters:
  • module (str) –

  • source_file (str) –

  • petab_problem_name (str) –

  • precompile (bool) –

  • force_compile (bool) –

precompile_model(force_compile=False)[source]

Use Julias PrecompilationTools to precompile the relevant code.

Only needs to be done once, and speeds up Julia loading drastically.

Parameters:

force_compile (bool) –

pypesto.objective.julia.display_source_ipython(source_file)[source]

Display source code as syntax highlighted HTML within IPython.

Parameters:

source_file (str) –