-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor [examples] - teleportation * refactor [examples] - teleportation remove default optional parameters Co-authored-by: Theodor <theodor.isacsson@gmail.com> * fix [examples] - gaussian_cloning * fix [examples] - gate_teleportation use the .par attribute of a measured parameter Co-authored-by: Theodor <theodor.isacsson@gmail.com>
- Loading branch information
1 parent
724b0a7
commit 717e7a1
Showing
3 changed files
with
59 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,51 @@ | ||
#!/usr/bin/env python3 | ||
import strawberryfields as sf | ||
from strawberryfields.ops import * | ||
from strawberryfields.utils import scale | ||
from strawberryfields.ops import ( | ||
Coherent, | ||
Squeezed, | ||
BSgate, | ||
Xgate, | ||
Zgate, | ||
MeasureX, | ||
MeasureP, | ||
) | ||
|
||
import numpy as np | ||
from numpy import pi, sqrt | ||
|
||
# initialize engine and program objects | ||
eng = sf.Engine(backend="gaussian") | ||
teleportation = sf.Program(3) | ||
|
||
with teleportation.context as q: | ||
psi, alice, bob = q[0], q[1], q[2] | ||
|
||
# state to be teleported: | ||
Coherent(1+0.5j) | psi | ||
|
||
# 50-50 beamsplitter | ||
BS = BSgate(pi/4, 0) | ||
|
||
# maximally entangled states | ||
Squeezed(-2) | alice | ||
Squeezed(2) | bob | ||
BS | (alice, bob) | ||
|
||
# Alice performs the joint measurement | ||
# in the maximally entangled basis | ||
BS | (psi, alice) | ||
MeasureX | psi | ||
MeasureP | alice | ||
|
||
# Bob conditionally displaces his mode | ||
# based on Alice's measurement result | ||
Xgate(psi.par*sqrt(2)) | bob | ||
Zgate(alice.par*sqrt(2)) | bob | ||
# end circuit | ||
|
||
results = eng.run(teleportation) | ||
# view Bob's output state and fidelity | ||
print(results.samples) | ||
print(results.state.displacement([2])) | ||
print(results.state.fidelity_coherent([0, 0, 1+0.5j])) | ||
# set the random seed | ||
np.random.seed(42) | ||
|
||
prog = sf.Program(3) | ||
|
||
alpha = 1 + 0.5j | ||
r = np.abs(alpha) | ||
phi = np.angle(alpha) | ||
|
||
with prog.context as q: | ||
# prepare initial states | ||
Coherent(r, phi) | q[0] | ||
Squeezed(-2) | q[1] | ||
Squeezed(2) | q[2] | ||
|
||
# apply gates | ||
BS = BSgate(pi / 4, pi) | ||
BS | (q[1], q[2]) | ||
BS | (q[0], q[1]) | ||
|
||
# Perform homodyne measurements | ||
MeasureX | q[0] | ||
MeasureP | q[1] | ||
|
||
# Displacement gates conditioned on | ||
# the measurements | ||
Xgate(sqrt(2) * q[0].par) | q[2] | ||
Zgate(sqrt(2) * q[1].par) | q[2] | ||
|
||
eng = sf.Engine("fock", backend_options={"cutoff_dim": 15}) | ||
result = eng.run(prog) | ||
|
||
# view output state and fidelity | ||
print(result.samples) | ||
print(result.state) | ||
print(result.state.fidelity_coherent([0, 0, alpha])) |