Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code runs in Julia but not in pyjulia #229

Open
michaelkyu opened this issue Dec 21, 2018 · 1 comment
Open

Code runs in Julia but not in pyjulia #229

michaelkyu opened this issue Dec 21, 2018 · 1 comment

Comments

@michaelkyu
Copy link

The following code to solve an ODE using DifferentialEquations.jl does not work in pyjulia. Strangely, the code works in a native Julia terminal (v1.0.2).

I am using the latest 'master' branch of pyjulia.

from julia import Main

Main.eval("""
using DifferentialEquations

function lorenz(u,p,t)
 dx = 10.0*(u[2]-u[1])
 dy = u[1]*(28.0-u[3]) - u[2]
 dz = u[1]*u[2] - (8/3)*u[3]
 [dx,dy,dz]
end

u0 = [1.0;0.0;0.0]
tspan = (0.0,100.0)
prob = ODEProblem(lorenz,u0,tspan)
solve(prob,Tsit5())
""")

I get the error

---------------------------------------------------------------------------
JuliaError                                Traceback (most recent call last)
<ipython-input-4-326c146306c2> in <module>
     15 prob = ODEProblem(lorenz,u0,tspan)
     16 solve(prob,Tsit5())
---> 17 """)

~/.pyenv/versions/3.7.0/lib/python3.7/site-packages/julia/core.py in eval(self, src)
    773 
    774         if res is None:
--> 775             self.check_exception("convert(PyCall.PyObject, {})".format(src))
    776         return self._as_pyobj(res)
    777 

~/.pyenv/versions/3.7.0/lib/python3.7/site-packages/julia/core.py in check_exception(self, src)
    750             exception = sprint(showerror, self._as_pyobj(res))
    751         raise JuliaError(u'Exception \'{}\' occurred while calling julia code:\n{}'
--> 752                          .format(exception, src))
    753 
    754     def _typeof_julia_exception_in_transit(self):

JuliaError: Exception 'MethodError: no method matching strides(::ODESolution{Float64,2,Array{Array{Float64,1},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Float64,1},1},1},ODEProblem{Array{Float64,1},Tuple{Float64,Float64},false,Nothing,ODEFunction{false,typeof(lorenz),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Nothing,DiffEqBase.StandardODEProblem},Tsit5,OrdinaryDiffEq.InterpolationData{ODEFunction{false,typeof(lorenz),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Float64,1},1},Array{Float64,1},Array{Array{Array{Float64,1},1},1},OrdinaryDiffEq.Tsit5ConstantCache{Float64,Float64}}})
Closest candidates are:
  strides(!Matched::SubArray) at subarray.jl:264
  strides(!Matched::Base.CodeUnits) at strings/basic.jl:696
  strides(!Matched::PermutedDimsArray{T,N,perm,iperm,AA} where AA<:AbstractArray where iperm) where {T, N, perm} at permuteddimsarray.jl:62
  ...' occurred while calling julia code:
convert(PyCall.PyObject, 
using DifferentialEquations

function lorenz(u,p,t)
 dx = 10.0*(u[2]-u[1])
 dy = u[1]*(28.0-u[3]) - u[2]
 dz = u[1]*u[2] - (8/3)*u[3]
 [dx,dy,dz]
end

u0 = [1.0;0.0;0.0]
tspan = (0.0,100.0)
prob = ODEProblem(lorenz,u0,tspan)
solve(prob,Tsit5())
)

@tkf
Copy link
Member

tkf commented Dec 22, 2018

There is no good solution for it at the moment. The right solution would be JuliaPy/PyCall.jl#617

For now, using diffeqpy would be the way to go. Maybe something like:

from diffeqpy import de
prob = Main.prob
sol = de.solve(prob, de.Tsit5)

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

No branches or pull requests

2 participants