Skip to content

visualization

Visualization utils.

plot_cf(state, pts_x, pts_y=None, axs=None, contour=True, qp_type=WIGNER, cbar_label='', axis_scale_factor=1, plot_cbar=True, plot_grid=True, x_ticks=None, y_ticks=None, z_ticks=None, subtitles=None, figtitle=None, gif=False, gif_params=None)

Plot a characteristic function as paired real/imag subplots.

Each batch element produces two adjacent subplots — real part followed by imaginary part — so the rendered grid has shape (rows, 2 * cols).

Parameters:

Name Type Description Default
state

state with arbitrary number of batch dimensions, result will be flattened to a 2d grid to allow for plotting

required
pts_x

x points to evaluate the characteristic function at

required
pts_y

y points to evaluate the characteristic function at

None
axs

matplotlib axes to plot on

None
contour

make the plot use contouring

True
qp_type

type of characteristic function. Currently only "wigner" is supported.

WIGNER
cbar_label

labels for the real and imaginary cbar (overridden internally based on qp_type)

''
axis_scale_factor

scale of the axes labels relative

1
plot_cbar

whether to plot cbar

True
plot_grid

whether to draw gridlines on each subplot

True
x_ticks

tick position for the x-axis

None
y_ticks

tick position for the y-axis

None
z_ticks

tick position for the z-axis

None
subtitles

subtitles for the subplots (shape must match state.bdims)

None
figtitle

figure title

None
gif

if True, render an animation over one batch axis instead of a tiled grid. Returns a matplotlib.animation.FuncAnimation that auto-renders inline in Jupyter.

False
gif_params

dict of options for the gif path. Recognized keys: save_path (default None) — if set, save the animation here via PillowWriter; interval_ms (default 200) — milliseconds per frame; ts (default None) — optional 1D array of timestamps matching the animation-axis length; when set, each frame's suptitle gets a t = … label; batch_animation_axis (default 0) — index into state.bdims selecting which axis becomes the animation/time axis (the remaining batch dims form the per-frame subplot grid).

None

Returns:

Type Description

(axs, im) in the static case, or a FuncAnimation when

gif=True.

