4
$\begingroup$

I am just starting to get around Qiskit, I'm going at baby steps, so I tried to run the code below and I noticed three things:

  1. I tried using matplotlib_circuit_drawer() instead of circuit_drawer(), but is return a DeprecationWarning and sugested using circuit_drawer. I assume this is due to the constant updates and the functions are going to change frequently;

  2. In the qc.measure(q, c) I get a highlight in PyCharm saying Unresolved attribute reference 'measure' for class 'QuantumCircuit', and I don't know what that really means;

  3. I think this is also related to 1). When using draw(qc) I get the warning DeprecationWarning: The current behavior for the default output will change in a future release. Instead of trying latex and falling back to mpl on failure it will just use "text" by default '"text" by default', DeprecationWarning) and no image pops up. However when I use print(qc) the circuit pops up in text format;

How can I be up to date about the commands?

from qiskit import ClassicalRegister, QuantumRegister, QuantumCircuit
from qiskit.tools.visualization import circuit_drawer as draw

c = ClassicalRegister(2)
q = QuantumRegister(2)
qc=QuantumCircuit(q, c)

qc.measure(q, c)
draw(qc)
$\endgroup$
3
$\begingroup$

Qiskit Terra 0.7 changed visualization quite a bit. This blog post from the Qiskit team might be helpful.

Here's your code, updated for Qiskit Terra 0.7.2:

from qiskit import ClassicalRegister, QuantumRegister, QuantumCircuit

c = ClassicalRegister(2)
q = QuantumRegister(2)
qc=QuantumCircuit(q, c)

qc.measure(q, c)

# draws an ascii circuit
print(qc)

# Output:
#             ┌─┐
# q0_0: |0>───┤M├
#          ┌─┐└╥┘
# q0_1: |0>┤M├─╫─
#          └╥┘ ║
#  c0_0: 0 ═╬══╩═
#           ║
#  c0_1: 0 ═╩════

# draws a circuit with Matplotlib 
diagram = qc.draw(output="mpl")

# if you'd like to save to a file
diagram.savefig("test.svg", format="svg")

Here's the SVG that was generated (converted to PNG for StackExchange):

As for your second question... this sounds like something with your IDE's access to the library symbols. I don't have help for you there, except to say it's a fairly common problem. Good luck!


Note: This advice applies to Qiskit 0.7.x. Qiskit is rapidly evolving and you should expect breaking changes on new versions. You can find the release notes here.


Troubles installing Matplotlib/visualizations?

Per the blog post, you should be able to run:

pip install qiskit[visualization]

While it has worked for me in the past, it currently returns:

qiskit 0.7.2 does not provide the extra 'visualization'

As a workaround, you can install the packages this "extra" references:

pip install matplotlib nxpd ipywidgets pydot

Also, in the off chance you are using MacOS with virtualenv, you may run into this issue. I had to use venv to get it to work.

Good luck!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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