Skip to content

Conversation

@huanglangwen
Copy link
Contributor

@devmotion
Copy link
Member

@codecov
Copy link

codecov bot commented Aug 14, 2019

Codecov Report

Merging #873 into master will increase coverage by 0.18%.
The diff coverage is 85.05%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #873      +/-   ##
==========================================
+ Coverage   80.16%   80.35%   +0.18%     
==========================================
  Files          92       92              
  Lines       30269    30244      -25     
==========================================
+ Hits        24265    24302      +37     
+ Misses       6004     5942      -62
Impacted Files Coverage Δ
src/caches/rosenbrock_caches.jl 99.58% <100%> (+14.77%) ⬆️
src/tableaus/rosenbrock_tableaus.jl 99.19% <100%> (+0.02%) ⬆️
src/generic_rosenbrock.jl 98.3% <100%> (ø) ⬆️
src/caches/firk_caches.jl 93.75% <50%> (-2.81%) ⬇️
src/integrators/integrator_utils.jl 86.72% <65.62%> (+1.55%) ⬆️
src/caches/adams_bashforth_moulton_caches.jl 80.7% <0%> (+0.44%) ⬆️
src/caches/kencarp_kvaerno_caches.jl 97.02% <0%> (+1.98%) ⬆️
src/caches/sdirk_caches.jl 96.52% <0%> (+3.47%) ⬆️
src/caches/bdf_caches.jl 89.54% <0%> (+3.92%) ⬆️
... and 1 more

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 cd45039...dee2e87. Read the comment docs.

@huanglangwen
Copy link
Contributor Author

It seems the oopgenW is broken when u is a StaticArray. Not sure how to fix it.
https://travis-ci.org/JuliaDiffEq/OrdinaryDiffEq.jl/jobs/571800687

@devmotion
Copy link
Member

I guess it's the first time that someone actually tests the whole logic of oop_generate_W. I think
https://github.com/JuliaDiffEq/OrdinaryDiffEq.jl/blob/cd45039e49eefdc5d60aa72b54f91e84851eb747/src/integrators/integrator_utils.jl#L426-L432
is incorrect, since column vectors with only one entry end up in the second branch. I assume it should be changed to

J = if ndims(u) == 2 # `u` is already a matrix
        u
      else # `u` is a vector
        hcat(u, u)
      end

Can you check if that solves the issue?

To be honest, it still feels very crude to me, the units are incorrect and will fail if the dimension of u is greater than 2.

@ChrisRackauckas
Copy link
Member

Aren't we already vecing u when applying the linear operator? If not, we should, and in that case false .* rate_prototype .* rate_prototype' should work, ever for u a Number.

@devmotion
Copy link
Member

Aren't we already vecing u when applying the linear operator? If not, we should, and in that case false .* rate_prototype .* rate_prototype' should work, ever for u a Number.

I don't see how this is related to the test failure? But I agree that probably we should just replace the snippet above and https://github.com/JuliaDiffEq/OrdinaryDiffEq.jl/blob/cd45039e49eefdc5d60aa72b54f91e84851eb747/src/integrators/integrator_utils.jl#L438 with

J = false .* _vec(u) .* _vec(u)'

That would be much cleaner.

