-
Notifications
You must be signed in to change notification settings - Fork 7
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
fix!: serialisation schema #968
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
a2090d0
add ruff to devenv, format ops.py
doug-q 3c3b420
Add schema for serialising a single type
doug-q 71040f1
Fix serialisation, enable round trip schema checking
doug-q 40506fb
Condition schema-checking on an env var HUGR_TEST_SCHEMA
doug-q 9f3e525
rename Testing Schema, add Value
doug-q 8abe0de
ci: run on all PRs
doug-q 5d6b717
Add Type and SumType roundtrip serialisation tests
doug-q bfb15e8
some more test cases + refactorin
doug-q 6e97f25
move serialize tests to new file
doug-q a2db6d3
revert CI hacking
doug-q e14b4ea
Add support for PolyFuncType in testing_schema, add a few tests
doug-q 2247a02
Add tests for PolyFuncType serialisation
doug-q d3a1641
refactor: outline hugr::serialize::test
doug-q b7d0186
rebase fixes
doug-q ee37468
Address comments
doug-q d82db9c
Fix typing in generate_schema.py
doug-q File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from typing import Literal, Optional | ||
from pydantic import BaseModel | ||
from .tys import Type, SumType, PolyFuncType | ||
from .ops import Value | ||
|
||
|
||
class TestingHugr(BaseModel): | ||
"""A serializable representation of a Hugr Type, SumType, PolyFuncType, or | ||
Value. Intended for testing only.""" | ||
|
||
version: Literal["v1"] = "v1" | ||
typ: Optional[Type] = None | ||
sum_type: Optional[SumType] = None | ||
poly_func_type: Optional[PolyFuncType] = None | ||
value: Optional[Value] = None | ||
|
||
@classmethod | ||
def get_version(cls) -> str: | ||
"""Return the version of the schema.""" | ||
return cls().version | ||
|
||
class Config: | ||
title = "HugrTesting" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we use hypothesis/proptest for at least some of these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that it would be better. Hugr-Valued Values would not be possible, and anything with type variables may be tricky (if it turns out they have to make sense).
I would prefer to leave this as-is for now and convert to proptest in a second pass. Do lmk if you disagree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On further investigation, it seems like it will be fine to construct and round trip types with typevars that don't make sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have agreed to try proptest, I hope you are ok merging this PR first?