Tutorials
qcr:2606.05350.1

Dynamic Circuits with OpenQASM 3.0 on Braket

OpenQASM 3.0 substantially extends the OpenQASM quantum assembly language with the control-flow and classical-computation features needed to express dynamic circuits, and this Amazon Braket notebook shows how to use it to program mid-circuit measurement and feedforward for IQM's Garnet processor. Where earlier versions of OpenQASM described essentially static circuits, OpenQASM 3.0 adds real-time classical variables, conditional statements, and the ability to apply gates based on mid-circuit measurement outcomes, making it a natural textual representation for dynamic quantum programs. The notebook demonstrates writing dynamic circuits directly in OpenQASM 3.0 source, including measuring qubits partway through, storing the results in classical registers, and conditionally applying subsequent operations, then submitting these programs to Braket for execution on IQM Garnet. By working at the OpenQASM 3.0 level, it highlights how the open intermediate representation captures the measure-and-act semantics of dynamic circuits in a portable, hardware-agnostic form, supporting reproducibility and interoperability. It is an advanced example combining two important modern capabilities, dynamic circuits and the OpenQASM 3.0 standard, on Amazon Braket.
Compilation
Qubit
Circuit-based
Uploaded 3 days ago
10
Views
GitHub582
Citing this entry? Use this QCR ID
Uploaded by
QL
QCR Librarian

Overview

amazon-braket/amazon-braket-examples
582261
In [ ]:
# --- Setup cell added by QCR (not part of the original tutorial) ---
# Source: amazon-braket/amazon-braket-examples @ 0c0818f315479aab9deebed7e7ed7533ac581923, Apache License 2.0.
# Installs the example's dependencies. If a later cell still reports a missing
# package, restart the runtime/kernel and run again from the top.
%pip install -q amazon-braket-sdk==1.117.3

Dynamic Circuits with OpenQASM 3.0 with Amazon Braket

In this notebook, we show how to utilize dynamic circuit tools for IQM Garnet with Braket using OpenQASM 3.0.

OpenQASM is an intermediate representation for quantum instructions, used extensively in quantum programming. One goal of OpenQASM 3.0 specifically was to support emerging usecases requiring "real-time" classical feedback, which encompasses dynamic circuit constructions.

Notebook Setup

Here, we will only use the device configuration in iqm_config, as the simulator instructions produce different OpenQASM files. We utilize a run_qpu flag for device execution. Notice the additional IR and serialization imports from Braket.

In [1]:
from math import pi

import iqm_config

from braket.circuits import Circuit
from braket.circuits.serialization import (
    IRType,
    OpenQASMSerializationProperties,
    QubitReferenceType,
)
from braket.experimental_capabilities import EnableExperimentalCapability
from braket.ir.openqasm import Program
from braket.tracking import Tracker

run_qpu = True

qd = iqm_config.qd

track = Tracker().start()

The following block shows the basic syntax in OpenQASM 3.0 for the measure_ff and cc_prx instructions included in the braket.experimental_capabilities.

// mcm_ff.qasm
// perform mid circuit measurement and active qubit reset on a single qubit
OPENQASM 3;
bit[1] c;
#pragma braket verbatim
box{
    prx(3.14, 0) $1;
    measure_ff(0) $1;
    cc_prx(3.14, 0, 0) $1;
    }
c[0] = measure $1;

Below, we load the local qasm file, view it, and then submit it on the device.

In [2]:
with open("mcm_ff.qasm", "r") as fp:
    qasm = fp.read()

qasm_prog = Program(source=qasm)
print(qasm)

if run_qpu:
    result = qd.run(qasm_prog, shots=100).result()
    print(f"Measurement counts: {result.measurement_counts}")
// mcm_ff.qasm
// perform mid circuit measurement and active qubit reset 
OPENQASM 3;
bit[1] c;
#pragma braket verbatim
box{
    prx(3.14, 0) $1;
    measure_ff(0) $1;
    cc_prx(3.14, 0, 0) $1;
    }
c[0] = measure $1;

Measurement counts: Counter({'0': 94, '1': 6})

Another way of generating the QASM file is directly from a Braket Circuit.

In [3]:
with EnableExperimentalCapability():
    circ = Circuit()
    circ.prx(0,pi,0)
    circ.measure_ff(0,0)
    circ.cc_prx(0, pi, 0, 0)

print(circ)
T  : │       0        │    1    │         2          │
      ┌──────────────┐ ┌───────┐ ┌──────────────────┐ 
q0 : ─┤ PRx(3.14, 0) ├─┤ MFF→0 ├─┤ 0→CCPRx(3.14, 0) ├─
      └──────────────┘ └───────┘ └──────────────────┘ 
T  : │       0        │    1    │         2          │
In [4]:
circ = Circuit().add_verbatim_box(circ)
qasm = circ.to_ir(IRType.OPENQASM, OpenQASMSerializationProperties(QubitReferenceType.PHYSICAL), {}).source
print(qasm)
OPENQASM 3.0;
bit[1] b;
#pragma braket verbatim
box{
prx(3.141592653589793, 0.0) $0;
measure_ff(0) $0;
cc_prx(3.141592653589793, 0.0, 0) $0;
}
b[0] = measure $0;

Cost Tracking

The total cost of running these examples is given below:

In [5]:
print("Quantum Task Summary")
print(track.quantum_tasks_statistics())
print(
    "\nNote: Charges shown are estimates based on your Amazon Braket simulator and quantum processing unit (QPU) task usage.\nEstimated charges shown may differ from your actual charges. Estimated charges do not factor in any discounts or credits,\nand you may experience additional charges based on your use of other services such as Amazon Elastic Compute Cloud (Amazon EC2).",
)
print(
    f"\nEstimated cost to run this example: {track.qpu_tasks_cost() + track.simulator_tasks_cost():.3f} USD",
)
Quantum Task Summary
{<_IQM.Garnet: 'arn:aws:braket:eu-north-1::device/qpu/iqm/Garnet'>: {'shots': 100, 'tasks': {'COMPLETED': 1}}}

Note: Charges shown are estimates based on your Amazon Braket simulator and quantum processing unit (QPU) task usage.
Estimated charges shown may differ from your actual charges. Estimated charges do not factor in any discounts or credits,
and you may experience additional charges based on your use of other services such as Amazon Elastic Compute Cloud (Amazon EC2).

Estimated cost to run this example: 0.445 USD

References

Join the Discussion

Comments (0)

No comments yet. Be the first to share your thoughts!

Indexed by QCR Librarian

This entry was created automatically from publicly available records. QCR links to public sources and only stores repository content where the license permits redistribution.

Versions

v1 Latest
Jun 16, 2026
qcr:2606.05350.1

Cite all versions? Use the base QCR ID to always reference the latest version of this entry.

Tools used

Amazon Braket SDK

Keywords

dynamic-circuits
openqasm
feedforward
braket
format-conversion

You may also like5