SciML / diffeqpy

Solving differential equations in Python using DifferentialEquations.jl and the SciML Scientific Machine Learning organization
MIT License
508 stars 39 forks source link

Error when importing de #135

Closed natasa-pavlov closed 1 month ago

natasa-pavlov commented 5 months ago

Question❓

I'm having issues when I run the line from diffeqpy import de in Python 3.9.6 and with Julia 1.8.3. installed.

I get the following error:

>>> from diffeqpy import de
  Activating project at `~/.julia/environments/diffeqpy`
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/natasa/Library/Python/3.9/lib/python/site-packages/diffeqpy/de.py", line 5, in <module>
    de.jit = Main.seval("jit(x) = typeof(x).name.wrapper(ModelingToolkit.modelingtoolkitize(x), x.u0, x.tspan, x.p)") # kinda hackey
  File "/Users/natasa/.julia/packages/PythonCall/wXfah/src/jlwrap/any.jl", line 204, in __setattr__
    self._jl_callmethod($(pyjl_methodnum(pyjlany_setattr)), k, v)
AttributeError: Julia: cannot assign variables in other modules

Any feedback will be much appreciated!

ChrisRackauckas commented 4 months ago

Are you sure you're on the latest versions of the packages?

HuynhTran0301 commented 1 month ago

I have the same problem. I use Python 3.9.13, but I have several versions of Julia, ranging from 1.8.x to 1.10.x. I have installed the latest version of diffeqpy. When I implemented the ode it did not have the issue. How could I fix it?

ChrisRackauckas commented 1 month ago

@LilithHafner can you look into this?

LilithHafner commented 1 month ago

I'm having trouble reproducing this issue. I've tried on MacOS 13.6.3 on apple silicon with Julia 1.10.3 and python 3.9.13, using diffeqpy version 2.4.1 and juliacall version 0.9.20. (I've also tried on Asahi linux with a variety over versions).

Would either of you be willing to report more detailed reproduction instructions?

Some useful things to know would be

(@diffeqpy) pkg> st Status ~/.julia/environments/diffeqpy/Project.toml [0c46a032] DifferentialEquations v7.13.0 [961ee093] ModelingToolkit v9.15.0 [6099a3de] PythonCall v0.9.20



I'll try to debug and fix this without reproducing it, but it would be much more effective if I can get the error to appear locally. Thanks!
LilithHafner commented 1 month ago

I'm guessing that updating to Julia 1.9 or higher will fix this (see: https://github.com/JuliaLang/julia/issues/54607)

I can also prepare a PR to this package that works around this behavior if @ChrisRackauckas would like us to continue supporting versions of Julia prior to 1.9.

I mistakenly assumed that @HuynhTran0301 reproduced this error using Julia 1.10; I will try to convince diffeqpy to use Julia 1.8 instead and see if I can reproduce the issue then.

ChrisRackauckas commented 1 month ago

I mistakingly believed this was reproduced with Julia v1.10, but since it was demonstrated to actually only be v1.8 and below, I'm willing to say that doesn't need to be solved. The new v1.10 LTS will be coming out rather soon, so it won't even be easy for most people to find pre v1.10 versions. We're fine just supporting LTS and above.

HuynhTran0301 commented 1 month ago

Thank you for the reply from @LilithHafner I have checked the package version as you suggested. I run the diffeqpy on Python 3.9.13. with the version 2.4.1. However, I am not sure about the Julia version. I have installed different versions of Julia from 1.8.5, 1.9.2, 1.9.4 and 1.9.10. After running the code you provided I got the same information as follows:

Status `C:\Users\htran\.julia\environments\diffeqpy\Project.toml`
⌃ [0c46a032] DifferentialEquations v7.10.0
⌃ [961ee093] ModelingToolkit v8.70.0
  [6099a3de] PythonCall v0.9.20

How could I set up the specified version using Julia through PythonCall? As you mentioned the error may be happened for version 1.10 or 1.8.

LilithHafner commented 1 month ago

@HuynhTran0301, you can run this to determine which version of Julia is running:

x@fedora:~$ python
Python 3.12.3 (main, Apr 17 2024, 00:00:00) [GCC 13.2.1 20240316 (Red Hat 13.2.1-7)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from juliacall import Main
>>> Main.seval("versioninfo()")
Julia Version 1.10.3
Commit 0b4590a5507 (2024-04-30 10:59 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (aarch64-linux-gnu)
  CPU: 8 × unknown
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, generic)
Threads: 1 default, 0 interactive, 1 GC (on 8 virtual cores)
Environment:
  JULIA_PYTHONCALL_EXE = /usr/bin/python

How could I set up the specified version using Julia through PythonCall?

I don't know yet but see https://github.com/JuliaPy/PythonCall.jl/discussions/506

HuynhTran0301 commented 1 month ago

@LilithHafner Thank you for your reply. Now I understand why I got the issue, the Julia API is run with Julia version 1.8.5. I am trying to change it to 1.9.x. I will update the information.