---
title: QASM Circuits with Qiskit AER
url: https://www.emergentmind.com/topics/qasm-circuits-using-qiskit-aer
type: topic
---

# QASM Circuits with Qiskit AER

A QASM circuit is a text-based description of a quantum circuit written in the OpenQASM (Open Quantum Assembly Language) format, commonly used for representing quantum computations in a hardware-agnostic, portable manner. Qiskit AER is a high-performance quantum circuit simulator that allows for the simulation, transformation, obfuscation, and measurement of QASM circuits using advanced techniques in unitary transformation, randomized basis changes, Markov-chain mixing, and group-theoretic constructions. This article surveys the formalism, algorithmic protocols, statistical properties, hardware mappings, and security implications of QASM circuits within the Qiskit AER ecosystem, emphasizing recent research advances.

## 1. QASM Circuit Formalism and Representation

A QASM circuit encodes a sequence of quantum gates and measurements on an $n$-qubit register, using standardized instructions and optional classical registers. Each primitive gate, such as Hadamard or CNOT, can be represented as a unitary matrix; arbitrary single-qubit unitaries are typically parameterized as U3 gates:
\[
\text{U3}(\theta,\phi,\lambda) = 
\begin{pmatrix}
\cos(\theta/2) & -e^{i\lambda} \sin(\theta/2) \\
e^{i\phi} \sin(\theta/2) & e^{i(\phi+\lambda)} \cos(\theta/2)
\end{pmatrix}
\]
Qiskit parses QASM source code via `qiskit.qasm2.loads()` or `qiskit.qasm3.loads()`, generating a `QuantumCircuit` object that preserves the gate structure, barriers, measurements, and resets [2512.19314].

The structural representation of QASM circuits enables downstream transformations such as obfuscation by conjugation, randomized twirling, or re-basing in alternative group-theoretic decompositions.

## 2. Randomization, Obfuscation, and Compiler-Resistance

