Skip to main content

AWS Braket Qubit Executor

This quantum executor accesses quantum resources operating under the qubit model as made available through AWS ("braket.aws.qubit").

It utilizes the Pennylane plugin found here. BraketQubitExecutor introduces thread-based parallelism for circuit execution on the "braket.aws.qubit" device.

1. Installation

BraketQubitExecutor is included in Covalent. To use it, however, you will need to install the amazon-braket-pennylane-plugin:

pip install amazon-braket-pennylane-plugin

and have valid AWS credentials as specified here.

2. Usage Example

Using BraketQubitExecutor requires specifying an AWS Quantum backend through the device_arn argument.

# Statevector simulator
sv1 = ct.executor.BraketQubitExecutor(
device_arn="arn:aws:braket:::device/quantum-simulator/amazon/sv1",
shots=1024,
s3_destination_folder=(),
)
# Tensor network simulator
tn1 = ct.executor.BraketQubitExecutor(
device_arn="arn:aws:braket:::device/quantum-simulator/amazon/tn1",
shots=1024,
s3_destination_folder=(),
)

@ct.qelectron(executors=[sv1, tn1])
@qml.qnode(qml.device("default.qubit", wires=2, shots=1000))
def circuit(x):
qml.IQPEmbedding(features=x, wires=[0, 1])
qml.Hadamard(wires=1)
return [qml.expval(qml.PauliZ(0)), qml.expval(qml.PauliZ(1))]

As a QElectron, the circuit can be called either normally or asynchronously using circuit.run_later(). With the default "cyclic" selector, circuit calls will alternate between the executors, [sv1, tn1].

Synchronous example output is below

>>> print(circuit([0.5, 0.1]))  # alternate between sv1 and tn1

[array(0.008), array(0.996)]

and asynchronously:

>>> x = [0.6, -1.57]

>>> # Queue jobs for all three circuit calls simultaneously on AWS Braket.
>>> # Uses same executor order as above (sv1, tn1, ...).
>>> futs = [circuit.run_later(x) for _ in range(3)]

>>> # Wait for all circuits to finish.
>>> [fut.result() for fut in futs]

[[array(-0.02), array(0.01)],
[array(0.014), array(-0.022)],
[array(-0.074), array(0.05)]]

3. Overview of Configuration

The BraketQubitExecutor configuration is found under [qelectron.BraketQubitExecutor] in the Covalent configuration file.

ConfigIs RequiredDefaultDescription
s3_destination_folderNo() an empty tupleThe location of the s3 bucket that simulation data will be stored in. I.e, you can set s3 = ("my-bucket", "my-prefix").

4. Required Cloud Resources

Users must acquire AWS credentials and make them discoverable following the instructions here.


pydantic model covalent.executor.BraketQubitExecutor

#

The remote Braket executor based on the existing Pennylane Braket qubit device.

Usage of this device requires valid AWS credentials as set up following the instructions at https://github.com/aws/amazon-braket-sdk-python#prerequisites.

max_jobs

Maximum number of parallel jobs sent by threads on batch_submit.

shots

Number of shots used to estimate quantum observables.

device_arn

An alpha-numeric code (arn=Amazon Resource Name) specifying a quantum device.

poll_timeout_seconds

Number of seconds before a poll to the remote device is considered timed-out.

poll_interval_seconds

Number of seconds before a poll to the remote device is considered timed-out.

aws_session

An AwsSession object created to manage interactions with AWS services, to be supplied if extra control is desired.

parallel

Turn parallel execution on or off.

max_parallel

The maximum number of circuits to be executed in parallel.

max_connections

The maximum number of connections in the Boto3 connection pool.

max_retries

The maximum number of times a job will be re-sent if it failed.

s3_destination_folder

Name of the S3 bucket and folder, specified as a tuple.

run_kwargs

Variable length keyword arguments for braket.devices.Device.run()

