File:Wigner quasiprobability distribution of superpositioned squeezed states, varying purity.webm
The media handler extension for this file format is missing. Advanced media features may not work unless the file is viewed at Wikimedia Commons.

Size of this preview: 600 × 600 pixels. Other resolutions: 240 × 240 pixels | 480 × 480 pixels | 768 × 768 pixels | 1,024 × 1,024 pixels | 1,600 × 1,600 pixels.
Original file (file size: 1.19 MB, MIME type: video/webm)
![]() | This is a file from the Wikimedia Commons. Information from its description page there is shown below. Commons is a freely licensed media file repository. You can help. |
Summary
DescriptionWigner quasiprobability distribution of superpositioned squeezed states, varying purity.webm |
English: Wigner quasiprobability distribution of superpositioned squeezed states, with varying purity, from totally pure to totally mixed.
Matplotlib codeimport matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
from IPython.display import display
from qutip import (about, basis, coherent, coherent_dm, displace, fock, ket2dm,
plot_wigner, squeeze, thermal_dm, wigner_cmap, wigner)
import scipy.ndimage
import os
from tqdm import tqdm
def rotate_and_crop(array, angle, xvec, yvec):
rotated_array = scipy.ndimage.rotate(array, -angle, reshape=False)
rows, cols = rotated_array.shape
center_row, center_col = rows // 2, cols // 2
target_rows, target_cols = len(yvec), len(xvec)
start_row = center_row - target_rows // 2
end_row = start_row + target_rows
start_col = center_col - target_cols // 2
end_col = start_col + target_cols
return rotated_array[start_row:end_row, start_col:end_col]
def plot_wigner_marginals(W, xvec, yvec, marginal_max, resolution=200, angle=0):
wmap = wigner_cmap(W)
wlim = np.abs(W).max()
cmap = plt.colormaps['RdBu']
fig = plt.figure()
n, m = 5, 1
fig, axes = plt.subplot_mosaic(
[ ["top"] * n + ["3d"] * m ] * m + [ ["mid"] * n + ["right"] * m] * n,
figsize=(20, 20),
layout="constrained",
width_ratios=[1.05] * (n+m))
ax = axes["mid"]
norm = mpl.colors.Normalize(-wlim, wlim)
ax.contourf(xvec, yvec, W, resolution // 3, norm=norm, cmap=cmap)
ax = axes["top"]
x_marginal = np.sum(W, axis=0)
y_marginal = np.sum(W, axis=1)
ax.fill_between(xvec, x_marginal, 0, color='#938fba', alpha=0.5)
ax.plot(xvec, x_marginal, color='#4a5a90')
ax.set_xlim(min(xvec), max(xvec))
ax.set_ylim(0, marginal_max * 1.05)
ax.set_xticks([])
ax.set_yticks([])
ax = axes["right"]
ax.fill_betweenx(yvec, np.sum(W, axis=1), 0, color='#938fba', alpha=0.5)
ax.plot(y_marginal, yvec, color='#4a5a90')
ax.set_xlim(0, marginal_max * 1.05)
ax.set_ylim(min(yvec), max(yvec))
ax.set_xticks([])
ax.set_yticks([])
ax = axes["3d"]
ax.axis('off')
return fig
def plot_wigner_with_marginals(psi, **kwargs):
radius = kwargs.get('radius', 5)
resolution = kwargs.get('resolution', 500)
angles = kwargs.get('angles', np.linspace(0, 2*np.pi, 100))
dir_path = kwargs.get('dir_path', './output')
xvec_upscaled = np.linspace(-radius*1.5, radius*1.5, int(resolution*1.5))
yvec_upscaled = np.linspace(-radius*1.5, radius*1.5, int(resolution*1.5))
xvec = np.linspace(-radius, radius, int(resolution))
yvec = np.linspace(-radius, radius, int(resolution))
W_upscaled = wigner(psi, xvec_upscaled, yvec_upscaled)
temp = rotate_and_crop(W_upscaled, 45, xvec, yvec) # This one needs to be rotated 45 degrees to find its maxima.
marginal_max = max(max(np.sum(temp, axis=0)), max(np.sum(temp, axis=1)))
print(f"outputting to {dir_path}")
for N, angle in tqdm(enumerate(angles)):
W = rotate_and_crop(W_upscaled, angle, xvec, yvec)
fig = plot_wigner_marginals(W, xvec, yvec, marginal_max=marginal_max, resolution=resolution, angle=angle)
if not os.path.exists(dir_path):
os.makedirs(dir_path)
fig.savefig(f"{dir_path}/{N:03d}.png",bbox_inches='tight')
plt.close(fig)
mpl.use('agg')
configs = {
"N_dim" : 40,
"radius" : 3.5,
"resolution" : 500,
"angles" : [i for i in range(90)],
"dir_path" : ""
}
N = configs["N_dim"]
dm_pure = ket2dm((squeeze(N, 0.75j) * basis(N, 0) - squeeze(N, -0.75j) * basis(N, 0)))
dm_mixed = (
ket2dm(squeeze(N, 0.75j) * basis(N, 0)) +
ket2dm(squeeze(N, -0.75j) * basis(N, 0))
)
for ratio in [0.0001, 0.5, 0.7, 0.9999]:
psi = (dm_pure * (1-ratio) + dm_mixed * ratio).unit()
configs["dir_path"] = f"./squeezed_mixture/squeezed_mixture_{ratio:.1f}"
plot_wigner_with_marginals(psi, **configs)
Sh codefor dir in ./*/; do
# Extract folder name
folder_name=$(basename "$dir")
# Create output path
output_path="./${folder_name}.webm"
# Convert images to webm
echo $output_path
ffmpeg -y -framerate 24 -i "$dir"%03d.png -c:v libvpx-vp9 -b:v 0 -crf 30 -pix_fmt yuva420p "$output_path"
done
ffmpeg -y \
-i ./squeezed_mixture_0.0.webm \
-i ./squeezed_mixture_0.5.webm \
-i ./squeezed_mixture_0.7.webm \
-i ./squeezed_mixture_1.0.webm \
-filter_complex "
[0:v]scale=800:800[v0];
[1:v]scale=800:800[v1];
[2:v]scale=800:800[v2];
[3:v]scale=800:800[v3];
[v0][v1]hstack=inputs=2[row0];
[v2][v3]hstack=inputs=2[row1];
[row0][row1]vstack=inputs=2[out]
" \
-map "[out]" \
-c:v libvpx-vp9 -b:v 0 -crf 30 -pix_fmt yuva420p \
output_grid.webm
ffmpeg -y -stream_loop 4 -i output_grid.webm -c copy output_grid_2.webm
|
Date | |
Source | Own work |
Author | Cosmia Nebula |
Licensing
I, the copyright holder of this work, hereby publish it under the following license:



This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license.
- You are free:
- to share – to copy, distribute and transmit the work
- to remix – to adapt the work
- Under the following conditions:
- attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
- share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.
Captions
Add a one-line explanation of what this file represents
Items portrayed in this file
depicts
some value
30 August 2024
video/webm
File history
Click on a date/time to view the file as it appeared at that time.
Date/Time | Thumbnail | Dimensions | User | Comment | |
---|---|---|---|---|---|
current | 06:28, 31 August 2024 | ![]() | (1.19 MB) | wikimediacommons>Cosmia Nebula | Uploaded while editing "Wigner quasiprobability distribution" on en.wikipedia.org |
File usage
There are no pages that use this file.