<jupyter_start><jupyter_text>Making big cat states using even-parity projectors Author: <NAME> In this tutorial, we numerically simulate the protocol proposed in [arXiv:1908.10314](https://arxiv.org/abs/1908.10314) for engineering superpositions of coherent states. We study how to make big cat states $|\text{cat}\rangle \sim |\alpha \rangle + |-\alpha \rangle$ with $|\alpha|^2 = 10$.<jupyter_code>import numpy as np
from qutip import wigner, Qobj, wigner_cmap

import matplotlib.pyplot as plt
import matplotlib as mpl
from matplotlib import cm

import strawberryfields as sf
from strawberryfields.ops import *
from thewalrus.quantum import state_vector, density_matrix<jupyter_output><empty_output><jupyter_text>Ideal preparation Here we setup some basic parameters, like the value of the photon-number-resolving detectors we will use to herald and the parameters of the different Gaussian unitaries.<jupyter_code>Lambda = 0.9 # Lambda is a squeezing parameter in [0,1)
r = np.arctanh(Lambda)
catSize = 10 # One obtains a better fidelity when this number is an integer (see paper for explanation)
alpha = np.sqrt(catSize)*Lambda # Coherent state amplitude is chosen to compensate finite squeezing, Lambda < 1
detOutcome = int(round(catSize))
m0 = detOutcome
m1 = detOutcome
print(m0,m1)<jupyter_output>10 10<jupyter_text>Now we setup a 3-mode quantum circuit in Strawberry Fields and obtain the covariance matrix and vector of means of the Gaussian state.<jupyter_code>nmodes = 3
prog = sf.Program(nmodes)
eng = sf.Engine("gaussian")
with prog.context as q:
    S2gate(r)             | (q[1],q[2])
    Dgate(1j*alpha)       | q[0]
    BSgate()              | (q[0],q[1])
state = eng.run(prog).state
mu = state.means()
cov = state.cov()
# Here we use the sf circuit drawer and standard linux utilities 
# to generate an svg representing the circuit
file, _ = prog.draw_circuit()
filepdf = file[0:-3]+"pdf"
filepdf = filepdf.replace("circuit_tex/","")
filecrop = filepdf.replace(".pdf","-crop.pdf")
name = "cat_circuit.svg"
!pdflatex  $file > /dev/null 2>&1
!pdfcrop $filepdf > /dev/null 2>&1
!pdf2svg $filecrop $name<jupyter_output><empty_output><jupyter_text>Here is a graphical representation of the circuit. It is always assumed that the input is vacuum in all the modes. ![img](./cat_circuit.svg) We can now inspect the covariance matrix and vector of means. Note that the vector of means is non-zero since we used a displacement gate.<jupyter_code>print(np.round(mu,10))
print(np.round(cov,10))<jupyter_output>[0.         0.         0.         4.02492236 4.02492236 0.        ]
[[ 5.26315789 -4.26315789 -6.69890635  0.         -0.          0.        ]
 [-4.26315789  5.26315789  6.69890635 -0.          0.         -0.        ]
 [-6.69890635  6.69890635  9.52631579  0.         -0.          0.        ]
 [ 0.         -0.          0.          5.26315789 -4.26315789  6.69890635]
 [-0.          0.         -0.         -4.26315789  5.26315789 -6.69890635]
 [ 0.         -0.          0.          6.69890635 -6.69890635  9.52631579]]<jupyter_text>We now use The Walrus to obtain the Fock representation of the state `psi` that is heralded when modes 0 and 1 are measured to have the value $n=10$. We also calculate the probability of success in heralding in the variable `p_psi`.<jupyter_code>cutoff = 18
psi = state_vector(mu, cov, post_select={0:m0,1:m1}, normalize=False, cutoff=cutoff)
p_psi = np.linalg.norm(psi)
psi = psi/p_psi
print("The probability of successful heralding is ", np.round(p_psi**2,5))<jupyter_output>The probability of successful heralding is  0.0006<jupyter_text>We now plot the photon-number distribution of the heralded state. Note that the state only has even photon components.<jupyter_code>plt.bar(np.arange(cutoff),np.abs(psi)**2)
plt.xlabel("$i$")
plt.ylabel(r"$p_i$")
plt.show()<jupyter_output><empty_output><jupyter_text>We can now plot the Wigner function of the heralded state,<jupyter_code>grid = 100
xvec = np.linspace(-7,7,grid)
Wp = wigner(Qobj(psi), xvec, xvec)
wmap = wigner_cmap(Wp)
sc1 = np.max(Wp)
nrm = mpl.colors.Normalize(-sc1, sc1)
fig, axes = plt.subplots(1, 1, figsize=(5, 4))
plt1 = axes.contourf(xvec, xvec, Wp, 60,  cmap=cm.RdBu, norm=nrm)
axes.contour(xvec, xvec, Wp, 60,  cmap=cm.RdBu, norm=nrm)
axes.set_title("Wigner function of the heralded state");
cb1 = fig.colorbar(plt1, ax=axes)
fig.tight_layout()
plt.show()<jupyter_output><empty_output><jupyter_text>and a cut of the Wigner function along $p=0$.<jupyter_code>plt.plot(xvec, Wp[:,grid//2])
plt.title(r"$W(0,p)$")
plt.xlabel(r"p")
plt.show()
%reload_ext version_information
%version_information qutip, strawberryfields, thewalrus<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11786096256684492, 'fraction_numerical': 0.06374331550802138, 'mean_word_length': 4.011789924973205, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 35, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '400414', 'license': 'Apache-2.0', 'n_tokens_mistral': 1855, 'n_tokens_neox': 1642, 'n_words': 479, 'path': 'docs/gallery/cat.ipynb', 'repo_name': 'nagaj/thewalrus', 'size': '4689'}