Show JSON Schema
{
"title": "BraketQubitExecutor",
"description": "The remote Braket executor based on the existing Pennylane Braket\nqubit device. Usage of this device requires valid AWS credentials as\nset up following the instructions at\nhttps://github.com/aws/amazon-braket-sdk-python#prerequisites.\n\nAttributes:\n max_jobs:\n maximum number of parallel jobs sent by threads on :code:`batch_submit`.\n shots: number of shots used to estimate quantum observables.\n device_arn:\n an alpha-numeric code (arn=Amazon Resource Name) specifying a quantum device.\n poll_timeout_seconds:\n number of seconds before a poll to remote device is considered timed-out.\n poll_interval_seconds:\n number of seconds between polling of a remote device's status.\n aws_session:\n An :code:`AwsSession` object created to manage interactions with AWS services,\n to be supplied if extra control is desired.\n parallel: turn parallel execution on or off.\n max_parallel: the maximum number of circuits to be executed in parallel.\n max_connections: the maximum number of connections in the :code:`Boto3` connection pool.\n max_retries: the maximum number of time a job will be re-sent if it failed\n s3_destination_folder: Name of the S3 bucket and folder, specified as a tuple.\n run_kwargs: Variable length keyword arguments for :code:`braket.devices.Device.run()`",
"type": "object",
"properties": {
"persist_data": {
"title": "Persist Data",
"default": true,
"type": "boolean"
},
"qnode_device_import_path": {
"title": "Qnode Device Import Path",
"type": "array",
"minItems": 2,
"maxItems": 2,
"items": [
{
"type": "string"
},
{
"type": "string"
}
]
},
"qnode_device_shots": {
"title": "Qnode Device Shots",
"type": "integer"
},
"qnode_device_wires": {
"title": "Qnode Device Wires",
"type": "integer"
},
"pennylane_active_return": {
"title": "Pennylane Active Return",
"type": "boolean"
},
"device": {
"title": "Device",
"default": "default.qubit",
"type": "string"
},
"num_threads": {
"title": "Num Threads",
"default": 10,
"type": "integer"
},
"max_jobs": {
"title": "Max Jobs",
"default": 20,
"type": "integer"
},
"shots": {
"title": "Shots",
"default": [
null
],
"type": "integer"
},
"device_arn": {
"title": "Device Arn",
"type": "string"
},
"poll_timeout_seconds": {
"title": "Poll Timeout Seconds",
"default": 432000,
"type": "number"
},
"poll_interval_seconds": {
"title": "Poll Interval Seconds",
"default": 1,
"type": "number"
},
"aws_session": {
"title": "Aws Session",
"type": "string"
},
"parallel": {
"title": "Parallel",
"default": false,
"type": "boolean"
},
"max_parallel": {
"title": "Max Parallel",
"type": "integer"
},
"max_connections": {
"title": "Max Connections",
"default": 100,
"type": "integer"
},
"max_retries": {
"title": "Max Retries",
"default": 3,
"type": "integer"
},
"s3_destination_folder": {
"title": "S3 Destination Folder",
"type": "array",
"items": {}
},
"run_kwargs": {
"title": "Run Kwargs",
"default": {},
"type": "object"
}
}
}

CONFIG

extra: EXTRA = allow

field aws_session: Optional[str] = None

#

Validated by

set_name

field device_arn: str = None

#

Validated by

set_name

field max_connections: int = 100

#

Validated by

set_name

field max_jobs: int = 20

#

Validated by

set_name

field max_parallel: Optional[int] = None

#

Validated by

set_name

field max_retries: int = 3

#

Validated by

set_name

field parallel: bool = False

#

Validated by

set_name

field poll_interval_seconds: float = 1

#

Validated by

set_name

field poll_timeout_seconds: float = 432000

#

Validated by

set_name

field run_kwargs: dict = {}

#

Validated by

set_name

field s3_destination_folder: tuple [Optional]

#

Validated by

set_name

field shots: int =

#

Validated by

set_name

batch_submit

#

Submit qscripts for execution using max_jobs-many threads.

Parameters

qscripts_list – a list of Pennylane style QuantumScripts

Returns

a list of tasks submitted by threads.

Return type

jobs

dict

#

Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.