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

Fix for rand + replace overloads of rand with rand_prior_true for testing models #541

Merged
merged 18 commits into from
Oct 26, 2023

Conversation

torfjelde
Copy link
Member

@torfjelde torfjelde commented Oct 6, 2023

This PR does two things:

  1. rand(model) and others now, correctly, makes use of the context already attached to model. If we don't, stuff like condition will be completely ignored.
  2. Removes overloads of rand(rng, NamedTuple, model) in TestUtils. This has annoyed me for quite some while because it means that we can't use properly test rand(model) since all of our test-models have this explicitly implemented (this was originally example_values in the PR where TestUtils but we decided to change it to overloading rand somewhere along the way).

Technically we can put change (1) in a PR on its own, but without change (2) it's non-trivial to test properly, hence why I'm doing both together.

The question is: is this then a breaking PR? Technically the existing rand implementations did exactly what they were supposed to do, i.e. when you called rand, you got back a NamedTuple of the variables as they appear in model, hence removing these implementations of rand (and thus hitting the default impl of rand for Model) should not change the behavior, as seen from the callers. In effect, we're just adding another method rand_prior_true 🤷

So maybe it's okay to just make this a patch-release? The "new" (i.e. now default) implementations of rand are also now tested to be the same as rand_prior_true.

EDIT: Nvm, this needs to be breaking since some of the models will have different results when calling rand now 😕

src/test_utils.jl Outdated Show resolved Hide resolved
src/test_utils.jl Outdated Show resolved Hide resolved
src/test_utils.jl Outdated Show resolved Hide resolved
src/test_utils.jl Outdated Show resolved Hide resolved
@torfjelde torfjelde changed the title Fix for rand + remove overloads of rand for testing models Fix for rand + replace overloads of rand with rand_prior_true for testing models Oct 7, 2023
src/test_utils.jl Outdated Show resolved Hide resolved
src/test_utils.jl Outdated Show resolved Hide resolved
src/test_utils.jl Outdated Show resolved Hide resolved
@coveralls
Copy link

coveralls commented Oct 8, 2023

Pull Request Test Coverage Report for Build 6629476487

  • 13 of 17 (76.47%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.09%) to 82.852%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/test_utils.jl 13 17 76.47%
Totals Coverage Status
Change from base Build 6619122585: 0.09%
Covered Lines: 2638
Relevant Lines: 3184

💛 - Coveralls

@codecov
Copy link

codecov bot commented Oct 8, 2023

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Comparison is base (12e7c27) 82.76% compared to head (5ec07a9) 82.85%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #541      +/-   ##
==========================================
+ Coverage   82.76%   82.85%   +0.08%     
==========================================
  Files          25       25              
  Lines        3180     3184       +4     
==========================================
+ Hits         2632     2638       +6     
+ Misses        548      546       -2     
Files Coverage Δ
src/model.jl 88.34% <ø> (ø)
src/test_utils.jl 87.16% <76.47%> (+0.62%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@torfjelde
Copy link
Member Author

This should be good for a review, though it requires minor version bump, unfortunately 😕

@torfjelde
Copy link
Member Author

torfjelde commented Oct 9, 2023

So this is now passing and everything looks decent:)

Codecov is complaining but I don't understand how this can be true given that we've literally just:

  1. Renamed a function
  2. Added more tests.

@torfjelde
Copy link
Member Author

But maybe we should wait with this until #542 and maybe #543 has gone through, as these are not breaking changes?

@torfjelde torfjelde mentioned this pull request Oct 23, 2023
Copy link
Member

@devmotion devmotion left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Project.toml Outdated Show resolved Hide resolved
@yebai yebai assigned yebai and unassigned yebai Oct 24, 2023
test/varinfo.jl Outdated Show resolved Hide resolved
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@torfjelde
Copy link
Member Author

Tests should hopefully pass now that we yanked the AbstractMCMC release.

