Amazon Braket
Developer Guide
Amazon Braket: Developer Guide
Copyright © 2020 Amazon Web Services, Inc. and/or its affiliates. All rights reserved.
Amazon's trademarks and trade dress may not be used in connection with any product or service that is not Amazon's, in any manner that is likely to cause confusion among customers, or in any manner that disparages or discredits Amazon. All other trademarks not owned by Amazon are the property of their respective owners, who may or may not be affiliated with, connected to, or sponsored by Amazon.
Table of Contents
What Is Amazon Braket? ... 1
Amazon Braket terms and concepts ... 2
AWS terminology and tips for Amazon Braket ... 4
How it works ... 5
Amazon Braket task flow ... 6
Third-party data processing ... 7
Supported devices ... 8
IonQ ... 10
Rigetti ... 10
OQC ... 10
D-Wave ... 10
Local state vector simulator (braket_sv) ... 11
Local density matrix simulator (braket_dm) ... 11
State vector simulator (SV1) ... 11
Density matrix simulator (DM1) ... 12
Tensor network simulator (TN1) ... 13
Compare simulators ... 14
Regions and endpoints ... 17
Pricing ... 18
Best practices for cost savings ... 18
Quotas ... 19
Additional quotas and limits ... 22
When will my task run? ... 23
Status change notifications in email or SMS ... 23
QPU availability windows and status ... 23
Enable Amazon Braket ... 24
Prerequisites ... 24
Steps to enable Amazon Braket ... 24
Common causes of failure when enabling Amazon Braket ... 24
Get started ... 26
Create an Amazon Braket notebook instance ... 26
Run your first circuit using the Amazon Braket Python SDK ... 28
Run your first annealing problem with Ocean ... 31
Work with Amazon Braket ... 34
Construct circuits in the SDK ... 35
Gates and circuits ... 35
Manual qubit allocation ... 38
Verbatim compilation ... 39
Noise simulation ... 39
Inspecting the circuit ... 40
Result types ... 41
Run your circuits with OpenQASM 3.0 ... 44
What is OpenQASM 3.0? ... 44
When to use OpenQASM 3.0 ... 45
How OpenQASM 3.0 works ... 45
Prerequisites ... 45
What OpenQASM features are supported by Braket? ... 45
Create and submit an example OpenQASM 3.0 task ... 47
Support for OpenQASM on different Braket Devices ... 49
Simulate noise with OpenQASM3 ... 52
Qubit rewiring with OpenQASM3 ... 53
Verbatim Compilation with OpenQASM3 ... 53
Braket Console ... 53
More resources ... 54
Submitting tasks to QPUs and simulators ... 54
Example tasks on Amazon Braket ... 54
Submitting tasks to a QPU ... 57
Running a task with the local simulator ... 59
Task batching ... 59
Set up SNS notifications (optional) ... 60
Monitoring and tracking tasks ... 60
Tracking tasks from the Amazon Braket SDK ... 60
Advanced logging ... 62
Monitoring tasks through the Amazon Braket console ... 64
Working with Boto3 ... 67
Enable the Amazon Braket Boto3 client ... 68
Configure AWS CLI profiles for Boto3 and the Amazon Braket SDK ... 70
Amazon Braket Hybrid Jobs ... 72
When to use Amazon Braket Hybrid Jobs ... 72
Run a job with Amazon Braket Hybrid Jobs ... 73
Create your first job ... 75
Inputs, outputs, environmental variables, and helper functions ... 87
Inputs ... 87
Outputs ... 88
Environmental variables ... 88
Helper functions ... 89
Save job results ... 89
Save and restart jobs using checkpoints ... 90
Define the environment for your algorithm script ... 91
Use hyperparameters ... 93
Configure the job instance to run your algorithm script ... 93
Cancel a job ... 95
Use Amazon Braket Hybrid Jobs to run a QAOA algorithm ... 98
Build and debug a job with local mode ... 101
Bring your own container (BYOC) ... 101
Configure the default bucket in AwsSession ... 103
Interact with jobs directly using the API ... 103
Use PennyLane with Amazon Braket ... 107
Amazon Braket with PennyLane ... 107
Hybrid algorithms in Amazon Braket example notebooks ... 108
Security ... 109
Shared responsibility for security ... 109
Data protection ... 109
Data retention ... 110
Managing access to Amazon Braket ... 110
Amazon Braket resources ... 110
Notebooks and roles ... 110
About the AmazonBraketFullAccess policy ... 111
About the AmazonBraketJobsExecutionPolicy policy ... 114
Restrict user access to certain devices ... 116
Amazon Braket updates to AWS managed policies ... 117
Service-linked role ... 118
Service-linked role permissions for Amazon Braket ... 118
Resilience ... 119
Compliance validation ... 119
Infrastructure Security ... 119
Third Party Security ... 120
Troubleshoot ... 121
Access denied exception ... 121
A task is failing creation ... 123
An SDK feature does not work ... 123
A job fails due to an exceeded quota ... 123
Something stopped working in your notebook instance ... 124
Troubleshoot OpenQASM ... 124
Include statement error ... 124
Non-contiguous qubits error ... 124
Mixing physical qubits with virtual qubits error ... 125
Requesting result types and measuring qubits in the same program error ... 125
Classical and qubit register limits exceeded error ... 125
Box not preceded by a verbatim pragma error ... 126
Verbatim boxes missing native gates error ... 126
Verbatim boxes missing physical qubits error ... 126
The verbatim pragma is missing "braket" error ... 126
Single qubits cannot be indexed error ... 126
The physical qubits in a two qubit gate are not connected error ... 127
GetDevice does not return OpenQASM results error ... 127
VPC endpoints (PrivateLink) ... 129
Considerations for Amazon Braket VPC endpoints ... 129
Set up Braket and PrivateLink ... 129
Step 1: Launch an Amazon VPC if needed ... 129
Step 2: Create an interface VPC endpoint for Braket ... 130
Step 3: Connect and run Braket tasks through your endpoint ... 130
More about creating an endpoint ... 130
Control access with Amazon VPC endpoint policies ... 131
Tagging resources ... 132
Using tags ... 132
More about AWS and tags ... 132
Supported resources in Amazon Braket ... 132
Tag restrictions ... 133
Managing tags in Amazon Braket ... 133
Add tags ... 133
View tags ... 133
Edit tags ... 134
Remove tags ... 134
Example of CLI tagging in Amazon Braket ... 134
Tagging with the Amazon Braket API ... 134
Monitor with CloudWatch ... 136
Amazon Braket Metrics and Dimensions ... 136
Supported Devices ... 136
Amazon Braket Events with EventBridge ... 137
Monitor task status with EventBridge ... 137
Example Amazon Braket EventBridge event ... 138
Logging with CloudTrail ... 140
Amazon Braket Information in CloudTrail ... 140
Understanding Amazon Braket Log File Entries ... 141
Document history ... 143
What Is Amazon Braket?
Amazon Braket is a fully-managed AWS service that helps researchers, scientists, and developers get started with quantum computing. Quantum computing has the potential to solve computational problems that are beyond the reach of classical computers, because it harnesses the laws of quantum mechanics to process information in new ways.
Gaining access to quantum computing hardware can be expensive and inconvenient. Limited access makes it is difficult to run algorithms, optimize designs, evaluate the current state of the technology, and plan for when to invest your resources for maximum benefit. Amazon Braket helps you overcome these challenges.
Amazon Braket offers a single point of access to a variety of quantum computing technologies. It enables you to:
• Explore and design quantum and hybrid algorithms
• Test algorithms on different quantum circuit simulators
• Run algorithms on different types of quantum computers
• Create proof of concept applications
Defining quantum problems and programming quantum computers to solve them requires a new set of skills. To help you gain these skills, Amazon Braket offers different environments to simulate and run your quantum algorithms. You can find the approach that best suits your requirements, and you can get started quickly with a set of example environments, called notebooks.
Amazon Braket development has three aspects — Build, Test, and Run:
Build - Amazon Braket provides fully-managed Jupyter notebook environments that make it easy to get started. Amazon Braket notebooks are pre-installed with sample algorithms, resources, and developer tools, including the Amazon Braket SDK. With the Amazon Braket SDK, you can build quantum algorithms, then test and run them on different quantum computers and simulators by changing a single line of code.
Test - Amazon Braket provides access to fully-managed, high-performance, quantum circuit simulators.
You can test and validate your circuits. Amazon Braket handles all the underlying software components and EC2 clusters to take away the burden of simulating quantum circuits on classical HPC infrastructure.
Run - Amazon Braket provides secure, on-demand access to different types of quantum computers.
You have access to gate-based quantum computers from IonQ and Rigetti, as well as a quantum
annealer from D-Wave. You have no upfront commitment, and no need to procure access with individual providers.
About quantum computing and Amazon Braket
Quantum computing is in early developmental stages. It’s important to understand that no universal, fault-tolerant quantum computer exists at present. Therefore, certain types of quantum hardware are better suited for certain use cases, and it is crucial to have access to a variety of computing hardware.
Amazon Braket offers a variety of hardware, through third-party providers.
Existing quantum hardware is limited due to noise, which introduces errors. The industry is in the Noisy Intermediate Scale Quantum (NISQ) era. In the NISQ era, quantum computing devices are too noisy to sustain pure quantum algorithms, such as Shor’s algorithm or Grover’s algorithm. Until better quantum error correction is available, the most practical quantum computing requires the combination of classical (traditional) computing resources with quantum computers, to create hybrid algorithms. Amazon Braket helps you work with hybrid quantum algorithms.
Amazon Braket terms and concepts
In hybrid quantum algorithms, quantum processing units (QPUs) are used as co-processors for CPUs, thus speeding up specific calculations in a classical algorithm. These algorithms utilize iterative processing, in which computation moves between classical and quantum computers. For example, current applications of quantum computing in chemistry, optimization, and machine learning are based on variational quantum algorithms, which are a type of hybrid quantum algorithm. In variational quantum algorithms, classical optimization routines adjust the parameters of a parameterized quantum circuit iteratively, much in the same way the weights of a neural network are adjusted iteratively, based on the error in a machine learning training set. Amazon Braket offers access to the PennyLane open source software library, which assists you with variational quantum algorithms.
Quantum computing is gaining traction for computations in four main areas:
• Number theory — including factoring and cryptography. (For example, Shor’s algorithm is a primary quantum method for number theory computations.)
• Optimization — including constraint satisfaction, solving linear systems, and machine learning.
• Oracular computing — including search, hidden subgroups, and order finding. (For example, Grover’s algorithm is a primary quantum method for oracular computations.)
• Simulation — including direct simulation, knot invariants, and quantum approximate optimization algorithm (QAOA) applications.
Applications for these categories of computations can be found in financial services, biotechnology, manufacturing, and pharmaceuticals, to name a few. Amazon Braket offers capabilities and notebook examples that can apply to many proof of concept problems, and certain practical problems, today.
Amazon Braket terms and concepts
The following terms and concepts are used in Amazon Braket:
Braket
We named the Amazon Braket service after the bra-ket notation, a standard notation in quantum mechanics. It was introduced by Paul Dirac in 1939 to describe the state of quantum systems, and it is also known as the Dirac notation.
Quantum computer
A quantum computer is a physical device that uses quantum-mechanical phenomena such as superposition and entanglement to perform computations. There are different paradigms to quantum computing (QC), such as, gate-based QC or quantum annealing.
Qubit
The basic unit of information in a quantum computer is called a qubit (quantum bit), in analogy to classical bits. A qubit is a two-level quantum system that can be realized by different physical implementations, such as superconducting circuits, or individual ions and atoms. Other qubit types are based on photons, electronic or nuclear spins, or more exotic quantum systems.
Gate-based Quantum Computing
In gate-based QC (also called circuit-based QC), computations are broken down into elementary operations (gates). It can be shown that certain sets of gates are universal, meaning that every computation can be expressed as a finite sequence of those gates. Gates are the building blocks of quantum circuits, in analogy to the logic gates of classical digital circuits.
Quantum Annealing
Quantum annealing is a form of special purpose quantum computing that tries to utilize quantum fluctuations to find global minima of an objective function. In most approaches, the objective
Amazon Braket terms and concepts
function that is encoded directly in the physical couplings parameters of the qubits. Quantum annealing is mainly used for combinatorial optimization problems (e.g., QUBO problems), where one has a finite and discrete search space.
Device
In Amazon Braket, a device is a backend that can execute quantum tasks. A device can be a QPU or a quantum circuit simulator. To learn more, see Amazon Braket supported devices (p. 8).
Quantum Circuit Simulator
A quantum circuit simulator is a computer program that runs on classical computers and calculates the measurement outcomes of a quantum circuit. For general circuits, the resource requirements of a quantum simulation grows exponentially with the number of qubits to simulate. Amazon Braket provides access to both managed (accessed through the Braket API) and local (part of the Amazon Braket SDK) quantum circuit simulators.
Quantum Processing Unit (QPU)
A QPU is a physical quantum computing device that can execute a quantum task. QPUs can be based on different QC paradigms, e.g., gate-based QC or quantum annealing. To learn more, see Amazon Braket supported devices (p. 8).
Quantum Circuit
A quantum circuit is the instruction set that defines a computation on a gate-based quantum computer. A quantum circuit is a sequence of quantum gates (which are reversible transformations on a qubit register) together with measurement instructions.
Shots
Since quantum computing is inherently probabilistic, any circuit (or annealing schedule) needs to be evaluated multiple times to get an accurate results. A single circuit execution and measurement is called a shot. The number of shots (repeated executions) for circuit is chosen based on the desired accuracy for the result. The number of shots can range from 10 to 100,000 shots per task.
Quantum Task
In Amazon Braket, a quantum task is the atomic request to a device. For gate-based QC devices, this includes the quantum circuit (including the measurement instructions and number of shots), and other request metadata. You can create quantum tasks through Amazon Braket SDK or by using the CreateQuantumTask API operation directly. After you create a task, it will be queued until the requested device becomes available. You can view your quantum tasks on the Tasks page of the Amazon Braket console, or by using the GetQuantumTask or SearchQuantumTasks API operations.
Braket job
Amazon Braket has a feature called Amazon Braket Hybrid Jobs (or Braket Jobs for short) that provides fully managed executions of hybrid algorithms. A Braket job consists of three components:
1. The definition of your algorithm, which can be provided as a script, python module, or Docker container.
2. The job instance, based on Amazon EC2, on which to run your algorithm. The default is an ml.m5.xlarge instance.
3. The quantum device on which to execute the quantum tasks that are part of your algorithm. A single job typically contains a collection of many tasks.
QPU supported gates
QPU supported gates are the gates accepted by the QPU device. These gates might not be able to directly run on the QPU, meaning that they might need to be decomposed into native gates. You can find the supported gates of a device on the Devices page in the Amazon Braket console and through the Braket SDK.
AWS terminology and tips for Amazon Braket
QPU native gates
QPU native gates are the gates that can be directly mapped to control pulses by the QPU control system. Native gates can be run on the QPU device without further compilation. Subset of QPU supported gates. You can find the native gates of a device on the Devices page in the Amazon Braket console and through the Braket SDK.
AWS terminology and tips for Amazon Braket
IAM users
An IAM user is an identity that you create in AWS. It represents the person or application that interacts with AWS services and resources. It consists of a name and credentials. By default, when you create a new IAM user in AWS, it has no permissions associated with it. To allow the IAM user to perform specific actions in AWS, such as launching an Amazon EC2 instance or creating an Amazon S3 bucket, you must grant the IAM user the necessary permissions.
• Best practice: We recommend that you create an individual IAM user for each person who needs access to AWS. Even if you have multiple employees who require the same level of access, create individual IAM users for each of them. This approach provides additional security by allowing each IAM user to have a unique set of security credentials.
IAM policies
An IAM policy is a document that allows or denies permissions to AWS services and resources. IAM policies enable you to customize users’ levels of access to resources. For example, you can allow users access to all of the Amazon S3 buckets within your AWS account, or only a specific bucket.
• Best practice: Follow the security principle of least privilege when granting permissions. By following this principle, you help to prevent users or roles from having more permissions than needed to perform their tasks. For example, if an employee needs access to only a specific bucket, specify the bucket in the IAM policy. Do this instead of granting the employee access to all of the buckets in your AWS account.
IAM roles
An IAM role is an identity that you can assume to gain temporary access to permissions. Before an IAM user, application, or service can assume an IAM role, they must be granted permissions to switch to the role. When someone assumes an IAM role, they abandon all previous permissions that they had under a previous role and assume the permissions of the new role.
• Best practice: IAM roles are ideal for situations in which access to services or resources needs to be granted temporarily, instead of long-term.
Amazon S3 bucket
Amazon Simple Storage Service (Amazon S3) is an AWS service that lets you store data as objects in buckets. Amazon S3 buckets offer unlimited storage space. The maximum size for an object in an Amazon S3 bucket is 5 TB. You can upload any type of file data to an Amazon S3 bucket, such as images, videos, text files, backup files, media files for a website, archived documents, and your Braket task results.
• Best practice: You can set permissions to control access to your S3 bucket. For more information, see Bucket policies and user policies in the Amazon S3 documentation.
How Amazon Braket works
Amazon Braket provides on-demand access to quantum computing devices, including managed circuit simulators and different types of QPUs. In Amazon Braket, the atomic request to a device is a task. For gate-based QC devices, this includes the quantum circuit (including the measurement instructions and number of shots), and other request metadata. For annealing devices it includes the problem definition, the number of shots, and other optional parameters.
In this section, we are going to learn about the high-level flow of executing tasks on Amazon Braket.
Amazon Braket task flow
Amazon Braket task flow
To make it easy for customers to define, submit, and monitor their tasks, Amazon Braket provides managed Jupyter notebooks (1) that come pre-installed with the Amazon Braket SDK. You can build
Third-party data processing
your quantum circuits directly in the SDK or, for annealing devices, define the annealing problem and parameter. The Amazon Braket SDK also provides a plugin for D-Wave’s Ocean tool suite, so you can natively program the D-Wave device. After your task is defined, you can choose a device to execute it on, and submit it to the Amazon Braket API (2). Depending on the device you chose, the task is queued until the device becomes available and the task is sent to the QPU or simulator for execution (3). Amazon Braket gives you access to 3 different types of QPUs (D-Wave, IonQ, Rigetti) and one managed Simulator, SV1. To learn more, see Amazon Braket supported devices (p. 8).
After your task is processed, Amazon Braket returns the results to an Amazon S3 bucket, where the data is stored in your AWS account (4). At the same time, the SDK polls for the results in the background and loads them into the Jupyter notebook at task completion. You can also view and manage your tasks on the Tasks page in the Amazon Braket console, or by using the GetQuantumTask operation of the Amazon Braket API.
Of course, Amazon Braket is integrated with Amazon Identity and Access Management (IAM), Amazon CloudWatch, Amazon CloudTrail and Amazon EventBridge for user access management, monitoring and logging, as well as, for event based processing (5).
Third-party data processing
Tasks that are submitted to a QPU device, process on quantum computers located in facilities operated by third party providers. To learn more about Security and third-party processing in Amazon Braket, see Security of Amazon Braket Hardware Providers (p. 120).
Amazon Braket supported devices
In Amazon Braket, a device represents a QPU or simulator that you can call to run quantum tasks. That is, a device refers to a set of circuits for gate-based quantum computing, or it refers to an annealing problem for a quantum annealer device.
Amazon Braket provides access to four QPU devices—from D-Wave, IonQ, and Rigetti—and three simulator devices. For all devices, you can find further device properties, such as device topology,
calibration data, and native gate sets in the Amazon Braket console in the Devices tab or by means of the GetDevice API.
When constructing a circuit with the simulators, Amazon Braket currently requires that you use contiguous qubits/indices.
If you are working with the Amazon Braket SDK, you have access to device properties as shown in the following code example:
from braket.aws import AwsDevice
from braket.devices import LocalSimulator
device = AwsDevice('arn:aws:braket:::device/quantum-simulator/amazon/sv1') #SV1
# device = LocalSimulator() #Local State Vector Simulator
# device = LocalSimulator("default") #Local State Vector Simulator
# device = LocalSimulator(backend="default") #Local State Vector Simulator
# device = LocalSimulator(backend="braket_sv") #Local State Vector Simulator
# device = LocalSimulator(backend="braket_dm") #Local Density Matrix Simulator
# device = AwsDevice('arn:aws:braket:::device/quantum-simulator/amazon/tn1') #TN1
# device = AwsDevice('arn:aws:braket:::device/quantum-simulator/amazon/dm1') #DM1
# device = AwsDevice('arn:aws:braket:::device/qpu/d-wave/DW_2000Q_6') #D-Wave 2000Q
# device = AwsDevice('arn:aws:braket:::device/qpu/d-wave/Advantage_system4') #D-Wave Advantage_system4.1
# device = AwsDevice('arn:aws:braket:::device/qpu/ionq/ionQdevice') #IonQ
# device = AwsDevice('arn:aws:braket:::device/qpu/rigetti/Aspen-11') #Aspen-11
# device = AwsDevice('arn:aws:braket:us-west-1::device/qpu/rigetti/Aspen-M-1') #Aspen M-1
# device = AwsDevice('arn:aws:braket:eu-west-2::device/qpu/oqc/Lucy') #Lucy
# get device properties device.properties
Supported QPUs:
• IonQ
• Rigetti Aspen-11
• D-Wave 2000Q
• D-Wave Advantage_system4.1
• Rigetti Aspen M-1
• OQC Lucy
Supported Simulators:
• Local state vector simulator (braket_sv) (p. 11) ('Default Simulator')
• Local density matrix simulator (braket_dm) (p. 11)
• State vector simulator (SV1) (p. 11)
• Density matrix simulator (DM1) (p. 12)
• Tensor network simulator (TN1) (p. 13)
NoteTo view the available AWS Regions for each device, you can scroll the following table horizontally toward the right.
Amazon Braket devices
Provider Device Name Paradigm Type Device ARN Region
D-Wave DW_2000Q_6 quantum
annealer QPU arn:aws:braket:::device/
qpu/d-wave/
DW_2000Q_6
us-west-2
D-Wave Advantage_system4quantum
annealer QPU arn:aws:braket:::device/
qpu/d-wave/
Advantage_system4 us-west-2
IonQ ionQdevice gate-based QPU arn:aws:braket:::device/
qpu/ionq/
ionQdevice
us-east-1
Rigetti Aspen-11 gate-based QPU arn:aws:braket:::device/
qpu/rigetti/
Aspen-11
us-west-1
Rigetti Aspen M-1 gate-based QPU arn:aws:braket:us-
west-1::device/
qpu/rigetti/
Aspen-M-1
us-west-1
Oxford Quantum Circuits
Lucy gate-based QPU arn:aws:braket:eu-
west-2::device/
qpu/oqc/Lucy
eu-west-2
AWS braket_sv gate-based Simulator N/A (local
simulator in Braket SDK)
N/A
AWS braket_dm gate-based Simulator N/A (local
simulator in Braket SDK)
N/A
AWS SV1 gate-based Simulator arn:aws:braket:::device/
quantum- simulator/
amazon/sv1
All Regions where Amazon Braket is available.
AWS DM1 gate-based Simulator arn:aws:braket:::device/
quantum- simulator/
amazon/dm1
All Regions where Amazon Braket is available.
IonQ
Provider Device Name Paradigm Type Device ARN Region
AWS TN1 gate-based Simulator arn:aws:braket:::device/
quantum- simulator/
amazon/tn1
us-west-2 and us-east-1
To view additional details about the QPUs you can use with Amazon Braket, see Amazon Braket Hardware Providers.
IonQ
IonQ offers a gate-based QPU based on ion trap technology. IonQ’s trapped ion QPUs are built on a chain of trapped 171Yb+ ions, spatially confined by means of a microfabricated surface electrode trap within a vacuum chamber.
Quantum gates supported by the IonQ device:
'x', 'y', 'z', 'rx', 'ry', 'rz', 'h', 'cnot', 's', 'si', 't', 'ti', 'v', 'vi', 'xx', 'yy', 'zz', 'swap', 'i'
Rigetti
Rigetti quantum processors are universal, gate-model machines based on all-tunable superconducting qubits. The Rigetti Aspen-11 system is based on scalable 40-qubit node technology. The Rigetti Aspen- M-1 system leverages their proprietary multi-chip technology, and is assembled from two 40-qubit processors.
Quantum gates supported by the Aspen-11 device and Aspen-M-1:
'cz', 'xy', 'ccnot', 'cnot', 'cphaseshift', 'cphaseshift00', 'cphaseshift01',
'cphaseshift10', 'cswap', 'h', 'i', 'iswap', 'phaseshift', 'pswap', 'rx', 'ry', 'rz', 's', 'si', 'swap', 't', 'ti', 'x', 'y', 'z'
OQC
OQC quantum processors are universal, gate-model machines, built using scalable Coaxmon technology.
The OQC Lucy system is an 8-qubit device with a topology of a ring where each qubit is connected to its two nearest neighbors.
Quantum gates supported by the Lucy device:
i,rz,sx,x,ecr
D-Wave
D-Wave offers quantum annealers based on superconducting qubits. Quantum annealing processors naturally return low-energy solutions. This type of QPU is a specific-purpose machine, designed and
Local state vector simulator (braket_sv)
best suited to solve problems belonging to the class of Quadratic Unconstrained Optimization (QUBO) problems, such as optimization problems and probabilistic sampling problems.
Quantum annealers do not have to meet the strict engineering requirements that universal gate-based machines have to meet. Already today this technology features approximately 5000 superconducting qubits, compared to less than 100 qubits on gate-model quantum computers. Amazon Braket offers access to the superconducting quantum annealers provided by D-Wave Systems that can be programmed using the high-level, open source tool suite called Ocean.
For more information, see the quantum annealing example notebooks.
Local state vector simulator (braket_sv)
The local state vector simulator ("braket_sv") is part of the Amazon Braket SDK that runs locally in your environment. It is well-suited for rapid prototyping on small circuits, up to 25 qubits, depending on the hardware specifications of your Braket notebook instance or your local environment.
The simulator supports all gates in the Amazon Braket SDK, but QPU devices support a smaller subset.
You can find the supported gates of a device in the device properties.
For more information about how to work with simulators, see the Amazon Braket examples.
Local density matrix simulator (braket_dm)
The local density matrix simulator ("braket_dm") is part of the Amazon Braket SDK that runs locally in your environment. It is well-suited for rapid prototyping on small circuits with noise, up to 12 qubits, depending on the hardware specifications of your Braket notebook instance or your local environment.
You can build common noisy circuits from the ground up using gate noise operations such as bit-flip and depolarizing error. You can also apply noise operations to specific qubits and gates of existing circuits that are intended to run both with and without noise.
The braket_dm local simulator can provide the following results, given the specified number of shots:
• Reduced density matrix: Shots = 0
To learn more about the local density matrix simulator, see the Braket introductory noise simulator example.
State vector simulator (SV1)
SV1 is a fully-managed, high-performance, universal state vector simulator. It can simulate circuits of up to 34 qubits. You can expect a 34-qubit, dense, and square circuit (circuit depth = 34) to take approximately 1 to 2 hours to complete, depending on the type of gates used and other factors. Circuits with all-to-all gates are well suited for SV1. It returns results in forms such as a full state vector or an array of amplitudes.
SV1 has a maximum runtime of 6 hours. It has a default of 35 concurrent tasks, and a maximum of 50 concurrent tasks.
SV1 Results
Density matrix simulator (DM1)
SV1 can provide the following results, given the specified number of shots:
• Sample: Shots > 0
• Expectation: Shots >= 0
• Variance: Shots >= 0
• Probability: Shots > 0
• Amplitude: Shots = 0
For more about results, see Result types.
SV1 is always available, it executes your circuits on demand, and it can run multiple circuits in parallel.
The runtime scales linearly with the number of operations and exponential with the number of qubits.
The number of shots has a small impact on the runtime. To learn more, visit Compare simulators.
Simulators support all gates in the Braket SDK, but QPU devices support a smaller subset. You can find the supported gates of a device in the device properties.
Density matrix simulator (DM1)
DM1 is a fully-managed, high-performance, density matrix simulator. It can simulate circuits of up to 17 qubits.
DM1 has a maximum runtime of 6 hours. It has a default of 35 concurrent tasks, and a maximum of 50 concurrent tasks.
DM1 Results
DM1 can provide the following results, given the specified number of shots:
• Sample: Shots > 0
• Expectation: Shots >= 0
• Variance: Shots >= 0
• Probability: Shots > 0
• Reduced density matrix: Shots = 0, up to max 8 qubits
For more about results, see Result types (https://docs.aws.amazon.com/braket/latest/developerguide/
braket-result-types.html).
DM1 is always available, it executes your circuits on demand, and it can run multiple circuits in parallel.
The runtime scales linearly with the number of operations and exponential with the number of qubits.
The number of shots has a small impact on the runtime. To learn more, visit Compare simulators.
Noise Gates and Limitations AmplitudeDamping
Probability has to be within [0,1]
BitFlip
Probability has to be within [0,0.5]
Depolarizing
Probability has to be within [0,0.75]
GeneralizedAmplitudeDamping
Probability has to be within [0,1]
PauliChannel
Tensor network simulator (TN1)
The sum of the probabilities has to be within [0,1]
Kraus
At most 2 qubits
At most 4 (16) Kraus matrices for 1 (2) qubit PhaseDamping
Probability has to be within [0,1]
PhaseFlip
Probability has to be within [0,0.5]
TwoQubitDephasing
Probability has to be within [0,0.75]
TwoQubitDepolarizing
Probability has to be within [0,0.9375]
Tensor network simulator (TN1)
TN1 is a fully-managed, high-performance, tensor network simulator. TN1 can simulate certain circuit types with up to 50 qubits, and a circuit depth of 1000 or smaller. TN1 is particularly powerful for sparse circuits, circuits with local gates, and other circuits with special structure — for example, quantum Fourier transform (QFT) circuits. TN1 operates in two phases. First, the rehearsal phase attempts to identify an efficient computational path for your circuit, so TN1 can estimate the runtime of the next stage, which is called the contraction phase. If the estimated contraction time exceeds the TN1 simulation runtime limit, TN1 does not attempt contraction.
TN1 has a runtime limit of 6 hours. It is limited to a maximum of 10 (5 in eu-west-2) concurrent tasks.
TN1 Results
The contraction phase consists of a series of matrix multiplications. The series of multiplications continues, until a result is reached, or until it is determined that a result cannot be reached.
Note: Shots must be > 0 for the TN1 simulator.
Result types include:
• Sample
• Expectation
• Variance
For more about results, see Result types.
TN1 is always available, it executes your circuits on demand, and it can run multiple circuits in parallel. To learn more, visit Compare simulators.
Simulators support all gates in the Braket SDK, but QPU devices support a smaller subset. You can find the supported gates of a device in the device properties.
Visit the Amazon Braket GitHub repository for a TN1 example notebook to help you get started with TN1.
Best practices for working with the TN1 simulator
• Avoid all-to-all circuits.
• Test a new circuit or class of circuits with a small number of shots, to learn the circuit’s "hardness" for TN1.
• Split large shot simulations over multiple tasks.
Compare simulators
Compare simulators
This section helps you select the Amazon Braket simulator that’s best suited for your task, by describing some concepts, limitations, and use cases.
What is a state vector simulator?
The Amazon Braket state vector simulator (SV1) is a universal state vector simulator. It stores the full wave function of the quantum state and sequentially applies gate operations to the state. It stores all possibilities, even the extremely unlikely ones. The SV1 simulator’s run time for a task increases linearly, with the number of gates in the circuit.
What is a density matrix simulator?
The Amazon Braket density matrix simulator (DM1) simulates quantum circuits with noise. It stores the full density matrix of the system and sequentially applies gates and noise operations of the circuit. The final density matrix contains complete information of the quantum state after execution of the circuit.
The runtime generally scales linearly with the number of operations and exponential with the number of qubits.
What is a tensor network simulator?
The Amazon Braket tensor network simulator (TN1) encodes quantum circuits into a structured graph.
• The nodes of the graph consist of quantum gates, or qubits.
• The edges of the graph represent connections between gates.
As a result of this structure, TN1 can find simulated solutions for relatively large and complex quantum circuits.
The TN1 simulator requires two phases
Typically, TN1 operates in a two-phase approach to simulating quantum computation.
• The rehearsal phase: In this phase, TN1 comes up with a way to traverse the graph in an efficient manner, which involves visiting every node, so that you can obtain the measurement you desire. As a customer, you do not see this phase because TN1 performs both phases together for you. It completes the first phase and determines whether to perform the second phase, on its own, based on practical constraints. You have no input into that decision after the simulation has begun.
• The contraction phase: This phase is analogous to the execution phase of a computation in a classical computer. The phase consists of a series of matrix multiplications. The order of these multiplications has a great effect on the difficulty of the computation. Therefore, the rehearsal phase is accomplished first, to find the most effective computation paths across the graph. After it finds the contraction path during the rehearsal phase, TN1 contracts together the gates of your circuit to produce the results of the simulation.
TN1 Concept: It’s like reading a map
Metaphorically, you can compare the underlying TN1 graph to the streets of a city. In a city with a planned grid, it is easy to find a route to your destination using a map. In a city with unplanned streets, duplicate street names, and so forth, it can be difficult to find a route to your destination by looking at a map.
If TN1 did not perform the rehearsal phase, it would be like walking around the streets of the city to find your destination, instead of looking at a map first. It can really pay off in terms of walking time to spend more time looking at the map. Similarly, the rehearsal phase provides valuable information.
Compare simulators
You might say that the TN1 has a certain “awareness” of the structure of the underlying circuit that it traverses. It gains this awareness during the rehearsal phase.
Types of problems best suited for each of these types of simulators
For SV1, any class of problems that rely primarily on having a certain number of qubits and gates is well- suited. The number of qubits and gates matters most. Generally, the time required grows linearly with the number of gates, and it does not depend on the number of shots. SV1 is generally faster than TN1 for circuits under 28 qubits.
The SV1 simulator can be slower for higher qubit numbers, because it actually simulates all possibilities, even the extremely unlikely ones. It has no way to determine which outcomes are likely. Thus, for a 30- qubit evaluation, SV1 must calculate 2^30 configurations. The limit of 34 qubits for the Amazon Braket SV1 simulator is a practical constraint due to memory and storage limitations. You can think of it like this: Each time you add a qubit to the SV1 simulator, the problem becomes twice as hard.
For many classes of problems, the TN1 simulator can evaluate much larger circuits in realistic time than the SV1 simulator, because TN1 takes advantage of the structure of the graph. It essentially tracks the evolution of solutions from its starting place, and it retains only the configurations that contribute to an efficient traversal; that is, it saves the configurations to create an ordering of matrix multiplication that results in a simpler evaluation process.
For TN1, the number of qubits and gates matters, but the structure of the graph matters a lot more.
For example, TN1 is very good at evaluating circuits (graphs) in which the gates are short-range (that is, each qubit is connected by gates only to its nearest neighbour qubits), and circuits (graphs) in which the connections (or gates) have similar range, for example, if each qubit talks only to other qubits that are 5 qubits away. If most of the structure can be decomposed into simpler relationships such as these, which can be represented in more, smaller, or more uniform matrices, TN1 performs the evaluation easily.
Limitations of the TN1 simulator
The TN1 simulator can be slower than the SV1 simulator, depending on the graph’s structural complexity. For certain graphs, TN1 terminates the simulation after the rehearsal stage, and shows a status of FAILED, for either of these two reasons:
• Cannot find a path — If the graph is too complex, it is too difficult to find a good traversal path, and you can give up on the computation, practically speaking. TN1 cannot perform the contraction. You may see an error message similar to this one: No viable contraction path found.
• Contraction stage is too difficult — In some graphs, TN1 can find a traversal path, but it is very long, and extremely time-consuming to evaluate. In this case, the contraction is so expensive that the cost would be prohibitive. Instead, TN1 exits after the rehearsal phase. You may see an error message similar to this one: Predicted runtime based on best contraction path found exceeds TN1 limit.
Note: You are billed for the rehearsal stage of TN1 even if contraction is not performed and you see a FAILED status.
The predicted runtime also depends on the shot count. In worst-case scenarios, TN1 contraction time depends linearly on the shot count. The circuit may be contractable with fewer shots. For example, you might submit a task with 100 shots, which TN1 decides is uncontractable, but if you resubmit with only 10, the contraction proceeds. In this situation, to attain 100 samples, you could submit 10 tasks of 10 shots for the same circuit, combining the results in the end.
As a best practice, we recommend that you always test your circuit or circuit class with a few shots (for example, 10) to find out how hard your circuit is for TN1, before you proceed with a higher number of shots.
A note for the curious: The series of multiplications that forms the contraction phase begins with small, NxN matrices. For example, a 2-qubit gate requires a 4x4 matrix. The intermediate matrices required
Compare simulators
during a contraction that is adjudged to be too difficult are gigantic. Such a computation would require days to complete. That’s why Amazon Braket does not attempt extremely complex contractions.
Concurrency
All Braket simulators give you the ability to run multiple circuits concurrently. Concurrency limits vary by simulator and region. For more information on concurrency limits, see the Quotas page.
Example notebooks
Amazon Braket provides a variety of example notebooks showing the types of circuits that can either work well for, or challenge, the TN1 and SV1 simulators, such as the quantum Fourier transformation (QFT).
Amazon Braket Regions and endpoints
Amazon Braket is available in the following AWS Regions:
Region availability of Amazon Braket
Region Name Region Braket Endpoint QPU
US East (N. Virginia) us-east-1 braket.us-
east-1.amazonaws.com IonQ US West (N. California) us-west-1 braket.us-
west-1.amazonaws.com Rigetti
US West (Oregon) us-west-2 braket.us-
west-2.amazonaws.com D-Wave
EU West 2 (London) eu-west-2 braket.eu-
west-2.amazonaws.com OQC
You can run Amazon Braket from any Region in which it is available, but each QPU is available only in a single Region. Tasks that run on a QPU device can be viewed in the Amazon Braket console, in the Region of that device. If you are using the Amazon Braket SDK, you can submit tasks to any QPU device, regardless of the Region in which you are working. The SDK automatically creates a session to the Region for the QPU specified, as shown in the following image.
The Amazon Braket SDK automatically routes device requests to the correct region
For general information about how AWS works with Regions and endpoints, see AWS service endpoints in the AWS General Reference.
Best practices for cost savings
Amazon Braket pricing
With Amazon Braket, you have access to quantum computing resources on demand, without upfront commitment. You pay only for what you use. To learn more about pricing, please visit our pricing page.
Best practices for cost savings
Consider the following best practices for using Amazon Braket. Save time, minimize costs, and avoid common errors.
Verify with simulators
• Verify your circuits using a simulator before you run it on a QPU, so you can fine-tune your circuit without incurring charges for QPU usage.
• Although the results from running the circuit on a simulator may not be identical to the results from running the circuit on a QPU, you can identify coding errors or configuration issues using a simulator.
Restrict user access to certain devices
• You can set up restrictions that keep unauthorized users from submitting tasks on certain devices. The recommended method for restricting access is with AWS IAM. For more information about how to do that, see Restrict access.
• We recommend that you do not use your admin account as a way to give or restrict user access to Amazon Braket devices.
Set billing alarms
• You can set a billing alarm to notify you when your bill reaches a preset limit. The recommended way to set up an alarm is through AWS Budgets. You can set custom budgets and receive alerts when your costs or usage may exceed your budgeted amount. Information is available at AWS Budgets.
Test TN1 simulator tasks with low shot counts
• Simulators cost less than QHPs, but certain simulators can be expensive if tasks are run with high shot counts. We recommend that you test your TN1 simulator tasks with a low shot count. Shot count does not affect the cost for SV1 and local simulator tasks.
Check all Regions for tasks
• The console displays tasks only for your current AWS Region. When looking for billable tasks that have been submitted, be sure to check all Regions.
• You can view a list of devices and their associated Regions on the Supported Devices (p. 8) documentation page.
Amazon Braket Quotas
The following table lists the service quotas for Amazon Braket. Service quotas, also referred to as limits, are the maximum number of service resources or operations for your AWS account.
Some quotas can be increased. For more information, see AWS service quotas.
• Burst rate quotas cannot be increased.
• The maximum rate increase for adjustable quotas (except burst rate, which cannot be adjusted) is 2X the specified default rate limit. For example, a default quota of 60 can be adjusted to a maximum of 120.
• The adjustable quota for concurrent SV1 (DM1) tasks allows a maximum of 60 per AWS Region.
Resource Description Limit Adjustable
Rate of API requests The maximum number of requests per second that you can send in this account in the current Region.
140 Yes
Burst rate of API
requests The maximum number
of additional requests per second (RPS) that you can send in one burst in this account in the current Region.
600 No
Rate of
CreateQuantumTask requests
The maximum number of
CreateQuantumTask requests you can send per second in this account per Region.
20 Yes
Burst rate of
CreateQuantumTask requests
The maximum number of additional CreateQuantumTask requests per second (RPS) that you can send in one burst in this account in the current Region.
40 No
Rate of
SearchQuantumTasks requests
The maximum number of
SearchQuantumTasks requests you can send per second in this account per Region.
5 Yes
Burst rate of
SearchQuantumTasks requests
The maximum number of additional SearchQuantumTasks
50 No
Resource Description Limit Adjustable requests per second
(RPS) that you can send in one burst in this account in the current Region.
Rate of
GetQuantumTask requests
The maximum number of GetQuantumTask requests you can send per second in this account per Region.
100 Yes
Burst rate of GetQuantumTask requests
The maximum number of additional GetQuantumTask requests per second (RPS) that you can send in one burst in this account in the current Region.
500 No
Rate of
CancelQuantumTask requests
The maximum number of
CancelQuantumTask requests you can send per second in this account per Region.
2 Yes
Burst rate of
CancelQuantumTask requests
The maximum number of additional CancelQuantumTask requests per second (RPS) that you can send in one burst in this account in the current Region.
20 No
Rate of GetDevice
requests The maximum number
of GetDevice requests you can send per second in this account per Region.
5 Yes
Burst rate of
GetDevice requests
The maximum number of additional GetDevice requests per second (RPS) that you can send in one burst in this account in the current Region.
50 No
Rate of
SearchDevices requests
The maximum number of SearchDevices requests you can send per second in this account per Region.
5 Yes
Resource Description Limit Adjustable Burst rate of
SearchDevices requests
The maximum number of additional SearchDevices requests per second (RPS) that you can send in one burst in this account in the current Region.
50 No
Rate of CreateJob
requests The maximum number
of CreateJob requests you can send per second in this account per Region.
1 Yes
Burst rate of
CreateJob requests
The maximum number of additional CreateJob requests per second (RPS) that you can send in one burst in this account in the current Region.
5 No
Rate of SearchJob
requests The maximum number
of SearchJob requests you can send per second in this account per Region.
5 Yes
Burst rate of
SearchJob requests
The maximum number of additional SearchJob requests per second (RPS) that you can send in one burst in this account in the current Region.
50 No
Rate of GetJob
requests The maximum number
of GetJob requests you can send per second in this account per Region.
5 Yes
Burst rate of GetJob
requests The maximum number
of additional GetJob requests per second (RPS) that you can send in one burst in this account in the current Region.
25 No
Rate of CancelJob
requests The maximum number
of CancelJob requests you can send per second in this account per Region.
2 Yes
Additional quotas and limits
Resource Description Limit Adjustable
Burst rate of
CancelJob requests
The maximum number of additional CancelJob requests per second (RPS) that you can send in one burst in this account in the current Region.
5 No
Number of concurrent
SV1 tasks The maximum number
of concurrent tasks running on the state vector simulator (SV1) in the current Region.
100 (50 in us-west-1
and eu-west-2) No
Number of concurrent
DM1 tasks The maximum number
of concurrent tasks running on the density matrix simulator (DM1) in the current Region.
100 (50 in us-west-1
and eu-west-2) No
Number of concurrent
TN1 tasks The maximum number
of concurrent tasks running on the tensor network simulator (TN1) in the current Region.
10 (5 in eu-west-2) Yes
Number of concurrent
jobs The maximum number
of concurrent jobs in the current Region.
5 Yes
Additional quotas and limits
• The Amazon Braket quantum task action (for example, a circuit or annealing problem) is limited to 3MB in size.
• The maximum number of shots allowed for the SV1 managed simulator, DM1 managed simulator and Rigetti device is 100,000.
• The maximum number of shots allowed for the TN1 managed simulator is 1000.
• For D-Wave and IonQ devices, the maximum is 10,000 shots.
• For TN1 and the QPU devices, shots must be > 0.
Status change notifications in email or SMS
When will my task run?
When you submit a circuit, Amazon Braket sends it to the device you specify. QPU and simulator tasks are queued and processed in the order they are received. The time required to process your task after you submit it varies, depending on the number and complexity of tasks submitted by other Amazon Braket customers, and on the availability of the QPU you selected.
Status change notifications in email or SMS
Amazon Braket sends events to Amazon EventBridge when the availability of a QPU changes, or when your task’s state changes. Follow these steps to receive device and task status change notifications by email or SMS message:
1. Create an Amazon SNS topic and a subscription to email or SMS. Availability of email or SMS depends on your Region. See Getting started with Amazon SNS and Sending SMS messages.
2. Create a rule in EventBridge that triggers the notifications to your SNS topic. See Monitoring Amazon Braket with Amazon EventBridge (p. 137).
Task completion alerts
You can set up notifications through the Amazon Simple Notification Service (SNS), so that you receive an alert when your Amazon Braket task is complete. Active notifications are useful if you expect a long wait time — for example, when you submit a large task, or when you submit a task outside of a device’s availability window. If you do not want to wait for the task to complete, you can set up an SNS notification.
An Amazon Braket notebook walks you through the setup steps. For more information, see the Amazon Braket example notebook for setting up notifications.
QPU availability windows and status
QPU availability varies among the Quantum Hardware Providers (QHPs).
In the Devices page of the Amazon Braket console, you can see the current and upcoming availability windows for each device. You also can view the status of each device.
A device is considered offline if is not available to customers, regardless of availability window. For example, it could be offline due to scheduled maintenance, upgrades, or operational issues.
The Announcements page in the Amazon Braket console shows scheduled downtime in advance, to all Amazon Braket customers.
Prerequisites
Enable Amazon Braket
You can enable Amazon Braket in your account through the AWS console.
Prerequisites
To enable and run Amazon Braket, you must have an IAM user or role with permission to initiate Amazon Braket actions. These permissions are included in the AmazonBraketFullAccess IAM policy.
In particular, your IAM user or role must have permission to create an S3 bucket in the AWS account, because Amazon Braket requires an Amazon S3 bucket to store results from your tasks. Results from all users and roles in the account are stored in the same bucket location, which you specify when you enable Amazon Braket.
The next section shows how to create or select an S3 bucket associated with the AWS account in which you enable Amazon Braket.
NoteIf you are an administrator:
To enable Amazon Braket for other IAM users, for IAM roles, or for an IAM group in an account, you must grant permissions to each user, role, or group. You can grant these permissions by attaching the AmazonBraketFullAccess policy or by attaching a custom policy that you create.
To learn more about the permissions necessary to use Amazon Braket, see Managing access to Amazon Braket.
Steps to enable Amazon Braket
1. Log in to your AWS account and then open the Amazon Braket console.
2. Choose Go to Braket.
3. To specify an Amazon S3 bucket to use for your results, do one of the following tasks:
a. Choose Create new bucket to have Amazon Braket create a bucket in your account named amazon- braket-uniqueString.
b. Choose Specify bucket name and enter a name to append to the bucket name after amazon- braket-. For example, if you enter mycircuits, the resulting bucket name is amazon-braket- mycircuits.
c. Choose Select an existing bucket to use an existing bucket from your account. The bucket name must start with amazon-braket-. You also can specify a folder within the bucket to store your task results.
4. Review the permission policy attached to the service-linked role that Amazon Braket creates in your account.
5. Review the Terms and Conditions for using Amazon Braket, then select the check box to confirm that you have read and accept these terms.
6. Choose Enable Amazon Braket.
Common causes of failure when enabling Amazon Braket
Here are some error messages you might see when you enable or run Amazon Braket.
Common causes of failure when enabling Amazon Braket
Access denied due to lacking S3 permissions
This error means that the user or role tried to create or manage access to an Amazon S3 bucket, without the required permissions. Be sure that you’re signed in with a user or role has the AmazonBraketFullAccess policy enabled.
Create an Amazon Braket notebook instance
Get started with Amazon Braket
After you have followed the instructions in Enable Amazon Braket (p. 24), you can get started with Amazon Braket.
The steps to get started include:
• Create an Amazon Braket notebook instance (p. 26)
• Run your first circuit using the Amazon Braket Python SDK (p. 28)
• Run your first annealing problem with Ocean (p. 31)
Create an Amazon Braket notebook instance
Amazon Braket provides fully-managed Jupyter notebooks to get you started. The Amazon Braket notebook instances are based on Amazon SageMaker notebook instances. You can learn more about notebook instances. To get started with Braket, follow these steps to create an Amazon Braket notebook instance.
1. Open the Amazon Braket console.
2. Choose Notebooks in the left pane, then choose Create notebook.
3. In Notebook instance settings, enter a Notebook instance name using only alphanumeric and hyphen characters.
4. Select the Notebook instance type. Choose the smallest type you need. To get started, choose a cost- effective instance type, such as ml.t3.medium.
The instance types are Amazon SageMaker notebook instances. To learn more, see Amazon SageMaker pricing.
5. In Permissions and encryption, select Create a new role (a new role with a name that begins with`AmazonBraketServiceSageMakerNotebook` is created).
6. If you want to associate a public Github repository with your notebook instance, click on the Git repository dropdown and select Clone a public git repository from url from the Repository dropdown menu. Enter the URL of the repo in the Git repository URL text bar.
Create an Amazon Braket notebook instance
7. Choose Create notebook instance.
It takes several minutes to create the notebook. The notebook is displayed on the Notebooks page with a status of Pending. When the notebook instance is ready to use, the status changes to InService. You may need to refresh the page to display the updated status for the notebook.
NoteYou can view and manage your Amazon Braket notebook instances in the Amazon Braket and Amazon SageMaker consoles. Additional Amazon Braket notebook settings are available through the SageMaker console. Open the SageMaker console at https://
console.aws.amazon.com/sagemaker/ .
If you’re working in the Amazon Braket console within AWS, as given previously, the Amazon Braket SDK and plugins are preloaded in the notebooks you just created. If you want to run on your own machine, you can install the SDK and plugins when you run the command pip install amazon-braket-sdk
Run your first circuit using the Amazon Braket Python SDK
or when you run the command pip install amazon-braket-pennylane-plugin (the latter for use with PennyLane plugins).
Run your first circuit using the Amazon Braket Python SDK
After your notebook instance has launched, open the instance with a standard Jupyter interface by choosing the notebook you just created.
Amazon Braket notebook instances are pre-installed with the Amazon Braket SDK and all its dependencies. Start by creating a new notebook with conda_braket kernel.
Run your first circuit using the Amazon Braket Python SDK
You can start with a simple “Hello, world!” example. First, construct a circuit that prepares a Bell state, and then run that circuit on different devices to obtain the results.
Begin by importing the Amazon Braket SDK modules and defining a simple Bell State circuit.
import boto3
from braket.aws import AwsDevice
from braket.devices import LocalSimulator from braket.circuits import Circuit
# create the circuit
bell = Circuit().h(0).cnot(0, 1)
You can visualize the circuit with this command:
print(bell)
Run your circuit on the local simulator
Run your first circuit using the Amazon Braket Python SDK
Next, choose the quantum device on which to execute the circuit. The Amazon Braket SDK comes with a local simulator for rapid prototyping and testing. We recommend using the local simulator for smaller circuits up to 25 qubits (depending on your local hardware).
Here’s how to instantiate the local simulator:
# instantiate the local simulator local_sim = LocalSimulator()
and run the circuit:
# run the circuit
result = local_sim.run(bell, shots=1000).result() counts = result.measurement_counts
print(counts)
You should see a result something like this:
Counter({'11': 503, '00': 497})
The specific Bell state you have prepared is an equal superposition of |00> and |11>, and you’ll find a roughly equal (up to shot noise) distribution of 00 and 11 as measurement outcomes, as expected.
Run your circuit on a managed simulator
Amazon Braket also provides access to a fully-managed, high-performance simulator, SV1, for running larger circuits. SV1 is a state-vector simulator that allows for simulation of quantum circuits of up to 34 qubits. You can find more information on SV1 in the Supported Devices (p. 8) section and in the AWS console. When running tasks on SV1 (and on TN1 or any QPU), the results of your task are stored in an S3 bucket in your account.
For now, we will use the S3 bucket you created in Enable Amazon Braket (p. 24), but you can choose any S3 bucket that Amazon Braket has permissions to access. To learn more, see Managing access to Amazon Braket (p. 110).
NoteFill in your actual, existing bucket name where the following example shows example-bucket as your bucket name. Bucket names for Amazon Braket always begin with amazon-braket- followed by other identifying characters you add.
# get the account ID
aws_account_id = boto3.client("sts").get_caller_identity()["Account"]
# the name of the bucket my_bucket = "example-bucket"
# the name of the folder in the bucket my_prefix = "simulation-output"
s3_folder = (my_bucket, my_prefix)
To run a circuit on SV1, you must provide the location of the S3 bucket you previously selected, as a positional argument in the .run() call.
# choose the cloud-based managed simulator to run your circuit
device = AwsDevice("arn:aws:braket:::device/quantum-simulator/amazon/sv1")
# execute the circuit
task = device.run(bell, s3_folder, shots=100)
# display the results
Run your first annealing problem with Ocean
print(task.result().measurement_counts)
The Amazon Braket console provides further information about your task. Navigate to the Tasks tab in the console; your task should be on the top of the list. Alternatively, you can search for your task using the unique task ID or other criteria.
NoteAfter 90 days, Amazon Braket automatically removes all task IDs and other metadata associated with your tasks. For more information, see Data retention.
Running on a QPU
With Amazon Braket, you can run the previous quantum circuit example on a physical quantum computer, just by changing a single line of code. Amazon Braket provides access to QPU devices from IonQ, Rigetti, and D-Wave. You can find information about the different devices and availability windows in the Supported Devices (p. 8) section, and in the AWS console under the Devices tab. The following example shows how to instantiate a Rigetti device.
# choose the Rigetti hardware to run your circuit
device = AwsDevice("arn:aws:braket:::device/qpu/rigetti/Aspen-11")
Choose an IonQ device with this code:
# choose the Ionq device to run your circuit
device = AwsDevice("arn:aws:braket:::device/qpu/ionq/ionQdevice")
D-wave devices are quantum annealers. They follow a different programming paradigm. The next section explains annealing devices.
When you execute your task, the Amazon Braket SDK polls for a result, with a default timeout of 5 days.
You can change this default by modifying the poll_timeout_seconds parameter in the the .run() command, as shown in the example that follows. Keep in mind that if your polling timeout is too short, results may not be returned within the polling time, such as when a QPU is unavailable, and a local timeout error is returned. You can restart the polling by calling the task.result() function.
# define task with 1 day polling timeout
task = device.run(bell, s3_folder, poll_timeout_seconds=24*60*60) print(task.result().measurement_counts)
Run your first annealing problem with Ocean
Quantum annealers are special-purpose quantum computers designed to solve combinatorial optimization problems. In particular, quantum annealers solve problems belonging to the class of Quadratic Unconstrained Optimization (QUBO). Amazon Braket allows you to program the D-Wave QPUs natively, using D-Wave’s Ocean software through the Braket-Ocean plugin. Amazon Braket notebook instances are pre-installed with Ocean and the Braket-Ocean plugin.
Get started with a simple example of solving the Minimum Vertex Cover (MVC) problem. Here’s the problem definition:
Given an undirected graph with a vertex set and an edge set, a vertex cover is a subset of the vertices (nodes) such that each edge in the graph is incident to at least one vertex in the subset. The Minimum Vertex Cover problem seeks to find a cover with a minimum number of vertices in the subset. In other words, in a graph like this:
Run your first annealing problem with Ocean
The goal is to color nodes in red such that every edge touches at least one red node. And you want to do it with as little paint as possible. The optimal solution is to paint the central node red, as shown in the figure that follows.
How to solve such a problem with D-Wave’s 2000Q QPU
To begin, import the following dependencies and specify an S3 location.
NoteFill in your actual, existing bucket name where the following example shows example-bucket as your bucket name. Bucket names for Amazon Braket always begin with amazon-braket- followed by other identifying characters you add.