Search code examples
jupyter-notebookquantum-computingqiskit

Why does drawing a qiskit quantum circuit look different when I run a jupyter notebook locally


I'm using the qiskit textbook, and it creates a QuantumCircuit and then draws the circuit, and it looks like this: visualization of quantum circuit from qiskit textbook

I see the same result when running the textbook as a jupyter notebook in IBM's quantum lab.

However, when I download the textbook as a jupyter notebook and run it myself locally, it looks like this: visualization of quantum circuit from locally hosted jupyter notebook

I don't like this very much, and I think I am missing something simple. The code that is running is exactly the same. I am using MacOS 11.4 (Big Sur). The following code is sufficient to show a difference when I run it online vs. locally:

from qiskit import QuantumCircuit

qc = QuantumCircuit(1)  # Create a quantum circuit with one qubit
initial_state = [0,1]   # Define initial_state as |1>
qc.initialize(initial_state, 0) # Apply initialisation operation to the 0th qubit
qc.draw()  # Let's view our circuit

Solution

  • Because Qiskit has multiple drawers. Those are:

    • text
    • mpl
    • latex
    • latex_source.

    The drawer you see in the IBM Quantum Lab is the one based on Matplotlib. You can get the same output by qc.draw('mpl').

    To set a default, you can change (or create if does not exist) the file ~/.qiskit/settings.conf) with the entry circuit_drawer = mpl.