# Convert from QASM code to Qiskit Code

I'm looking for something that performs a conversion such as qiskit.circuit.QuantumCircuit.qasm, but for qasm code. In other words, a means to convert qasm code to qiskit code?

Not just converting from qasm code to a QuantumCircuit object, but yielding the actual qiskit code. The closest method I've found is to paste the qasm code into IBM's circuit composer then copying from there. However, I need to automate the process. Does anyone know about an existing function like this or do I need to write it myself?

Thanks in advance, and I'm new to this site so hopefully I haven't broken any rules! If I have, please let me know.

• You might want to check out this StackOverflow answer: quantumcomputing.stackexchange.com/questions/29586/… Commented Jan 6, 2023 at 19:28
• Thanks for the link @FrankYellin, seems related yes.
– Loqi
Commented Jan 9, 2023 at 13:58
• tbh you could try gpt4 with an API key. Might not get it perfect but will come pretty close Commented Jun 7, 2023 at 16:35

I've just come across a website called the 'Quantum Programming Studio' which seems to serve this purpose: https://quantum-circuit.com/qconvert

Hope that helps!

The QuantumCircuit's method from_qasm_str takes an OpenQASM 2 definition of a circuit and converts it into a QuantumCircuit Qiskit object:

from qiskit import QuantumCircuit

circuit = QuantumCircuit.from_qasm_str("""
OPENQASM 2.0;
include "qelib1.inc";
qreg q[2];
cz q[0],q[1];
u(2*pi,3*pi,-5*pi) q[0];
""")
circuit.draw('mpl')


If the OpenQASM code is in a file, you can use QuantumCircuit.from_qasm_file('filename.qasm').

• Thanks for the answer @luciano. However, I'm looking for a method that converts qasm code into qiskit code such that it can be automated. Not a QuantumCircuit object. But perhaps there is a way to convert a QuantumCircuit object into qiskit code? I'm not sure yet.
– Loqi
Commented Jan 9, 2023 at 13:43
• there is now way to do that at the moment. What's the use case for it? Commented Jan 9, 2023 at 17:50
• For example using a benchmark set of quantum programs written in qasm, but you want to automatically load them into another backend that reads qiskit code. So just practical things like that. @luciano
– Loqi
Commented Jan 12, 2023 at 14:26
• Backends consume Qiskit QuantumCircuit objects. You can do that loading a QASM and send it to run. Commented Jan 12, 2023 at 19:34
• For the benchmarks, it may make sense to start from something framework-independent and generate framework-specific circuits from there. Commented Feb 8, 2023 at 1:51