diff --git a/phir/model.py b/phir/model.py index 5d858b6..e199f71 100644 --- a/phir/model.py +++ b/phir/model.py @@ -270,6 +270,13 @@ class SeqBlock(Block): ops: list[OpType | BlockType] +class QParBlock(Block): + """Parallel quantum operations block.""" + + block: Literal["qparallel"] + ops: list[QOp] + + class IfBlock(Block): """If/else block.""" @@ -279,7 +286,8 @@ class IfBlock(Block): false_branch: list[OpType] | None = None -BlockType: TypeAlias = SeqBlock | IfBlock +BlockType: TypeAlias = SeqBlock | QParBlock | IfBlock + # Comments diff --git a/schema.json b/schema.json index 5664fb8..12abbad 100644 --- a/schema.json +++ b/schema.json @@ -549,6 +549,54 @@ "title": "MeasOp", "type": "object" }, + "QParBlock": { + "additionalProperties": false, + "description": "Parallel quantum operations block.", + "properties": { + "metadata": { + "anyOf": [ + { + "type": "object" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Metadata" + }, + "block": { + "const": "qparallel", + "title": "Block" + }, + "ops": { + "items": { + "anyOf": [ + { + "$ref": "#/$defs/MeasOp" + }, + { + "$ref": "#/$defs/SQOp" + }, + { + "$ref": "#/$defs/TQOp" + }, + { + "$ref": "#/$defs/ThreeQOp" + } + ] + }, + "title": "Ops", + "type": "array" + } + }, + "required": [ + "block", + "ops" + ], + "title": "QParBlock", + "type": "object" + }, "QVarDefine": { "additionalProperties": false, "description": "Defining Quantum Variables.", @@ -743,6 +791,9 @@ { "$ref": "#/$defs/SeqBlock" }, + { + "$ref": "#/$defs/QParBlock" + }, { "$ref": "#/$defs/IfBlock" } @@ -1039,6 +1090,9 @@ { "$ref": "#/$defs/SeqBlock" }, + { + "$ref": "#/$defs/QParBlock" + }, { "$ref": "#/$defs/IfBlock" }, diff --git a/spec.md b/spec.md index 65358a1..355e0c1 100644 --- a/spec.md +++ b/spec.md @@ -31,9 +31,17 @@ sequence of operations the program encapsulates. - `"format"`: Signifies the utilization of the PHIR/JSON format. - `"version"`: Represents the semantic version number adhering to the PHIR spec. - `"metadata"`: An optional segment where users can incorporate additional details. This segment holds potential for -future expansion, possibly to guid compilation processes and error modeling. +future expansion, possibly to guide compilation processes and error modeling. - `"ops": [{...}, ...]`: A linear sequence denoting the operations and blocks that constitute the program. +### Metadata Options + + +| parameter | options | description | +| ---------------------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `"strict_parallelism"` | `"true", "false"` | If `"true"`, tell emulator to interpret `"qop"`s with multiple arguments (outside a [qparallel block](#qparallel-block)) as parallel application of the `"qop"` to those arguments. If `"false"` (default), the emulator is free to decide how much parallelism to apply to multiple argument `"qop"`s. | + + ## Comments All entries in PHIR, whether instructions or blocks, adopt the dictionary format `{...}`. One @@ -491,6 +499,31 @@ The foundation block simply sequences operations and other blocks } ``` +### QParallel block + +A grouping of quantum operations to be performed in parallel. + +```json5 +{ + "block": "qparallel", + "ops": [{...}, ...], + "metadata": {...} // Optional +} +``` + +The following example contains 6 RZ gate applications. There is 1 `"qop"` per unique gate angle, each with 2 qubit arguments. +All gates within the block will be applied in parallel. + +```json5 +{ + "block": "qparallel", + "ops": [{"qop": "RZ", "angles": [[1.5], "pi"], "args": [["q", 0], ["q", 1]]}, + {"qop": "RZ", "angles": [[1.0], "pi"], "args": [["q", 2], ["q", 3]]}, + {"qop": "RZ", "angles": [[0.5], "pi"], "args": [["q", 4], ["q", 5]]} + ] +} +``` + ### If/else block An if-else block: