From 72a47a269f65a2c6a365e30d0cea356d5889ae8d Mon Sep 17 00:00:00 2001 From: Kartik Singhal Date: Mon, 23 Oct 2023 11:28:30 -0500 Subject: [PATCH] feat(model): Angle unit is appended after the angles list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Based on feedback from Ciarán on the PR --- phir/model.py | 6 +----- phir_spec_qasm.md | 11 +++++------ schema.json | 33 +++++++++++++++------------------ 3 files changed, 21 insertions(+), 29 deletions(-) diff --git a/phir/model.py b/phir/model.py index c5cecf1..6a6f6c2 100644 --- a/phir/model.py +++ b/phir/model.py @@ -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): diff --git a/phir_spec_qasm.md b/phir_spec_qasm.md index 2af2540..7e64435 100644 --- a/phir_spec_qasm.md +++ b/phir_spec_qasm.md @@ -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. @@ -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] ] @@ -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] ] ], diff --git a/schema.json b/schema.json index f3fcf70..44d9d57 100644 --- a/schema.json +++ b/schema.json @@ -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" }, {