Skip to content

Cleanup frozen FunctionGraph#2043

Open
ricardoV94 wants to merge 4 commits intopymc-devs:v3from
ricardoV94:cleanup_frozen_fg
Open

Cleanup frozen FunctionGraph#2043
ricardoV94 wants to merge 4 commits intopymc-devs:v3from
ricardoV94:cleanup_frozen_fg

Conversation

@ricardoV94
Copy link
Copy Markdown
Member

@ricardoV94 ricardoV94 commented Apr 11, 2026

Related to #2033

  • Removed special work-around for broken scalar signature (there are some fundamental issues described in Constant.signature() is broken or missing for several subclasses #2044 but they are not specific to here)
  • Intern and fix equality for FunctionGraph with constant outputs
  • Add output node client to outputs (so it won't look like a variable has no clients, or if shared, only has the non-output clients).

@ricardoV94 ricardoV94 changed the title cleanup frozen fg Cleanup frozen FunctionGraph Apr 11, 2026
@ricardoV94 ricardoV94 marked this pull request as ready for review April 11, 2026 22:55
(t0, d0), (t1, d1) = self, other
if t0 != t1:
return False
return (d0 == d1) or (np.isnan(d0) and np.isnan(d1))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

are there any other corner cases with np.inf? I don't think so just checking.

cache hit overwrites memo[c2]=c1, c2 is evicted from variables
while the cache-miss node still references it.
"""
from pytensor.graph.fg import FrozenFunctionGraph
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we should consider adding the ruff rule that all imports need to be on top of the file, im embarrassed i checked this in.


def test_constant_output_equality(self):
"""FFGs with distinct but equal constant outputs should be equal."""
c1 = ScalarConstant(float64, 3.14)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There are other circle constants you know: https://www.youtube.com/watch?v=dUGFb_HgG1c

except KeyError:
if not isinstance(o, AtomicVariable):
raise ValueError(
f"Output variable {o} could not be mapped to a frozen graph variable. "
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it really possible for a user to reach here? I ask because the error isn't really actionable, so it's another pytensor-special cryptic error if you do end up here somewhere.

Copy link
Copy Markdown
Member Author

@ricardoV94 ricardoV94 Apr 11, 2026

Choose a reason for hiding this comment

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

I had this doubt myself before. I don't think so, it would trigger in the first loop. Wanna take it out?

One edge case is a NominalVariable output not specified as input. That should fail, which means this branch should only really accept Constants (not general AtomicVariables)

That may be findable only here but would need to check

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We can make it an assert if we just want it for safety but dont think it should ever be hit (keeping the message)

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.

2 participants