DEV Community

Cover image for Getting Started with Quantum Computing on AWS Braket
Sreekesh Iyer for AWS Community Builders

Posted on Originally published at builder.aws.com

Getting Started with Quantum Computing on AWS Braket

I'm having a super hard time understanding Quantum Computing as a part of my Master's in Dublin this year, so I'm doing what I do best when it comes to learning something super new to me. Write about it.
I'm writing this article as a beginner's walkthrough to quantum computing and setting up an initial environment to get going with libraries like qiskit, running operations on real quantum computers provided by AWS.

My understanding of Quantum Computing so far

In the last couple of weeks, despite trying to wrap my brain around it, I still see quantum information as an abstract concept. I cannot visualise it. And that's probably for the best, because the more I read about trying to make sense out of it, it doesn't.

Fundamentally, the world of quantum opens up when a state cannot be represented by just 1s and 0s, something we are so used to in general technology. I tried to re-explore theories of superposition, uncertainty and electron spin which drag me into a brief amount of Quantum Physics I learned from yesteryear.

That's the best way I can describe a qubit. It is information, a quantity that can be represented only in a probabilistic state with a mix of real and complex numbers. We'll walk a bit further into this once the environment is setup. Let's do that.

Setting up an AWS Braket Notebook

Braket Dashboard

A standard notebook should work just fine for us, and it should also be up in a couple of clicks. This is honestly all we need from a setup perspective to get going, we can start writing python code now.

Jupyter Server Landing Page

Choosing a quantum computer

By default, you will be running on t3 EC2 compute and will be charged only on the basis of their tier prices. To run your quantum workloads on real quantum machines, you need to pick them. Braket as a service is available only in limited AWS regions and you can look up available quantum devices for your region.

from braket.aws import AwsDevice
from braket.circuits import Circuit

device = AwsDevice(
    "arn:aws:braket:eu-north-1::device/qpu/iqm/Garnet"
)

bell = Circuit().h(0).cnot(0, 1)
Enter fullscreen mode Exit fullscreen mode

The code snippet above lets you pick your preferred quantum device. I've selected Garnet for now as it's one of the cheapest, and gets the job done for learning and exploration. We'll explore circuits later on, don't worry about them for now. I just added them here for you to show you the braket API.
*Warning: * Please bear in mind that devices charge you per task and per shot. Your usage may shoot up exponentially if you're not mindful.

Representing a Qubit Mathematically

Coming from traditional computer science degree, this was honestly the toughest part to uncover. The scary math notations. They're only scary at first, we can get through them one after another. For starters, let's see how you write a qubit state.

∣ψ⟩=α∣0⟩+β∣1⟩​ where α,β ∈ C

Think of ψ as a vector in the 2D space. α and β are probability amplitudes (real or complex numbers) (not probabilities) -- fundamentally, they show us that there is something uncertain that does not clearly state 1 or 0 (a case of superposition if both α and β are not zero).

Their squares however do represent probabilities, and as probabilities do, they sum to 1.

∣α∣^2 +∣β∣^2 = 1

∣0⟩ and ∣1⟩ are computational basis states. They use the "ket" notation (the weird looking brackets, you see where the name comes from)

This is what they look like in their matrix forms (apologies for spamming images, the markdown here doesn't like me using matrices). In the world of quantum, they are called state vectors.

State vectors

All operations on qubits (I will explore multiple qubits in a separate article) are possible through traditional algebra, so that is one silver lining I stick around with. Let's take a look at coding this now.

Algebraic descriptions of a Qubit in Superposition

We use the StateVector class to represent a qubit in superposition. You can see their probabilities sum to 1, and since they are both real numbers in this case, the state vector shows 0j for both α and β. We can obviously have them as complex numbers.

--
Fundamentally, this would be a good start to exploring quantum computing. Now is a good reminder to save your work on GitHub and clean up the notebook so that you do not wake up to an interesting email from AWS with an invoice. I aim to explore quantum computing and especially the math in-depth In the near future, so stick around for it. Thanks for reading, cheers :)

Top comments (0)