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

Bugfixes to increase robustness against unnamed dims #6339

Merged
merged 2 commits into from
Nov 27, 2022

Conversation

michaelosthege
Copy link
Member

This fixes the two bugs I described in #6335.

Essentially two Model.get_plates and Model.add_named_variable methods did not anticipate that elements of a dims tuple can be None.

I added some comments to the refactored code and tests.

Checklist

Major / Breaking Changes

  • None

Bugfixes / New features

  • Fixes bugs in pm.model_to_graphviz and Model.add_named_variable that were triggered by None elements in dims tuples.

Docs / Maintenance

  • None

@michaelosthege michaelosthege self-assigned this Nov 27, 2022
Comment on lines +209 to +212
# TODO: Evaluate all RV shapes and dim_length at once.
# This should help to find discrepancies, and
# avoids unncessary function compiles for deetermining labels.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is not needed for the bugfix, but I commented it here for the next person touching this code.

@codecov
Copy link

codecov bot commented Nov 27, 2022

Codecov Report

Merging #6339 (01fb0a8) into main (e0d25c8) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #6339   +/-   ##
=======================================
  Coverage   94.14%   94.15%           
=======================================
  Files         132      132           
  Lines       26714    26726   +12     
=======================================
+ Hits        25150    25163   +13     
+ Misses       1564     1563    -1     
Impacted Files Coverage Δ
pymc/model.py 89.93% <100.00%> (+0.16%) ⬆️
pymc/model_graph.py 80.00% <100.00%> (+1.17%) ⬆️

Copy link
Member

@ricardoV94 ricardoV94 left a comment

Choose a reason for hiding this comment

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

LGTM except one line.

pymc/model.py Outdated
@@ -1507,7 +1509,7 @@ def add_named_variable(self, var, dims: Optional[Tuple[Union[str, None], ...]] =
for dim in dims:
if dim not in self.coords and dim is not None:
raise ValueError(f"Dimension {dim} is not specified in `coords`.")
if any(var.name == dim for dim in dims):
if any(var.name == dim != None for dim in dims):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if any(var.name == dim != None for dim in dims):
if any(var.name == dim for dim in dims if dim is not None):

Copy link
Member Author

Choose a reason for hiding this comment

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

My code worked too, but OK let's have it your way ;)

@michaelosthege michaelosthege marked this pull request as ready for review November 27, 2022 13:38
@michaelosthege michaelosthege merged commit 3ff4e7a into pymc-devs:main Nov 27, 2022
@michaelosthege michaelosthege deleted the issue-6335 branch November 27, 2022 15:04
ricardoV94 pushed a commit to michaelosthege/pymc that referenced this pull request Nov 29, 2022
* Extract `ModelGraph._eval` to a function
* More robustness against unlabeled `dims` entries

Closes pymc-devs#6335
ricardoV94 pushed a commit to ricardoV94/pymc that referenced this pull request Nov 29, 2022
* Extract `ModelGraph._eval` to a function
* More robustness against unlabeled `dims` entries

Closes pymc-devs#6335
wrongu pushed a commit to wrongu/pymc that referenced this pull request Dec 1, 2022
* Extract `ModelGraph._eval` to a function
* More robustness against unlabeled `dims` entries

Closes pymc-devs#6335
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants