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

feat(hugr-py): CFG builder #1192

Merged
merged 6 commits into from
Jun 17, 2024
Merged

feat(hugr-py): CFG builder #1192

merged 6 commits into from
Jun 17, 2024

Conversation

ss2165
Copy link
Member

@ss2165 ss2165 commented Jun 13, 2024

Closes #1188

@ss2165 ss2165 marked this pull request as ready for review June 14, 2024 16:04
@ss2165 ss2165 requested a review from a team as a code owner June 14, 2024 16:04
@ss2165 ss2165 requested review from mark-koch and removed request for a team June 14, 2024 16:04
Base automatically changed from ss/type-hier to main June 14, 2024 16:05
Copy link

codecov bot commented Jun 14, 2024

Codecov Report

Attention: Patch coverage is 93.29609% with 12 lines in your changes missing coverage. Please review.

Project coverage is 86.61%. Comparing base (10f4c42) to head (58a03b3).
Report is 2 commits behind head on main.

Files Patch % Lines
hugr-py/src/hugr/_dfg.py 91.07% 5 Missing ⚠️
hugr-py/src/hugr/_cfg.py 96.66% 2 Missing ⚠️
hugr-py/src/hugr/_hugr.py 88.88% 2 Missing ⚠️
hugr-py/src/hugr/_ops.py 94.59% 2 Missing ⚠️
hugr-py/src/hugr/_exceptions.py 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1192      +/-   ##
==========================================
+ Coverage   86.52%   86.61%   +0.09%     
==========================================
  Files          95       96       +1     
  Lines       17894    18042     +148     
  Branches    16796    16796              
==========================================
+ Hits        15482    15627     +145     
- Misses       1643     1646       +3     
  Partials      769      769              
