Skip to content

Add helper explicit_graph_inputs #712

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 2 commits into from
Apr 30, 2024
Merged

Conversation

Dhruvanshu-Joshi
Copy link
Member

@Dhruvanshu-Joshi Dhruvanshu-Joshi commented Apr 13, 2024

Description

This PR aims to integrate a helper that builds on the current graph_input helper to return only variable inputs as in pymc.pytensorf.inputvars .

Related Issue

Checklist

Type of change

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

@ricardoV94 ricardoV94 added the enhancement New feature or request label Apr 15, 2024
@ricardoV94
Copy link
Member

ricardoV94 commented Apr 15, 2024

Small note, in your top level message, the raw for Closes #695 looks like this:

Closes [#695](https://github.com/pymc-devs/pytensor/issues/695)

This however misses the automatic closing of issues: https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword

It should just be

Closes #695

Once you do that the closes will be underlined and if you hover it will show a pop-up saying that merging this PR will automatically close the linked issue. That's what we want!

@ricardoV94 ricardoV94 changed the title Add helper to extract variable graph_input Add helper required_graph_inputs Apr 19, 2024
Copy link

codecov bot commented Apr 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.78%. Comparing base (eb18f0e) to head (3637e39).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #712   +/-   ##
=======================================
  Coverage   80.78%   80.78%           
=======================================
  Files         162      162           
  Lines       46757    46762    +5     
  Branches    11440    11442    +2     
=======================================
+ Hits        37773    37778    +5     
+ Misses       6735     6732    -3     
- Partials     2249     2252    +3     
Files Coverage Δ
pytensor/graph/basic.py 88.96% <100.00%> (+0.07%) ⬆️

... and 3 files with indirect coverage changes

Comment on lines 916 to 955
Parameters
----------
graph: PyTensor `Variable` instances
Output `Variable` instances from which to search backward through
owners.

Returns
-------
List of tensor variables that are input nodes with no owner, in the order
found by a left-recursive depth-first search started at the nodes in `graphs`.

Copy link
Member

Choose a reason for hiding this comment

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

These docstrings are not well formatted. @OriolAbril can we point to the same docs as for PyMC for PyTensor docs?

Copy link
Member

Choose a reason for hiding this comment

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

not sure what you mean, link to numpydoc? https://numpydoc.readthedocs.io/en/latest/format.html

Copy link
Member Author

Choose a reason for hiding this comment

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

I referred the format that pymc uses for logp. Does it seem right?

Copy link
Member

Choose a reason for hiding this comment

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

not sure what you mean, link to numpydoc? https://numpydoc.readthedocs.io/en/latest/format.html

I was asking if we were using a style in PyTensor. I think you answered it

Copy link
Member

Choose a reason for hiding this comment

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

oh, yes, same style as in pymc, numpydoc

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.

Small tweak requests

@Dhruvanshu-Joshi Dhruvanshu-Joshi force-pushed the ticket3 branch 2 times, most recently from 8634a55 to efa088a Compare April 27, 2024 05:35
@@ -936,6 +936,55 @@ def graph_inputs(
yield from (r for r in ancestors(graphs, blockers) if r.owner is None)


def explicit_graph_inputs(
graph: Variable[Any, Any] | Iterable[Variable[Any, Any]],
Copy link
Member

@ricardoV94 ricardoV94 Apr 28, 2024

Choose a reason for hiding this comment

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

Do we need the Any, Any? The function above doesn't have it. Tbh I never had time to check where do these Any come from

Suggested change
graph: Variable[Any, Any] | Iterable[Variable[Any, Any]],
graph: Variable | Iterable[Variable],

Copy link
Member Author

@Dhruvanshu-Joshi Dhruvanshu-Joshi Apr 28, 2024

Choose a reason for hiding this comment

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

This is what mypy suggested to add as type-hints when the first one that I was trying failed. However, I don't see reason for as to why Varaible in itself as a type-hint won't work. Would you suggest I revert to Variable instead of Variable[Any, Any]. Mypy seems to be happy with both.

Copy link
Member

Choose a reason for hiding this comment

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

Let's try it without then

@ricardoV94 ricardoV94 changed the title Add helper required_graph_inputs Add helper explicit_graph_inputs Apr 30, 2024
@ricardoV94 ricardoV94 merged commit 044910b into pymc-devs:main Apr 30, 2024
55 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add helper function to find all inputs needed to a compile a graph
4 participants