Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i161: Allow use of deriv in delay models #162

Merged
merged 6 commits into from Apr 11, 2019
Merged

i161: Allow use of deriv in delay models #162

merged 6 commits into from Apr 11, 2019

Conversation

@richfitz
Copy link
Member

@richfitz richfitz commented Apr 10, 2019

This PR allows the deriv() method to be used with models that include delays.

Previously this was disabled because we need to be careful about treatment of the history. However, it's not too hard to do something along the lines of the Right Thing:

  • if the model has never been run, there is no history, and so deriv() should treat this as if it's still burning the delays in (i.e., use the initial conditions)
  • if the model has been run, then running deriv() should not affect the history (especially once model resuming is implemented - #141) so we should just use the history stored in the model

In order to support this:

  1. the create phase initialises the initial_t member to NA (previously was default-initialised to zero which is not ideal)
  2. when using the deriv wrapper from R, we check that the initial time is NA and if so it means that the model has not been run. In that case we temporarily set the initial_t element to the same time as current so that we always compute the delay-free derivatives - on exit we reset the initial_t to zero.

Most of the PR is a contrived test case that checks this is all reasonable.

@richfitz richfitz marked this pull request as ready for review Apr 10, 2019
@richfitz
Copy link
Member Author

@richfitz richfitz commented Apr 10, 2019

Looks like Appveyor is unhappy for some reason

AppVeyor was unable to build non-mergeable pull request

Workaround is apparently to close and reopen ¯\_(ツ)_/¯
https://mail.python.org/pipermail/python-committers/2017-July/004766.html

@richfitz richfitz closed this Apr 10, 2019
@richfitz richfitz reopened this Apr 10, 2019
@codecov
Copy link

@codecov codecov bot commented Apr 10, 2019

Codecov Report

Merging #162 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #162   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          38     38           
  Lines        4474   4500   +26     
=====================================
+ Hits         4474   4500   +26
Impacted Files Coverage Δ
R/generate_r_class.R 100% <100%> (ø) ⬆️
R/generate_r.R 100% <100%> (ø) ⬆️
R/generate_c_compiled.R 100% <100%> (ø) ⬆️
R/generate_c_class.R 100% <100%> (ø) ⬆️
R/generate_c_utils.R 100% <100%> (ø) ⬆️

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 1bae83c...8034b07. Read the comment docs.

@codecov
Copy link

@codecov codecov bot commented Apr 10, 2019

Codecov Report

Merging #162 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #162   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          38     38           
  Lines        4474   4501   +27     
=====================================
+ Hits         4474   4501   +27
Impacted Files Coverage Δ
R/generate_r_class.R 100% <100%> (ø) ⬆️
R/generate_c_utils.R 100% <100%> (ø) ⬆️
R/generate_r.R 100% <100%> (ø) ⬆️
R/generate_c_compiled.R 100% <100%> (ø) ⬆️
R/generate_c_class.R 100% <100%> (ø) ⬆️

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 1bae83c...7f57c9e. Read the comment docs.

@richfitz richfitz requested a review from r-ash Apr 10, 2019
@r-ash
r-ash approved these changes Apr 10, 2019
Copy link
Contributor

@r-ash r-ash left a comment

Sorry this has taken a while, this is first time I've read through any of this code. I feel I still don't understand all of these changes but the bits I do look good.

One small question about the testing but I expect that is just something testthat related that I don't know about.

"Can't call deriv() on delay models", fixed = TRUE)
deriv_c <- mod_c$deriv(t0, mod_c$initial(t0))
deriv_r <- mod_r$derivs(t0, mod_c$initial(t0))
expect_equal(deriv_c, deriv_r[[1L]], check.attributes = FALSE)

This comment has been minimized.

@r-ash

r-ash Apr 10, 2019
Contributor

Is there any reason you choose not to use expect_equivalent here?

This comment has been minimized.

@richfitz

richfitz Apr 10, 2019
Author Member

Mostly I forget that it exists - have you been using it a lot? I don't see it in dettl

This comment has been minimized.

@r-ash

r-ash Apr 10, 2019
Contributor

I think more in specio stuff particularly where I'm comparing output from Jeff's code and mine

This comment has been minimized.

@richfitz

richfitz Apr 10, 2019
Author Member

cool, that's good to know - I've updated the usages here, which adds a little noise to the diff but it's best if we're using the same things for the same purpose

@r-ash r-ash merged commit eca316c into master Apr 11, 2019
6 checks passed
6 checks passed
codecov/patch 100% of diff hit (target 100%)
Details
codecov/project 100% (+0%) compared to 1bae83c
Details
continuous-integration/appveyor/branch AppVeyor build succeeded
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.