Skip to content

Replace str "output" by a dummy Op in the clients of the FunctionGraph #790

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

Merged
merged 1 commit into from
Jul 8, 2024

Conversation

ricardoV94
Copy link
Member

@ricardoV94 ricardoV94 commented May 30, 2024

Description

This is often a source of bug, because everything in the clients graph is a node with an Op, except these sneaky string labels "output". It also messes up mypy in multiple places.

The whole point of having "output" in the clients dictionary is so we know if a variable is used in multiple places (i.e., may still need to be computed even if we do a rewrite that gets rid of it as an intermediate operation). For that purpose it doesn't really matter if it's an output or used by another node. This approach allows handling these cases more easily because it looks like just another client.

We could also get rid of this dummy client, and force rewrites to check if a node is in fgraph.outputs separately but that feels more cumbersome. I understand why they added "output" as a client. I just think it hurts a bit more than needed to have it be so different.

Having said and done this PR I'm happy to just close it if people don't agree with it.

Related Issue

  • Closes #
  • Related to #

Checklist

Type of change

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

@ricardoV94 ricardoV94 force-pushed the remove_output_client branch 5 times, most recently from ba93370 to a9204fb Compare May 30, 2024 14:03
@ricardoV94 ricardoV94 force-pushed the remove_output_client branch 2 times, most recently from 4b9ed3a to 3ab8992 Compare May 31, 2024 15:16
@ricardoV94 ricardoV94 marked this pull request as ready for review May 31, 2024 15:46
@ricardoV94 ricardoV94 requested a review from jessegrabowski May 31, 2024 15:50
@ricardoV94 ricardoV94 force-pushed the remove_output_client branch 3 times, most recently from 707ce87 to f7da400 Compare May 31, 2024 18:45
Copy link

codecov bot commented May 31, 2024

Codecov Report

Attention: Patch coverage is 91.02564% with 7 lines in your changes missing coverage. Please review.

Project coverage is 80.78%. Comparing base (2143d85) to head (f7da400).
Report is 90 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #790      +/-   ##
==========================================
+ Coverage   80.76%   80.78%   +0.01%     
==========================================
  Files         163      163              
  Lines       46938    46921      -17     
  Branches    11497    11490       -7     
==========================================
- Hits        37911    37903       -8     
+ Misses       6785     6774      -11     
- Partials     2242     2244       +2     
Files Coverage Δ
pytensor/compile/function/types.py 79.60% <100.00%> (ø)
pytensor/graph/destroyhandler.py 69.74% <100.00%> (+0.53%) ⬆️
pytensor/graph/rewriting/utils.py 95.34% <100.00%> (ø)
pytensor/link/c/basic.py 87.61% <ø> (ø)
pytensor/link/vm.py 92.55% <100.00%> (-0.02%) ⬇️
pytensor/printing.py 51.44% <ø> (ø)
pytensor/scan/rewriting.py 81.20% <100.00%> (ø)
pytensor/tensor/basic.py 88.42% <100.00%> (ø)
pytensor/tensor/random/rewriting/basic.py 92.05% <100.00%> (-0.21%) ⬇️
pytensor/tensor/rewriting/elemwise.py 90.84% <100.00%> (-0.32%) ⬇️
... and 7 more

... and 1 file with indirect coverage changes

@ricardoV94 ricardoV94 requested a review from aseyboldt June 11, 2024 16:05
Copy link
Member

@jessegrabowski jessegrabowski left a comment

Choose a reason for hiding this comment

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

Really like this one, the code looks a lot cleaner without having to check for strings.

ApplyOrOutput = Apply | Literal["output"]
ClientType = tuple[ApplyOrOutput, int]

class Output(Op):
Copy link
Member

Choose a reason for hiding this comment

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

It's quite surprising we don't have another class named Output anywhere else in the codebase

@ricardoV94 ricardoV94 marked this pull request as draft July 8, 2024 09:32
@ricardoV94
Copy link
Member Author

Marking as a draft because I want to do a release before these changes

@ricardoV94 ricardoV94 force-pushed the remove_output_client branch from f7da400 to 5b8f38a Compare July 8, 2024 09:34
@ricardoV94 ricardoV94 marked this pull request as ready for review July 8, 2024 13:40
@ricardoV94 ricardoV94 merged commit 9ba6d99 into pymc-devs:main Jul 8, 2024
53 of 55 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.

2 participants