Skip to content

Commit

Permalink
Merge pull request #9 from CQCL/units-for-angles-and-duration
Browse files Browse the repository at this point in the history
  • Loading branch information
qartik authored Oct 23, 2023
2 parents 7a74328 + bc528fe commit 760d4f3
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 11 deletions.
6 changes: 5 additions & 1 deletion phir/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class QOp(Op):
qop: str
returns: list[Bit] | None = None
args: list[Bit | list[Bit]]
angles: list[float] | None = None
angles: tuple[list[float], Literal["rad", "pi"]] | None = None


class COp(Op):
Expand All @@ -92,10 +92,14 @@ class FFCall(COp):
function: str


Duration = NewType("Duration", tuple[float, Literal["s", "ms", "us", "ns"]])


class MOp(Op):
"""Machine operation."""

mop: str
duration: Duration | None = None


OpType: TypeAlias = FFCall | COp | QOp | MOp
Expand Down
20 changes: 13 additions & 7 deletions phir_spec_qasm.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,13 +312,15 @@ The generic qop gate structure is:
```json5
{
"qop": str,
"angles": [float...], // 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"` 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.

For qops like `H q[0]; H q[1]; H q[4];` in QASM, it is translated as:
Expand Down Expand Up @@ -350,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 in the `"angles"` list:
For gates with one or multiple angles, angles are denoted as a list of floats and a unit in the `"angles"` field:

```json5
{
"qop": "RZZ",
"angles": [0.173],
"angles": [[0.173], "rad"],
"args": [
[ ["q", 0], ["q", 1] ],
[ ["q", 2], ["q", 3] ]
Expand All @@ -367,7 +369,7 @@ For gates with one or multiple angles, angles are denoted as floats in the `"ang
```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 Expand Up @@ -437,27 +439,31 @@ The general form of `"mop"`s is:
{
"mop": str, // identifying name
"args": [qubit_id, ... | [qubit_id, ... ], ...], // optional
"duration": [float, "s"|"ms"|"us"|"ns"], // optional
"metadata": {} // Optional metadata for potential auxiliary info or to be utilized by error models.
}
```

The `"duration"` field supports seconds (s), milliseconds (ms), microseconds (us), and nanoseconds (ns) as its units.

Currently, `"mop"`s are more defined by the implementation of the Machine and ErrorModel classes in PECOS. Therefore,
the `"metadata"` tag is heavily depended on up to supply values that these classes expect. An example of indicating
the `"metadata"` tag is heavily depended upon to supply values that these classes expect. An example of indicating
idling and transport include:

```json5
{
"mop": "Idle",
"args": [["q", 0], ["q", 5], ["w", 1] ],
"metadata": {"duration": 0.000123 } // typically in seconds
"duration": [0.000123, "s"] // typically in seconds
}
```

```json5
{
"mop": "Transport",
// potentially using "args" to indicate what qubits are being transported
"metadata": {"duration": 0.0005 } // potentially including what positions to and from qubits moved between or what path taken
"duration": [0.5, "ms"]
"metadata": {...} // potentially including what positions to and from qubits moved between or what path taken
}
```

Expand Down
48 changes: 45 additions & 3 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,34 @@
"mop": {
"title": "Mop",
"type": "string"
},
"duration": {
"anyOf": [
{
"maxItems": 2,
"minItems": 2,
"prefixItems": [
{
"type": "number"
},
{
"enum": [
"s",
"ms",
"us",
"ns"
],
"type": "string"
}
],
"type": "array"
},
{
"type": "null"
}
],
"default": null,
"title": "Duration"
}
},
"required": [
Expand Down Expand Up @@ -500,9 +528,23 @@
"angles": {
"anyOf": [
{
"items": {
"type": "number"
},
"maxItems": 2,
"minItems": 2,
"prefixItems": [
{
"items": {
"type": "number"
},
"type": "array"
},
{
"enum": [
"rad",
"pi"
],
"type": "string"
}
],
"type": "array"
},
{
Expand Down

0 comments on commit 760d4f3

Please sign in to comment.