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: Pydantic model for the serialization schema #888

Merged
merged 15 commits into from
Mar 19, 2024
Merged

Conversation

aborgna-q
Copy link
Collaborator

@aborgna-q aborgna-q commented Mar 19, 2024

This PR ports the pydantic definition from guppy (including CQCL/guppylang#172), and updates it to sync up with the current schema.

Changes to the schema:

  • Renamed the InputExtensions class to ExtensionSet
  • Added a named definition for Const
  • Dropped DummyOp. It was referenced in a couple field types, but the model was never defined.

The main difference with the model in guppy is the use of RootModel-based classes instead of variables assigned to a TypeAliasType for defining aliases on type unions.
They both work the same, but mypy doesn't like using variables in types.

Additionally, I updated some READMEs and added a CI check to ensure that the json in specification/schema/ is always up to date.

Copy link

codecov bot commented Mar 19, 2024

Codecov Report

Attention: Patch coverage is 0% with 19 lines in your changes are missing coverage. Please review.

Project coverage is 85.50%. Comparing base (555b8c0) to head (5082685).

❗ Current head 5082685 differs from pull request most recent head 1200731. Consider uploading reports for the commit 1200731 to get more accurate results

Files Patch % Lines
scripts/generate_schema.py 0.00% 19 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #888      +/-   ##
==========================================
- Coverage   85.55%   85.50%   -0.06%     
==========================================
  Files          78       79       +1     
  Lines       14397    14416      +19     
  Branches    14397    14397              
==========================================
+ Hits        12318    12327       +9     
- Misses       1445     1455      +10     
  Partials      634      634              
Flag Coverage Δ
python 0.00% <0.00%> (?)
rust 85.62% <ø> (+0.06%) ⬆️

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.

@aborgna-q
Copy link
Collaborator Author

Sorry for the noisy metadata changes, the CI still needed some fixes to work correctly...

Copy link
Contributor

@mark-koch mark-koch left a comment

Choose a reason for hiding this comment

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

Nice, the Python stuff looks good to me 👍 Can't comment on the CI though :D

Now, what would be the best path for Guppy to migrate to this? Publish quantinuum_hugr on PyPI or pull in the dependency from this repo for now?

vs: list["Const"]

class Config:
# Need to avoid random '\n's in the pydantic description
Copy link
Contributor

Choose a reason for hiding this comment

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

This is quite annoying :(

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep :/

class Config:
# Need to avoid random '\n's in the pydantic description
json_schema_extra = {
"description": "A Sum variant For any Sum type where this value meets the type of the variant indicated by the tag.",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"description": "A Sum variant For any Sum type where this value meets the type of the variant indicated by the tag.",
"description": "A Sum variant. For any Sum type where this value meets the type of the variant indicated by the tag.",

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, why is ruff not complaining about the long line?

It might be nicer to split the string into multiple lines

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done 👍

Comment on lines 168 to 171
# The types will be all None because it's not dataflow, but we only care about
# the number of outputs. Note that we don't make use of the HUGR feature where
# the variant data is appended to successor input. Thus, `predicate_variants`
# will only contain empty rows.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we get rid of these Guppy specific comments?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍

@aborgna-q
Copy link
Collaborator Author

We could publish a 0.0.0.a1 alpha version and use it from guppy.

I would wait for the builder API before releasing 0.1.0.

@aborgna-q aborgna-q added this pull request to the merge queue Mar 19, 2024
Merged via the queue into main with commit 3406e88 Mar 19, 2024
15 checks passed
@aborgna-q aborgna-q deleted the feat/pydantic branch March 19, 2024 17:50
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