-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Minimal implementation for YAML extensions (#833)
This PR add a method `hugr::extensions::declarative::load_extensions` that dynamically loads a set of extensions defined as YAML onto a registry. The code is mostly comprised of struct definitions to match the human-readable serialisation format described in the spec, and some methods to translate them into the internal hugr definitions. There's a myriad of TODOs that should be addressed in future PRs, including: - Most parametric things (operations, type bounds, number of ports in a signature, ...). - Lowering functions, operations with non explicit signatures. - Resolving the signature types. - The syntax for describing these is not defined in the spec, so currently there's just a couple of basic hard-coded types used for testing: "Q" and "USize". Here's an example of a supported definition: ```yaml imports: [prelude] extensions: - name: SimpleExt types: - name: MyType description: A simple type with no parameters operations: - name: MyOperation description: A simple operation with no inputs nor outputs signature: inputs: [] outputs: [] - name: AnotherOperation description: An operation from 2 qubits to 2 qubits signature: inputs: [["Target", Q], ["Control", Q, 1]] outputs: [[null, Q, 2]] ```
- Loading branch information
Showing
11 changed files
with
1,031 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Optionally import other extensions. The `prelude` is always imported. | ||
imports: [logic] | ||
|
||
extensions: | ||
- # Each extension must have a name | ||
name: SimpleExt | ||
types: | ||
- # Types must have a name. | ||
# Parameters are not currently supported. | ||
name: Copyable type | ||
description: A simple type with no parameters | ||
# Types may have a "Eq", "Copyable", or "Any" bound. | ||
# This field is optional and defaults to "Any". | ||
bound: Copyable | ||
operations: | ||
- # Operations must have a name and a signature. | ||
name: MyOperation | ||
description: A simple operation with no inputs nor outputs | ||
signature: | ||
inputs: [] | ||
outputs: [] | ||
- name: AnotherOperation | ||
description: An operation from 3 qubits to 3 qubits | ||
signature: | ||
# The input and outputs can be written directly as the types | ||
inputs: [Q, Q, Q] | ||
outputs: | ||
- # Or as the type followed by a number of repetitions. | ||
[Q, 1] | ||
- # Or as a description, followed by the type and a number of repetitions. | ||
[Control, Q, 2] |
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.