3
$\begingroup$

This is what drawing a circuit looks like in the Qiskit textbook:

enter image description here

and this is the ugly version I am stuck with in my own notebooks:

enter image description here

On their Prerequisites page they write:

enter image description here

However, there is no .qiskit file in my home directory, and I can't locate it anywhere else. I installed it simply with the usual pip install command, without setting up any virtual environment, so that may be the issue. I am not a Linux expert so perhaps there is something simple I am missing.

How can I set up this configuration file? Creating a .qiskit directory manually doesn't do the job.

$\endgroup$
4
  • 1
    $\begingroup$ Rather than changing the default, you can request the mpl backend each time using `.draw(output='mpl')'. $\endgroup$ Commented Jan 29, 2021 at 22:47
  • $\begingroup$ Awesome, thanks. Would still be nice to figure out where that damn file is stored though. $\endgroup$ Commented Jan 29, 2021 at 22:53
  • $\begingroup$ Hey! I wrote that "ugly" circuit drawer. I feel a bit disparaged ;) $\endgroup$
    – luciano
    Commented Jan 30, 2021 at 8:33
  • $\begingroup$ Oops, sorry :) I should have rather called it charmingly rustic or tastefully minimalistic perhaps... $\endgroup$ Commented Jan 30, 2021 at 20:39

1 Answer 1

0
$\begingroup$

As James noted in the comment. You can use the .draw( output = 'mpl', ... ) or to help you to get a nicer figure. That is, suppose I have the following circuit:

q_0: ┤ X ├┤M├─────────
     ├───┤└╥┘┌─┐      
q_1: ┤ X ├─╫─┤M├──────
     ├───┤ ║ └╥┘┌─┐   
q_2: ┤ H ├─╫──╫─┤M├───
     ├───┤ ║  ║ └╥┘┌─┐
q_3: ┤ H ├─╫──╫──╫─┤M├
     └───┘ ║  ║  ║ └╥┘
c: 4/══════╩══╩══╩══╩═
           0  1  2  3 

which can be created by running the code:

from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
from numpy import pi

qreg_q = QuantumRegister(4, 'q')
creg_c = ClassicalRegister(4, 'c')
circuit = QuantumCircuit(qreg_q, creg_c)

circuit.x(qreg_q[0])
circuit.x(qreg_q[1])
circuit.h(qreg_q[2])
circuit.h(qreg_q[3])
circuit.measure(qreg_q[0], creg_c[0])
circuit.measure(qreg_q[1], creg_c[1])
circuit.measure(qreg_q[2], creg_c[2])
circuit.measure(qreg_q[3], creg_c[3])

then by specifying:

circuit.draw( output = 'mpl', style={'name': 'bw'}, plot_barriers= True, initial_state = True, scale = 1)

I will get the figure:

enter image description here

and if i specify:

circuit.draw( output = 'latex',style={'name': 'bw'}, plot_barriers= True, initial_state = True, scale = 1)

I will get the figure:

enter image description here

and if you want to save the image file, then include the file name in the option. That is, something like:

circuit.draw( 'mpl',style={'name': 'bw'},filename= 'MyCircuit', plot_barriers= True, initial_state = True, scale = 1)
$\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.