3

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.

Loqi
  • 31
  • 1
  • 3

2 Answers2

2

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!

ryanhill1
  • 2,623
  • 1
  • 11
  • 39
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(""" OPENQASM 2.0; include "qelib1.inc"; qreg q[2]; cz q[0],q[1]; u(2pi,3pi,-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').

luciano
  • 6,084
  • 1
  • 13
  • 34