Source code in jaxquantum/core/visualization.py
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
def plot_cf(
        state,
        pts_x,
        pts_y=None,
        axs=None,
        contour=True,
        qp_type=WIGNER,
        cbar_label="",
        axis_scale_factor=1,
        plot_cbar=True,
        plot_grid=True,
        x_ticks=None,
        y_ticks=None,
        z_ticks=None,
        subtitles=None,
        figtitle=None,
        gif=False,
        gif_params=None,
):
    """Plot a characteristic function as paired real/imag subplots.

    Each batch element produces two adjacent subplots — real part followed
    by imaginary part — so the rendered grid has shape ``(rows, 2 * cols)``.

    Args:
        state: state with arbitrary number of batch dimensions, result will
            be flattened to a 2d grid to allow for plotting
        pts_x: x points to evaluate the characteristic function at
        pts_y: y points to evaluate the characteristic function at
        axs: matplotlib axes to plot on
        contour: make the plot use contouring
        qp_type: type of characteristic function. Currently only
            ``"wigner"`` is supported.
        cbar_label: labels for the real and imaginary cbar (overridden
            internally based on ``qp_type``)
        axis_scale_factor: scale of the axes labels relative
        plot_cbar: whether to plot cbar
        plot_grid: whether to draw gridlines on each subplot
        x_ticks: tick position for the x-axis
        y_ticks: tick position for the y-axis
        z_ticks: tick position for the z-axis
        subtitles: subtitles for the subplots (shape must match ``state.bdims``)
        figtitle: figure title
        gif: if True, render an animation over one batch axis instead of a
            tiled grid. Returns a ``matplotlib.animation.FuncAnimation``
            that auto-renders inline in Jupyter.
        gif_params: dict of options for the gif path. Recognized keys:
            ``save_path`` (default None) — if set, save the animation here
            via PillowWriter; ``interval_ms`` (default 200) — milliseconds
            per frame; ``ts`` (default None) — optional 1D array of
            timestamps matching the animation-axis length; when set, each
            frame's suptitle gets a ``t = …`` label;
            ``batch_animation_axis`` (default 0) — index into
            ``state.bdims`` selecting which axis becomes the animation/time
            axis (the remaining batch dims form the per-frame subplot grid).

    Returns:
        ``(axs, im)`` in the static case, or a ``FuncAnimation`` when
        ``gif=True``.
    """
    if pts_y is None:
        pts_y = pts_x
    pts_x = jnp.array(pts_x)
    pts_y = jnp.array(pts_y)

    if gif:
        return _plot_cf_gif(
            state=state,
            pts_x=pts_x,
            pts_y=pts_y,
            axs=axs,
            contour=contour,
            qp_type=qp_type,
            axis_scale_factor=axis_scale_factor,
            plot_cbar=plot_cbar,
            plot_grid=plot_grid,
            x_ticks=x_ticks,
            y_ticks=y_ticks,
            z_ticks=z_ticks,
            subtitles=subtitles,
            figtitle=figtitle,
            gif_params=gif_params or {},
        )

    bdims = state.bdims
    added_baxes = 0

    if subtitles is not None:
        if subtitles.shape != bdims:
            raise ValueError(
                f"labels must have same shape as bdims, "
                f"got shapes {subtitles.shape} and {bdims}"
            )

    if len(bdims) == 0:
        bdims = (1,)
        added_baxes += 1
    if len(bdims) == 1:
        bdims = (1, bdims[0])
        added_baxes += 1

    extra_dims = bdims[2:]
    if extra_dims != ():
        state = state.reshape_bdims(
            bdims[0] * int(jnp.prod(jnp.array(extra_dims))), bdims[1]
        )
        if subtitles is not None:
            subtitles = subtitles.reshape(
                bdims[0] * int(jnp.prod(jnp.array(extra_dims))), bdims[1]
            )
        bdims = state.bdims

    if axs is None:
        _, axs = plt.subplots(
            bdims[0],
            bdims[1]*2,
            figsize=(4 * bdims[1]*2, 3 * bdims[0]),
            dpi=200,
        )


    if qp_type == WIGNER:
        vmin = -1
        vmax = 1
        scale = 1
        cmap = "seismic"
        cbar_label = [r"$\mathcal{Re}(\chi_W(\alpha))$", r"$\mathcal{"
                                                         r"Im}(\chi_W("
                                                         r"\alpha))$"]
        QP = scale * cf_wigner(state, pts_x, pts_y)

    for _ in range(added_baxes):
        QP = jnp.array([QP])
        axs = np.array([axs])
        if subtitles is not None:
            subtitles = np.array([subtitles])

    if added_baxes==2:
        axs = axs[0] # When the input state is zero-dimensional, remove an
                     # axis that is automatically added due to the subcolumns


    pts_x = pts_x * axis_scale_factor
    pts_y = pts_y * axis_scale_factor

    x_ticks = (
        jnp.linspace(jnp.min(pts_x), jnp.max(pts_x),
                     5) if x_ticks is None else x_ticks
    )
    y_ticks = (
        jnp.linspace(jnp.min(pts_y), jnp.max(pts_y),
                     5) if y_ticks is None else y_ticks
    )
    z_ticks = jnp.linspace(vmin, vmax, 11) if z_ticks is None else z_ticks

    im = _render_cf_grid(
        axs,
        QP,
        pts_x,
        pts_y,
        contour=contour,
        cmap=cmap,
        vmin=vmin,
        vmax=vmax,
        x_ticks=x_ticks,
        y_ticks=y_ticks,
        z_ticks=z_ticks,
        cbar_label=cbar_label,
        plot_cbar=plot_cbar,
        plot_grid=plot_grid,
        subtitles=subtitles,
        decorate=True,
    )

    fig = axs[0, 0].get_figure()
    fig.tight_layout()
    if figtitle is not None:
        fig.suptitle(figtitle, y=1.04)
    return axs, im

plot_cf_wigner(state, pts_x, pts_y=None, axs=None, contour=True, cbar_label='', axis_scale_factor=1, plot_cbar=True, plot_grid=True, x_ticks=None, y_ticks=None, z_ticks=None, subtitles=None, figtitle=None, gif=False, gif_params=None)

Plot the Wigner characteristic function of the state.

Thin wrapper around :func:plot_cf with qp_type='wigner'. Each batch element is rendered as two subplots side-by-side: real then imaginary part of the characteristic function.

Parameters:

Name Type Description Default
state

state with arbitrary number of batch dimensions, result will be flattened to a 2d grid to allow for plotting

required
pts_x

x points to evaluate the characteristic function at

required
pts_y

y points to evaluate the characteristic function at

None
axs

matplotlib axes to plot on

None
contour

make the plot use contouring

True
cbar_label

label for the cbar

''
axis_scale_factor

scale of the axes labels relative

1
plot_cbar

whether to plot cbar

True
plot_grid

whether to draw gridlines on each subplot

True
x_ticks

tick position for the x-axis

None
y_ticks

tick position for the y-axis

None
z_ticks

tick position for the z-axis

None
subtitles

subtitles for the subplots

None
figtitle

figure title

None
gif

if True, render an animation over one batch axis instead of a tiled subplot grid. See :func:plot_cf for details.

False
gif_params

dict of options for the gif path. Recognized keys: save_path (default None), interval_ms (default 200), ts (default None — adds a t = … label per frame), batch_animation_axis (default 0).

None

Returns:

Type Description

(axs, im) in the static case, or a matplotlib.animation.FuncAnimation

when gif=True.

Source code in jaxquantum/core/visualization.py
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
def plot_cf_wigner(
    state,
    pts_x,
    pts_y=None,
    axs=None,
    contour=True,
    cbar_label="",
    axis_scale_factor=1,
    plot_cbar=True,
    plot_grid=True,
    x_ticks=None,
    y_ticks=None,
    z_ticks=None,
    subtitles=None,
    figtitle=None,
    gif=False,
    gif_params=None,
):
    """Plot the Wigner characteristic function of the state.

    Thin wrapper around :func:`plot_cf` with ``qp_type='wigner'``. Each batch
    element is rendered as two subplots side-by-side: real then imaginary
    part of the characteristic function.

    Args:
        state: state with arbitrary number of batch dimensions, result will
            be flattened to a 2d grid to allow for plotting
        pts_x: x points to evaluate the characteristic function at
        pts_y: y points to evaluate the characteristic function at
        axs: matplotlib axes to plot on
        contour: make the plot use contouring
        cbar_label: label for the cbar
        axis_scale_factor: scale of the axes labels relative
        plot_cbar: whether to plot cbar
        plot_grid: whether to draw gridlines on each subplot
        x_ticks: tick position for the x-axis
        y_ticks: tick position for the y-axis
        z_ticks: tick position for the z-axis
        subtitles: subtitles for the subplots
        figtitle: figure title
        gif: if True, render an animation over one batch axis instead of a
            tiled subplot grid. See :func:`plot_cf` for details.
        gif_params: dict of options for the gif path. Recognized keys:
            ``save_path`` (default None), ``interval_ms`` (default 200),
            ``ts`` (default None — adds a ``t = …`` label per frame),
            ``batch_animation_axis`` (default 0).

    Returns:
        ``(axs, im)`` in the static case, or a ``matplotlib.animation.FuncAnimation``
        when ``gif=True``.
    """
    return plot_cf(
        state=state,
        pts_x=pts_x,
        pts_y=pts_y,
        axs=axs,
        contour=contour,
        qp_type=WIGNER,
        cbar_label=cbar_label,
        axis_scale_factor=axis_scale_factor,
        plot_cbar=plot_cbar,
        plot_grid=plot_grid,
        x_ticks=x_ticks,
        y_ticks=y_ticks,
        z_ticks=z_ticks,
        subtitles=subtitles,
        figtitle=figtitle,
        gif=gif,
        gif_params=gif_params,
    )

plot_qfunc(state, pts_x, pts_y=None, g=2, axs=None, contour=True, cbar_label='', axis_scale_factor=1, plot_cbar=True, x_ticks=None, y_ticks=None, z_ticks=None, subtitles=None, figtitle=None, gif=False, gif_params=None)

Plot the husimi (Q) function of the state.

Thin wrapper around :func:plot_qp with qp_type='husimi'.

Parameters:

Name Type Description Default
state

state with arbitrary number of batch dimensions, result will be flattened to a 2d grid to allow for plotting

required
pts_x

x points to evaluate quasi-probability distribution at

required
pts_y

y points to evaluate quasi-probability distribution at

None
g

float, default 2. Scaling factor for a = 0.5 * g * (x + iy). The value of g is related to the value of :math:\hbar in the commutation relation :math:[x,\,y] = i\hbar via :math:\hbar=2/g^2.

