Skip to content

Commit 97a39dd

Browse files
Merge pull request #129 from JuliaDiff/downstream
Revert non-square and add downstream test
2 parents 89654d7 + 96029ba commit 97a39dd

File tree

6 files changed

+125
-4
lines changed

6 files changed

+125
-4
lines changed

.github/workflows/CI.yml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: CI
2+
on:
3+
pull_request:
4+
branches:
5+
- master
6+
push:
7+
branches:
8+
- master
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
#fail-fast: false
14+
matrix:
15+
group:
16+
- Core
17+
- Downstream
18+
version:
19+
- '1'
20+
- '1.6'
21+
steps:
22+
- uses: actions/checkout@v2
23+
- uses: julia-actions/setup-julia@v1
24+
with:
25+
version: ${{ matrix.version }}
26+
- uses: actions/cache@v1
27+
env:
28+
cache-name: cache-artifacts
29+
with:
30+
path: ~/.julia/artifacts
31+
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
32+
restore-keys: |
33+
${{ runner.os }}-test-${{ env.cache-name }}-
34+
${{ runner.os }}-test-
35+
${{ runner.os }}-
36+
- uses: julia-actions/julia-buildpkg@v1
37+
- uses: julia-actions/julia-runtest@v1
38+
env:
39+
GROUP: ${{ matrix.group }}
40+
- uses: julia-actions/julia-processcoverage@v1
41+
- uses: codecov/codecov-action@v1
42+
with:
43+
file: lcov.info

.github/workflows/Downstream.yml

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: IntegrationTest
2+
on:
3+
push:
4+
branches: [master]
5+
tags: [v*]
6+
pull_request:
7+
8+
jobs:
9+
test:
10+
name: ${{ matrix.package.repo }}/${{ matrix.package.group }}/${{ matrix.julia-version }}
11+
runs-on: ${{ matrix.os }}
12+
env:
13+
GROUP: ${{ matrix.package.group }}
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
julia-version: [1,1.6]
18+
os: [ubuntu-latest]
19+
package:
20+
- {user: SciML, repo: OrdinaryDiffEq.jl, group: InterfaceII}
21+
steps:
22+
- uses: actions/checkout@v2
23+
- uses: julia-actions/setup-julia@v1
24+
with:
25+
version: ${{ matrix.julia-version }}
26+
arch: x64
27+
- uses: julia-actions/julia-buildpkg@latest
28+
- name: Clone Downstream
29+
uses: actions/checkout@v2
30+
with:
31+
repository: ${{ matrix.package.user }}/${{ matrix.package.repo }}
32+
path: downstream
33+
- name: Load this and run the downstream tests
34+
shell: julia --color=yes --project=downstream {0}
35+
run: |
36+
using Pkg
37+
try
38+
# force it to use this PR's version of the package
39+
Pkg.develop(PackageSpec(path=".")) # resolver may fail with main deps
40+
Pkg.update()
41+
Pkg.test() # resolver may fail with test time deps
42+
catch err
43+
err isa Pkg.Resolve.ResolverError || rethrow()
44+
# If we can't resolve that means this is incompatible by SemVer and this is fine
45+
# It means we marked this as a breaking change, so we don't need to worry about
46+
# Mistakenly introducing a breaking change, as we have intentionally made one
47+
@info "Not compatible with this release. No problem." exception=err
48+
exit(0) # Exit immediately, as a success
49+
end

src/jacobians.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,8 @@ function finite_difference_jacobian!(
373373
# Now return x1 back to its original value
374374
ArrayInterface.allowed_setindex!(x1, x1_save, color_i)
375375
else # Perturb along the colorvec vector
376-
idx = findfirst(isequal(color_i), _color)
377-
tmp = norm(x1[idx])
376+
@. fx1 = x1 * (_color == color_i)
377+
tmp = norm(fx1)
378378
epsilon = compute_epsilon(Val(:forward), sqrt(tmp), relstep, absstep, dir)
379379
@. x1 = x1 + epsilon * (_color == color_i)
380380
f(fx1, x1)
@@ -416,8 +416,8 @@ function finite_difference_jacobian!(
416416
@. J[:,color_i] = (vfx1 - vfx) / 2epsilon
417417
ArrayInterface.allowed_setindex!(x1, x_save, color_i)
418418
else # Perturb along the colorvec vector
419-
idx = findfirst(isequal(color_i), _color)
420-
tmp = norm(x1[idx])
419+
@. fx1 = x1 * (_color == color_i)
420+
tmp = norm(fx1)
421421
epsilon = compute_epsilon(Val(:central), sqrt(tmp), relstep, absstep, dir)
422422
@. x1 = x1 + epsilon * (_color == color_i)
423423
@. x = x - epsilon * (_color == color_i)

test/downstream/Project.toml

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
[deps]
22
FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41"
3+
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
34
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using OrdinaryDiffEq, ForwardDiff, LinearAlgebra, Test
2+
3+
const nknots = 10
4+
const h = 1.0/(nknots+1)
5+
x = range(0, step=h, length=nknots)
6+
u0 = sin.(π*x)
7+
8+
@inline function f(du,u,p,t)
9+
du .= zero(eltype(u))
10+
u₃ = @view u[3:end]
11+
u₂ = @view u[2:end-1]
12+
u₁ = @view u[1:end-2]
13+
@. du[2:end-1] = p[1]*((u₃ - 2*u₂ + u₁)/(h^2.0))
14+
nothing
15+
end
16+
17+
p_true = [0.42]
18+
jac_proto = Tridiagonal(similar(u0,nknots-1), similar(u0), similar(u0, nknots-1))
19+
prob = ODEProblem(ODEFunction(f,jac_prototype=jac_proto), u0, (0.0,1.0), p_true)
20+
sol_true = solve(prob, Rodas4P(), saveat=0.1)
21+
22+
function loss(p)
23+
_prob = remake(prob, p=p)
24+
sol = solve(_prob, Rodas4P(autodiff=false), saveat=0.1)
25+
sum((sol .- sol_true).^2)
26+
end
27+
@test ForwardDiff.gradient(loss, [1.0])[1] 0.6662949361011025

test/runtests.jl

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ if GROUP == "All" || GROUP == "Downstream"
2323
activate_downstream_env()
2424
@time @safetestset "ODEs" begin
2525
import OrdinaryDiffEq
26+
@time @safetestset "OrdinaryDiffEq Tridiagonal" begin include("downstream/ordinarydiffeq_tridiagonal_solve.jl") end
2627
include(joinpath(dirname(pathof(OrdinaryDiffEq)), "..", "test/interface/sparsediff_tests.jl"))
2728
end
2829
end

0 commit comments

Comments
 (0)