Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Unitary-Hack][Sub-ir-task_result] Doc strings in submission/ir/task_result.py #979

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 67 additions & 1 deletion src/bloqade/submission/ir/task_results.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -47,15 +60,59 @@ 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`
weinbe58 marked this conversation as resolved.
Show resolved Hide resolved
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.

Args:
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)

indices = np.random.choice(len(probabilities), p=probabilities, size=shots)
Expand All @@ -79,6 +136,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) = []

Expand Down
Loading