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

Don't include lhs of := in results of predict() #766

Merged
merged 5 commits into from
Jan 3, 2025
Merged

Conversation

penelopeysm
Copy link
Member

@penelopeysm penelopeysm commented Dec 21, 2024

Closes #765

Specifically, lhs := rhs expressions are treated here:

# Modify the assignment operators.
args_assign = getargs_coloneq(expr)
if args_assign !== nothing
L, R = args_assign
return Base.remove_linenums!(
generate_assign(
generate_mainbody!(mod, found, L, warn),
generate_mainbody!(mod, found, R, warn),
),
)
end

This in turn checks for is_extracting_values(context):

function generate_assign(left, right)
right_expr = :($(TrackedValue)($right))
tilde_expr = generate_tilde(left, right_expr)
return quote
if $(is_extracting_values)(__context__)
$tilde_expr
else
$left = $right
end
end
end

Currently, this function only returns true for ValuesAsInModelContext, and returns false for every other context.

is_extracting_values(context::ValuesAsInModelContext) = true
function is_extracting_values(context::AbstractContext)
return is_extracting_values(NodeTrait(context), context)
end
is_extracting_values(::IsParent, ::AbstractContext) = false
is_extracting_values(::IsLeaf, ::AbstractContext) = false

This PR adds a new boolean field to ValuesAsInModelContext which controls whether is_extracting_values(context) is true. For predict, this field is set to false, so that lhs := rhs lines are not included in the resulting chain.

Instead of providing a default value, I've opted to force callers of values_as_in_model specify whether they want the := variables, so this is a minor release.

@TuringLang TuringLang deleted a comment from github-actions bot Dec 21, 2024
@TuringLang TuringLang deleted a comment from github-actions bot Dec 21, 2024
@TuringLang TuringLang deleted a comment from github-actions bot Dec 21, 2024
@TuringLang TuringLang deleted a comment from github-actions bot Dec 21, 2024
@TuringLang TuringLang deleted a comment from github-actions bot Dec 21, 2024
@TuringLang TuringLang deleted a comment from github-actions bot Dec 21, 2024
Copy link

codecov bot commented Dec 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.12%. Comparing base (b7fd9ea) to head (a055574).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #766      +/-   ##
==========================================
+ Coverage   86.05%   86.12%   +0.06%     
==========================================
  Files          36       36              
  Lines        4325     4324       -1     
==========================================
+ Hits         3722     3724       +2     
+ Misses        603      600       -3     

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

@coveralls
Copy link

coveralls commented Dec 21, 2024

Pull Request Test Coverage Report for Build 12598010488

Details

  • 7 of 7 (100.0%) changed or added relevant lines in 2 files are covered.
  • 51 unchanged lines in 11 files lost coverage.
  • Overall coverage increased (+0.07%) to 86.204%

Files with Coverage Reduction New Missed Lines %
src/varnamedvector.jl 1 88.25%
src/sampler.jl 1 94.55%
src/utils.jl 2 73.2%
src/contexts.jl 3 27.27%
src/values_as_in_model.jl 3 70.37%
src/distribution_wrappers.jl 4 41.67%
src/model.jl 5 77.39%
src/varinfo.jl 6 84.62%
src/simple_varinfo.jl 6 81.96%
src/compiler.jl 8 86.58%
Totals Coverage Status
Change from base Build 12597566459: 0.07%
Covered Lines: 3724
Relevant Lines: 4320

💛 - Coveralls

@TuringLang TuringLang deleted a comment from github-actions bot Dec 21, 2024
@TuringLang TuringLang deleted a comment from github-actions bot Dec 21, 2024
@penelopeysm penelopeysm mentioned this pull request Jan 2, 2025
@yebai yebai requested a review from sunxd3 January 3, 2025 11:28
Copy link
Member

@sunxd3 sunxd3 left a comment

Choose a reason for hiding this comment

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

very sensible, thanks!

@penelopeysm penelopeysm added this pull request to the merge queue Jan 3, 2025
Merged via the queue into master with commit 3d18cfc Jan 3, 2025
20 checks passed
@penelopeysm penelopeysm deleted the py/contexts branch January 3, 2025 18:28
@torfjelde
Copy link
Member

Didn't see this as I was on vacation, but if this had been done as a kwarg with default to true, this could have been a non-breaking change?

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.

Chain returned by predict will contain variables used in := statements
4 participants