Skip to content

Allow GraphViews to be cloned#293

Closed
justinchuby wants to merge 2 commits intomainfrom
justinchu/graphview-clone
Closed

Allow GraphViews to be cloned#293
justinchuby wants to merge 2 commits intomainfrom
justinchu/graphview-clone

Conversation

@justinchuby
Copy link
Copy Markdown
Member

This is useful for extracting a subgraph without breaking the original graph.

This is useful for extracting a subgraph without breaking the original graph.

Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 30, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.22%. Comparing base (be11acc) to head (fcc59fd).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #293      +/-   ##
==========================================
+ Coverage   78.19%   78.22%   +0.03%     
==========================================
  Files          42       42              
  Lines        5206     5209       +3     
  Branches     1041     1041              
==========================================
+ Hits         4071     4075       +4     
+ Misses        834      833       -1     
  Partials      301      301              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds the ability to clone GraphView objects, which is useful for extracting and working with subgraphs without modifying the original graph structure. The implementation follows the same pattern as the existing Graph.clone() method.

Key Changes:

  • Added clone() method to the GraphView class that returns a new Graph instance
  • Updated the Cloner.clone_graph() method to accept both Graph and GraphView types
  • Removed an assertion in clone_value() that was incorrect for GraphView inputs (which can have producers)

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/onnx_ir/_core.py Added clone() method to GraphView class with documentation
src/onnx_ir/_cloner.py Updated type hints and removed incorrect assertion about value producers
src/onnx_ir/_core_test.py Added comprehensive test suite covering 11 different cloning scenarios

Comment thread src/onnx_ir/_core_test.py Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
@justinchuby justinchuby added this to the 0.1.14 milestone Dec 30, 2025
@justinchuby
Copy link
Copy Markdown
Member Author

Merged together with #294

justinchuby added a commit that referenced this pull request Dec 30, 2025
Extract subgraphs with `onnx_ir.convenience.extract()`. Migrated from
microsoft/onnxscript#2119.

Requires #293

---------

Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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