pypesto.objective.julia
Julia objective
- class pypesto.objective.julia.JuliaObjective(module: str, source_file: str | None = None, fun: str | None = None, grad: str | None = None, hess: str | None = None, res: str | None = None, sres: str | None = None)[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
topython-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 – Julia module name.
source_file – Julia source file name. Defaults to {module}.jl.
fun – Names of callables within the Julia code of the corresponding objective functions and derivatives.
grad – Names of callables within the Julia code of the corresponding objective functions and derivatives.
hess – Names of callables within the Julia code of the corresponding objective functions and derivatives.
res – Names of callables within the Julia code of the corresponding objective functions and derivatives.
sres – Names of callables within the Julia code of the corresponding objective functions and derivatives.
- class pypesto.objective.julia.PEtabJlObjective(module: str, source_file: str | None = None, petab_problem_name: str = 'petabProblem', precompile: bool = True, force_compile: bool = False)[source]
Bases:
JuliaObjective
Wrapper around an objective defined in PEtab.jl.
- Parameters:
module – Name of the julia module containing the objective.
source_file – Julia source file. Defaults to “{module}.jl”.
petab_problem_name – Name of the petab problem variable in the julia module.