Skip to content

Conversation

Kishore96in
Copy link

Checklist

  • Appropriate tests were added (I think tests are not needed for this change)
  • Any code changes were done in a way that does not break public API (does not affect the API in any way)
  • All documentation related to code changes were updated (I could not find Jill mentioned anywhere in the documentation)
  • The new code follows the
    contributor guidelines, in particular the SciML Style Guide and
    COLPRAC.
  • Any new documentation only uses public API

Additional context

If the user already has Julia installed, there is no need to require them to also have jill installed.

Before this change,

$ ipython

In [1]: import diffeqpy
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[1], line 1
----> 1 import diffeqpy

File /usr/lib/python3.13/site-packages/diffeqpy/__init__.py:2
      1 import shutil
----> 2 from jill.install import install_julia
      4 # juliacall must be loaded after `_ensure_julia_installed()` is run,
      5 # so this import is in `load_julia_packages()`
      6 # from juliacall import Main
      8 def _find_julia():
      9     # TODO: this should probably fallback to query jill

ModuleNotFoundError: No module named 'jill'

After this change

With neither Jill nor Julia installed:

$ ipython

In [1]: from diffeqpy import de
No Julia version found. Installing Julia.
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[1], line 1
----> 1 from diffeqpy import de

File /usr/lib/python3.13/site-packages/diffeqpy/de.py:3
      1 import sys
      2 from . import load_julia_packages
----> 3 de, _, _ = load_julia_packages("DifferentialEquations", "ModelingToolkit", "PythonCall")
      4 from juliacall import Main
      5 de.seval("jit(x) = typeof(x).name.wrapper(Main.ModelingToolkit.complete(Main.ModelingToolkit.modelingtoolkitize(x); split = false), [], x.tspan)") # kinda hackey

File /usr/lib/python3.13/site-packages/diffeqpy/__init__.py:33, in load_julia_packages(*names)
     28 """
     29 Load Julia packages and return references to them, automatically installing julia and
     30 the packages as necessary.
     31 """
     32 # This is terrifying to many people. However, it seems SciML takes pragmatic approach.
---> 33 _ensure_julia_installed()
     35 script = """import Pkg
     36 Pkg.activate(\"diffeqpy\", shared=true)
     37 try
   (...)     43 end
     44 {0}""".format(", ".join(names), ", ".join(f'"{name}"' for name in names))
     46 # Unfortunately, `seval` doesn't support multi-line strings
     47 # https://github.com/JuliaPy/PythonCall.jl/issues/433

File /usr/lib/python3.13/site-packages/diffeqpy/__init__.py:20, in _ensure_julia_installed()
     18 if not _find_julia():
     19     print("No Julia version found. Installing Julia.")
---> 20     install_julia()
     21     if not _find_julia():
     22         raise RuntimeError(
     23             "Julia installed with jill but `julia` binary cannot be found in the path"
     24         )

File /usr/lib/python3.13/site-packages/diffeqpy/__init__.py:7, in install_julia()
      6 def install_julia():
----> 7     raise RuntimeError("Could not install Julia as the Jill module was not found.")

RuntimeError: Could not install Julia as the Jill module was not found.

@ChrisRackauckas
Copy link
Member

The code doesn't quite do what is mentioned here though. It uses the jill even if julia is installed, if the jill works. Otherwise it assumes Julia is installed? It seems the logic is inverted.

@Kishore96in
Copy link
Author

@ChrisRackauckas

In _ensure_julia_installed, install_julia is called only if a Julia executable is not available. However, this install_julia function was earlier imported from jill.install unconditionally (in the line from jill.install import install_julia), leading to import diffeqpy failing on systems where Jill is not installed (regardless of whether Julia is installed).

I have now added a comment explaining this. A more detailed explanation is below.

Case by case comparison of old and new behaviour

Case 1: Both Jill and Julia are installed

No change in behaviour, since the install_julia function is never called.

Case 2: Jill is not installed, but Julia is installed

Old

import diffeqpy would fail due to the line from jill.install import install_julia

New

install_julia is defined as a function that raises an error if it is called. However, this function never ends up being called, as the Julia executable is available.

Case 3: Julia is not installed, but Jill is installed.

No change in behaviour, since install_julia is still imported from jill.install.

Case 4: Neither Julia nor Jill are installed.

Old

import diffeqpy would fail due to not being able to import Jill

New

An error is raised mentioning that neither Jill nor Julia are installed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants