Skip to content

Commit

Permalink
Parallel blocks (#31)
Browse files Browse the repository at this point in the history
* parallel block definition in spec

* table for metadata options, need to fix formatting

* fix formatting

* fix formatting

* added parallel block to model

* added parallelblock to Blocktype

* markdownlinter remove line too long error for long description

* changed metadata table in spec and specify only qops in ParQBlock

* style: reformat and disable MD013 around metadata table, edit desc

* added parallel quantum block example to spec

* edit

* edit

* edit

* edit

* edit

* edit

* edit

* make updateschema

* leaving parblocks open to extensibility in the future with ops naming convention but only supporting qops in the model

* edit

* make updateschema

* qparallel

* chore/style: update schema, reformat table

---------

Co-authored-by: Kartik Singhal <kartik.singhal@quantinuum.com>
  • Loading branch information
Asa-Kosto-QTM and qartik authored Dec 1, 2023
1 parent 1120b2d commit efda950
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 2 deletions.
10 changes: 9 additions & 1 deletion phir/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand All @@ -279,7 +286,8 @@ class IfBlock(Block):
false_branch: list[OpType] | None = None


BlockType: TypeAlias = SeqBlock | IfBlock
BlockType: TypeAlias = SeqBlock | QParBlock | IfBlock


# Comments

Expand Down
54 changes: 54 additions & 0 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -743,6 +791,9 @@
{
"$ref": "#/$defs/SeqBlock"
},
{
"$ref": "#/$defs/QParBlock"
},
{
"$ref": "#/$defs/IfBlock"
}
Expand Down Expand Up @@ -1039,6 +1090,9 @@
{
"$ref": "#/$defs/SeqBlock"
},
{
"$ref": "#/$defs/QParBlock"
},
{
"$ref": "#/$defs/IfBlock"
},
Expand Down
35 changes: 34 additions & 1 deletion spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

<!-- markdownlint-disable MD013 -->
| 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. |
<!-- markdownlint-enable MD013 -->

## Comments

All entries in PHIR, whether instructions or blocks, adopt the dictionary format `{...}`. One
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit efda950

Please sign in to comment.