From baf63b89550f96b9495fefdae96ee89632694299 Mon Sep 17 00:00:00 2001 From: Manvi Agrawal Date: Fri, 31 May 2024 19:29:26 -0700 Subject: [PATCH 1/3] doc --- src/bloqade/submission/ir/task_results.py | 46 ++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/src/bloqade/submission/ir/task_results.py b/src/bloqade/submission/ir/task_results.py index 2be55073c..86d9932fc 100644 --- a/src/bloqade/submission/ir/task_results.py +++ b/src/bloqade/submission/ir/task_results.py @@ -1,3 +1,6 @@ +"""Module to represent the various enums and classes to assist with task +results after execution on QuEra system.""" + from enum import Enum from pydantic.v1 import BaseModel, conlist, conint from typing import List, Tuple @@ -9,6 +12,16 @@ class QuEraShotStatusCode(str, Enum): + """ + An Enum representing the status code the task executed on the QuEra system. + + Attributes: + Completed: The task has completed successfully. + MissingPreSequence = Pre sequence is missing for the task + MissingPostSequence = Post sequence is missing for the task + MissingMeasurement = Measurement is missing for the task + """ + Completed = "Completed" MissingPreSequence = "MissingPreSequence" MissingPostSequence = "MissingPostSequence" @@ -47,15 +60,37 @@ class QuEraTaskStatusCode(str, Enum): class QuEraShotResult(BaseModel): + """Object representing results after executing a task in QuEra system. + + Attributes: + shot_status (QuEraShotStatusCode): status code of task + after running on QuEra system. Defaults to + `QuEraShotStatusCode.MissingMeasurement` + pre_sequence: Set of preprocessing instructions. + post_sequence: Set of preprocessing instructions. + """ + shot_status: QuEraShotStatusCode = QuEraShotStatusCode.MissingMeasurement pre_sequence: conlist(conint(ge=0, le=1), min_items=0) = [] post_sequence: conlist(conint(ge=0, le=1), min_items=0) = [] class TaskProbabilities(BaseModel): + """The task results as probabilties. + + Attributes: + probabilities (List[Tuple[Tuple[str, str], float]]): + task results as probabilities + """ + probabilities: List[Tuple[Tuple[str, str], float]] - def simulate_task_results(self, shots=1) -> "QuEraTaskResults": + def simulate_task_results(self, shots: int = 1) -> "QuEraTaskResults": + """Simulate the task results as probabilties. + + Arguments: + shots (int): Number of shots, Defaults to 1 + """ bit_strings, probabilities = zip(*self.probabilities) indices = np.random.choice(len(probabilities), p=probabilities, size=shots) @@ -79,6 +114,15 @@ def simulate_task_results(self, shots=1) -> "QuEraTaskResults": class QuEraTaskResults(BaseModel): + """Object representing results after executing a task in QuEra system. + + Attributes: + task_status (QuEraShotStatusCode): states of task in the QuEra system. + Defaults to `QuEraShotStatusCode.Failed` + shot_outputs (conlist(QuEraShotResult, min_items=0)): + list representing shot outputs from QuEra system. + """ + task_status: QuEraTaskStatusCode = QuEraTaskStatusCode.Failed shot_outputs: conlist(QuEraShotResult, min_items=0) = [] From fbc51b6e2cbc027bc6d341131f76f2ee3431064c Mon Sep 17 00:00:00 2001 From: Manvi Agrawal Date: Fri, 31 May 2024 20:36:00 -0700 Subject: [PATCH 2/3] Minor edit --- src/bloqade/submission/ir/task_results.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bloqade/submission/ir/task_results.py b/src/bloqade/submission/ir/task_results.py index 86d9932fc..20630b028 100644 --- a/src/bloqade/submission/ir/task_results.py +++ b/src/bloqade/submission/ir/task_results.py @@ -88,7 +88,7 @@ class TaskProbabilities(BaseModel): def simulate_task_results(self, shots: int = 1) -> "QuEraTaskResults": """Simulate the task results as probabilties. - Arguments: + Args: shots (int): Number of shots, Defaults to 1 """ bit_strings, probabilities = zip(*self.probabilities) From 171080c86d02a1aedd2401c162709365bedaf464 Mon Sep 17 00:00:00 2001 From: Manvi Agrawal Date: Tue, 11 Jun 2024 01:32:35 -0700 Subject: [PATCH 3/3] PR feedback: add example --- src/bloqade/submission/ir/task_results.py | 24 ++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/bloqade/submission/ir/task_results.py b/src/bloqade/submission/ir/task_results.py index 20630b028..8954d0cef 100644 --- a/src/bloqade/submission/ir/task_results.py +++ b/src/bloqade/submission/ir/task_results.py @@ -89,7 +89,29 @@ def simulate_task_results(self, shots: int = 1) -> "QuEraTaskResults": """Simulate the task results as probabilties. Args: - shots (int): Number of shots, Defaults to 1 + shots (int): Number of shots, Defaults to 1. + + Returns: + task_result (QuEraTaskResults): Result of task simulation + For example: + ```python + { + "task_status": "Completed", + "shot_outputs": [ + { + "shot_status": "Completed", + "pre_sequence": [1], + "post_sequence": [1] + }, + .... + { + "shot_status": "Completed", + "pre_sequence": [1], + "post_sequence": [1] + } + ], + } + ``` """ bit_strings, probabilities = zip(*self.probabilities)