Flag Coverage Δ
python 88.92% <93.29%> (+1.21%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

hugr-py/src/hugr/_cfg.py Outdated Show resolved Hide resolved
hugr-py/src/hugr/_cfg.py Show resolved Hide resolved
hugr-py/src/hugr/_dfg.py Outdated Show resolved Hide resolved
Comment on lines +355 to +364
cfg = Cfg(input_types, output_types)
mapping = self.insert_hugr(cfg.hugr, self.root)
cfg.hugr = self
cfg._entry_block.root = mapping[cfg.entry]
cfg._entry_block.input_node = mapping[cfg._entry_block.input_node]
cfg._entry_block.output_node = mapping[cfg._entry_block.output_node]
cfg._entry_block.hugr = self
cfg.exit = mapping[cfg.exit]
cfg.root = mapping[cfg.root]
# TODO this is horrible
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be nicer to add an optional hugr argument to Cfg.__init__? If supplied, the CFG is inserted into the given Hugr, otherwise a new one is created.

Alternatively, it could be a classmethod Cfg.new_nested(hugr, input_types, output_types) or something similar?

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 like the class method idea, I'll try it out on #1194

hugr-py/src/hugr/_ops.py Show resolved Hide resolved
hugr-py/src/hugr/_cfg.py Outdated Show resolved Hide resolved
hugr-py/tests/test_cfg.py Show resolved Hide resolved
hugr-py/tests/test_cfg.py Outdated Show resolved Hide resolved
cfg._entry_block.hugr = self
cfg.exit = mapping[cfg.exit]
cfg.root = mapping[cfg.root]
# TODO this is horrible
Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed in #1194

Comment on lines +355 to +364
cfg = Cfg(input_types, output_types)
mapping = self.insert_hugr(cfg.hugr, self.root)
cfg.hugr = self
cfg._entry_block.root = mapping[cfg.entry]
cfg._entry_block.input_node = mapping[cfg._entry_block.input_node]
cfg._entry_block.output_node = mapping[cfg._entry_block.output_node]
cfg._entry_block.hugr = self
cfg.exit = mapping[cfg.exit]
cfg.root = mapping[cfg.root]
# TODO this is horrible
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 like the class method idea, I'll try it out on #1194

hugr-py/src/hugr/_ops.py Show resolved Hide resolved
hugr-py/tests/test_cfg.py Outdated Show resolved Hide resolved
hugr-py/tests/test_cfg.py Show resolved Hide resolved
hugr-py/src/hugr/_cfg.py Outdated Show resolved Hide resolved
@ss2165 ss2165 requested a review from mark-koch June 17, 2024 11:34
@ss2165 ss2165 enabled auto-merge June 17, 2024 11:34
@ss2165 ss2165 added this pull request to the merge queue Jun 17, 2024
Merged via the queue into main with commit c5ea47f Jun 17, 2024
20 checks passed
@ss2165 ss2165 deleted the ss/cfg-build branch June 17, 2024 11:45
github-merge-queue bot pushed a commit that referenced this pull request Jun 17, 2024
this exists as a tension between global/compositional building.
Inter-graph edges necessitate global, all-at-once building for some
cases. ~These update functions are required when inserting graphs in to
other ones~ Instead replaced with `new_nested` classmethods inspired by
#1192 (comment)
github-merge-queue bot pushed a commit that referenced this pull request Jul 3, 2024
🤖 I have created a release *beep* *boop*
---


##
[0.3.0](hugr-py-v0.2.1...hugr-py-v0.3.0)
(2024-07-03)


### ⚠ BREAKING CHANGES

* * `add_child_op`(`_with_parent`), etc., gone; use
`add_child_node`(`_with_parent`) with an (impl Into-)OpType.
    * `get_nodetype` gone - use `get_optype`.
    * `NodeType` gone - use `OpType` directly. 
    * Various (Into<)Option<ExtensionSet> params removed from builder
    methods especially {cfg_,dfg_}builder.
    * `input_extensions` removed from serialization schema.
* the Signature class is gone, but it's not clear how or why you might
have been using it...
* TailLoop node and associated builder functions now require specifying
an ExtensionSet; extension/validate.rs deleted; some changes to Hugrs
validated/rejected when the `extension_inference` feature flag is turned
on
* Type::validate takes extra bool (allow_rowvars); renamed
{FunctionType, PolyFuncType}::(validate=>validate_var_len).

### Features

* Allow "Row Variables" declared as List&lt;Type&gt;
([#804](#804))
([3ea4834](3ea4834))
* **hugr-py:** add builders for Conditional and TailLoop
([#1210](#1210))
([43569a4](43569a4))
* **hugr-py:** add CallIndirect, LoadFunction, Lift, Alias
([#1218](#1218))
([db09193](db09193)),
closes [#1213](#1213)
* **hugr-py:** add values and constants
([#1203](#1203))
([f7ea178](f7ea178)),
closes [#1202](#1202)
* **hugr-py:** automatically add state order edges for inter-graph edges
([#1165](#1165))
([5da06e1](5da06e1))
* **hugr-py:** builder for function definition/declaration and call
([#1212](#1212))
([af062ea](af062ea))
* **hugr-py:** builder ops separate from serialised ops
([#1140](#1140))
([342eda3](342eda3))
* **hugr-py:** CFG builder
([#1192](#1192))
([c5ea47f](c5ea47f)),
closes [#1188](#1188)
* **hugr-py:** define type hierarchy separate from serialized
([#1176](#1176))
([10f4c42](10f4c42))
* **hugr-py:** only require input type annotations when building
([#1199](#1199))
([2bb079f](2bb079f))
* **hugr-py:** python hugr builder
([#1098](#1098))
([23408b5](23408b5))
* **hugr-py:** store children in node weight
([#1160](#1160))
([1cdaeed](1cdaeed)),
closes [#1159](#1159)
* **hugr-py:** ToNode interface to treat builders as nodes
([#1193](#1193))
([1da33e6](1da33e6))
* Validate Extensions using hierarchy, ignore input_extensions, RIP
inference ([#1142](#1142))
([8bec8e9](8bec8e9))


### Bug Fixes

* Add some validation for const nodes
([#1222](#1222))
([c05edd3](c05edd3))
* **hugr-py:** more ruff lints + fix some typos
([#1246](#1246))
([f158384](f158384))
* **py:** get rid of pydantic config deprecation warnings
([#1084](#1084))
([52fcb9d](52fcb9d))


### Documentation

* **hugr-py:** add docs link to README
([#1259](#1259))
([d2a9148](d2a9148))
* **hugr-py:** build and publish docs
([#1253](#1253))
([902fc14](902fc14))
* **hugr-py:** docstrings for builder
([#1231](#1231))
([3e4ac18](3e4ac18))


### Code Refactoring

* Remove "Signature" from hugr-py
([#1186](#1186))
([65718f7](65718f7))
* Remove NodeType and input_extensions
([#1183](#1183))
([ea5213d](ea5213d))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: hugrbot <agustin.borgna+hugrbot@quantinuum.com>
Co-authored-by: Seyon Sivarajah <seyon.sivarajah@quantinuum.com>
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.

CFG python builder
2 participants