qilisdk.utils.visualization.hamiltonian_renderers

Classes

MatplotlibHamiltonianRenderer

Render a Hamiltonian as an interaction graph using matplotlib.

Module Contents

class MatplotlibHamiltonianRenderer(hamiltonian: qilisdk.analog.hamiltonian.Hamiltonian, ax: matplotlib.axes.Axes | None = None, *, style: qilisdk.utils.visualization.style.HamiltonianStyle | None = None)[fuente]

Render a Hamiltonian as an interaction graph using matplotlib.

Every qubit becomes a node whose disc is split into one slice per local field acting on it, and every two-qubit term becomes an edge between the qubits it couples. Slice and edge colours encode the coefficient of the corresponding term, while the edge line style encodes the coupling type. Terms acting on three or more qubits are drawn as star-shaped hyperedges.

Ejemplo

from qilisdk.analog import X, Z
from qilisdk.utils.visualization.hamiltonian_renderers import MatplotlibHamiltonianRenderer

H = X(0) + 2 * Z(1) + 0.5 * Z(0) * Z(1)
renderer = MatplotlibHamiltonianRenderer(H)
renderer.plot()

Initialize the renderer.

Parámetros:
  • hamiltonian (Hamiltonian) – The Hamiltonian to render.

  • ax (Axes | None) – Axes to draw on. A new figure and axes are created when omitted.

  • style (HamiltonianStyle | None) – Customization options for the plot appearance. Defaults to HamiltonianStyle.

hamiltonian[fuente]
style[fuente]
ax[fuente]
property axes: matplotlib.axes.Axes[fuente]

The axes the Hamiltonian is drawn on.

plot() None[fuente]

Render the Hamiltonian interaction graph on the current axes.

Muestra:

ValueError – If the Hamiltonian acts on no qubits and therefore has no graph to draw.

build_graph() rustworkx.PyGraph[fuente]

Build the qubit interaction graph backing the drawing.

Nodes are added in qubit order, so a node’s index equals its qubit index. Each node payload maps a local field type to its coefficient, and each edge payload maps a coupling type to its coefficient.

Devuelve:

Graph with one node per qubit and one edge per coupled qubit pair.

Tipo del valor devuelto:

rx.PyGraph

save(filename: str) None[fuente]

Save the current figure to disk.

Parámetros:

filename (str) – Path to save the figure to (e.g. 'hamiltonian.png').

show() None[fuente]

Show the current figure.