Skip to content

Conversation

@tyf0420
Copy link
Contributor

@tyf0420 tyf0420 commented Jun 4, 2018

I am new to Julia, programming, and open-source. If there is any mistake, please tell me. @YingboMa is currently mentoring me.

@coveralls
Copy link

Coverage Status

Coverage decreased (-4.7%) to 73.665% when pulling 28461c4 on tyfff:rock into 57f1eae on JuliaDiffEq:master.

2 similar comments
@coveralls
Copy link

Coverage Status

Coverage decreased (-4.7%) to 73.665% when pulling 28461c4 on tyfff:rock into 57f1eae on JuliaDiffEq:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-4.7%) to 73.665% when pulling 28461c4 on tyfff:rock into 57f1eae on JuliaDiffEq:master.

@coveralls
Copy link

coveralls commented Jun 4, 2018

Coverage Status

Coverage decreased (-0.9%) to 94.985% when pulling b1f1236 on tyfff:rock into 9469b67 on JuliaDiffEq:master.

ms::SVector{46, Int}
fp1::SVector{46, T}
fp2::SVector{46, T}
recfi::SVector{4476, T2}
Copy link
Member

Choose a reason for hiding this comment

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

This should be a Vector. You typically don't want to use SVector for large arrays. All of these should probably be arrays, but some testing would need to be done on the 46.

recfi::SVector{4476, T2}
end

Base.@pure function ROCK2ConstantCache{T,T2}(::Type{T},::Type{T2})
Copy link
Member

Choose a reason for hiding this comment

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

What code generated these coefficients?

@ChrisRackauckas
Copy link
Member

Looks like a great start! Could you link what you're getting this from? It looks like there's a lot of hardcoded constants, so if this comes from another code we need to be careful about the license. It should be an MIT-compatible license. If it's generated from some formula in the paper, the generated code should be included (commented) and cited.

@tyf0420
Copy link
Contributor Author

tyf0420 commented Jun 4, 2018

The hardcoded constants are from http://www.unige.ch/~hairer/software.html rock.tar. The recfi constants are the recurrence relations' parameters that are described in this paper from #2 equations (3.4). In A. Abdulle's implementation, there is a routine to compute the spectral radius of the Jacobian matrix and uses that information to select a suitable stage number, as different stage numbers have different stability region. Stepping with different stage numbers have different coefficients for the recurrence relations. They have the parameters for s=3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,24,26,28,30,32,35,38,41,45,49,53,58,63,68,74,80,87,95,104,114,125,137,150,165,182,200, thus there are many constants. I am not sure how did they generate the constants though. I will look into it tomorrow. Thanks for the code review!

@ChrisRackauckas
Copy link
Member

Cool, that page is all MIT licensed: http://www.unige.ch/~hairer/prog/licence.txt so we're good.

@codecov
Copy link

codecov bot commented Jun 5, 2018

Codecov Report

Merging #374 into master will decrease coverage by 0.94%.
The diff coverage is 69.87%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #374      +/-   ##
==========================================
- Coverage   95.93%   94.98%   -0.95%     
==========================================
  Files          74       78       +4     
  Lines        9073     8933     -140     
==========================================
- Hits         8704     8485     -219     
- Misses        369      448      +79
Impacted Files Coverage Δ
src/tableaus/rkc_tableaus.jl 100% <ø> (ø)
src/alg_utils.jl 89.09% <ø> (-7.34%) ⬇️
src/caches/rkc_caches.jl 100% <100%> (ø)
src/algorithms.jl 100% <100%> (ø) ⬆️
src/rkc_utils.jl 61.76% <61.76%> (ø)
src/perform_step/rkc_perform_step.jl 71.42% <71.42%> (ø)
src/perform_step/composite_perform_step.jl 30% <0%> (-60%) ⬇️
src/composite_algs.jl 75% <0%> (-25%) ⬇️
src/exponential_utils.jl 80.62% <0%> (-14.81%) ⬇️
src/initdt.jl 80% <0%> (-14.45%) ⬇️
... and 30 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 9469b67...1fda238. Read the comment docs.

temp2 = 1 - temp3
ci1 = temp1 + temp2 * ci2 + temp3 * ci3
u = temp1 * u + temp2 * gprev + temp3 * gprev2
i < ms[cache.mdeg] && (gprev2 = gprev, gprev = u)
Copy link
Member

Choose a reason for hiding this comment

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

I think (gprev2 = gprev, gprev = u) should be (gprev2 = gprev; gprev = u).

Copy link
Member

@YingboMa YingboMa Jun 21, 2018

Choose a reason for hiding this comment

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

Also, the conditioning in here seems superfluous. Nevermind.

