Overview of Amazon Bracket with a Practical Example
In this article, I am going to give an overview of Amazon Bracket based on my exploration. I will give a basic introduction, security aspects, costs, product offerings and finally I will show a simple circuit run in one of the simulators. The documentation on Amazon Bracket is available publicly and you can get more details as required from the documentation.
So, let's begin with a fun fact. What does “Bra-ket” signify? In the “bra-ket” notation or Direc notation, the “Ket” - represented by a vertical bar & right angular bracket (|>) - denotes a vector in a complex vector space and this physically represents a quantum state. The “Bra” - represented by the left angular bracket and a vertical bar (<|) - represents a linear map of each element of a vector in a complex plane. Bra-Ket notations are used heavily in quantum mechanics as a large part of it is based on linear algebra.
General Overview of AWS Braket service:
Now, after the fun fact, let me describe in a simplistic term what Amazon Braket offering is. Amazon Braket service gives a platform to build, test, and run quantum algorithms. Below is the AWS elaboration of what bracket service is (sourced from AWS documents):
The build part is done through a set of jupyter notebooks (SagerMaker). When you register for the bracket service, you can spin up jupyter notebook instances for your own. There are multiple Notebook instance types available to choose from and you can pick the one which meets your requirements. The process to create the notebook is very simple. Select the instance name, instance type, and custom the volume size to your need. Below is the reference screenshot to create a notebook instance:
The next step is selecting the Role, access & encryption. Here is the screenshot:
Finally, if you want to make any changes for the network or if you want to put any tags, go ahead and make the required selections.
After all the fields are populated, just click on “Create Notebook Instance” and your notebook will spin up in a few minutes. To access the notebook, click the URL.
When you log into the instance, you will see multiple examples, which I found quite useful and give good study material.
You can go to any of the examples and try to run. When you run the notebook, it shows it is running at the backend and you get charged based on the time spent. Below is an example of how it looks when you run a basic simulator.
You can see the notebook from the running pen, and don’t forget to shut it down when you are done with your simulation.
Now, after the Notebook and build part, let's explore what is available for Devices. The device section is where you get the list of available Quantum Processing Units and simulators. You can use any of the available providers to run & test your algorithm. The pricing of the QPU depends on the vendor and the number of Tasks & shots. For example the D-Wave — Advantage_system1.1 cost is $0.30 / task + $0.00019 / shot. Below is the device (QPU) listing from the service.
In addition to the QPUs there are simulators available to run and test your algorithms. Below are the offerings available.
Cost of Braket Service:
After the offering, let's look at the cost part. There are two cost components for using the QPU, a per-shot cost and a per-task cost. A shot is defined as a single execution of the algorithm in the QPU. while a task is a sequence of repeated shots.
Refer to AWS Service page for more details on costs.
Recommended by LinkedIn
Security Controls on Braket Components:
Now, as we have spoken about the service & cost, let’s look into the security aspect and how we can keep our notebooks, algorithms & results secured.
- We can use specific IAM roles to control access
- We can control the access for the user (root or general user)
- We can encrypt the notebook data.
- We can use VPC, subnet & define the private access for the notebook.
A Sample Run to Demonstrate the Service:
Finally, I will conclude the article by showing a very simple circuit run in one of the simulators available as part of the service. I have picked Amazon Web Services — SV1 to run my task. I will take an example of 12 Qbits, and will draw a circuit with some basic gates (Hadamard, S, T, CNOT) and run the circuit in the local simulator and SV1 simulator.
The 1st step is to open a notebook and import the general modules and AWS modules. Now those who are familiar with Qiskit, will find a difference here as we will be importing the AWS-specific modules.
Next, I will define my bucket and folder to store the result.
Followed by that, comes my circuit definition, as I mentioned, this is a very simple circuit with H gate at q0, t & s gate at q1 and then cnot gates for other qn.
Here comes the circuit print with 12 Qbits.
Now, I will run this circuit in a local simulator with 500 shots and will count the bitstrings. I will use the device = LocalSimulator().
In the final part, I will use an SV1 simulator with 500 shots. Just to make sure, running in an SV1 simulator has a cost @ $0.075 / minute.
If you want to run this in a real quantum computer, the cost is based on the number of tasks + number of shots. so , if you run 1 task and define 500 shots for a D-Wave 2000Q system, it is going to cost you @ $0.30 / task + $0.00019 / shot: hence ( $0.30 + 500 * $0.00019) = $0.395.
Below is the distribution of the 500 shots in SV1.
The results get stored in the S3 bucket, below is a screenshot of how it looks.
As a concluding remark, I would say, I found Amazon Braket very interesting, this gives you a chance to run your algorithm across multiple devices and simulators. You can choose what you need. The service is easily configurable and you can secure your work with the controls as I mentioned earlier.