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: Draft for hugr-model with export, import, parsing and pretty printing #1542

Merged
merged 29 commits into from
Oct 7, 2024

Conversation

zrho
Copy link
Contributor

@zrho zrho commented Oct 2, 2024

This PR defines a draft of the model format, and the following parts that operate on the format:

  • Import: A module in the model format can be imported as a core hugr module.
  • Export: A core hugr module can be exported into the model format.
  • Parsing: A model hugr can be parsed from an s-expression based text format.
  • Pretty printing:: A model hugr can be printed into the s-expression format, with readable indentation.

This PR is very big, and yet it does not present a completed feature. The model and core format differ in several aspects. Where they differ, this is mostly intentional: The model is kept flexible enough to incorporate features that we know that we want in the future but are currently hard or impossible to express in the core. Import and export perform conversions where possible, but do not yet cover everything.

To prevent this PR from becoming even bigger and to allow for core and model to converge incrementally from both directions, I suggest the following plan: We merge this PR into main with the model related code being feature gated and considered experimental. We then perform tweaks to model and core in smaller PRs where necessary until they are sufficiently close.

Copy link

codecov bot commented Oct 2, 2024

Codecov Report

Attention: Patch coverage is 69.09570% with 704 lines in your changes missing coverage. Please review.

Project coverage is 85.71%. Comparing base (fc3efe5) to head (5c9299f).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
hugr-core/src/import.rs 70.15% 122 Missing and 109 partials ⚠️
hugr-model/src/v0/text/print.rs 59.32% 116 Missing and 76 partials ⚠️
hugr-model/src/v0/text/parse.rs 65.89% 70 Missing and 92 partials ⚠️
hugr-core/src/export.rs 82.55% 67 Missing and 19 partials ⚠️
hugr-model/src/v0/mod.rs 42.10% 33 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1542      +/-   ##
==========================================
- Coverage   87.43%   85.71%   -1.72%     
==========================================
  Files         127      132       +5     
  Lines       21740    24017    +2277     
  Branches    18740    21017    +2277     
==========================================
+ Hits        19008    20587    +1579     
- Misses       1964     2366     +402     
- Partials      768     1064     +296     
Flag Coverage Δ
python 92.46% <ø> (ø)
rust 84.75% <69.09%> (-1.88%) ⬇️

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.

@zrho zrho marked this pull request as ready for review October 3, 2024 09:00
@zrho zrho requested review from aborgna-q, cqc-alec, ss2165 and a team as code owners October 3, 2024 09:00
Copy link
Member

@ss2165 ss2165 left a comment

Choose a reason for hiding this comment

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

first review of mod.rs

hugr-model/src/v0/mod.rs Outdated Show resolved Hide resolved
hugr-model/src/v0/mod.rs Show resolved Hide resolved
hugr-model/src/v0/mod.rs Outdated Show resolved Hide resolved
hugr-model/src/v0/mod.rs Show resolved Hide resolved
hugr-model/src/v0/mod.rs Outdated Show resolved Hide resolved
hugr-model/src/v0/mod.rs Show resolved Hide resolved
hugr-model/src/v0/mod.rs Show resolved Hide resolved
hugr-core/tests/model.rs Outdated Show resolved Hide resolved
hugr-model/src/v0/mod.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@aborgna-q aborgna-q left a comment

Choose a reason for hiding this comment

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

Some general comments, I'll do mod/export next.

Other tidbits:

  • Add hugr-model to .github/change-filters.yml

Cargo.toml Outdated Show resolved Hide resolved
hugr-core/src/lib.rs Outdated Show resolved Hide resolved
hugr-model/Cargo.toml Show resolved Hide resolved
hugr-model/README.md Outdated Show resolved Hide resolved
hugr-model/README.md Outdated Show resolved Hide resolved
hugr-model/src/v0/mod.rs Outdated Show resolved Hide resolved
zrho and others added 2 commits October 3, 2024 15:32
Co-authored-by: Agustín Borgna <121866228+aborgna-q@users.noreply.github.com>
zrho and others added 3 commits October 3, 2024 15:40
Co-authored-by: Agustín Borgna <121866228+aborgna-q@users.noreply.github.com>
Co-authored-by: Agustín Borgna <121866228+aborgna-q@users.noreply.github.com>
Also added hugr model to change-filters.yaml
Copy link
Collaborator

@cqc-alec cqc-alec left a comment

Choose a reason for hiding this comment

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

(Looked at parse.rs and print.rs.) LGTM, I just highlighted some TODO comments that you may or may not want to address here (if not we should make issues).

hugr-model/src/v0/text/print.rs Show resolved Hide resolved
hugr-model/src/v0/text/parse.rs Show resolved Hide resolved
hugr-model/src/v0/text/parse.rs Show resolved Hide resolved
Copy link
Member

@ss2165 ss2165 left a comment

Choose a reason for hiding this comment

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

import first pass, second half coming soon

