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

PyCall no longer used #124

Closed PallHaraldsson closed 8 months ago

PallHaraldsson commented 8 months ago

Do not merge. I'm not sure a version has been tagged. This is just a suggested text. PyCall is also still mentioned in two other files.

ChrisRackauckas commented 8 months ago

The version is already tagged, so it's good to improve this.

PallHaraldsson commented 8 months ago

That was quick. I'm not really a SciML user or dev, so I didn't need credit.

I'm at best a tester of SciML, out of curiosity to see how well PythonCall works with it (since I suggested that change). I get a wall of text, ERRORs and Warnings, likely not because of it though.

While I think I know why, many Python users would probably not (nor would have my environment, the likely cause):

>>> diffeqpy.install()
   Resolving package versions...
  No Changes to `~/.julia/environments/v1.9/Project.toml`
  No Changes to `~/.julia/environments/v1.9/Manifest.toml`
Precompiling project...
  ✗ REPLCompletions
  ✗ Adapt → AdaptStaticArraysExt
  ✗ ArbFloats
  ✗ SteadyStateDiffEq
  ✗ DifferentialEquations
  147 dependencies successfully precompiled in 217 seconds. 282 already precompiled.
  5 dependencies errored. To see a full report either run `import Pkg; Pkg.precompile()` or load the packages
  26 dependencies had warnings during precompilation:
┌ SparseDiffTools [47a9eef4-7e08-11e9-0b38-333d64bd3804]
│  ERROR: LoadError: ArgumentError: Package AdaptStaticArraysCoreExt does not have Adapt in its dependencies:
│  - You may have a partially installed environment. Try `Pkg.instantiate()`

[..]

┌ ShaderAbstractions [65257c39-d410-5151-9873-9b3e5be5013e]
│  ERROR: LoadError: ArgumentError: Package AdaptStaticArraysCoreExt does not have Adapt in its dependencies:
│  - You may have a partially installed environment. Try `Pkg.instantiate()`

│  ┌ Error: Error during loading of extension AdaptStaticArraysExt of Adapt, use `Base.retry_load_extensions()` to retry.

│  WARNING: Method definition lmul!(LinearAlgebra.Givens{T} where T, Nothing) in module GenericSVD at /home/pharaldsson/.julia/packages/GenericSVD/cT5Cu/src/utils.jl:28 overwritten in module GenericLinearAlgebra at /home/pharaldsson/.julia/packages/GenericLinearAlgebra/skQkq/src/svd.jl:7.
│    ** incremental compilation may be fatally broken for this module **

┌ GridLayoutBase [3955a311-db13-416c-9275-1d80ed98e5e9]
│  ERROR: LoadError: ArgumentError: Package AdaptStaticArraysCoreExt does not have Adapt in its dependencies:
│  - You may have a partially installed environment. Try `Pkg.instantiate()`
│    to ensure all packages in the environment are installed.
│  - Or, if you have AdaptStaticArraysCoreExt checked out for development and have
│    added Adapt as a dependency but haven't updated your primary
│    environment's manifest file, try `Pkg.resolve()`.

ERROR: LoadError: Failed to precompile DifferentialEquations [0c46a032-eb83-5123-abaf-570d42b7fbaa] to "/home/pharaldsson/.julia/compiled/v1.9/DifferentialEquations/jl_lQJf1z".
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] compilecache(pkg::Base.PkgId, path::String, internal_stderr::IO, internal_stdout::IO, keep_loaded_modules::Bool)
   @ Base ./loading.jl:2300
 [3] compilecache
   @ ./loading.jl:2167 [inlined]
 [4] _require(pkg::Base.PkgId, env::String)
   @ Base ./loading.jl:1805
 [5] _require_prelocked(uuidkey::Base.PkgId, env::String)
   @ Base ./loading.jl:1660
 [6] macro expansion
   @ ./loading.jl:1648 [inlined]
 [7] macro expansion
   @ ./lock.jl:267 [inlined]
 [8] require(into::Module, mod::Symbol)
   @ Base ./loading.jl:1611
in expression starting at /home/pharaldsson/.local/lib/python3.10/site-packages/diffeqpy/install.jl:6
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pharaldsson/.local/lib/python3.10/site-packages/diffeqpy/__init__.py", line 11, in install
    subprocess.check_call(['julia', os.path.join(script_dir, 'install.jl')])
  File "/usr/lib/python3.10/subprocess.py", line 369, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['julia', '/home/pharaldsson/.local/lib/python3.10/site-packages/diffeqpy/install.jl']' returned non-zero exit status 1.
ChrisRackauckas commented 8 months ago

It's because you have weird packages in your environment. Normal people from Python won't have a whole environment full of junk to start with that block the packages from installing.

PallHaraldsson commented 8 months ago

Yes, what I thought. Is there a way or should there be a way that the package would use a clean environment? Python users shouldn't have to know or care about what Julia environments are ideally. Nor if they later start messing with Julia and install packages, screw things up for already installed Python "[impure] world".

ChrisRackauckas commented 8 months ago

@LilithHafner do you know if there's a way that we can force this to always use an environment we control?

LilithHafner commented 8 months ago

Strange. I thaught this did it

https://github.com/SciML/diffeqpy/blob/df65e85e3405d1689f065e9b3959749c3775ac6d/diffeqpy/__init__.py#L46

LilithHafner commented 8 months ago

What version of diffeqpy are you using?

PallHaraldsson commented 8 months ago

EDIT: it works now with later version (installation, didn't go further yet).

I had version 1.1.0, or so I recall, pretty sure (maybe can't confirm since I now updated to later):

I had to do (I suppose will be default soon, just quote new) and am trying again: pip install diffeqpy=2.2.0

I think it may be working now, i.e. I'm not seeing my environment, only that SciML is huge):

   Updating `~/.julia/environments/diffeqpy/Project.toml`
  [0c46a032] + DifferentialEquations v7.11.0
  [961ee093] + ModelingToolkit v8.72.2
  [1dea7af3] + OrdinaryDiffEq v6.58.0
  [6099a3de] + PythonCall v0.9.14
    Updating `~/.julia/environments/diffeqpy/Manifest.toml`
  [47edcb42] + ADTypes v0.2.4
⌅ [c3fe647b] + AbstractAlgebra v0.32.5
[..]

At least not all at latest, but plausibly not a problem.