<jupyter_start><jupyter_text>CGAN<jupyter_code>fig, ax = plot_shaded_fidelities(fdict['fidelities-gan_l1_0'], x=x, color=color_dict['fidelities-gan_l1_0'],
                                label=labels['fidelities-gan_l1_0'])

for key in ['fidelities-gan_l1_1', 'fidelities-gan_l1_10', 'fidelities-gan_l1_100']:
    fig, ax = plot_shaded_fidelities(fdict[key], x=x, fig=fig, ax=ax, color=color_dict[key], label=labels[key])
    
plt.legend(frameon=False)
plt.title("QST-CGAN + L1 loss")
plt.show()
# plt.savefig(figpath+"fig-12-gan-cat.pdf", bbox_inches = "tight", pad_inches=0)
bmat = loadmat("data/cat-2-0-0/matlab-data/cat_reconstructed.mat")
pgd_fidelities = bmat['fmatrix']
key = 'fidelities-imle'

fig, ax = plot_shaded_fidelities(fdict[key], x=x, color=color_dict[key], label=labels[key])
ax.semilogx(x, np.mean(pgd_fidelities, 0), "--", color="black", label="APG-MLE")
plt.title("MLE")
plt.legend(loc="lower left")
plt.show()
# plt.savefig(figpath+"fig-12-imle-apg-cat.pdf", bbox_inches = "tight", pad_inches=0)<jupyter_output>/Users/shahnawaz/Dropbox/phd/tomography/manuscript/code/qst-nn/qst_nn/utils.py:599: RuntimeWarning: Mean of empty slice
  return np.nanmean(arr, axis=0), np.nanstd(arr, axis=0)
/Users/shahnawaz/miniconda3/envs/qst-nn/lib/python3.9/site-packages/numpy/lib/nanfunctions.py:1664: RuntimeWarning: Degrees of freedom <= 0 for slice.
  var = nanvar(a, axis=axis, dtype=dtype, out=out, ddof=ddof,<jupyter_text>Show the state<jupyter_code>hilbert_size = 32


# Betas can be selected in a grid or randomly in a circle
num_grid = 32
num_points = num_grid*num_grid
beta_max_x = 5
beta_max_y = 5

xvec = np.linspace(-beta_max_x, beta_max_x, num_grid)
yvec = np.linspace(-beta_max_y, beta_max_y, num_grid)

X, Y = np.meshgrid(xvec, yvec)
betas = (X + 1j*Y).ravel()

# betas = [random_alpha(5) for i in range(num_grid*num_grid)]
psi = coherent(32, 2) + coherent(32, -2)
psi = psi.unit()
rho = psi*psi.dag()

x = qfunc(rho, xvec, yvec, g=2)

fig, ax = plt.subplots(1, 1, figsize=(2*fig_width/5, 2*fig_width/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=-8)
cbar = plt.colorbar(im, fraction=0.046, ticks=[0, 0.5, 1])
cbar.ax.set_yticklabels(["0", "0.5", "1"])

# plt.savefig(figpath+"fig-12-cat-data.pdf", bbox_inches = "tight", pad_inches=0)
plt.show()
def psi_cat(hilbert_size, alpha=None, S=None, mu=None):
    """
    Generates a cat state. For a detailed discussion on the definition
    see `<NAME>. et al. “Performance and Structure of Single-Mode Bosonic Codes.” Physical Review A 97.3 (2018) <https://arxiv.org/abs/1708.05010>`_
    and `<NAME> et al., “Classification and reconstruction of quantum states with neural networks.” Journal <https://arxiv.org/abs/1708.05010>`_
    
    Args:
    -----
        N (int): Hilbert size dimension.
        alpha (complex64): Complex number determining the amplitude.
        S (int): An integer >= 0 determining the number of coherent states used
                 to generate the cat superposition. S = {0, 1, 2, ...}.
                 corresponds to {2, 4, 6, ...} coherent state superpositions.
        mu (int): An integer 0/1 which generates the logical 0/1 encoding of 
                  a computational state for the cat state.


    Returns:
    -------
        cat (:class:`qutip.Qobj`): Cat state density matrix
    """
    if alpha == None:
        alpha = random_alpha(2, 3)

    if S == None:
        S = np.random.randint(0, 3)

    if mu is None:
        mu = np.random.randint(0, 2)

    kend = 2 * S + 1
    cstates = 0 * (coherent(hilbert_size, 0))

    for k in range(0, int((kend + 1) / 2)):
        sign = 1

        if k >= S:
            sign = (-1) ** int(mu > 0.5)

        prefactor = np.exp(1j * (np.pi / (S + 1)) * k)

        cstates += sign * coherent(hilbert_size, prefactor * alpha * (-((1j) ** mu)))
        cstates += sign * coherent(hilbert_size, -prefactor * alpha * (-((1j) ** mu)))

    return cstates.unit()

a = destroy(hilbert_size)
psi = psi_cat(hilbert_size, alpha=2, S=0, mu=0)
psi2 = a*psi

rho_2 = psi2*psi2.dag()
rho_2 = rho_2.unit()
rho2 = a*rho*a.dag()
rho2 = rho2.unit()
plot_wigner_fock_distribution(rho2)
hilbert_size = 32


# Betas can be selected in a grid or randomly in a circle
num_grid = 32
num_points = num_grid*num_grid
beta_max_x = 5
beta_max_y = 5

xvec = np.linspace(-beta_max_x, beta_max_x, num_grid)
yvec = np.linspace(-beta_max_y, beta_max_y, num_grid)

x = qfunc(rho_2/rho_2.tr(), xvec, yvec, g=2)

fig, ax = plt.subplots(1, 1, figsize=(2*fig_width/5, 2*fig_width/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=-8)
cbar = plt.colorbar(im, fraction=0.046, ticks=[0, 0.5, 1])
cbar.ax.set_yticklabels(["0", "0.5", "1"])

# plt.savefig(figpath+"fig-12-cat-orthogonal-data.pdf", bbox_inches = "tight", pad_inches=0)
plt.show()<jupyter_output>/var/folders/8s/tfpsk_fx609f8w7z__yzz9vh0000gn/T/ipykernel_29328/2910761354.py:16: MatplotlibDeprecationWarning: shading='flat' when X and Y have the same dimensions as C is deprecated since 3.3.  Either specify the corners of the quadrilaterals with X and Y, or pass shading='auto', 'nearest' or 'gouraud', or set rcParams['pcolor.shading'].  This will become an error two minor releases later.
  im = ax.pcolor(xvec, yvec, x/np.max(x), cmap="hot", vmin=0, vmax=1)
{'fraction_non_alphanumeric': 0.16348233597692863, 'fraction_numerical': 0.04019466474405191, 'mean_word_length': 3.9412288512911844, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 14, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '290139', 'license': 'MIT', 'n_tokens_mistral': 2381, 'n_tokens_neox': 2241, 'n_words': 492, 'path': 'paper_figures/fig-12-reconstruction-losses-cat.ipynb', 'repo_name': 'quantshah/qst-nn', 'size': '5568'}