3
$\begingroup$

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.

$\endgroup$
3
  • $\begingroup$ You might want to check out this StackOverflow answer: quantumcomputing.stackexchange.com/questions/29586/… $\endgroup$ Jan 6, 2023 at 19:28
  • $\begingroup$ Thanks for the link @FrankYellin, seems related yes. $\endgroup$
    – Loqi
    Jan 9, 2023 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, 2023 at 16:35

2 Answers 2

1
$\begingroup$

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

Quantum Programming Studio

Hope that helps!

$\endgroup$
0
$\begingroup$

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')

Quantum circuit

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

$\endgroup$
5
  • 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, 2023 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, 2023 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, 2023 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, 2023 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, 2023 at 1:51

Your Answer

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

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