Skip to content

Commit

Permalink
fix: correct typing for task results methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Coull committed Oct 11, 2024
1 parent 36e32f6 commit 04a88a2
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/braket/aws/aws_quantum_task_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import time
from concurrent.futures.thread import ThreadPoolExecutor
from itertools import repeat
from typing import Any, Union
from typing import TYPE_CHECKING, Any, Union

from braket.ahs.analog_hamiltonian_simulation import AnalogHamiltonianSimulation
from braket.annealing import Problem
Expand All @@ -30,6 +30,11 @@
from braket.registers.qubit_set import QubitSet
from braket.tasks.quantum_task_batch import QuantumTaskBatch

if TYPE_CHECKING:
from braket.tasks.annealing_quantum_task_result import AnnealingQuantumTaskResult
from braket.tasks.gate_model_quantum_task_result import GateModelQuantumTaskResult
from braket.tasks.photonic_model_quantum_task_result import PhotonicModelQuantumTaskResult

Check warning on line 36 in src/braket/aws/aws_quantum_task_batch.py

View check run for this annotation

Codecov / codecov/patch

src/braket/aws/aws_quantum_task_batch.py#L34-L36

Added lines #L34 - L36 were not covered by tests


class AwsQuantumTaskBatch(QuantumTaskBatch):
"""Executes a batch of quantum tasks in parallel.
Expand Down Expand Up @@ -331,7 +336,9 @@ def results(
fail_unsuccessful: bool = False,
max_retries: int = MAX_RETRIES,
use_cached_value: bool = True,
) -> list[AwsQuantumTask]:
) -> list[
GateModelQuantumTaskResult | AnnealingQuantumTaskResult | PhotonicModelQuantumTaskResult
]:
"""Retrieves the result of every quantum task in the batch.
Polling for results happens in parallel; this method returns when all quantum tasks
Expand All @@ -348,7 +355,8 @@ def results(
even when results have already been cached. Default: `True`.
Returns:
list[AwsQuantumTask]: The results of all of the quantum tasks in the batch.
list[GateModelQuantumTaskResult | AnnealingQuantumTaskResult | PhotonicModelQuantumTaskResult]: The # noqa: E501
results of all of the quantum tasks in the batch.
`FAILED`, `CANCELLED`, or timed out quantum tasks will have a result of None
"""
if not self._results or not use_cached_value:
Expand All @@ -369,7 +377,11 @@ def results(
return self._results

@staticmethod
def _retrieve_results(tasks: list[AwsQuantumTask], max_workers: int) -> list[AwsQuantumTask]:
def _retrieve_results(
tasks: list[AwsQuantumTask], max_workers: int
) -> list[
GateModelQuantumTaskResult | AnnealingQuantumTaskResult | PhotonicModelQuantumTaskResult
]:
with ThreadPoolExecutor(max_workers=max_workers) as executor:
result_futures = [executor.submit(task.result) for task in tasks]
return [future.result() for future in result_futures]
Expand Down

0 comments on commit 04a88a2

Please sign in to comment.