Skip to content

Better representation of state vectors#512

Open
nils-wittemeier wants to merge 9 commits into
mainfrom
better-representation-of-state-vectors
Open

Better representation of state vectors#512
nils-wittemeier wants to merge 9 commits into
mainfrom
better-representation-of-state-vectors

Conversation

@nils-wittemeier

@nils-wittemeier nils-wittemeier commented Mar 11, 2026

Copy link
Copy Markdown
Contributor

Visualization

Adds a draw() method with three visualization modes to QuantumStateVector

from quri_parts.core.state import QuantumStateVector
import numpy as np

amp = np.sqrt(1/2)
state = QuantumStateVector(1, [amp, -amp])

state.draw(output="bloch")       # Bloch sphere
state.draw(output="qsphere")     # Q-sphere (multi-qubit phase/probability view)
state.draw(output="hinton")      # Hinton diagram of the density matrix
  • bloch: Visualizes the state as a point on the Bloch sphere. For multi-qubit states, reduced single-qubit states are shown via partial trace.
    image

  • qsphere: Global view of a multi-qubit state in the computational basis. Dot size = probability, color = phase of each basis state.
    image

  • hinton: Hinton diagram of the density matrix. Square size encodes magnitude, color (white/black) encodes the sign of real/imaginary parts.
    image

Text/Latex Representation

Adds text/latex representation of QuantumState, which uses mpmath to find expressions for floating point coefficients.

from quri_parts.core.state import QuantumStateVector
import numpy as np

amp = np.sqrt(1/2)
state = QuantumStateVector(1, [amp, -amp])

state.draw()
state.draw(output="latex_source")
state.draw(output="latex") 
|0> amp=0.707107 prob=0.5
|1> amp=-0.707107 prob=0.5
\frac{\sqrt{2}}{2}|0\rangle + -\frac{\sqrt{2}}{2}|1\rangle
<IPython.core.display.Latex object>

Jupyter notebooks will automatically render the LaTeX object as formatted math when evaluating a cell.
image

@github-actions

github-actions Bot commented Mar 11, 2026

Copy link
Copy Markdown

@github-actions github-actions Bot temporarily deployed to pull request March 11, 2026 21:03 Inactive
@NaoQunaSys

Copy link
Copy Markdown

This is a very useful feature! Until now, when I wanted to display LaTeX in a Jupyter Notebook, I had to convert it into Qiskit and implement it like below, so I'm glad to see it supported natively.

from quri_parts.qiskit.circuit import convert_circuit as convert_circuit_qiskit
qc_qiskit = convert_circuit_qiskit(qc) # qc is a QuantumCircuit Object
return Statevector(qc_qiskit).draw('latex')

@ThomasenQunasys ThomasenQunasys left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I'm sorry, I forgot to approve this. I've already gone over the changes earlier LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants