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

Terminating integration based on maxiters results in RuntimeError #112

Closed laurent90git closed 8 months ago

laurent90git commented 1 year ago

Hi,

I have issues using the library if I specifiy a maximmum number of step (maxiters) and this number of steps is actually reached during the integration.

Here is an example:

from julia.api import Julia
jl = Julia(compiled_modules=False)
from diffeqpy import de

def f(u,p,t):
    return -2*u

u0 = 0.5
tspan = (0., 1.)
tol = 1e-10

prob = de.ODEProblem(f, u0, tspan)
sol = de.solve(prob, alg=de.RadauIIA5(autodiff=False), maxiters=1000, abstol=tol/10, reltol=tol) # works
sol = de.solve(prob, alg=de.RadauIIA5(autodiff=False), maxiters=10, abstol=tol/10, reltol=tol) # fails

import matplotlib.pyplot as plt
plt.plot(sol.t,sol.u)
plt.show()

Here is the obtained error message:

Traceback (most recent call last):

  File "[...]/test_diffeqpy.py", line 24, in <module>
    sol = de.solve(prob, alg=de.RadauIIA5(autodiff=False), maxiters=10, abstol=tol/10, reltol=tol)

RuntimeError: <PyCall.jlwrap (in a Julia function called from Python)
JULIA: IOError: write: broken pipe (EPIPE)
Stacktrace:
 [1] uv_write(s::Base.PipeEndpoint, p::Ptr{UInt8}, n::UInt64)
   @ Base ./stream.jl:1064
 [2] unsafe_write(s::Base.PipeEndpoint, p::Ptr{UInt8}, n::UInt64)
   @ Base ./stream.jl:1118>

Do you have any idea on how to circumvent this issue or resolve it ?

I am using the Python package "julia" version 0.6.1 with Python 3.8.3 and IPython 7.16.1. Julia itself is version 1.8.2.

EDIT: it is possible that this error simply comes from Julia trying to print a warning (like "too many steps"). Trying the following also fails:

from julia import Main
Main.eval('println("Hello World")')
File "[...]/anaconda3/lib/python3.8/site-packages/julia-0.6.1-py3.8.egg/julia/core.py", line 609, in check_exception
    raise JuliaError(u'Exception \'{}\' occurred while calling julia code:\n{}'

JuliaError: Exception 'IOError: write: broken pipe (EPIPE)' occurred while calling julia code:
println("Hello World")

Thanks in advance for you help !

laurent90git commented 1 year ago

Turns out using verbose=False solves the issue. I guess the problem is Julia trying to print something through the Python console and somehow not being able to.

ChrisRackauckas commented 1 year ago

Yeah this looks like an upstream pyjulia issue.

ChrisRackauckas commented 8 months ago

Fixed by transition to PythonCall