temp3 = temp2 * ( u - gprev2)
u = gprev + temp1 * u + temp3
ci1 = max(abs(u), abs(uprev)) * rto
calculate_residuals!(atmp, utilde, uprev, u, integrator.opts.abstol, integrator.opts.reltol,integrator.opts.internalnorm)
Copy link
Member

Choose a reason for hiding this comment

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

Use calculate_residuals for the mutable version.

if ntol = 0 # what is ntol?
temp3 = temp2 * ( u - gprev2)
u = gprev + temp1 * u + temp3
ci1 = max(abs(u), abs(uprev)) * rto
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't look right. u and uprev are vectors in here.

gprev = u + temp1 * gprev2
ci1 += temp1
# error estimate
if ntol = 0 # what is ntol?
Copy link
Member

Choose a reason for hiding this comment

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

ms[cache.mdeg] < 2 && u = gprev
# for the second to the ms[cache.mdeg] th stages
for i in 2:ms[cache.mdeg]
temp1 = h * recf[cache.recind + 2 * (i - 2) + 1]
Copy link
Member

Choose a reason for hiding this comment

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

h -> dt

temp2 = 1 - temp3
ci1 = temp1 + temp2 * ci2 + temp3 * ci3
u = temp1 * u + temp2 * gprev + temp3 * gprev2
i < ms[cache.mdeg] && (gprev2 = gprev, gprev = u)
Copy link
Member

@YingboMa YingboMa Jun 21, 2018

Choose a reason for hiding this comment

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

Also, the conditioning in here seems superfluous. Nevermind.

ci3 = t
gprev2 = uprev
gprev = uprev + temp1 * fsalfirst
ms[cache.mdeg] < 2 && u = gprev
Copy link
Member

Choose a reason for hiding this comment

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

u = gprev -> ( u = gprev ).

mdeg = Int(floor(sqrt((1.5 + dt * integrator.eigen_est)/0.811) + 1))
if mdeg >= 200
h = 0.8 * (200 ^ 2 * 0.811 - 1.5)/integrator.eigen_est
dt = 0.8 * (200 ^ 2 * 0.811 - 1.5)/integrator.eigen_est
Copy link
Member

Choose a reason for hiding this comment

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

this won't actually update the dt. A more sophisticated approach will be required here. Is the dt only ever decreased by this?

@ChrisRackauckas
Copy link
Member

How's this doing?

@ChrisRackauckas
Copy link
Member

Looks like there's been a lot of progress and a lot of it looks great. However, I don't understand the implementation of your core inner loop there. What paper did you work from? Looking at http://www.dumkaland.org/publications/content.pdf , I don't understand what the mu, nu, and kappa terms are, or how your loop corresponds to (26) and (27).

@tyf0420
Copy link
Contributor Author

tyf0420 commented Jul 15, 2018

I used this paper as a reference. The recf array stores the recurrence parameters (mu, nu and kapa in (3.4)). Here is how I get these parameters. We don't need to store nu because of the relation -nu-kapa=1. The indexing for recurrence parameters are computed in here.

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.

We need more tests to ensure the correctness of this algorithm, as there are many recurrence parameters and a simple linear convergence test only covers a few of them.

@ChrisRackauckas
Copy link
Member

So the recf = [mu1,nu1,mu2,nu2,...]?

Then is ms the number of stages in the nth order method, so to get to the nth order method you offset by recind = sum(2ms[1:n])?

I think I am getting it but this can be cleaned up a bit so that way it's clearer at first glance what's going on. First off, why not split this up into mu and nu arrays? Then instead of recind, you can just have mus[j] be a static array of all mus for the jth order method, and same for nu. So then mus[j][i] would be the ith mu for the jth order method. Note that there's no tuple_len recursion maximum anymore (JuliaLang/julia#27398) and so making this a big Vector{StaticVector} (or tuple) should be fine performance-wise on v0.7. I think this would make the algorithm much much easier to read than the Fortran original, and would probably be slightly faster since you'd have more cache efficiency.

Other than that, I'm not entirely sure how you're choosing the maximum stages. You have the eigenvalue computation here https://github.com/tyfff/OrdinaryDiffEq.jl/blob/ebff1738d6dfe08d7c6277d80abda1cde842ce3e/src/rkc_utils.jl#L4 but I don't see it actually used? Could you describe the stage number choice?

@ChrisRackauckas
Copy link
Member

That test failure is fixed on master

@ChrisRackauckas ChrisRackauckas merged commit 1fda238 into SciML:master Jul 15, 2018
@ChrisRackauckas
Copy link
Member

This is a pretty straight port of the Fortran code and it passes tests so I decided to merge. I still want to do a reorganization so that way it's much easier to follow, but this will be a separate issue and PR. Thanks! This is a very strong first contribution!

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