2
axs

matplotlib axes to plot on

None
contour

make the plot use contouring

True
cbar_label

label for the cbar

''
axis_scale_factor

scale of the axes labels relative

1
plot_cbar

whether to plot cbar

True
x_ticks

tick position for the x-axis

None
y_ticks

tick position for the y-axis

None
z_ticks

tick position for the z-axis

None
subtitles

subtitles for the subplots

None
figtitle

figure title

None
gif

if True, render an animation over one batch axis instead of a tiled subplot grid. See :func:plot_qp for details.

False
gif_params

dict of options for the gif path. Recognized keys: save_path (default None), interval_ms (default 200), ts (default None — adds a t = … label per frame), batch_animation_axis (default 0).

None

Returns:

Type Description

(axs, im) in the static case, or a matplotlib.animation.FuncAnimation

when gif=True.

Source code in jaxquantum/core/visualization.py
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
def plot_qfunc(
    state,
    pts_x,
    pts_y=None,
    g=2,
    axs=None,
    contour=True,
    cbar_label="",
    axis_scale_factor=1,
    plot_cbar=True,
    x_ticks=None,
    y_ticks=None,
    z_ticks=None,
    subtitles=None,
    figtitle=None,
    gif=False,
    gif_params=None,
):
    """Plot the husimi (Q) function of the state.

    Thin wrapper around :func:`plot_qp` with ``qp_type='husimi'``.

    Args:
        state: state with arbitrary number of batch dimensions, result will
            be flattened to a 2d grid to allow for plotting
        pts_x: x points to evaluate quasi-probability distribution at
        pts_y: y points to evaluate quasi-probability distribution at
        g: float, default 2. Scaling factor for ``a = 0.5 * g * (x + iy)``.
            The value of ``g`` is related to the value of :math:`\\hbar` in
            the commutation relation :math:`[x,\,y] = i\\hbar` via
            :math:`\\hbar=2/g^2`.
        axs: matplotlib axes to plot on
        contour: make the plot use contouring
        cbar_label: label for the cbar
        axis_scale_factor: scale of the axes labels relative
        plot_cbar: whether to plot cbar
        x_ticks: tick position for the x-axis
        y_ticks: tick position for the y-axis
        z_ticks: tick position for the z-axis
        subtitles: subtitles for the subplots
        figtitle: figure title
        gif: if True, render an animation over one batch axis instead of a
            tiled subplot grid. See :func:`plot_qp` for details.
        gif_params: dict of options for the gif path. Recognized keys:
            ``save_path`` (default None), ``interval_ms`` (default 200),
            ``ts`` (default None — adds a ``t = …`` label per frame),
            ``batch_animation_axis`` (default 0).

    Returns:
        ``(axs, im)`` in the static case, or a ``matplotlib.animation.FuncAnimation``
        when ``gif=True``.
    """
    return plot_qp(
        state=state,
        pts_x=pts_x,
        pts_y=pts_y,
        g=g,
        axs=axs,
        contour=contour,
        qp_type=HUSIMI,
        cbar_label=cbar_label,
        axis_scale_factor=axis_scale_factor,
        plot_cbar=plot_cbar,
        x_ticks=x_ticks,
        y_ticks=y_ticks,
        z_ticks=z_ticks,
        subtitles=subtitles,
        figtitle=figtitle,
        gif=gif,
        gif_params=gif_params,
    )

plot_qp(state, pts_x, pts_y=None, g=2, axs=None, contour=True, qp_type=WIGNER, cbar_label='', axis_scale_factor=1, plot_cbar=True, x_ticks=None, y_ticks=None, z_ticks=None, subtitles=None, figtitle=None, gif=False, gif_params=None)

Plot a quasi-probability distribution (Wigner or Husimi-Q).

The state may carry an arbitrary number of batch dimensions; they are flattened to a 2D (rows, cols) grid of subplots. With gif=True, one batch axis is animated instead and the remaining batch dims form the per-frame subplot grid.

Parameters:

Name Type Description Default
state

state with arbitrary number of batch dimensions; result will be flattened to a 2d grid to allow for plotting

required
pts_x

x points to evaluate the quasi-probability distribution at

required
pts_y

y points to evaluate the quasi-probability distribution at; defaults to pts_x