hugr-core/src/import.rs Show resolved Hide resolved
hugr-core/src/import.rs Outdated Show resolved Hide resolved
hugr-core/src/import.rs Show resolved Hide resolved
hugr-core/src/import.rs Outdated Show resolved Hide resolved
hugr-core/src/import.rs Outdated Show resolved Hide resolved
Copy link
Member

@ss2165 ss2165 left a comment

Choose a reason for hiding this comment

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

import round 2

hugr-core/src/import.rs Show resolved Hide resolved
hugr-core/src/import.rs Outdated Show resolved Hide resolved
hugr-core/src/import.rs Outdated Show resolved Hide resolved
hugr-core/src/import.rs Show resolved Hide resolved
hugr-core/src/import.rs Outdated Show resolved Hide resolved
hugr-core/src/import.rs Show resolved Hide resolved
hugr-core/src/import.rs Outdated Show resolved Hide resolved
hugr-core/src/import.rs Outdated Show resolved Hide resolved
hugr-core/src/import.rs Show resolved Hide resolved
hugr-core/src/import.rs Show resolved Hide resolved
Co-authored-by: Seyon Sivarajah <seyon.sivarajah@quantinuum.com>
hugr-core/src/export.rs Show resolved Hide resolved
hugr-core/src/export.rs Outdated Show resolved Hide resolved
hugr-core/src/export.rs Show resolved Hide resolved
hugr-core/src/export.rs Outdated Show resolved Hide resolved
hugr-core/src/export.rs Show resolved Hide resolved
hugr-core/src/export.rs Show resolved Hide resolved
hugr-core/src/export.rs Show resolved Hide resolved
hugr-core/src/export.rs Show resolved Hide resolved
@zrho
Copy link
Contributor Author

zrho commented Oct 7, 2024

Given that the code is deliberately declared unstable and after looking over what the tests cover, I am currently fine with the extent of test coverage. This will increase as more features are built around it. So if you agree do not let that be an obstacle to approving.

@cqc-alec
Copy link
Collaborator

cqc-alec commented Oct 7, 2024

Happy to approve the parts I looked at.

@ss2165
Copy link
Member

ss2165 commented Oct 7, 2024

Happy to approve mod and import

@aborgna-q
Copy link
Collaborator

aborgna-q commented Oct 7, 2024

Same here. Re-request the review once there's no more expected changes.

@zrho zrho requested a review from aborgna-q October 7, 2024 15:05
@zrho zrho added this pull request to the merge queue Oct 7, 2024
Merged via the queue into main with commit a2e92e8 Oct 7, 2024
20 of 21 checks passed
@zrho zrho deleted the zrho/model-import branch October 7, 2024 15:09
@hugrbot hugrbot mentioned this pull request Oct 4, 2024
github-merge-queue bot pushed a commit that referenced this pull request Oct 8, 2024
## 🤖 New release
* `hugr`: 0.12.1 -> 0.13.0 (✓ API compatible changes)
* `hugr-core`: 0.9.1 -> 0.10.0 (✓ API compatible changes)
* `hugr-passes`: 0.8.1 -> 0.8.2 (✓ API compatible changes)
* `hugr-cli`: 0.6.0 -> 0.6.1 (✓ API compatible changes)

<details><summary><i><b>Changelog</b></i></summary><p>

## `hugr`
<blockquote>

## 0.13.0 (2024-10-08)

### Bug Fixes

- [**breaking**] Make list length op give back the list
([#1547](#1547))

### Features

- [**breaking**] Allow CustomConsts to (optionally) be hashable
([#1397](#1397))
- Add an `OpLoadError` variant of `BuildError`.
([#1537](#1537))
- [**breaking**] `HugrMut::remove_node` and `SimpleReplacement` return
removed weights ([#1516](#1516))
- Draft for `hugr-model` with export, import, parsing and pretty
printing ([#1542](#1542))
</blockquote>

## `hugr-core`
<blockquote>

## 0.10.0 (2024-10-08)

### Bug Fixes

- [**breaking**] Make list length op give back the list
([#1547](#1547))

### Features

- [**breaking**] Allow CustomConsts to (optionally) be hashable
([#1397](#1397))
- Add an `OpLoadError` variant of `BuildError`.
([#1537](#1537))
- [**breaking**] `HugrMut::remove_node` and `SimpleReplacement` return
removed weights ([#1516](#1516))
- Draft for `hugr-model` with export, import, parsing and pretty
printing ([#1542](#1542))
</blockquote>

## `hugr-passes`
<blockquote>

## 0.8.1 (2024-09-04)

### Features

- Op replacement and lowering functions
([#1509](#1509))
</blockquote>

## `hugr-cli`
<blockquote>

## 0.6.0 (2024-09-04)

### Features

- [**breaking**] Allow registry specification in `run_dump`
([#1501](#1501))
- [**breaking**] Add `Package::validate` and return `ExtensionRegistry`
in helpers. ([#1507](#1507))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/MarcoIeni/release-plz/).
@ss2165 ss2165 mentioned this pull request Oct 9, 2024
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.

5 participants