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

Deprecate block_diag from math module in favor of PyTensor #7132

Merged
merged 6 commits into from
Feb 8, 2024
Merged

Deprecate block_diag from math module in favor of PyTensor #7132

merged 6 commits into from
Feb 8, 2024

Conversation

AryanNanda17
Copy link
Contributor

@AryanNanda17 AryanNanda17 commented Feb 3, 2024

The new code uses the sparse parameter to determine whether to call the sparse block_diag function (pytensor.sparse.basic.block_diag) or the dense version (pt.slinalg.block_diag).

Related Issue

Checklist

Type of change

  • New feature/enhancement
  • Bug fix
  • Documentation
  • Maintenance
  • Other (please specify):

📚 Documentation preview 📚: https://pymc--7132.org.readthedocs.build/en/7132/

@AryanNanda17
Copy link
Contributor Author

AryanNanda17 commented Feb 3, 2024

@larryshamalama, @ricardoV94, and @jessegrabowski please look into the PR and suggest if any changes are required.

Copy link

codecov bot commented Feb 3, 2024

Codecov Report

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

Comparison is base (94020c9) 90.17% compared to head (fe8a065) 39.96%.
Report is 12 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #7132       +/-   ##
===========================================
- Coverage   90.17%   39.96%   -50.21%     
===========================================
  Files         101      101               
  Lines       16932    16928        -4     
===========================================
- Hits        15269     6766     -8503     
- Misses       1663    10162     +8499     
Files Coverage Δ
pymc/math.py 30.00% <20.00%> (-39.16%) ⬇️

... and 81 files with indirect coverage changes

@AryanNanda17
Copy link
Contributor Author

What am I doing wrong here, the Codecov/patch test failed?

@ricardoV94
Copy link
Member

ricardoV94 commented Feb 6, 2024

@AryanNanda17 I asked the person commenting earlier on the original issue if they would be interested in working on this issue as a courtesy. If you see an issue you would like to work on where someone else seemed to be interested recently please confirm with them first if they are happy to let you take over.

Our official policy is opening a PR first is what counts, but for these small non critical issues we would like to give room for everyone to have their first chance. There are many harder issues that we need help with for which there's no risk of multiple people being interested at the same time.

@AryanNanda17
Copy link
Contributor Author

@ricardoV94, Can You suggest some harder issues?
It would be my first hard issue so I am not sure which one to start with.

@ricardoV94
Copy link
Member

@AryanNanda17

These beginner friendly ones don't seem to have anyone interested and may be good?

We also have many good issue in the related repos: PyTensor and PyMC-Experimental that tend to fall more out of the radar:

pymc/math.py Outdated
@@ -577,4 +528,8 @@ def block_diagonal(matrices, sparse=False, format="csr"):
"""
if len(matrices) == 1: # graph optimization
return matrices[0]
return BlockDiagonalMatrix(sparse=sparse, format=format)(*matrices)

Copy link
Member

Choose a reason for hiding this comment

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

Can you add a FutureWarning mentioning this is deprecated in favor of the pytensor function, so we can remove this thin wrapper sometime in the future?

@AryanNanda17
Copy link
Contributor Author

@ricardoV94, I made the changes please checkout.

pymc/math.py Outdated
@@ -576,5 +527,13 @@ def block_diagonal(matrices, sparse=False, format="csr"):
matrix
"""
if len(matrices) == 1: # graph optimization
warnings.warn(
Copy link
Member

Choose a reason for hiding this comment

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

Any use of the function should issue a warning, not just this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright!

pymc/math.py Outdated
Comment on lines 529 to 533
warnings.warn(
"The behavior of block_diagonal when only one matrix is provided is deprecated. Use pytensor function instead.",
FutureWarning,
stacklevel=2,
)
Copy link
Member

@ricardoV94 ricardoV94 Feb 8, 2024

Choose a reason for hiding this comment

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

Suggested change
warnings.warn(
"The behavior of block_diagonal when only one matrix is provided is deprecated. Use pytensor function instead.",
FutureWarning,
stacklevel=2,
)
warnings.warn(
"`pymc.math.block_diagonal` is deprecated in favor of `pytensor.tensor.linalg.block_diag` and `pytensor.sparse.block_diag`. This function will be removed in a future release.",
)

@AryanNanda17
Copy link
Contributor Author

Thanks for looking into the issue @ricardoV94.

pymc/math.py Outdated
def block_diagonal(matrices, sparse=False, format="csr"):
r"""See scipy.sparse.block_diag or
scipy.linalg.block_diag for reference
def block_diagonal(*matrices, sparse=False, format="csr"):
Copy link
Member

Choose a reason for hiding this comment

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

We should keep the old signature, missed this before:

Suggested change
def block_diagonal(*matrices, sparse=False, format="csr"):
def block_diagonal(matrices, sparse=False, format="csr"):

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated it!

@ricardoV94
Copy link
Member

Thanks @AryanNanda17

@ricardoV94 ricardoV94 changed the title Removed block_diag from pymc.math in favor of alias to pytensor.tensor… Deprecate block_diag from pymc.math in favor of PyTensor Feb 8, 2024
@ricardoV94 ricardoV94 changed the title Deprecate block_diag from pymc.math in favor of PyTensor Deprecate block_diag from math module in favor of PyTensor Feb 8, 2024
@ricardoV94 ricardoV94 merged commit 627a8dd into pymc-devs:main Feb 8, 2024
19 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove block_diag from pymc.math in favor of alias to pytensor.tensor.slinalg.block_diag
2 participants