None
g

float, default 2. Scaling factor for a = 0.5 * g * (x + iy). The value of g is related to the value of :math:\hbar in the commutation relation :math:[x,\,y] = i\hbar via :math:\hbar=2/g^2.

2
axs

matplotlib axes to plot on (created if None)

None
contour

use contourf if True, otherwise pcolormesh

True
qp_type

type of quasi-probability distribution ("wigner" or "husimi")

WIGNER
cbar_label

label for the cbar (overridden internally based on qp_type)

''
axis_scale_factor

multiplicative scale applied to the axis tick positions and labels

1
plot_cbar

whether to draw a colorbar on each subplot

True
x_ticks

tick positions for the x-axis (auto if None)

None
y_ticks

tick positions for the y-axis (auto if None)

None
z_ticks

tick positions for the colorbar (auto if None)

None
subtitles

subtitles for the subplots; shape must match state.bdims (or the per-frame batch dims when gif=True)

None
figtitle

figure title

None
gif

if True, render an animation over one batch axis instead of a tiled subplot grid. Returns a matplotlib.animation.FuncAnimation that auto-renders inline in Jupyter (its _repr_html_ is patched to to_jshtml).

False
gif_params

dict of options for the gif path (ignored if gif=False). Recognized keys:

  • save_path (default None) — if set, save the animation to this path via matplotlib.animation.PillowWriter.
  • interval_ms (default 200) — milliseconds per frame; also derives fps = round(1000 / interval_ms) for the writer.
  • ts (default None) — optional 1D array of timestamps matching the animation-axis length; when set, each frame's suptitle gets a t = … label.
  • batch_animation_axis (default 0) — index into state.bdims selecting which axis becomes the animation axis. The remaining batch dims form the per-frame subplot grid.
None

Returns:

Type Description

(axs, im) in the static case, or a FuncAnimation when

gif=True.

