Skip to content

Code runs in Julia but not in pyjulia #229

Open
@michaelkyu

Description

@michaelkyu

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())
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions