-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hugr-py): use serialized extensions in python (#1459)
Copies standard extensions to hugr-py source tree, as poetry won't include anything from outside the tree (not symlinks either). Existing op/type wrappers now just point to loaded extensions. Closes #1450
- Loading branch information
Showing
21 changed files
with
4,602 additions
and
52 deletions.
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 |
---|---|---|
@@ -1 +1,13 @@ | ||
"""Types and operations from the standard extension set.""" | ||
|
||
import pkgutil | ||
|
||
from hugr.ext import Extension | ||
from hugr.serialization.extension import Extension as PdExtension | ||
|
||
|
||
def _load_extension(name: str) -> Extension: | ||
replacement = name.replace(".", "/") | ||
json_str = pkgutil.get_data(__name__, f"_json_defs/{replacement}.json") | ||
assert json_str is not None | ||
return PdExtension.model_validate_json(json_str).deserialize() |
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,2 @@ | ||
The files in this directory are generated and copied in, don't edit by hand. See | ||
repository justfile `gen-extensions` command. |
222 changes: 222 additions & 0 deletions
222
hugr-py/src/hugr/std/_json_defs/arithmetic/conversions.json
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,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 | ||
} | ||
} | ||
} |
Oops, something went wrong.