Skip to content

Conversation

@mauro3
Copy link
Contributor

@mauro3 mauro3 commented Feb 28, 2020

As discussed on slack, this allows to use a sparse jacobian for out-of-place objective functions. This works for my case but probably could be done more general.

The solve time of https://gist.github.com/mauro3/e85c85a4257a46ed73999b08f9b80ec2 (a FD PDE code) improves from >100s to <1s with this PR.

@coveralls
Copy link

coveralls commented Feb 28, 2020

Coverage Status

Coverage decreased (-2.1%) to 84.793% when pulling c68e2ba on mauro3:m3/sparse_jac into d565aed on JuliaDiffEq:master.

@codecov
Copy link

codecov bot commented Feb 28, 2020

Codecov Report

Merging #1049 into master will increase coverage by 0.14%.
The diff coverage is 94.44%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1049      +/-   ##
==========================================
+ Coverage   76.87%   77.02%   +0.14%     
==========================================
  Files          95       95              
  Lines       31107    31044      -63     
==========================================
- Hits        23914    23911       -3     
+ Misses       7193     7133      -60
Impacted Files Coverage Δ
src/derivative_wrappers.jl 88.23% <100%> (+5.19%) ⬆️
src/derivative_utils.jl 74.82% <85.71%> (+0.35%) ⬆️
src/caches/kencarp_kvaerno_caches.jl 92.3% <0%> (-1.1%) ⬇️
src/integrators/integrator_utils.jl 88.05% <0%> (-1%) ⬇️
src/alg_utils.jl 27.09% <0%> (-0.23%) ⬇️
src/solve.jl 92.5% <0%> (+20.51%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d565aed...c68e2ba. Read the comment docs.

@ChrisRackauckas
Copy link
Member

Thanks! Can we get a test on this?

@mauro3
Copy link
Contributor Author

mauro3 commented Feb 28, 2020

Which file to add the test?

Copy link
Member

@YingboMa YingboMa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot! Maybe we should add the interface factorization(A) -> FactorizationType in ArrayInterface.

@ChrisRackauckas
Copy link
Member

Thanks a lot! Maybe we should add the interface factorization(A) -> FactorizationType in ArrayInterface.

Yeah, that's what would need to happen.

@mauro3
Copy link
Contributor Author

mauro3 commented Feb 28, 2020

I'll add some tests and update the PR to use Yingbo's ArrayInterface changes.

for prob in map(f->ODEProblem(f,u0,tspan),
[ODEFunction(f,colorvec=colors,jac_prototype=jac_sp),
ODEFunction(f,jac_prototype=jac_sp),
#ODEFunction(f,colorvec=colors) # this one fails both the u[end] and length tests
Copy link
Contributor Author

@mauro3 mauro3 Feb 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any idea why the commented-out test would behave differently?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because one must have sparsity to get sparse jacobian work appropriately.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still the case now with our update? Because some tests still behave erratically.

@mauro3
Copy link
Contributor Author

mauro3 commented Feb 28, 2020

This will now fail tests because it needs JuliaArrays/ArrayInterface.jl#39.

I added some tests but I don't know to test the type of the used Jacobian.

Oh, and I should add OOP tests...

Edit: ok some tests are failing locally, so, it will need some more work.

@mauro3 mauro3 force-pushed the m3/sparse_jac branch 2 times, most recently from e30ce3e to 8ac8574 Compare February 28, 2020 22:04
- tests are failing for SDIRK methods, needs investigating
Comment on lines +66 to +74
isbroken = i==3 && (
(f, ad, tol) == (f_oop, true, nothing) ||
(f, ad, Solver, tol) == (f_oop, false, Trapezoid, nothing) ||
(f, Solver, tol) == (f_ip, Trapezoid, nothing) ||
(f, Solver) == (f_oop, Rodas5) ||
(f, Solver) == (f_ip, Rodas5) ||
(f, Solver) == (f_oop, KenCarp4) ||
(f, Solver) == (f_ip, KenCarp4)
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These failing tests need investigation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't expect colors without sparsity to work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, the color stuff should be independent of the matrix type of J.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are still "broken".

@mauro3
Copy link
Contributor Author

mauro3 commented Mar 2, 2020

The tests failed because the Jacobians sometimes got converted to dense arrays. I updated all the instances where I think that occurred. However, I do not fully understand the code, so this needs a careful review!

Also note that with JuliaArrays/ArrayInterface.jl#39, CI should now pass. (Although I haven't run the full test suite locally... but the new tests did pass locally.)

@mauro3 mauro3 requested a review from YingboMa March 2, 2020 21:46
ODEFunction(f,colorvec=colors)
]))
isbroken = i==3 && (
(f, ad, tol) == (f_oop, true, nothing) ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all with AD fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only those with ODEFunction(f,colorvec=colors), and Trapezoid passes there too. Note that they are not completely wrong, just about a factor 10 larger (different) error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a closer look at the broken tests:maximum(sol_std.u[end].-sol.u[end]) is around 1e-5 for tol=1e-10 and around 1e-3 for tol=nothing.

@mauro3
Copy link
Contributor Author

mauro3 commented Mar 3, 2020

It looks like that this touches a lot of the code from PR #937 of @huanglangwen. Maybe @huanglangwen has time to look at this?

@mauro3 mauro3 mentioned this pull request Mar 4, 2020
@mauro3
Copy link
Contributor Author

mauro3 commented Mar 4, 2020

Tests will fail because it now needs SciML/DiffEqBase.jl#449.

@mauro3
Copy link
Contributor Author

mauro3 commented Mar 5, 2020

The tests pass (apart from https://travis-ci.org/JuliaDiffEq/OrdinaryDiffEq.jl/jobs/658621217?utm_medium=notification&utm_source=github_status, which is due to SciML/DiffEqBase.jl#449 needing changes in DelayDiffEq) and I think this is ready to be merged.

For the broken tests, I would suggest to create an issue to not forget about them.

@ChrisRackauckas ChrisRackauckas merged commit 0863dab into SciML:master Mar 5, 2020
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

Successfully merging this pull request may close these issues.

5 participants