-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquditvis.py
59 lines (43 loc) · 1.74 KB
/
quditvis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import qutip as q
from qutip import spin_q_function
from qutip import Qobj
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm, colors
import matplotlib.pyplot as plt
import numpy as np
def plot_qudit_wigner(state, qudit_dim=None, azim=None, elev=None, resolution=500, cmap=None):
"""
Plot Qudit state from Wigner
This function takes a state and maps the Husimi Q function of saif state onto a sphere.
This helps to visualize the quantum state.
Paramerters:
state: numpy array of the state vector
qudit_num: Dimensionality of the qudit, used for plotting only
azim: azimuthal angle of the plotting view
elev: elevation angle of the plotting view
resolution: define resolution of plottted qudit sphere
cmap: used colormap
Returns:
figure
"""
if cmap == None:
cmap = cm.coolwarm
thetas = np.linspace(0, np.pi, resolution)
phis = np.linspace(0, 2*np.pi, resolution)
density, _, _ = spin_q_function(Qobj(state), thetas, phis)
thetam, phim = np.meshgrid(thetas,phis)
x = np.sin(thetam) * np.cos(phim)
y = np.sin(thetam) * np.sin(phim)
z = np.cos(thetam)
fig = plt.figure(figsize=(15, 11))
ax = fig.add_subplot(111, projection='3d')
norm=colors.Normalize(vmin = np.min(density),
vmax = np.max(density), clip = False)
ax.plot_surface(x, y, z, rstride=1, cstride=1, cmap=cm.coolwarm,
linewidth=0, antialiased=False,
facecolors=cmap(norm(density)))
if qudit_dim:
ax.text(0, 0, -1.3, rf"$|{0}\rangle$")
ax.text(0, 0, 1.2, rf"$|{qudit_num}\rangle$")
ax.view_init(azim, elev)
return fig