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.

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

1 Answer 1


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("""
include "qelib1.inc";
qreg q[2];
cz q[0],q[1];
u(2*pi,3*pi,-5*pi) q[0];

Quantum circuit

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

  • 1
    $\begingroup$ 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. $\endgroup$
    – Loqi
    Jan 9 at 13:43
  • $\begingroup$ there is now way to do that at the moment. What's the use case for it? $\endgroup$
    – luciano
    Jan 9 at 17:50
  • $\begingroup$ 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 $\endgroup$
    – Loqi
    Jan 12 at 14:26
  • $\begingroup$ Backends consume Qiskit QuantumCircuit objects. You can do that loading a QASM and send it to run. $\endgroup$
    – luciano
    Jan 12 at 19:34
  • $\begingroup$ For the benchmarks, it may make sense to start from something framework-independent and generate framework-specific circuits from there. $\endgroup$
    – rhundt
    Feb 8 at 1:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.