AWS Quantum Technologies Blog

Introducing the Wolfram Quantum Framework for Amazon Braket

Today, we are pleased to announce Wolfram Language support for Amazon Braket, the AWS quantum computing service.

Amazon Braket has a mission to accelerate research and application development in quantum computing by providing access to differentiated quantum processing units (QPUs) and state-of-the-art simulators. As part of this mission, Braket also provides low-level tooling, such as pulse control, to help researchers push the boundaries of current noisy quantum devices, and features like Hybrid Jobs to make running quantum algorithms easier and more performant. By integrating with the rest of AWS, Braket also provides a way to explore how quantum computing will eventually fit into a cloud-based IT infrastructure.

Wolfram Language is a symbolic programming language used in Mathematica and Wolfram Alpha. It’s recognized for its advanced computational capabilities, comprehensive built-in features, symbolic computation, and rule-based programming. Wolfram Language is powered by Wolfram Knowledgebase, a curated repository of data and algorithms across every major computational domain such as data science and machine learning.

The Wolfram Quantum Framework is a software tool available for the Wolfram Language that enables the development and simulation of quantum algorithms. This Framework features a library of prebuilt functions (like quantum Fourier transform, or Grover’s search algorithm), integration with the Wolfram Cloud, simulation of quantum systems symbolically and numerically, and now, for the first time, the ability for users to send queries for running quantum tasks on quantum hardware and simulators supported by Braket.

With this integration, users of the Wolfram Language can leverage the power of Amazon Braket to perform quantum tasks on real hardware or on simulators powered by AWS.

In this post, we’ll explore the Wolfram Quantum Framework and show you how to connect it with Amazon Braket to run quantum algorithms.

Setting Up Wolfram Language

Prerequisites

To get started, you’ll need to:

Installation and Configuration

You can download and install Mathematica using the instructions for your operating system. Next, install WolframScript and the Wolfram Language kernel for Jupyter. WolframScript enables Wolfram Language code to be run from any terminal.

You will also need to install the AWS CLI for your respective operating system, which allows you to interact with AWS services (like Amazon Braket) via the command line. In this step, you will need your AWS Access Key and AWS Secret Access Key, which you’ll use to configure your AWS CLI credentials. This will allow you to to submit tasks and jobs to Braket and interact with Amazon Simple Storage Service (Amazon S3) to retrieve results.

Run the following command to quickly set your credentials:

$ aws configure --profile default
AWS Access Key ID [None]: your-access-key
AWS Secret Access Key [None]: your-secret-key
Default region name [None]: us-east-1
Default output format [None]: json

You can now launch Mathematica and create a new notebook. In your notebook, add the following line of code to install the Wolfram Quantum Framework paclet:

PacletInstall["Wolfram/QuantumFramework"]

Next, we will connect to AWS using this line of code:

aws = ServiceConnect["AWS", "New"]

Once you connect to AWS, you’ll be prompted to select the authentication mode. Use Automatic to read the credentials that we provided using the aws configure command above.

Figure 1: AWS connection authentication mode

Figure 1: AWS connection authentication mode

After selecting the authentication mode, you’ll be prompted to provide an AWS credentials profile name. Use the profile name you specified when configuring the credentials:

Figure 2: AWS credentials profile and terms and conditions

Figure 2: AWS credentials profile and terms and conditions

At this point, you’re now ready to develop and run quantum algorithms using the Wolfram Quantum Framework on Amazon Braket.

Getting Started with the Wolfram Quantum Framework and Amazon Braket

Let’s jump in and explore how to use the power of Braket’s quantum computing resources using Wolfram Language. For more details, check out this published Wolfram Notebook.

To make sure that we have installed the Framework properly, let’s import the library:

Needs["Wolfram`QuantumFramework`"]

Once you’ve successfully imported the library, you can begin by initializing Amazon Braket and Amazon S3. These are used to interact with Braket and Amazon S3 services. Make sure you have sufficient IAM permissions to access Amazon S3:

s3 = ServiceExecute[aws, "GetService", {"Name" → "S3"}]
braket = ServiceExecute[aws, "GetService", {"Name" -> "Braket"}]

Using the Braket service object you just created, you can determine the available devices and their current statuses:

devices = braket["SearchDevices", "Filters" -> {}]["Devices", All] 
Figure 3: List of Braket devices in online status

Figure 3: List of Braket devices in online status

Before defining your circuit, you can also obtain a list of all the gates supported by a simulator or a QPU. We can take a look at Braket’s on-demand state vector simulator (SV1) and determine which gates are supported:

sv1 = devices[ SelectFirst[#DeviceName == "SV1" &], MapAt[ImportString[#, "RawJSON"] &, "DeviceCapabilities"]]
sim["DeviceCapabilities","action",All,"supportedOperations"]//Normal 
< braket.ir.jaged. program -> {ccnot, cnot, cphaseshift, cphaseshift00, phaseshift01, cphaseshiftI0, cswap, cy, cz, ecr, h, i, iswap, pswap, phaseshift, rx, ry, rz, s, si, swap, t, i, unitary, v, vi, x,
XX, xy, y, YY, Z, zz},
braket. ir opengasn. program -> {ccnot, not, cphaseshift, cphaseshift00, phaseshift01, cphaseshift10, swap, cy, cz, ecr, h, i, swap, pswap, phaseshift, rx, ry, rz, s, si, swap, t, ti, v, vi, x, xx, xy, Y, YY, z, zz, gpi, gpi2, ms)|>

Now let’s use some built-in circuits from the Wolfram Quantum Framework and create a circuit corresponding to a random graph with four vertices and five edges:

g = RandomGraph[{4, 5}];
circuit = 
  QuantumCircuitOperator[{{"Graph", g}, {"RZ", Pi/4} -> 
     2, {"RZ", Pi/2} -> 3, {"RZ", 3 Pi/4} -> 4, "H" -> 1, 
    "H" -> 2, "H" -> 3, "H" -> 4, {1}, {2}, {3}, {4}}];
circuit["Diagram"]
Figure 4: Quantum circuit for generating graph state

Figure 4: Quantum circuit for generating graph state

This circuit first generates a graph state (also known as a cluster state). These highly entangled states are foundational to the one-way quantum computing model (measurement-based quantum computing).

Then qubits are measured – each one in a specific direction on the x-y plane. For qubit 1, the measurement will be done along the x-axis (corresponding to Pauli-X measurement) and then for the next qubits, we will rotate the basis of measurement by π/4 around the z-axis.

After defining the circuit, you are now ready to run our circuit on Braket’s state vector simulator.

Figure 5: Different measurement directions for each qubit on xy-plane.

Figure 5: Different measurement directions for each qubit on xy-plane.

Running Circuits on Braket’s On-Demand Simulators

SV1 is one of Braket’s on-demand simulators, meaning it runs on AWS managed classical compute resources. We recommend using SV1 for efficient, scalable quantum circuit simulation for up to 34 qubits. For a 4-qubit circuit like the one in our example, you can actually run on the free Braket local simulator, but we’ll stick with SV1 for this example to demonstrate the functionality.

First, we’ll need to translate Wolfram code to OpenQASM, which Braket can understand, which we’ll do via Qiskit:

qasm_circ=circuit["Qiskit"]["QASM","Provider"→"AWSBraket"] 

Then, we’ll run the circuit as a quantum task on Amazon Braket with the following code:

taskSV1=braket["CreateQuantumTask",
"DeviceArn"→sv1["DeviceArn"],
"DeviceParameters"→{},
"OutputS3Bucket"→"amazon-braket-bucket-name",
"OutputS3KeyPrefix"→"tasks",
"Shots"→100,
"Action"→<|"braketSchemaHeader"→<|"name"→"braket.ir.openqasm.program",
"version"→"1"|>,
"source"→qasm_circ|>,
"ValidateRequest"→False,
"RequestRegion"→"us-east-1"]

Running Circuits on Braket QPUs

Now let’s look at how to run this Bell state on one of the quantum computers available on Braket. The only difference will be changing the DeviceArn to specify a QPU—in this case, the IonQ Harmony device. The following code shows how to submit such a task:

ionq = devices[ SelectFirst[#DeviceName == "Harmony" &], MapAt[ImportString[#, "RawJSON"] &, "DeviceCapabilities"]] 

Like with the SV1 circuit, we will need to translate the Wolfram circuit to OpenQASM, but additionally specify the IonQ Harmony device as our backend so that the code gets transpiled correctly for the hardware. Note that Amazon Braket charges on a per-shot and per-task basis for sending circuits to a QPU. For more information about Braket pricing, refer to the pricing page.

ionq_circ = circuit["Qiskit"]["QASM", "Provider" -> "AWSBraket", "Backend" -> "Harmony"]

Now we can send the queries to IonQ Harmony:

taskIONQ=braket["CreateQuantumTask",
"DeviceArn"→ionq["DeviceArn"],
"DeviceParameters"→{},
"OutputS3Bucket"→"amazon-braket-bucket-name",
"OutputS3KeyPrefix"→"tasks",
"Shots"→100,
"Action"→<|"braketSchemaHeader"→<|"name"→"braket.ir.openqasm.program",
"version"→"1"|>,
"source"→ionq_circ|>,
"ValidateRequest"→False,
"RequestRegion"→"us-east-1"]

Make sure to replace amazon-braket-bucket-name with the name of your Amazon S3 bucket. Depending on QPU availability, you may need to wait for it to finish and retrieve the task data from your Amazon S3 bucket asynchronously.

To retrieve it, use the following commands:

outputPathIONQ=braket["GetQuantumTask",
"QuantumTaskArn"→taskIONQ["QuantumTaskArn"],
"RequestRegion"→"us-east-1"]["OutputS3Directory"]
resultsIonQ=ImportByteArray[s3["GetObject",
"Bucket"->"amazon-braket-bucket-name",
"Key"->FileNameJoin[{outputPathIONQ,"results.json"}],
"RequestRegion"->"us-east-1"]["Body"],
"RawJSON"]["measurementProbabilities"]

We’ll go ahead and retrieve the SV1 simulated data as well:

outputPathSV1=braket["GetQuantumTask",
"QuantumTaskArn"→taskSV1["QuantumTaskArn"],
"RequestRegion"→"us-east-1"]["OutputS3Directory"]
resultsSV1=ImportByteArray[s3["GetObject",
"Bucket"->"amazon-braket-bucket-name",
"Key"->FileNameJoin[{outputPathSV1,"results.json"}],
"RequestRegion"->"us-east-1"]["Body"],
"RawJSON"]["measurementProbabilities"]

You can obtain the results from the Wolfram Quantum Framework like this:

circuit[]["Probabilities"]

Now we have results from the SV1 simulator (100 shots), IonQ QPU (100 shots) and the Framework (exact probabilities as predicted by quantum theory). Note that SV1 can also calculate the exact result with no measurement noise if we set shots=0.

Figure 6: Measurement results for graph state across quantum simulators from Wolfram and Braket, as well as IonQ through Braket.

Figure 6: Measurement results for graph state across quantum simulators from Wolfram and Braket, as well as IonQ through Braket.

Conclusion

Wolfram Language’s integration with Amazon Braket provides users with a powerful tool for quantum computing tasks. Customers can now perform quantum simulations, optimize quantum circuits, and analyze experimental results more easily and efficiently.

Our integration with Braket allows you to scale your quantum applications to run on real QPUs and make use of Braket’s on-demand simulators. By combining the capabilities of Wolfram Language and Amazon Braket, researchers and scientists can explore new frontiers in quantum computing with symbolic and functional computing.

You can read further about the Wolfram Language and Wolfram Quantum Framework. We invite academic researchers interested in exploring quantum applications on Amazon Braket to apply for research credits through the AWS Cloud Credits for Research program.

Mads Bahrami

Mads Bahrami

Mads Bahrami is the manager of Academic Innovation Support at Wolfram Research, where he works with academics to create cutting-edge programs for computational thinking using Wolfram technologies (e.g., on topics such as AI and LLMs, quantum computation). His background includes graduate studies and postdocs focused on the foundations of quantum theory, particularly in the persistence of quantum coherence in noisy environments.

Nik Murzin

Nik Murzin

Nik Murzin is a Research Fellow at the Wolfram Institute, where he focuses on metamathematics, formal rewriting systems, and the Physics Project. In addition to these pursuits, he is a key developer of the Wolfram Quantum Framework (WQF) and provides his expertise to various special projects at Wolfram Research.