I can't seem to find anything, but this seems like something that should be possible.
3 Answers
You can convert a qiskit circuit to QASM using circuit.qasm()
. You can copy this and then there's an "Import OpenQASM" button on the initial circuit composer page:
and you can paste the QASM into a tab of the composer itself:
-
1$\begingroup$ I am a little bit confused. I think that the question was on code in Qiskit, not QASM. $\endgroup$ Commented Dec 3, 2019 at 6:19
-
2$\begingroup$ IBM Q Experience circuit composer takes OpenQASM code, not Qiskit code. $\endgroup$ Commented Dec 3, 2019 at 11:33
-
$\begingroup$ Thank you, this is exactly what I was looking for! For anyone trying it, you have to do print(circuit.qasm()) if you want to be able to copy paste into the circuit editor. $\endgroup$– ejw_artCommented Dec 3, 2019 at 19:16
Let's say, you've the Qiskit
code for the circuit that you want to implement in Circuit Composer as shown below.
qr = QuantumRegister(3, name="q")
crz, crx = ClassicalRegister(1, name="crz"), ClassicalRegister(1, name="crx")
qc = QuantumCircuit(qr, crz, crx)
qc.h(1) # Put qubit a into state |+>
qc.cx(1,2) # CNOT with a as control and b as target
Then use print(qc.qasm())
to get the circuit equivalent, which is as follows
OPENQASM 2.0;
include "qelib1.inc";
qreg q[3];
creg crz[1];
creg crx[1];
h q[1];
cx q[1],q[2];
You can run this code in QASM / Circuit Composer.
This changed in Qiskit 1.0. You can still export to QASM code, but there is no more QuantumCircuit.qasm()
method.
https://docs.quantum.ibm.com/api/migration-guides/qiskit-1.0-features#quantumcircuitqasm
The new method is
from qiskit import QuantumCircuit
qc = QuantumCircuit(1)
from qiskit.qasm2 import dumps
qasm_str = dumps(qc)