OpenQASM 3.0 & High-Throughput ML

OpenQASM 3.0 & High-Throughput ML#

Quex acts as a highly forgiving OpenQASM 3.0 parser and a strictly compliant exporter.

Let’s read a raw parameterized string, attach a simulator, and run a high-speed Variational loop.

import time

import quex as qx

# 1. Parse a messy, lazy OpenQASM string
qasm_str = """
OPENQASM 3.0;
qubit[2] q;
h q[0];
rx(theta) q[1];
cx q[0], q[1];
"""
qc = qx.Circuit.from_qasm(qasm_str)

print("Parsed and normalized Circuit:")
print(qc)
Parsed and normalized Circuit:
q[0]: ───────[H]───────■───
                       │   
q[1]: ───[RX(theta)]───X───

In an ML loop, you don’t want to change the circuit’s inherent state permanently on every step.

You can use parameter_binds inside the run() method to temporarily override the variables at lightning speed, completely bypassing the string parser and DAG construction.

qc.simulator = qx.NumpySimulator()

iterations = 500
start_time = time.time()

# High-speed Late Binding execution loop
for i in range(iterations):
    # Pass overrides directly to the backend
    current_state = qc.run(parameter_binds={"theta": i * 0.01})

end_time = time.time()
print(f"Executed {iterations} unique parameter binds in {end_time - start_time:.4f} seconds!")
Executed 500 unique parameter binds in 0.0373 seconds!