qsphere

qsphere(state, state_labels=True, state_labels_kind='bits', as_widget=False)[source]

Plots a statevector of qubits using the qsphere representation.

Parameters
  • state (ndarray) – Statevector as 1D NumPy array.

  • state_labels (bool) – Show state labels.

  • state_labels_kind (str) – ‘bits’ (default) or ‘ints’.

  • as_widget (bool) – Return a widget instance.

Returns

Figure instance.

Return type

PlotlyFigure or PlotlyWidget

Raises

KaleidoscopeError – Invalid statevector input.

Example

from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector
import kaleidoscope.qiskit
from kaleidoscope.interactive import qsphere

qc = QuantumCircuit(3)
qc.h(range(3))
qc.ch(0,1)
qc.s(2)
qc.cz(2,1)
state = qc.statevector()

qsphere(state)