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

Do not rely on tag information for rv and logp conversions #6281

Merged
merged 6 commits into from
Nov 11, 2022

Conversation

ricardoV94
Copy link
Member

@ricardoV94 ricardoV94 commented Nov 9, 2022

This PR will finally clean the interface for accessing meta-information from RVs needed when transforming back and forth between the RV and logp representations of a PyMC model

It does not yet remove that information to not break anything. Some methods relied heavily on this local information and were simply marked for deprecation, with alternatives being provided from scratch.

Accessing these variables (as long as they were introduced by PyMC) via tag will issue a FutureWarning:

with pm.Model() as m:
  x = pm.Normal("x")
x.tag.value_var  # Warning: The tag attribute value_var is deprecated. Use model.rvs_to_values[rv] instead

Closes #5033
Closes #6236

Major / Breaking Changes

  • Deprecated accessing [value_variable|observations|transform|total_size] via var.tag in favor of model.rvs_to_[values|transforms|total_sizes]
  • Deprecated joint_logp in favor of model.logp
  • Deprecated aesaraf.rvs_to_value_vars in favor of model.replace_rvs_by_values

Bugfixes / New features

  • Fix bug when replacing random variables with nested value transforms

Docs / Maintenance

  • ...

@ricardoV94 ricardoV94 force-pushed the stop_using_tag_info branch 2 times, most recently from c217cf9 to f11923f Compare November 9, 2022 12:38
@ricardoV94 ricardoV94 changed the title Do not rely on tag information when transforming between rv and logp … Do not rely on tag information for rv and logp conversions Nov 9, 2022
@ricardoV94 ricardoV94 force-pushed the stop_using_tag_info branch 2 times, most recently from fadeedb to 12e2b17 Compare November 9, 2022 12:57
@ricardoV94 ricardoV94 added this to the v4.4.0 milestone Nov 9, 2022
@ricardoV94 ricardoV94 added the major Include in major changes release notes section label Nov 9, 2022
@ricardoV94 ricardoV94 force-pushed the stop_using_tag_info branch 2 times, most recently from 5f507fd to 6934a06 Compare November 9, 2022 13:34
@codecov
Copy link

codecov bot commented Nov 9, 2022

Codecov Report

Merging #6281 (2b266dc) into main (0be5295) will decrease coverage by 0.18%.
The diff coverage is 97.56%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #6281      +/-   ##
==========================================
- Coverage   94.30%   94.12%   -0.19%     
==========================================
  Files         111      111              
  Lines       23809    23861      +52     
==========================================
+ Hits        22452    22458       +6     
- Misses       1357     1403      +46     
Impacted Files Coverage Δ
pymc/backends/arviz.py 90.08% <50.00%> (ø)
pymc/tests/backends/fixtures.py 78.30% <50.00%> (ø)
pymc/distributions/logprob.py 67.28% <92.59%> (-29.98%) ⬇️
pymc/model.py 89.68% <96.29%> (+0.15%) ⬆️
pymc/aesaraf.py 94.86% <100.00%> (+0.82%) ⬆️
pymc/distributions/distribution.py 95.02% <100.00%> (+0.02%) ⬆️
pymc/distributions/shape_utils.py 97.87% <100.00%> (+0.01%) ⬆️
pymc/initial_point.py 100.00% <100.00%> (ø)
pymc/model_graph.py 78.82% <100.00%> (ø)
pymc/sampling/forward.py 95.55% <100.00%> (ø)
... and 15 more

@ricardoV94 ricardoV94 force-pushed the stop_using_tag_info branch 3 times, most recently from f7d6e08 to f649479 Compare November 9, 2022 17:53
@ricardoV94 ricardoV94 force-pushed the stop_using_tag_info branch 2 times, most recently from dd122ea to c2bc9b2 Compare November 10, 2022 09:31
@michaelosthege
Copy link
Member

michaelosthege commented Nov 10, 2022

@ricardoV94 the type hint in aeppl.transforms.TransformValuesRewrite is wrong: https://github.com/aesara-devs/aeppl/blob/961496a17e4291b76a5affc140ce85b42a6527cb/aeppl/transforms.py#L193

It should say Dict[TensorVariable, Optional[Union[RVTransform, DefaultTransformSentinel]]]

Best place a # type: ignore in the line here for now

@ricardoV94 ricardoV94 marked this pull request as ready for review November 10, 2022 10:29
@ricardoV94 ricardoV94 marked this pull request as draft November 10, 2022 10:29
@ricardoV94 ricardoV94 added the bug label Nov 10, 2022
@ricardoV94 ricardoV94 force-pushed the stop_using_tag_info branch 3 times, most recently from ffed024 to 2b266dc Compare November 10, 2022 14:12
@ricardoV94 ricardoV94 marked this pull request as ready for review November 10, 2022 14:14
Copy link
Member

@michaelosthege michaelosthege left a comment

Choose a reason for hiding this comment

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

Overall looking good; great work, @ricardoV94 👍

I found some minor things in docstrings and I'm slightly worried that the big multiline expressions in some tests might result in hard to read tracebacks if they fail but this is also just a minor concern.

pymc/distributions/logprob.py Outdated Show resolved Hide resolved
pymc/aesaraf.py Outdated Show resolved Hide resolved
pymc/model.py Outdated Show resolved Hide resolved
@ricardoV94 ricardoV94 merged commit 5d7283e into pymc-devs:main Nov 11, 2022
@ricardoV94
Copy link
Member Author

I'm slightly worried that the big multiline expressions in some tests might result in hard to read tracebacks if they fail but this is also just a minor concern.

Then we will make sure they never fail :D

Yeah those tests a bit messy, but on the bright sight they are due to be removed when we deprecate the warnings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug enhancements major Include in major changes release notes section
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Turn aesaraf.rvs_to_value_vars into a Model method Remove value variable information from RV.tag
2 participants