AwsQuantumTask
- class braket.aws.aws_quantum_task.AwsQuantumTask(arn, aws_session=None, poll_timeout_seconds=432000, poll_interval_seconds=1, logger=<Logger braket.aws.aws_quantum_task (WARNING)>, quiet=False, task_specification=None, **kwargs)[source]
Bases:
QuantumTaskAmazon Braket implementation of a quantum task. A quantum task can be a circuit, an OpenQASM program or an AHS program.
- Parameters:
arn (
str)aws_session (
AwsSession|None)poll_timeout_seconds (
float)poll_interval_seconds (
float)logger (
Logger)quiet (
bool)task_specification (
Circuit|SerializableProgram|ProgramSet|Program|ProgramSet|AnalogHamiltonianSimulation|PulseSequence|None)
Initializes an
AwsQuantumTask.- Parameters:
arn (str) – The ARN of the quantum task.
aws_session (AwsSession | None) – The
AwsSessionfor connecting to AWS services. Default isNone, in which case anAwsSessionobject 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.task_specification (TaskSpecification | None) – The specification the task was run with
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, device_arn, task_specification, s3_destination_folder, shots, device_parameters=None, disable_qubit_rewiring=False, tags=None, inputs=None, gate_definitions=None, quiet=False, reservation_arn=None, experimental_capabilities=None, *args, **kwargs)[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 (TaskSpecification) – Specification of the quantum task to run.
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=0is 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; ifFalse, qubit rewiring is allowed. Default: Falsetags (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
dictof user defined gate calibrations. Each calibration is defined for a particularGateon a particularQubitSetand is represented by aPulseSequence. 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.
experimental_capabilities (str | None) – Experimental capabilities to enable for the quantum task. Supported values are “ALL” to enable all experimental capabilities. If
None, the setting from the experimental capability context will be used if active. Default: None.
- Return type:
- Returns:
AwsQuantumTask – AwsQuantumTask tracking the quantum task execution on the device.
Note
- The following arguments are typically defined via clients of Device.
task_specifications3_destination_foldershots
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()[source]
Cancel the quantum task. This cancels the future and the quantum task in Amazon Braket.
- Return type:
None
- metadata(use_cached_value=False)[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 BraketGetQuantumTaskoperation, if it exists; if not,GetQuantumTaskwill be called to retrieve the metadata. IfFalse, always callsGetQuantumTask, which also updates the cached value. Default:False.- Return type:
dict[str,Any]- Returns:
dict[str, Any] – The response from the Amazon Braket
GetQuantumTaskoperation. Ifuse_cached_valueisTrue, Amazon Braket is not called and the most recently retrieved value is used, unlessGetQuantumTaskwas never called, in which case it will still be called to populate the metadata for the first time.
- property action_type: DeviceActionType
The type of action the task was created with.
- Type:
DeviceActionType
- state(use_cached_value=False)[source]
The state of the quantum task.
- Parameters:
use_cached_value (bool) – If
True, uses the value most recently retrieved from the Amazon BraketGetQuantumTaskoperation. IfFalse, calls theGetQuantumTaskoperation to retrieve metadata, which also updates the cached value. Default =False.- Return type:
str- Returns:
str – The value of
statusinmetadata(). This is the value of thestatuskey in the Amazon BraketGetQuantumTaskoperation. Ifuse_cached_valueisTrue, the value most recently returned from theGetQuantumTaskoperation is used.
See also
- queue_position()[source]
The queue position details for the quantum task.
- Return type:
- 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()[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
GateModelQuantumTaskResultorAnnealingQuantumTaskResultThis 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.- Return type:
GateModelQuantumTaskResult|ProgramSetQuantumTaskResult|AnalogHamiltonianSimulationQuantumTaskResult- Returns:
TaskResult – The result of the quantum task, if the quantum task completed successfully; returns
Noneif the quantum task did not complete successfully or the future timed out.