-
Notifications
You must be signed in to change notification settings - Fork 6
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): use serialized extensions in python #1459
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,15 @@ | ||
"""Types and operations from the standard extension set.""" | ||
|
||
from pathlib import Path | ||
|
||
from hugr.ext import Extension | ||
from hugr.serialization.extension import Extension as PdExtension | ||
|
||
_EXT_DIR = Path(__file__).parent / "_json_defs" | ||
|
||
|
||
def _load_extension(name: str) -> Extension: | ||
replacement = name.replace(".", "/") | ||
path = _EXT_DIR / f"{replacement}.json" | ||
with path.open() as f: | ||
return PdExtension.model_validate_json(f.read()).deserialize() |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't sure if the jsons would be kept when building the wheels, but they are still there after running There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes sorry should have said I checked that |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
The files in this directory are generated and copied in, don't edit by hand. See | ||
repository justfile `gen-extensions` command. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,222 @@ | ||
{ | ||
"version": "0.1.0", | ||
"name": "arithmetic.conversions", | ||
"extension_reqs": [ | ||
"arithmetic.float.types", | ||
"arithmetic.int.types" | ||
], | ||
"types": {}, | ||
"values": {}, | ||
"operations": { | ||
"convert_s": { | ||
"extension": "arithmetic.conversions", | ||
"name": "convert_s", | ||
"description": "signed int to float", | ||
"signature": { | ||
"params": [ | ||
{ | ||
"tp": "BoundedNat", | ||
"bound": 7 | ||
} | ||
], | ||
"body": { | ||
"input": [ | ||
{ | ||
"t": "Opaque", | ||
"extension": "arithmetic.int.types", | ||
"id": "int", | ||
"args": [ | ||
{ | ||
"tya": "Variable", | ||
"idx": 0, | ||
"cached_decl": { | ||
"tp": "BoundedNat", | ||
"bound": 7 | ||
} | ||
} | ||
], | ||
"bound": "C" | ||
} | ||
], | ||
"output": [ | ||
{ | ||
"t": "Opaque", | ||
"extension": "arithmetic.float.types", | ||
"id": "float64", | ||
"args": [], | ||
"bound": "C" | ||
} | ||
], | ||
"extension_reqs": [] | ||
} | ||
}, | ||
"binary": false | ||
}, | ||
"convert_u": { | ||
"extension": "arithmetic.conversions", | ||
"name": "convert_u", | ||
"description": "unsigned int to float", | ||
"signature": { | ||
"params": [ | ||
{ | ||
"tp": "BoundedNat", | ||
"bound": 7 | ||
} | ||
], | ||
"body": { | ||
"input": [ | ||
{ | ||
"t": "Opaque", | ||
"extension": "arithmetic.int.types", | ||
"id": "int", | ||
"args": [ | ||
{ | ||
"tya": "Variable", | ||
"idx": 0, | ||
"cached_decl": { | ||
"tp": "BoundedNat", | ||
"bound": 7 | ||
} | ||
} | ||
], | ||
"bound": "C" | ||
} | ||
], | ||
"output": [ | ||
{ | ||
"t": "Opaque", | ||
"extension": "arithmetic.float.types", | ||
"id": "float64", | ||
"args": [], | ||
"bound": "C" | ||
} | ||
], | ||
"extension_reqs": [] | ||
} | ||
}, | ||
"binary": false | ||
}, | ||
"trunc_s": { | ||
"extension": "arithmetic.conversions", | ||
"name": "trunc_s", | ||
"description": "float to signed int", | ||
"signature": { | ||
"params": [ | ||
{ | ||
"tp": "BoundedNat", | ||
"bound": 7 | ||
} | ||
], | ||
"body": { | ||
"input": [ | ||
{ | ||
"t": "Opaque", | ||
"extension": "arithmetic.float.types", | ||
"id": "float64", | ||
"args": [], | ||
"bound": "C" | ||
} | ||
], | ||
"output": [ | ||
{ | ||
"t": "Sum", | ||
"s": "General", | ||
"rows": [ | ||
[ | ||
{ | ||
"t": "Opaque", | ||
"extension": "arithmetic.int.types", | ||
"id": "int", | ||
"args": [ | ||
{ | ||
"tya": "Variable", | ||
"idx": 0, | ||
"cached_decl": { | ||
"tp": "BoundedNat", | ||
"bound": 7 | ||
} | ||
} | ||
], | ||
"bound": "C" | ||
} | ||
], | ||
[ | ||
{ | ||
"t": "Opaque", | ||
"extension": "prelude", | ||
"id": "error", | ||
"args": [], | ||
"bound": "C" | ||
} | ||
] | ||
] | ||
} | ||
], | ||
"extension_reqs": [] | ||
} | ||
}, | ||
"binary": false | ||
}, | ||
"trunc_u": { | ||
"extension": "arithmetic.conversions", | ||
"name": "trunc_u", | ||
"description": "float to unsigned int", | ||
"signature": { | ||
"params": [ | ||
{ | ||
"tp": "BoundedNat", | ||
"bound": 7 | ||
} | ||
], | ||
"body": { | ||
"input": [ | ||
{ | ||
"t": "Opaque", | ||
"extension": "arithmetic.float.types", | ||
"id": "float64", | ||
"args": [], | ||
"bound": "C" | ||
} | ||
], | ||
"output": [ | ||
{ | ||
"t": "Sum", | ||
"s": "General", | ||
"rows": [ | ||
[ | ||
{ | ||
"t": "Opaque", | ||
"extension": "arithmetic.int.types", | ||
"id": "int", | ||
"args": [ | ||
{ | ||
"tya": "Variable", | ||
"idx": 0, | ||
"cached_decl": { | ||
"tp": "BoundedNat", | ||
"bound": 7 | ||
} | ||
} | ||
], | ||
"bound": "C" | ||
} | ||
], | ||
[ | ||
{ | ||
"t": "Opaque", | ||
"extension": "prelude", | ||
"id": "error", | ||
"args": [], | ||
"bound": "C" | ||
} | ||
] | ||
] | ||
} | ||
], | ||
"extension_reqs": [] | ||
} | ||
}, | ||
"binary": false | ||
} | ||
} | ||
} |
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.
Use
pkgutil
https://stackoverflow.com/questions/6028000/how-to-read-a-static-file-from-inside-a-python-package/58941536#58941536