AWS Quantum Technologies Blog

Amazon Braket now supports verbatim compilation and native gates with IonQ

Previously, when customers submitted a circuit to the IonQ device on Amazon Braket, the circuit was automatically compiled to native instructions. Today, we are extending the verbatim compilation feature to IonQ’s 11-qubit device. With this launch, you have the option to run your circuits on the IonQ system with no intervening compiler passes. This allows researchers to be in control of what is executed on the device to support advanced applications, such as error mitigation, custom compilation, and device characterization.


Quantum circuit compilers enable developers of quantum computing applications to focus on developing their algorithms without having to worry about hardware restrictions such as the device topology or the native gates supported by the quantum computer. The quantum compiler automatically transforms the gates of an abstract circuit into the native instructions that can be executed on a specific device. Along the way, it also optimizes the circuit, for example by collapsing and combining certain gates, or rearranging instructions and qubits, to reduce the impact of noise and improve the quality of the results. With Amazon Braket, you can even program abstract circuits and run them against multiple devices from different providers such as IonQ, Rigetti, and Oxford Quantum Circuits (OQC) by only changing a few lines of code. Your circuits are automatically compiled to run on your desired hardware.

While compilation is convenient for developing applications, researchers in academia and industry often require the ability to run their programs exactly as defined, without any modifications by the compiler. For example, many device characterization algorithms, such as randomized benchmarking and volumetric benchmarking, require executing a specific set of instructions on certain qubits. Additionally, compilation researchers require their circuits to be executed exactly as defined in order to test their own compilation strategies. Further, research on error mitigation protocols, such as zero noise extrapolation, also requires the ability to specify exactly the gates and circuit layouts that will be executed on the chosen quantum hardware.

Amazon Braket provides the verbatim compilation feature, so you can run your circuits without any modifications. Until now, customers could execute verbatim circuits on Rigetti and OQC devices. Today, we have extended this capability to the IonQ device on Amazon Braket. You can now program your circuits with IonQ’s native gates, and execute them on hardware exactly as defined.

Getting started

To use verbatim compilation on the IonQ device, you first program a circuit with only native gates. One of IonQ’s one-qubit native gates is the GPi gate, a π rotation (or bit flip) that takes a phase as a parameter. This phase parameter lets the GPi gate act as either an X gate, Y gate, or a gate along any other arbitrary azimuthal angle. A second one-qubit native gate, the GPi2 gate, similarly takes an arbitrary phase as a parameter, but only performs a π /2 rotation. The two-qubit native gate is the Mølmer–Sørensen gate, or MS gate, which takes two phase angles as parameters. To learn more about IonQ’s native gates, we recommend reading the Amazon Braket Developer Guide and IonQ’s documentation.

To specify verbatim compilation, you include all gates of the circuit in a verbatim box, using add_verbatim_box.

from braket.circuits import Circuit
from import AwsDevice
from math import pi

circuit = Circuit().gpi(0,pi).gpi2(1,-pi).ms(0,1,pi,pi/2)
circuit = Circuit().add_verbatim_box(circuit)

The circuit is visualized as:

Now, you are ready to submit your circuit to run verbatim on the IonQ device!

device = AwsDevice("arn:aws:braket:::device/qpu/ionq/ionQdevice")
task =, shots=100)

Zero-noise extrapolation

Next we will provide an example of how you can apply verbatim compilation to implement error mitigation. The Variational Quantum Eigensolver (VQE) is an algorithm that finds the minimum energy of a Hamiltonian by optimizing the parameters in a circuit ansatz. A two-qubit circuit ansatz is shown in the following snippet. To minimize the energy, you compute the energy landscape by evaluating the ansatz for various values of the parameters. For example, the blue dots in Figure 1 show the energy with various choices of params[0].

def ansatz(params):
    circ = Circuit(),1,params[0],0).gpi2(0,params[1]).gpi2(1,params[2]),1,params[3],0).gpi2(0,params[4]).gpi2(1,params[5]),1,params[6],0).gpi2(0,params[7]).gpi2(1,params[8])
    return circ

Current quantum computers are subject to noise. With verbatim compilation, you can use error mitigation protocols to improve your hardware execution results. Zero-noise extrapolation is a technique to estimate the noiseless expectation value from noisy data. The idea is to intentionally insert layers of identity gates into a circuit. The greater the number of identity gates, the noisier the results. You can extrapolate the trend of the noise and estimate what the result would be without noise. To learn more about zero-noise extrapolation, see [1].

The following snippet shows how you can implement zero-noise extrapolation with the IonQ device on Amazon Braket. The zne function in the code snippet inserts a specified number of identity layers. The expectation values are computed on the IonQ device with three different numbers of identity layers. You can fit the data to estimate the noiseless expectation value. With zero-noise extrapolation, the energy landscape is shown by the orange dots in Figure 1. The accuracy is defined as the ratio of the expectation value from a hardware execution to the one from a noiseless simulation. Compared to the result without error mitigation (i.e., without zero-noise extrapolation; blue dots in Figure 1), the accuracy improves by up to 12% in this example.

def zne(circ, repeats=0):
    identity_layer = Circuit().add(circ).add(circ.adjoint())
    circ_zne = Circuit().add(circ)
    for _ in range(repeats):
    return circ_zne

device = AwsDevice("arn:aws:braket:::device/qpu/ionq/ionQdevice")

exp_values = []
for repeats in [0,1,2]:
    params = [0, -pi/4, pi, 0, 0, 0, 0, 0, 0]
    circ_zne = zne(ansatz(params), repeats=repeats)
    circ = Circuit().add_verbatim_box(circ_zne)
    circ.expectation(observable=Observable.Z()@Observable.Z(), target=[0,1])

    task =, shots=3000)
    exp_values.append(task.result().values[0]) # collect the ZZ expectation value

Figure 1. The energy landscape of a circuit ansatz when varying param[0]. Orange and blue dots are QPU results with and without error mitigation respectively. The solid green line is the exact result from a noiseless simulator.


In this blog, we demonstrated how to use verbatim compilation and native gates for the IonQ device on Amazon Braket. Verbatim compilation enables customers to explore use cases such as device and noise characterization, compilation research, and error mitigation protocols. Using VQE as an example, we showed how to use verbatim compilation to implement zero-noise extrapolation and mitigate the error in hardware results. To learn more, and to get started with verbatim compilation with the IonQ device on Amazon Braket, see our Developer Guide and example notebooks.