5
$\begingroup$

I can't seem to find anything, but this seems like something that should be possible.

$\endgroup$
1
  • $\begingroup$ Hi, does the purpose is a visualization of the circuit? $\endgroup$
    – Ron Cohen
    Commented Jun 2 at 5:35

3 Answers 3

6
$\begingroup$

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:

enter image description here

and you can paste the QASM into a tab of the composer itself:

enter image description here

$\endgroup$
3
  • 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_art
    Commented Dec 3, 2019 at 19:16
3
$\begingroup$

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.

$\endgroup$
1
$\begingroup$

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)
$\endgroup$

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.