# How to read QASM files for parametrized circuits (in QISKIT)? both from_qasm_file() and from_qasm_str() fail

I am trying to work with parametrized circuits in QISKIT. I can simply create parameterized circuits, bind value(s) to parameter(s), and execute/run all instances (after binding values for parameters) on different backends like ibmq_manhattan, ibmq_paris, etc.

To dump the resulting circuits to QASM files, I use the “qasm()” method of the QuantumCircuit objects, and I see no problem. Here is a simple (random) QASM file that I create:

OPENQASM 2.0; include "qelib1.inc"; qreg q[3]; creg c[3]; h q[0]; h q[1]; h q[2]; barrier q[0],q[1],q[2]; rx(beta) q[0];

As you can see, the last line of the QASM file specifies a parameterized RX rotation, on qubit q[0] and the angle is (beta). As far as I am working with QuantumCircuit objects, I can deal with these parameters. However, after writing the circuit to a QASM file, I lose the functionality.

More specifically, when I try to load/read the QASM file and create a QuantumCircuit, I face the following error:

Code: circ = QuantumCircuit.from_qasm_file(filepath) Error: qiskit.qasm.exceptions.QasmError: "Argument 'beta' in expression cannot be found, line 9 file …

I also tried the following alternative (just in case): Code: circ = QuantumCircuit.from_qasm_str(qasm_str) and faced the same error. Here the “filepath” specifies the path to the QASM file, and I obtain the “qasm_str” via reading the QASM file.

I checked the source code of the “from_qasm_file()” module in QISKIT, as well as “Qasm” class; however, I did not find any additional input argument/parameter to specify these parameters to the parser.

I just need to read the (abovementioned) QASM file and re-create a QuantumCircuit object.

I would appreciate it a lot if someone can help me in this regard.

Thanks, Ramin

• Can you do parametrized circuit in QASM code? I don't think this is possible. You have to specify exactly what the parameter is in the gate. You can use qiskit to write define your parameterized circuit. Mar 21, 2021 at 5:05

The .qasm output is a bit of notation abuse. There are experimental ideas to support a more comprehensive circuit serialization format https://github.com/Qiskit/qiskit-terra/pull/5578