Quantum circuit obfuscation aims to conceal logical structure while preserving semantics and performance. Parayil et al. [2512.19314] present a method where every gate $G$ in the QASM circuit is conjugated by randomly-selected global or per-gate U3 rotations, effecting the transformation:
\[
G \mapsto U^\dagger G U
\]
with $U=U_3(\theta,\phi,\lambda)$ sampled uniformly from the Haar distribution over SU(2). This process (the *obfuscation sandwich*, Editor's term) is applied as a QASM-to-QASM compiler pass:
- **Input Parsing:** QASM loaded, quantum/classical operations preserved.
- **Basis Generation:** Uniform random $(\theta,\phi,\lambda)$ triples, with $U = U_3(\theta, \phi, \lambda)^{\otimes n}$ and $U^\dagger$ at circuit boundaries.
- **Gate Transformation:** For each $G$, compute $M' = U^\dagger M_G U$, wrap into a Qiskit `UnitaryGate`, and replace $G$.
- **Circuit Reconstruction:** Prepend and append global U/U†, then transpile for Qiskit AER backends.

This technique guarantees functional equivalence due to the invariance property $U U^\dagger = I$, so $U\,(U^\dagger G U)\,U^\dagger = G$. All original measurement and reset regions are respected; only unitary gates are obfuscated.

Empirically, the method achieves greater than 93% semantic accuracy (e.g., 93.30% for QAOA circuits) and total variation distance below 0.084 over 1024-shot simulations, with runtime overhead under 1 ms on commodity hardware [2512.19314]. After merging pre/post U3 layers, the net circuit depth increase is $\Delta D = 2$.

Resistance to reverse engineering is achieved via two adversary models:
- **Black-box:** Continuous random basis makes extraction via I/O queries negligible-probability.
- **White-box:** If all $n$ gates are masked, reconstructing unitaries requires inverting $U^\dagger$ for each gate, which is only possible if adversary guesses the randomization pattern. Partial obfuscation with $x < n$ gates exponentially reduces success probability to $1/\binom{n}{x}$.

QASM-level compatibility is retained since the obfuscated gates appear as opaque `UnitaryGate` blocks, thwarting transpiler pattern-matching and optimization.

## 3. Markov Chain Sampling and Unitary Designs

Unitary $k$-designs are ensembles that replicate the $k$th statistical moments of the Haar measure on $U_N$. The protocol of Zhu and Gross [2011.00128] constructs an approximate unitary 3-design on $m$ qubits via a staged Markov process targeting the orbits of the m-qubit Pauli group modulo phases:
- **Pauli Graph Construction:** Vertices are non-identity Paulis; edges denote commutation, classified into type-1 (intra-group), type-2 (inter-group but commutative), and non-edges (anticommuting).
- **Sampling Protocol:**
  1. **Random Transvections:** Apply $T = O(\log(N^5/\epsilon))$ random symplectic transvections $Z_h$ acting as $x \mapsto x + (x \cdot h)h$, implemented via Mølmer–Sørensen gates.
  2. **Random Kerdock 2-design element $g$:** Uniformly drawn from the Kerdock subgroup (PSL$(2,2^m)$), mixing within edge types.
  3. **Random Pauli $D(a, b)$:** Ensures uniformity at the Pauli 1-moment.
  The resulting Clifford,
  \[
  U = D(a, b) \, g \, \prod_{i=1}^T Z_{h_i}
  \]
  is provably an $\epsilon$-approximate unitary 3-design, where $N=2^m$ [2011.00128].

Mixing analysis shows the protocol achieves $\ell_1$-distance within $\epsilon/(N^3)$ to Haar measure with $T=O(m+\log(1/\epsilon))$ rounds, and the ensemble converges to an exact 3-design in the limit $T\to\infty$.

## 4. Quantum Simulation of Haar Random Unitaries and Representation-Theoretic Protocols

Simulating Haar-random unitaries, such as random $U_3$ gates, can be performed via Clebsch–Gordan (CG) transforms, realized as a general compressed-oracle construction [2509.26623]. For $t$ sequential queries:
- The system is decomposed via Schur–Weyl duality into irreducible subspaces, with memory registers recording total spin $j$ and multiplicity $\alpha$ (cost $O(\log t)$ qubits).
- For each query, the CG process couples new qubit(s) using SU(2) CG coefficients, applies random Wigner $D$-matrices in each irrep block according to the Haar measure (which at spin-$\frac12$ corresponds to U3), then undoes the coupling.
- Controlled-rotations and lookup tables realize the CG step. Complexity per query is $O(\log t)$ gates and $O(\log t)$ depth; total ancilla requirements are $1$ (data) plus $O(\log t)$ (memory) qubits.

This formalism allows efficient simulation of forward, inverse, transpose, and conjugate queries by specifying the nature of the inserted block during the CG/dCG process. For $t=1$, closed-form parameterizations via Euler angles suffice; nontrivial CG network depth arises only for multiple queries [2509.26623].

## 5. Implementation in Qiskit AER: Workflow and Performance

The obfuscation, randomization, and design protocols described above are implemented natively within Qiskit AER:
- **Input:** QASM circuits loaded via `qiskit.qasm2.loads()`/`qasm3.loads()`.
- **Transformation:** Gate matrices extracted via `qiskit.quantum_info.Operator`, conjugated by randomly-sampled U3 or higher-level unitaries as per protocol, then re-embedded as `UnitaryGate` objects.
- **Boundary Correction:** Global U3 layers inserted at circuit start/end (or at partition points if handling mid-circuit measurements).
- **Simulation:** The transformed circuits, once fused, are transpiled for `AerSimulator`. Output distributions are compared using semantic accuracy and total variation distance.
- **Hardware Mapping:** For unitary 3-design protocols, native implementation leverages Mølmer–Sørensen XX-type entangling gates on trapped-ion hardware, with gate depth scaling as $O(m^2 + \log(N^5/\epsilon))$ [2011.00128].

Table: Complexity and Overhead Summary

| Protocol/Technique       | Overhead (Gate Depth)         | Native Gate Mapping           |
|-------------------------|-------------------------------|------------------------------|
| U3 Obfuscation [2512.19314]   | $\Delta D = 2$ (per circuit, after fusion) | U3, arbitrary single-qubit   |
| 3-Design Markov [2011.00128]  | $O(m^2 + \log(N^5/\epsilon))$            | Two-qubit Mølmer–Sørensen    |
| CG-based Haar [2509.26623]    | $O(\log t)$ per query                     | Controlled single-qubit, CG  |

For canonical circuits, the measured semantic fidelity is $\geq 93\%$ and obfuscated circuits remain efficiently simulable (<1 ms additional time per 1024 shots for QAOA) [2512.19314].

## 6. Statistical Properties and Random Matrix Connections

Randomization protocols invoked in QASM/AER workflows often reduce to classical results on the distributions of unitary and orthogonal transformations. For example, repeated Haar-random orthogonal transformations $\Gamma\in O(p)$ acting on the "north pole" $x_0$ yields nontrivial statistics for $U_3 = x_0^T \Gamma^3 x_0$:
\[
U_3 = \varphi_1^3 
  + 2\varphi_1(1-\varphi_1^2)\varphi_2 
  + (1-\varphi_1^2)[-\varphi_1\varphi_2^2 + (1-\varphi_2^2)\varphi_3]
\]
where $\varphi_i\sim f(\cdot|p+1-i)$ are independent first-coordinates of Haar vectors on $S^{p-i}$ [0811.2678]. The variance decays as $1/p$ and for large $p$, $U_3$ becomes approximately Gaussian.

Such detailed statistical characterizations are essential in benchmarking pseudo-randomness, spectral concentration, and deviation from ideal Haar-random sampling in QASM circuit simulation and design protocols.

## 7. Security, Applications, and Limitations

Compiler-resistant obfuscation via U3 conjugation [2512.19314] provides robust defense against both black-box and white-box circuit analysis, reducing the probability of reverse engineering to negligible (continuous basis) or exponentially small (combinatorial, when only a subset of gates is obfuscated). Unlike previous structure-preserving masking, randomized basis transforms render classical transpiler pattern-matching and circuit identification ineffective.

Approximate unitary 3-designs [2011.00128] facilitate randomized benchmarking, emulation of Haar-random unitaries, and secure cryptographic sampling, with strong hardware mapping to native gates on trapped-ion platforms. CG-based Haar constructions [2509.26623] provide efficient algorithms for realizing multiple independent Haar-sampled unitaries, critical for oracle constructions, randomized benchmarking, and design theory.

A plausible implication is that as circuits grow and obfuscation is performed gatewise, transparency for debugging and classical post-processing may be hampered; similarly, highly randomized designs can marginally increase simulation and transpilation cost, although empirical evidence shows these overheads remain pre-asymptotic for practically sized circuits. For multi-partite operations and mid-circuit measurements, circuit partitioning may be necessary to preserve correctness of transformations.

Overall, the integration of unitary design, group-theoretic randomization, and compiler-level obfuscation within the Qiskit AER and QASM circuit paradigm underpins modern approaches to robust, secure, and hardware-aware quantum circuit simulation and deployment.

Source: https://www.emergentmind.com/topics/qasm-circuits-using-qiskit-aer