-
Notifications
You must be signed in to change notification settings - Fork 14
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
Closed
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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: | ||
""" | ||
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( | ||
|
@@ -47,7 +83,22 @@ def run( | |
nsteps: int = 2_147_483_647, | ||
interaction_picture: bool = False, | ||
) -> "BloqadeTask": | ||
|
||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
) | ||
|
@@ -89,6 +140,15 @@ def run( | |
|
||
@BloqadeTask.set_serializer | ||
def _serialize(obj: BloqadeTask) -> Dict[str, Any]: | ||
""" | ||
shubhusion marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Serializes a BloqadeTask object to a dictionary. | ||
|
||
Args: | ||
obj (BloqadeTask): The BloqadeTask object to be serialized. | ||
|
||
Returns: | ||
Dict[str, Any]: The serialized representation of the BloqadeTask object. | ||
""" | ||
return { | ||
"shots": obj.shots, | ||
"emulator_ir": obj.emulator_ir, | ||
|
@@ -99,6 +159,15 @@ def _serialize(obj: BloqadeTask) -> Dict[str, Any]: | |
|
||
@BloqadeTask.set_deserializer | ||
def _deserialize(d: Dict[str, Any]) -> BloqadeTask: | ||
""" | ||
Deserializes a dictionary to a BloqadeTask object. | ||
|
||
Args: | ||
d (Dict[str, Any]): The dictionary to be deserialized. | ||
|
||
Returns: | ||
BloqadeTask: The deserialized BloqadeTask object. | ||
""" | ||
d["task_result_ir"] = ( | ||
QuEraTaskResults(**d["task_result_ir"]) if d["task_result_ir"] else None | ||
) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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