@yebai yebai enabled auto-merge October 25, 2023 21:26
@yebai yebai added this pull request to the merge queue Oct 25, 2023
Merged via the queue into master with commit 2e8adf4 Oct 26, 2023
11 of 13 checks passed
@yebai yebai deleted the torfjelde/rand-fix branch October 26, 2023 01:41
yebai added a commit that referenced this pull request Nov 1, 2023
…ep existing compat) (#553)

* Fix for `rand` + replace overloads of `rand` with `rand_prior_true` for testing models (#541)

* preserve context from model in `rand`

* replace rand overloads in TestUtils with definitions of
rand_prior_true so we can properly test rand

* removed NamedTuple from signature of TestUtils.rand_prior_true

* updated references to previous overloads of rand to now use rand_prior_true

* test rand for DEMO_MODELS

* formatting

* fixed tests for rand for DEMO_MODELS

* fixed linkning tests

* added missing impl of rand_prior_true for demo_static_transformation

* formatting

* fixed rand_prior_true for demo_static_transformation

* bump minor version as this will be breaking

* bump patch version

* fixed old usage of rand

* Update test/varinfo.jl

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fixed another usage of rand

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Remove `tonamedtuple` (#547)

* Remove dependencies to `tonamedtuple`

* Remove `tonamedtuple`s

* Minor version bump

---------

Co-authored-by: Hong Ge <[email protected]>

* CompatHelper: bump compat for AbstractMCMC to 5 for package test, (keep existing compat)

---------

Co-authored-by: Tor Erlend Fjelde <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Xianda Sun <[email protected]>
Co-authored-by: Hong Ge <[email protected]>
Co-authored-by: CompatHelper Julia <[email protected]>
github-merge-queue bot pushed a commit that referenced this pull request Nov 9, 2023
…t) (#551)

* CompatHelper: bump compat for AbstractMCMC to 5, (keep existing compat)

* CompatHelper: bump compat for AbstractMCMC to 5 for package test, (keep existing compat) (#552)

Co-authored-by: CompatHelper Julia <[email protected]>

* Update to AbstractMCMC 5

* Apply suggestions from code review

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update sampler.jl

* CompatHelper: bump compat for AbstractMCMC to 5 for package test, (keep existing compat) (#553)

* Fix for `rand` + replace overloads of `rand` with `rand_prior_true` for testing models (#541)

* preserve context from model in `rand`

* replace rand overloads in TestUtils with definitions of
rand_prior_true so we can properly test rand

* removed NamedTuple from signature of TestUtils.rand_prior_true

* updated references to previous overloads of rand to now use rand_prior_true

* test rand for DEMO_MODELS

* formatting

* fixed tests for rand for DEMO_MODELS

* fixed linkning tests

* added missing impl of rand_prior_true for demo_static_transformation

* formatting

* fixed rand_prior_true for demo_static_transformation

* bump minor version as this will be breaking

* bump patch version

* fixed old usage of rand

* Update test/varinfo.jl

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fixed another usage of rand

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Remove `tonamedtuple` (#547)

* Remove dependencies to `tonamedtuple`

* Remove `tonamedtuple`s

* Minor version bump

---------

Co-authored-by: Hong Ge <[email protected]>

* CompatHelper: bump compat for AbstractMCMC to 5 for package test, (keep existing compat)

---------

Co-authored-by: Tor Erlend Fjelde <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Xianda Sun <[email protected]>
Co-authored-by: Hong Ge <[email protected]>
Co-authored-by: CompatHelper Julia <[email protected]>

* bump AbstractPPL version to 0.7

* Update AbstractPPL test dependency

* add `Random.AbstractRNG`

* Update sampler.jl (#557)

* Update src/sampler.jl

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: CompatHelper Julia <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: David Widmann <[email protected]>
Co-authored-by: Tor Erlend Fjelde <[email protected]>
Co-authored-by: Xianda Sun <[email protected]>
Co-authored-by: Hong Ge <[email protected]>
Co-authored-by: Xianda Sun <[email protected]>
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