Source code in jaxquantum/core/visualization.py
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
def plot_qp(
    state,
    pts_x,
    pts_y=None,
    g=2,
    axs=None,
    contour=True,
    qp_type=WIGNER,
    cbar_label="",
    axis_scale_factor=1,
    plot_cbar=True,
    x_ticks=None,
    y_ticks=None,
    z_ticks=None,
    subtitles=None,
    figtitle=None,
    gif=False,
    gif_params=None,
):
    """Plot a quasi-probability distribution (Wigner or Husimi-Q).

    The state may carry an arbitrary number of batch dimensions; they are
    flattened to a 2D ``(rows, cols)`` grid of subplots. With ``gif=True``,
    one batch axis is animated instead and the remaining batch dims form
    the per-frame subplot grid.

    Args:
        state: state with arbitrary number of batch dimensions; result will
            be flattened to a 2d grid to allow for plotting
        pts_x: x points to evaluate the quasi-probability distribution at
        pts_y: y points to evaluate the quasi-probability distribution at;
            defaults to ``pts_x``
        g: float, default 2. Scaling factor for ``a = 0.5 * g * (x + iy)``.
            The value of ``g`` is related to the value of :math:`\\hbar` in
            the commutation relation :math:`[x,\,y] = i\\hbar` via
            :math:`\\hbar=2/g^2`.
        axs: matplotlib axes to plot on (created if None)
        contour: use ``contourf`` if True, otherwise ``pcolormesh``
        qp_type: type of quasi-probability distribution
            (``"wigner"`` or ``"husimi"``)
        cbar_label: label for the cbar (overridden internally based on
            ``qp_type``)
        axis_scale_factor: multiplicative scale applied to the axis tick
            positions and labels
        plot_cbar: whether to draw a colorbar on each subplot
        x_ticks: tick positions for the x-axis (auto if None)
        y_ticks: tick positions for the y-axis (auto if None)
        z_ticks: tick positions for the colorbar (auto if None)
        subtitles: subtitles for the subplots; shape must match
            ``state.bdims`` (or the per-frame batch dims when ``gif=True``)
        figtitle: figure title
        gif: if True, render an animation over one batch axis instead of a
            tiled subplot grid. Returns a
            ``matplotlib.animation.FuncAnimation`` that auto-renders inline
            in Jupyter (its ``_repr_html_`` is patched to ``to_jshtml``).
        gif_params: dict of options for the gif path (ignored if
            ``gif=False``). Recognized keys:

            - ``save_path`` (default ``None``) — if set, save the animation
              to this path via ``matplotlib.animation.PillowWriter``.
            - ``interval_ms`` (default ``200``) — milliseconds per frame;
              also derives ``fps = round(1000 / interval_ms)`` for the writer.
            - ``ts`` (default ``None``) — optional 1D array of timestamps
              matching the animation-axis length; when set, each frame's
              suptitle gets a ``t = …`` label.
            - ``batch_animation_axis`` (default ``0``) — index into
              ``state.bdims`` selecting which axis becomes the animation
              axis. The remaining batch dims form the per-frame subplot grid.

    Returns:
        ``(axs, im)`` in the static case, or a ``FuncAnimation`` when
        ``gif=True``.
    """
    if pts_y is None:
        pts_y = pts_x
    pts_x = jnp.array(pts_x)
    pts_y = jnp.array(pts_y)

    if len(state.bdims)==1 and state.bdims[0]==1:
        state = state[0]

    if gif:
        return _plot_qp_gif(
            state=state,
            pts_x=pts_x,
            pts_y=pts_y,
            g=g,
            axs=axs,
            contour=contour,
            qp_type=qp_type,
            axis_scale_factor=axis_scale_factor,
            plot_cbar=plot_cbar,
            x_ticks=x_ticks,
            y_ticks=y_ticks,
            z_ticks=z_ticks,
            subtitles=subtitles,
            figtitle=figtitle,
            gif_params=gif_params or {},
        )

    bdims = state.bdims
    added_baxes = 0

    if subtitles is not None:
        if subtitles.shape != bdims:
            raise ValueError(
                f"labels must have same shape as bdims, "
                f"got shapes {subtitles.shape} and {bdims}"
            )

    if len(bdims) == 0:
        bdims = (1,)
        added_baxes += 1
    if len(bdims) == 1:
        bdims = (1, bdims[0])
        added_baxes += 1

    extra_dims = bdims[2:]
    if extra_dims != ():
        state = state.reshape_bdims(
            bdims[0] * int(jnp.prod(jnp.array(extra_dims))), bdims[1]
        )
        if subtitles is not None:
            subtitles = subtitles.reshape(
                bdims[0] * int(jnp.prod(jnp.array(extra_dims))), bdims[1]
            )
        bdims = state.bdims

    if axs is None:
        _, axs = plt.subplots(
            bdims[0],
            bdims[1],
            figsize=(4 * bdims[1], 3 * bdims[0]),
            dpi=200,
        )

    if qp_type == WIGNER:
        vmin = -1
        vmax = 1
        scale = np.pi / 2
        cmap = "seismic"
        cbar_label = r"$\mathcal{W}(\alpha)$"
        QP = scale * wigner(state, pts_x, pts_y, g=g)

    elif qp_type == HUSIMI:
        vmin = 0
        vmax = 1
        scale = np.pi
        cmap = "jet"
        cbar_label = r"$\mathcal{Q}(\alpha)$"
        QP = scale * qfunc(state, pts_x, pts_y, g=g)



    for _ in range(added_baxes):
        QP = jnp.array([QP])
        axs = np.array([axs])
        if subtitles is not None:
            subtitles = np.array([subtitles])




    pts_x = pts_x * axis_scale_factor
    pts_y = pts_y * axis_scale_factor

    x_ticks = (
        jnp.linspace(jnp.min(pts_x), jnp.max(pts_x), 5) if x_ticks is None else x_ticks
    )
    y_ticks = (
        jnp.linspace(jnp.min(pts_y), jnp.max(pts_y), 5) if y_ticks is None else y_ticks
    )
    z_ticks = jnp.linspace(vmin, vmax, 3) if z_ticks is None else z_ticks

    im = _render_qp_grid(
        axs,
        QP,
        pts_x,
        pts_y,
        contour=contour,
        cmap=cmap,
        vmin=vmin,
        vmax=vmax,
        x_ticks=x_ticks,
        y_ticks=y_ticks,
        z_ticks=z_ticks,
        cbar_label=cbar_label,
        plot_cbar=plot_cbar,
        subtitles=subtitles,
        decorate=True,
    )

    fig = axs[bdims[0] - 1, bdims[1] - 1].get_figure()
    fig.tight_layout()
    if figtitle is not None:
        fig.suptitle(figtitle, y=1.04)
    return axs, im

