braket.aws.aws_quantum_task module

class braket.aws.aws_quantum_task.AwsQuantumTask(arn: str, aws_session: AwsSession | None = None, poll_timeout_seconds: float = 432000, poll_interval_seconds: float = 1, logger: Logger = <Logger braket.aws.aws_quantum_task (WARNING)>, quiet: bool = False)[source]

Bases: QuantumTask

Amazon Braket implementation of a quantum task. A quantum task can be a circuit, an OpenQASM program or an AHS program.

Initializes an AwsQuantumTask.

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

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

  • poll_timeout_seconds (float) – The polling timeout for result(). Default: 5 days.

  • poll_interval_seconds (float) – The polling interval for result(). Default: 1 second.

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

  • quiet (bool) – Sets the verbosity of the logger to low and does not report queue position. Default is False.

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: ClassVar[set[str]] = {'CANCELLED', 'FAILED'}
RESULTS_READY_STATES: ClassVar[set[str]] = {'COMPLETED'}
TERMINAL_STATES: ClassVar[set[str]] = {'CANCELLED', 'COMPLETED', 'FAILED'}
DEFAULT_RESULTS_POLL_TIMEOUT = 432000
DEFAULT_RESULTS_POLL_INTERVAL = 1
RESULTS_FILENAME = 'results.json'
static create(aws_session: AwsSession, device_arn: str, task_specification: Circuit | Problem | OpenQASMProgram | BlackbirdProgram | PulseSequence | AnalogHamiltonianSimulation, s3_destination_folder: AwsSession.S3DestinationFolder, shots: int, device_parameters: dict[str, Any] | None = None, disable_qubit_rewiring: bool = False, tags: dict[str, str] | None = None, inputs: dict[str, float] | None = None, gate_definitions: dict[tuple[Gate, QubitSet], PulseSequence] | None = None, quiet: bool = False, reservation_arn: str | None = None, *args, **kwargs) 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, OpenQASMProgram, BlackbirdProgram, PulseSequence, AnalogHamiltonianSimulation]) – # noqa The specification of the quantum 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 quantum task results in.

  • shots (int) – The number of times to run the quantum task on the device. If the device is a simulator, this implies the state is sampled N times, where N = shots. shots=0 is only available on simulators and means that the simulator will compute the exact results based on the quantum task specification.

  • device_parameters (dict[str, Any] | None) – Additional parameters to send to the device.

  • disable_qubit_rewiring (bool) – Whether to run the circuit with the exact qubits chosen, without any rewiring downstream, if this is supported by the device. Only applies to digital, gate-based circuits (as opposed to annealing problems). If True, no qubit rewiring is allowed; if False, qubit rewiring is allowed. Default: False

  • tags (dict[str, str] | None) – Tags, which are Key-Value pairs to add to this quantum task. An example would be: {"state": "washington"}

  • inputs (dict[str, float] | None) – Inputs to be passed along with the IR. If the IR supports inputs, the inputs will be updated with this value. Default: {}.

  • gate_definitions (dict[tuple[Gate, QubitSet], PulseSequence] | None) – A dict of user defined gate calibrations. Each calibration is defined for a particular Gate on a particular QubitSet and is represented by a PulseSequence. Default: None.

  • quiet (bool) – Sets the verbosity of the logger to low and does not report queue position. Default is False.

  • reservation_arn (str | None) – The reservation ARN provided by Braket Direct to reserve exclusive usage for the device to run the quantum task on. Note: If you are creating tasks in a job that itself was created reservation ARN, those tasks do not need to be created with the reservation ARN. Default: None.

Returns:

AwsQuantumTask – AwsQuantumTask tracking the quantum task execution on the device.

Note

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

  • s3_destination_folder

  • shots

See also

braket.aws.aws_quantum_simulator.AwsQuantumSimulator.run() braket.aws.aws_qpu.AwsQpu.run()

property id: str

The ARN of the quantum task.

Type:

str

cancel() None[source]

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

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

Get quantum task metadata defined in Amazon Braket.

Parameters:

use_cached_value (bool) – If True, uses the value most recently retrieved from the Amazon Braket GetQuantumTask operation, if it exists; if not, GetQuantumTask will be called to retrieve the metadata. If False, always calls GetQuantumTask, 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, unless GetQuantumTask was never called, in which case it will still be called to populate the metadata for the first time.

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

The state of the quantum task.

Parameters:

use_cached_value (bool) – 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()

queue_position() QuantumTaskQueueInfo[source]

The queue position details for the quantum task.

Returns:

QuantumTaskQueueInfo – Instance of QuantumTaskQueueInfo class representing the queue position information for the quantum task. The queue_position is only returned when quantum task is not in RUNNING/CANCELLING/TERMINAL states, else queue_position is returned as None. The normal tasks refers to the quantum tasks not submitted via Hybrid Jobs. Whereas, the priority tasks refers to the total number of quantum tasks waiting to run submitted through Amazon Braket Hybrid Jobs. These tasks run before the normal tasks. If the queue position for normal or priority quantum tasks is greater than 2000, we display their respective queue position as ‘>2000’.

Examples

task status = QUEUED and queue position is 2050 >>> task.queue_position() QuantumTaskQueueInfo(queue_type=<QueueType.NORMAL: ‘Normal’>, queue_position=’>2000’, message=None)

task status = COMPLETED >>> task.queue_position() QuantumTaskQueueInfo(queue_type=<QueueType.NORMAL: ‘Normal’>, queue_position=None, message=’Task is in COMPLETED status. AmazonBraket does not show queue position for this status.’)

result() GateModelQuantumTaskResult | AnnealingQuantumTaskResult | PhotonicModelQuantumTaskResult[source]

Get the quantum task result by polling Amazon Braket to see if the task is completed. Once the quantum 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.

Returns:

Union[GateModelQuantumTaskResult, AnnealingQuantumTaskResult, PhotonicModelQuantumTaskResult] – The result of the quantum task, if the quantum task completed successfully; returns None if the quantum task did not complete successfully or the future timed out.

async_result() Task[source]

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