Then we could just branch depending on the type of u for the computation of W (if we do not want to compute one LU factorization, see #672).

@ChrisRackauckas
Copy link
Member

The real difficulty is that we don't have an OOP linsolve interface, which we need to get in order to really complete this I think?

@devmotion
Copy link
Member

And the fact that lu(J) will fail since J is singular, as I just noticed...

@huanglangwen
Copy link
Contributor Author

And the fact that lu(J) will fail since J is singular, as I just noticed...

Your patch works anyway. Shall I push that?

@devmotion
Copy link
Member

And the fact that lu(J) will fail since J is singular, as I just noticed...

Actually, it seems lu(@SMatrix zeros(2,2)) works (and only lu(zeros(2,2)) fails), so I think you could even write

J = false .* _vec(u) .* _vec(u)'
W = if u isa StaticArray
  lu(J)
  elseif u isa Number
    u
  else
    LU{LinearAlgebra.lutype(uEltypeNoUnits)}(Matrix{uEltypeNoUnits}(undef, 0, 0),
                                                 Vector{LinearAlgebra.BlasInt}(undef, 0),
                                                 zero(LinearAlgebra.BlasInt))
  end

instead of https://github.com/JuliaDiffEq/OrdinaryDiffEq.jl/blob/1330fa7a01626a4c334d171a619802475be8d036/src/integrators/integrator_utils.jl#L432-L448

@huanglangwen
Copy link
Contributor Author

The real difficulty is that we don't have an OOP linsolve interface, which we need to get in order to really complete this I think?

What's the motivation to move from k₃ = _reshape(W\-_vec(linsolve_tmp), axes(uprev))?

@YingboMa
Copy link
Member

W\b is wasteful to do at every stage. A better strategy is to factorize it first and reuse the factorized object. Hence we need to add an OOP linsolve interface.

@YingboMa
Copy link
Member

W\b is wasteful to do at every stage. A better strategy is to factorize it first and reuse the factorized object.

Never mind. We want to use factorization methods other than lu, so we need it.

@huanglangwen huanglangwen changed the title add J and W cache for rosenbrock and firk oop add J, W cache and linsolve interface for rosenbrock oop methods and add J cache for firk oop Aug 15, 2019
tmp = zero(rate_prototype)
atmp = similar(u, uEltypeNoUnits)
tab = Rosenbrock23ConstantCache(real(uBottomEltypeNoUnits),identity,identity)
tab = Rosenbrock23ConstantCache(real(uBottomEltypeNoUnits),identity,identity,nothing,nothing,nothing)
Copy link
Member

Choose a reason for hiding this comment

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

I always thought that we shouldn't misuse the oop cache as tableau but rather use separate tableau structs - and even more so with the new fields for J and W.

Copy link
Member

Choose a reason for hiding this comment

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

yeah, it's really just a short hand that always worked... until it didn't.

@huanglangwen
Copy link
Contributor Author

Is this pr good for merge? I want to start a new pr for unifying oop and iip in derivative_utils.jl .

tmp = zero(rate_prototype)
atmp = similar(u, uEltypeNoUnits)
tab = Rosenbrock23ConstantCache(real(uBottomEltypeNoUnits),identity,identity,nothing,nothing,nothing)
tab = Ros23ConstantCache(real(uBottomEltypeNoUnits))
Copy link
Member

@devmotion devmotion Aug 15, 2019

Choose a reason for hiding this comment

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

I think I would prefer the name Rosenbrock23Tableau or something similar, Ros23ConstantCache seems a bit strange to me.

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 agree, but then we need to correct all the tab struct in \tableaus as well as places calling the tabs in \caches

Copy link
Member

Choose a reason for hiding this comment

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

Sure, there might be some other structs which probably should be renamed as well but that can be done in a different PR, I guess. For now, IMO it's sufficient to name the new struct in a reasonable way 😃

tmp = zero(rate_prototype)
atmp = similar(u, uEltypeNoUnits)
tab = Rosenbrock32ConstantCache(real(uBottomEltypeNoUnits),identity,identity,nothing,nothing,nothing)
tab = Ros32ConstantCache(real(uBottomEltypeNoUnits))
Copy link
Member

Choose a reason for hiding this comment

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

Similar to my comment above, I think we should use something a bit more meaningful than Ros32ConstantCache.

@ChrisRackauckas ChrisRackauckas merged commit 893bc16 into SciML:master Aug 16, 2019
@ChrisRackauckas
Copy link
Member

Let's continue the renames as another PR. Also note that in the sphere of influence for this should be @saurabhkgp21's newest implicit extrapolation methods. For those methods, we need a safe-hatch so that way Jacobian reuse is just generally turned off. In other cases, having an easy switch on it is nice anyways, so it's something to keep in mind.

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.

4 participants