plot_wigner(state, pts_x, pts_y=None, g=2, axs=None, contour=True, cbar_label='', axis_scale_factor=1, plot_cbar=True, x_ticks=None, y_ticks=None, z_ticks=None, subtitles=None, figtitle=None, gif=False, gif_params=None)

Plot the wigner function of the state.

Thin wrapper around :func:plot_qp with qp_type='wigner'.

Parameters:

Name Type Description Default
state

state with arbitrary number of batch dimensions, result will be flattened to a 2d grid to allow for plotting

required
pts_x

x points to evaluate quasi-probability distribution at

required
pts_y

y points to evaluate quasi-probability distribution at

None
g

float, default 2. Scaling factor for a = 0.5 * g * (x + iy). The value of g is related to the value of :math:\hbar in the commutation relation :math:[x,\,y] = i\hbar via :math:\hbar=2/g^2.

2
axs

matplotlib axes to plot on

None
contour

make the plot use contouring

True
cbar_label

label for the cbar

''
axis_scale_factor

scale of the axes labels relative

1
plot_cbar

whether to plot cbar

True
x_ticks

tick position for the x-axis

None
y_ticks

tick position for the y-axis

None
z_ticks

tick position for the z-axis

None
subtitles

subtitles for the subplots

None
figtitle

figure title

None
gif

if True, render an animation over one batch axis instead of a tiled subplot grid. See :func:plot_qp for details.

False
gif_params

dict of options for the gif path. Recognized keys: save_path (default None), interval_ms (default 200), ts (default None — adds a t = … label per frame), batch_animation_axis (default 0).

None

Returns:

Type Description

(axs, im) in the static case, or a matplotlib.animation.FuncAnimation

when gif=True.

Source code in jaxquantum/core/visualization.py
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
def plot_wigner(
    state,
    pts_x,
    pts_y=None,
    g=2,
    axs=None,
    contour=True,
    cbar_label="",
    axis_scale_factor=1,
    plot_cbar=True,
    x_ticks=None,
    y_ticks=None,
    z_ticks=None,
    subtitles=None,
    figtitle=None,
    gif=False,
    gif_params=None,
):
    """Plot the wigner function of the state.

    Thin wrapper around :func:`plot_qp` with ``qp_type='wigner'``.

    Args:
        state: state with arbitrary number of batch dimensions, result will
            be flattened to a 2d grid to allow for plotting
        pts_x: x points to evaluate quasi-probability distribution at
        pts_y: y points to evaluate quasi-probability distribution at
        g: float, default 2. Scaling factor for ``a = 0.5 * g * (x + iy)``.
            The value of ``g`` is related to the value of :math:`\\hbar` in
            the commutation relation :math:`[x,\,y] = i\\hbar` via
            :math:`\\hbar=2/g^2`.
        axs: matplotlib axes to plot on
        contour: make the plot use contouring
        cbar_label: label for the cbar
        axis_scale_factor: scale of the axes labels relative
        plot_cbar: whether to plot cbar
        x_ticks: tick position for the x-axis
        y_ticks: tick position for the y-axis
        z_ticks: tick position for the z-axis
        subtitles: subtitles for the subplots
        figtitle: figure title
        gif: if True, render an animation over one batch axis instead of a
            tiled subplot grid. See :func:`plot_qp` for details.
        gif_params: dict of options for the gif path. Recognized keys:
            ``save_path`` (default None), ``interval_ms`` (default 200),
            ``ts`` (default None — adds a ``t = …`` label per frame),
            ``batch_animation_axis`` (default 0).

    Returns:
        ``(axs, im)`` in the static case, or a ``matplotlib.animation.FuncAnimation``
        when ``gif=True``.
    """
    return plot_qp(
        state=state,
        pts_x=pts_x,
        pts_y=pts_y,
        g=g,
        axs=axs,
        contour=contour,
        qp_type=WIGNER,
        cbar_label=cbar_label,
        axis_scale_factor=axis_scale_factor,
        plot_cbar=plot_cbar,
        x_ticks=x_ticks,
        y_ticks=y_ticks,
        z_ticks=z_ticks,
        subtitles=subtitles,
        figtitle=figtitle,
        gif=gif,
        gif_params=gif_params,
    )