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] Improve docstrings for "task/bloqade" #973

Closed
wants to merge 3 commits into from
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
61 changes: 56 additions & 5 deletions src/bloqade/task/bloqade.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
"""
This module defines the BloqadeTask class, which is used to execute quantum tasks using the
Bloqade emulator. It also provides serialization and deserialization methods for the BloqadeTask
instances.
"""

from dataclasses import dataclass
from typing import Optional
import numpy as np
from beartype.typing import Dict, Any

from bloqade.serialize import Serializer
from bloqade.task.base import Geometry, LocalTask
from bloqade.emulate.ir.emulator import EmulatorProgram
Expand All @@ -13,30 +24,55 @@
QuEraTaskStatusCode,
QuEraShotStatusCode,
)
from beartype.typing import Dict, Any
from bloqade.builder.base import ParamType
from dataclasses import dataclass
from typing import Optional
import numpy as np


@dataclass
@Serializer.register
class BloqadeTask(LocalTask):
"""
Represents a quantum task to be executed on the Bloqade emulator.

Attributes:
shots (int): The number of shots to be executed.
emulator_ir (EmulatorProgram): The emulation program to be executed.
metadata (Dict[str, ParamType]): Metadata associated with the task.
compile_cache (Optional[CompileCache]): Cache for compiled code.
task_result_ir (Optional[QuEraTaskResults]): Results of the task execution.
"""

shots: int
emulator_ir: EmulatorProgram
metadata: Dict[str, ParamType]
compile_cache: Optional[CompileCache] = None
task_result_ir: Optional[QuEraTaskResults] = None

def _geometry(self) -> Geometry:
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a private function

Returns the geometry of the qubit register.

Returns:
Geometry: The geometry of the qubit register.
"""
return self.emulator_ir.register.geometry

def result(self) -> QuEraTaskResults:
"""
Returns the results of the task execution.

Returns:
QuEraTaskResults: The results of the task execution.
"""
return self.task_result_ir

@property
def nshots(self) -> int:
"""
Returns the number of shots to be executed.

Returns:
int: The number of shots to be executed.
"""
return self.shots

def run(
Expand All @@ -47,7 +83,22 @@ def run(
nsteps: int = 2_147_483_647,
interaction_picture: bool = False,
) -> "BloqadeTask":

"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please also add one example to demonstrate how this function can be used. This is a user API.

Runs the quantum task using the specified solver and options.

Args:
solver_name (str): The name of the solver to be used. Default is "dop853".
atol (float): Absolute tolerance for the solver. Default is 1e-14.
rtol (float): Relative tolerance for the solver. Default is 1e-7.
nsteps (int): Maximum number of steps for the solver. Default is 2_147_483_647.
interaction_picture (bool): Whether to use the interaction picture. Default is False.

Returns:
BloqadeTask: The current instance with updated task results.

Raises:
ValueError: If there is an error during the execution of the task.
"""
hamiltonian = RydbergHamiltonianCodeGen(self.compile_cache).emit(
self.emulator_ir
)
Expand Down
Loading