Main Content


Generate QASM code

Since R2023a

Installation Required: This functionality requires MATLAB Support Package for Quantum Computing.



qasm = generateQASM(c) generates a string representing Open Quantum Assembly Language (OpenQASM) 3.0 code for a quantum circuit.


collapse all

Create a quantum circuit that consists of a Hadamard gate and a controlled X gate to entangle two qubits.

gates = [hGate(1); cxGate(1,2)];
c = quantumCircuit(gates);

Generate OpenQASM 3.0 code for the circuit.

qasm = generateQASM(c)
qasm = 

    "OPENQASM 3.0;
     include "";
     qubit[2] q;
     bit[2] c;
     h q[0];
     cx q[0],q[1];
     c = measure q"

Input Arguments

collapse all

Quantum circuit, specified as a quantumCircuit object.

Version History

Introduced in R2023a