Skip to content

Commit

Permalink
feat(model): Angle unit is appended after the angles list
Browse files Browse the repository at this point in the history
Based on feedback from Ciarán on the PR
  • Loading branch information
qartik committed Oct 23, 2023
1 parent 072d904 commit 72a47a2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 29 deletions.
6 changes: 1 addition & 5 deletions phir/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,13 @@ class Op(BaseModel, abc.ABC):
metadata: dict[str, Any] | None = None


Radian: TypeAlias = float
PiRadian = NewType("PiRadian", tuple[float, Literal["pi"]])


class QOp(Op):
"""Quantum operation."""

qop: str
returns: list[Bit] | None = None
args: list[Bit | list[Bit]]
angles: list[Radian | PiRadian] | None = None
angles: tuple[list[float], Literal["rad", "pi"]] | None = None


class COp(Op):
Expand Down
11 changes: 5 additions & 6 deletions phir_spec_qasm.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,15 +312,14 @@ The generic qop gate structure is:
```json5
{
"qop": str,
"angles": [float | [float, "pi"] ...], // Include if gate has one or more angles.
"angles": [[float...], "rad" | "pi"], // Include if gate has one or more angles.
"args": [qubit_id, ... | [qubit_id, ... ], ...], // Can be a list of qubit IDs or a list of lists for multi-qubit gates.
"metadata": {}, // Optional metadata for potential auxiliary info or to be utilized by error models.
"returns": [[str, int], ...] // Include if gate produces output, e.g., a measurement.
}
```

`"angles"` list is expected to be in radians, ie, `float`. For convenience, multiples of ᴨ (pi radians) are also supported in the
form of tuples `[float, "pi"]`.
`"angles"` is a tuple of a list of `float`s and a unit. The units supported are radians (preferred) and multiples of ᴨ (pi radians).

Table II details the available qops.

Expand Down Expand Up @@ -353,12 +352,12 @@ However, multi-qubit gates, such as `CX`, use a list of lists of qubit IDs. E.g.

PECOS ensures all qubit IDs in `"args"` are unique, meaning gates don't overlap on the same qubits.

For gates with one or multiple angles, angles are denoted as floats (or pi radians, not shown) in the `"angles"` list:
For gates with one or multiple angles, angles are denoted as floats and a unit in the `"angles"` list:

```json5
{
"qop": "RZZ",
"angles": [0.173],
"angles": [[0.173], "rad"],
"args": [
[ ["q", 0], ["q", 1] ],
[ ["q", 2], ["q", 3] ]
Expand All @@ -370,7 +369,7 @@ For gates with one or multiple angles, angles are denoted as floats (or pi radia
```json5
{
"qop": "U1q",
"angles": [0.524, 1.834],
"angles": [[0.524, 1.834], "rad"],
"args": [
[ ["q", 0], ["q", 1], ["q", 2], ["q", 3] ]
],
Expand Down
33 changes: 15 additions & 18 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -528,26 +528,23 @@
"angles": {
"anyOf": [
{
"items": {
"anyOf": [
{
"maxItems": 2,
"minItems": 2,
"prefixItems": [
{
"items": {
"type": "number"
},
{
"maxItems": 2,
"minItems": 2,
"prefixItems": [
{
"type": "number"
},
{
"const": "pi"
}
],
"type": "array"
}
]
},
"type": "array"
},
{
"enum": [
"rad",
"pi"
],
"type": "string"
}
],
"type": "array"
},
{
Expand Down

0 comments on commit 72a47a2

Please sign in to comment.