Skip to content

Conversation

mhauru
Copy link
Member

@mhauru mhauru commented Mar 6, 2025

Previously, subset(vi, vns) had the variables in the return value ordered according to vns and not according to their order in vi. This PR makes the order be the same as that in vi.

This fixes the issue in TuringLang/Turing.jl#2300 (comment).

Since the docstring of subset previously said that the order was not guaranteed to be the same as vi, without saying what the order would be, I've marked this as a patch rather than a breaking release. I think this is debatable, so feel free to debate it.

@torfjelde, was there a particular reason to not do this before, other than no one bothering to implement it?

Copy link

codecov bot commented Mar 6, 2025

Codecov Report

Attention: Patch coverage is 95.23810% with 1 line in your changes missing coverage. Please review.

Project coverage is 84.56%. Comparing base (38dccd1) to head (8448645).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
src/varinfo.jl 91.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #832      +/-   ##
==========================================
- Coverage   84.60%   84.56%   -0.04%     
==========================================
  Files          34       34              
  Lines        3832     3830       -2     
==========================================
- Hits         3242     3239       -3     
- Misses        590      591       +1     

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

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mhauru mhauru changed the title Make subsume preserve varname ordering in varinfo Make subset preserve varname ordering in varinfo Mar 6, 2025
@mhauru mhauru marked this pull request as ready for review March 6, 2025 14:01
@mhauru mhauru requested a review from sunxd3 March 6, 2025 14:02
@coveralls
Copy link

coveralls commented Mar 6, 2025

Pull Request Test Coverage Report for Build 13699666388

Details

  • 20 of 21 (95.24%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.03%) to 84.658%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/varinfo.jl 11 12 91.67%
Totals Coverage Status
Change from base Build 13634518410: -0.03%
Covered Lines: 3239
Relevant Lines: 3826

💛 - Coveralls

@sunxd3
Copy link
Member

sunxd3 commented Mar 7, 2025

What is the reason why the before code doesn't preserve order?
nvm, I got it.

) where {names,sym}
return if (sym in names)
# TODO(mhauru) Note that this could still generate an empty metadata object if none
# of the lenses in `vns` are in `metadata`. Not sure if that's okay. Checking for
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 this is fine. But maybe we could add some isempty check where we use subset?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that would be preferable, but I don't know how to do it in a type stable manner. Specifically, I would like to implement it so that if we get a TypedVarInfo where for some symbol :dada the corresponding Metadata object is empty, we would drop :dada from the NamedTuple. But that means that the type of the return value depends on the value of the input (and not just the type of the input), since the keys of a NamedTuple are a part of its type.

@torfjelde
Copy link
Member

was there a particular reason to not do this before, other than no one bothering to implement it?

I don't think so tbh, so this seems completely fine to change to me 👍

@test [varinfo_merged[vn] for vn in vns] == [varinfo[vn] for vn in vns]
end

@testset "$(convert(Vector{VarName}, vns_subset)) order" for vns_subset in
Copy link
Member

Choose a reason for hiding this comment

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

Do you feel confident that all the methods we have for VarInfo will work correctly with "empty" NamedTuple entries in VarInfo? 👀

Copy link
Member

Choose a reason for hiding this comment

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

As in, is there more to be tested here or do we feel confident about this converage?

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you feel confident that all the methods we have for VarInfo will work correctly with "empty" NamedTuple entries in VarInfo? 👀

Confident, nope. Hopeful at best. I think this PR makes the situation marginally better though, in that it is a bit harder to create VarInfos with empty Metadatas using subset now. We should do all sorts of testing around such pathological VarInfos, but I think that would be a different PR.

I was about to say that delete! probably creates similar issues, but actually, seems delete! is broken/unimplemented for TypedVarInfo anyway. Should fix that too.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, definitively think this PR is making the situation better:) I was mainly trying to elude to whether we should add a few more test cases here / add an "empty" varinfo to be tested somewhere else.

Copy link
Member Author

Choose a reason for hiding this comment

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

Opened an issue about it here: #839

@mhauru mhauru added this pull request to the merge queue Mar 12, 2025
Merged via the queue into main with commit 0b13164 Mar 12, 2025
17 checks passed
@mhauru mhauru deleted the mhauru/subsumes-varname-order branch March 12, 2025 11:47
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