Skip to content

Commit

Permalink
Merge pull request #36 from tkf/fix
Browse files Browse the repository at this point in the history
Fix DAE and DDE tests
  • Loading branch information
ChrisRackauckas authored Dec 21, 2018
2 parents b3f77ad + 56304cd commit 01dd943
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 26 deletions.
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,12 @@ before_install:

- pip install --quiet tox-travis
script:

# Create an environment first so that we know what to use for $PYTHON:
- tox --notest

# PyCall requires to know the right Python executable to use:
- export PYTHON="$(echo $PWD/.tox/py*/bin/python)"
- echo "$PYTHON"

- tox -- --cov diffeqpy
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,11 @@ sol = de.solve(prob)

Additionally, you can directly define the functions in Julia. This will allow
for more specialization and could be helpful to increase the efficiency over
the Numba version for repeat or long calls. This is done via `de.eval`:
the Numba version for repeat or long calls. This is done via `julia.Main.eval`:

```py
jul_f = de.eval("(u,p,t)->-u") # Define the anonymous function in Julia
from julia import Main
jul_f = Main.eval("(u,p,t)->-u") # Define the anonymous function in Julia
prob = de.ODEProblem(jul_f, u0, tspan)
sol = de.solve(prob)
```
Expand Down Expand Up @@ -214,7 +215,7 @@ sol = de.solve(prob)
or using a Julia function:

```py
jul_f = de.eval("""
jul_f = Main.eval("""
function f(du,u,p,t)
x, y, z = u
sigma, rho, beta = p
Expand Down Expand Up @@ -366,7 +367,7 @@ def f(du,u,p,t):
resid3 = u[0] + u[1] + u[2] - 1.0
return [resid1,resid2,resid3]

u0 = [1.0, 0, 0]
u0 = [1.0, 0.0, 0.0]
du0 = [-0.04, 0.04, 0.0]
tspan = (0.0,100000.0)
differential_vars = [True,True,False]
Expand Down Expand Up @@ -404,14 +405,14 @@ the solver accuracy by accurately stepping at the points of discontinuity.
Together this is:

```py
f = de.eval("""
f = Main.eval("""
function f(du, u, h, p, t)
du[1] = 1.1/(1 + sqrt(10)*(h(p, t-20)[1])^(5/4)) - 10*u[1]/(1 + 40*u[2])
du[2] = 100*u[1]/(1 + 40*u[2]) - 2.43*u[2]
end""")
u0 = [1.05767027/3, 1.030713491/3]

h = de.eval("""
h = Main.eval("""
function h(p,t)
[1.05767027/3, 1.030713491/3]
end
Expand Down
15 changes: 7 additions & 8 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@ environment:
matrix:

# For Python versions available on Appveyor, see
# http://www.appveyor.com/docs/installed-software#python
# The list here is complete (excluding Python 2.6, which
# isn't covered by this document) at the time of writing.
# https://www.appveyor.com/docs/windows-images-software/#python

- PYTHON: "C:\\Python27-x64"
- PYTHONDIR: "C:\\Python27-x64"
JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/1.0/julia-1.0.1-win64.exe"
- PYTHON: "C:\\Python36-x64"
- PYTHONDIR: "C:\\Python36-x64"
JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/1.0/julia-1.0.1-win64.exe"

matrix:
allow_failures:
- PYTHON: "C:\\Python27-x64"
- PYTHONDIR: "C:\\Python27-x64"

notifications:
- provider: Email
Expand All @@ -38,14 +36,15 @@ install:
- set PATH=C:\projects\julia\bin;%PATH%

# Install Python packages
- "%PYTHON%\\python.exe -m pip install --quiet tox"
- "%PYTHONDIR%\\python.exe -m pip install --quiet tox"

build_script:
# Empty so that it doesn't think it needs Visual Studio?
- echo 'test'

test_script:
- "%PYTHON%\\scripts\\tox -- --cov diffeqpy"
- "SET PYTHON=%PYTHONDIR%\\python.exe"
- "%PYTHONDIR%\\scripts\\tox -- --cov diffeqpy"

artifacts:
# bdist_wheel puts your built wheel in the dist directory
Expand Down
1 change: 1 addition & 0 deletions diffeqpy/install.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Pkg
Pkg.add("DifferentialEquations")
Pkg.add("DiffEqBase")
Pkg.add("PyCall")
using DifferentialEquations
using PyCall
2 changes: 1 addition & 1 deletion diffeqpy/tests/test_dae.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def f(du,u,p,t):
resid3 = u[0] + u[1] + u[2] - 1.0
return [resid1,resid2,resid3]

u0 = [1.0, 0, 0]
u0 = [1.0, 0.0, 0.0]
du0 = [-0.04, 0.04, 0.0]
tspan = (0.0,100000.0)
differential_vars = [True,True,False]
Expand Down
29 changes: 18 additions & 11 deletions diffeqpy/tests/test_dde.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
from julia import Main

from .. import de


def test():
def f(du,u,p,t):
resid1 = - 0.04*u[0] + 1e4*u[1]*u[2] - du[0]
resid2 = + 0.04*u[0] - 3e7*u[1]**2 - 1e4*u[1]*u[2] - du[1]
resid3 = u[0] + u[1] + u[2] - 1.0
return [resid1,resid2,resid3]
f = Main.eval("""
function f(du, u, h, p, t)
du[1] = 1.1/(1 + sqrt(10)*(h(p, t-20)[1])^(5/4)) - 10*u[1]/(1 + 40*u[2])
du[2] = 100*u[1]/(1 + 40*u[2]) - 2.43*u[2]
end""")
u0 = [1.05767027/3, 1.030713491/3]

h = Main.eval("""
function h(p,t)
[1.05767027/3, 1.030713491/3]
end
""")

u0 = [1.0, 0, 0]
du0 = [-0.04, 0.04, 0.0]
tspan = (0.0,100000.0)
differential_vars = [True,True,False]
prob = de.DAEProblem(f,du0,u0,tspan,differential_vars=differential_vars)
sol = de.solve(prob)
tspan = (0.0, 100.0)
constant_lags = [20.0]
prob = de.DDEProblem(f,u0,h,tspan,constant_lags=constant_lags)
sol = de.solve(prob,saveat=0.1)
5 changes: 5 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@ passenv =
# Allow a workaround for "error initializing LibGit2 module":
# https://github.com/JuliaLang/julia/issues/18693
SSL_CERT_FILE

# PyCall uses $PYTHON to configure Python executable. It is
# useful to specify this in CI so that `diffeqpy.install()` can
# directly configure PyCall.
PYTHON

0 comments on commit 01dd943

Please sign in to comment.