braket.aws.aws_quantum_task module

class braket.aws.aws_quantum_task.AwsQuantumTask(arn: str, aws_session: Optional[braket.aws.aws_session.AwsSession] = None, poll_timeout_seconds: int = 120, poll_interval_seconds: int = 0.25, logger: logging.Logger = <Logger braket.aws.aws_quantum_task (WARNING)>)[source]

Bases: braket.tasks.quantum_task.QuantumTask

Amazon Braket implementation of a quantum task. A task can be a circuit or an annealing problem.

Parameters
  • arn (str) – The ARN of the task.

  • aws_session (AwsSession, optional) – The AwsSession for connecting to AWS services. Default is None, in which case an AwsSession object will be created with the region of the task.

  • poll_timeout_seconds (int) – The polling timeout for result(), default is 120 seconds.

  • poll_interval_seconds (int) – The polling interval for result(), default is 0.25 seconds.

  • logger (Logger) – Logger object with which to write logs, such as task statuses while waiting for task to be in a terminal state. Default is getLogger(__name__)

Examples

>>> task = AwsQuantumTask(arn='task_arn')
>>> task.state()
'COMPLETED'
>>> result = task.result()
AnnealingQuantumTaskResult(...)
>>> task = AwsQuantumTask(arn='task_arn', poll_timeout_seconds=300)
>>> result = task.result()
GateModelQuantumTaskResult(...)
NO_RESULT_TERMINAL_STATES = {'CANCELLED', 'FAILED'}
RESULTS_READY_STATES = {'COMPLETED'}
GATE_IR_TYPE = 'jaqcd'
ANNEALING_IR_TYPE = 'annealing'
DEFAULT_SHOTS = 1000
DEFAULT_RESULTS_POLL_TIMEOUT = 120
DEFAULT_RESULTS_POLL_INTERVAL = 0.25
static create(aws_session: braket.aws.aws_session.AwsSession, device_arn: str, task_specification: Union[braket.circuits.circuit.Circuit, braket.annealing.problem.Problem], s3_destination_folder: braket.aws.aws_session.S3DestinationFolder, shots: Optional[int] = None, backend_parameters: Optional[Dict[str, Any]] = None, *args, **kwargs)braket.aws.aws_quantum_task.AwsQuantumTask[source]

AwsQuantumTask factory method that serializes a quantum task specification (either a quantum circuit or annealing problem), submits it to Amazon Braket, and returns back an AwsQuantumTask tracking the execution.

Parameters
  • aws_session (AwsSession) – AwsSession to connect to AWS with.

  • device_arn (str) – The ARN of the quantum device.

  • task_specification (Union[Circuit, Problem]) – The specification of the task to run on device.

  • s3_destination_folder (AwsSession.S3DestinationFolder) – NamedTuple, with bucket for index 0 and key for index 1, that specifies the Amazon S3 bucket and folder to store task results in.

  • shots (int) – The number of times to run the task on the device. If the device is a simulator, this implies the state is sampled N times, where N = shots. Default shots = 1_000.

  • backend_parameters (Dict[str, Any]) – Additional parameters to send to the device. For example, for D-Wave: {"dWaveParameters": {"postprocessingType": "OPTIMIZATION"}}

Returns

AwsQuantumTask – AwsQuantumTask tracking the task execution on the device.

Note

The following arguments are typically defined via clients of Device.
  • task_specification

  • s3_destination_folder

  • shots

property id

The ARN of the quantum task.

Type

str

cancel() → None[source]

Cancel the quantum task. This cancels the future and the task in Amazon Braket.

metadata(use_cached_value: bool = False) → Dict[str, Any][source]

Get task metadata defined in Amazon Braket.

Parameters

use_cached_value (bool, optional) – If True, uses the value most recently retrieved from the Amazon Braket GetQuantumTask operation. If False, calls the GetQuantumTask operation to retrieve metadata, which also updates the cached value. Default = False.

Returns

Dict[str, Any] – The response from the Amazon Braket GetQuantumTask operation. If use_cached_value is True, Amazon Braket is not called and the most recently retrieved value is used.

state(use_cached_value: bool = False) → str[source]

The state of the quantum task.

Parameters

use_cached_value (bool, optional) – If True, uses the value most recently retrieved from the Amazon Braket GetQuantumTask operation. If False, calls the GetQuantumTask operation to retrieve metadata, which also updates the cached value. Default = False.

Returns

str – The value of status in metadata(). This is the value of the status key in the Amazon Braket GetQuantumTask operation. If use_cached_value is True, the value most recently returned from the GetQuantumTask operation is used.

See also

metadata()

result() → Union[braket.tasks.gate_model_quantum_task_result.GateModelQuantumTaskResult, braket.tasks.annealing_quantum_task_result.AnnealingQuantumTaskResult][source]

Get the quantum task result by polling Amazon Braket to see if the task is completed. Once the task is completed, the result is retrieved from S3 and returned as a GateModelQuantumTaskResult or AnnealingQuantumTaskResult

This method is a blocking thread call and synchronously returns a result. Call async_result() if you require an asynchronous invocation. Consecutive calls to this method return a cached result from the preceding request.

async_result() → _asyncio.Task[source]

Get the quantum task result asynchronously. Consecutive calls to this method return the result cached from the most recent request.