def plot_husimi_data(rho, title=""): """ """ # params = {# 'backend': 'ps', # 'axes.labelsize': 6, # 'font.size': 6, # 'xtick.labelsize': 6, # 'ytick.labelsize': 6, # 'axes.labelpad': 1, # 'text.usetex': False, # 'figure.figsize': fig_size} # plt.rcParams.update(params) # rho_tf = dm_to_tf([rho]) # data = batched_expect(ops_batch_husimi, rho_tf) # x = data.numpy().reshape((len(xvec), len(xvec))) xvec = np.linspace(-5, 5, 32) yvec = np.linspace(-5, 5, 32) x = qfunc(rho, xvec * np.sqrt(2), yvec * np.sqrt(2)) fig, ax = plt.subplots(1, 1, figsize=(fig_width / 3.5, fig_width / 3.5)) im = ax.pcolor(xvec, yvec, x / np.max(x), cmap="hot", vmin=0., vmax=1) ax.set_aspect("equal") ax.set_yticks([-5, 0, 5]) ax.set_xlabel(r"Re$(\beta)$", labelpad=0) ax.set_ylabel(r"Im$(\beta)$", labelpad=-5) cbar = plt.colorbar(im, fraction=0.0455, ticks=[0, 0.5, 1]) cbar.ax.set_yticklabels(["0", "0.5", "1"]) ax.set_title(title, y=0.93) cbar.solids.set_edgecolor("face") return fig, ax
def test_qfunc_dm(): "Husimi Q: Compare with/without precomputation for rand. dm" N = 20 xvec = np.linspace(-10, 10, 128) for _ in range(3): rho = rand_dm(N) precomp = qfunc_precompute(xvec, xvec, N) q_default = qfunc(rho, xvec, xvec, precompute=None) q_false = qfunc(rho, xvec, xvec, precompute=False) q_true = qfunc(rho, xvec, xvec, precompute=True) q_precomp = qfunc(rho, xvec, xvec, precompute=precomp) assert_equal(q_true, q_default) # Default: precompute assert_equal(q_true, q_precomp) # Compare precomputing before/during the call assert_equal(np.sum(np.abs(q_true - q_false)) < 1e-7, True) # Compare with/without
def update(self, rho): self.data = qfunc(rho, self.xvecs[0], self.xvecs[1])