140
140
# import PennyLane
141
141
import pennylane as qml
142
142
143
- ######################################################################
143
+ ##############################################################################
144
144
# We must define the unitary matrix we would like to embed in the circuit.
145
145
# We will use SciPy to generate a Haar-random unitary:
146
146
@@ -188,7 +188,7 @@ def gbs_circuit():
188
188
return qml .probs (wires = range (n_wires ))
189
189
190
190
191
- ######################################################################
191
+ ##############################################################################
192
192
# A couple of things to note in this particular example:
193
193
#
194
194
# 1. To prepare the input single mode squeezed vacuum state :math:`|re^{i\phi}\rangle,`
@@ -222,7 +222,8 @@ def gbs_circuit():
222
222
#
223
223
# (10, 10, 10, 10)
224
224
#
225
- ######################################################################
225
+
226
+ ##############################################################################
226
227
# For example, element ``[1,2,0,1]`` represents the probability of
227
228
# detecting 1 photon on wire
228
229
# ``0`` and wire ``3``, and 2 photons at wire ``1``, i.e., the value
@@ -251,7 +252,8 @@ def gbs_circuit():
251
252
# |1111>: 0.005957399165336106
252
253
# |2000>: 0.02957384308320549
253
254
#
254
- ######################################################################
255
+
256
+ ##############################################################################
255
257
# The GBS Distribution
256
258
# --------------------
257
259
#
@@ -315,13 +317,13 @@ def gbs_circuit():
315
317
316
318
from thewalrus import hafnian as haf
317
319
318
- ######################################################################
320
+ ##############################################################################
319
321
# Now, for the right-hand side numerator, we first calculate the submatrix
320
322
# :math:`A = [(UU^T\mathrm{tanh}(r))]_{st}:`
321
323
322
324
A = np .dot (U , U .T ) * np .tanh (1 )
323
325
324
- ######################################################################
326
+ ##############################################################################
325
327
# In GBS, we determine the submatrix by taking the
326
328
# rows and columns corresponding to the measured Fock state. For example, to calculate the submatrix
327
329
# in the case of the output measurement :math:`\left|{1,1,0,0}\right\rangle,`
@@ -338,11 +340,12 @@ def gbs_circuit():
338
340
# [[ 0.19343159-0.54582922j 0.43418269-0.09169615j]
339
341
# [ 0.43418269-0.09169615j -0.27554025-0.46222197j]]
340
342
#
341
- ######################################################################
343
+
344
+ ##############################################################################
342
345
# i.e., we consider only the rows and columns where a photon was detected, which gives us
343
346
# the submatrix corresponding to indices :math:`0` and :math:`1.`
344
347
345
- ######################################################################
348
+ ##############################################################################
346
349
# Comparing to simulation
347
350
# -----------------------
348
351
#
@@ -365,7 +368,8 @@ def gbs_circuit():
365
368
# 0.1763784476141347
366
369
# 0.17637844761413496
367
370
#
368
- ######################################################################
371
+
372
+ ##############################################################################
369
373
# **Measuring** :math:`|1,1,0,0\rangle` **at the output**
370
374
371
375
A = (np .dot (U , U .T ) * np .tanh (1 ))[:, [0 , 1 ]][[0 , 1 ]]
@@ -381,7 +385,8 @@ def gbs_circuit():
381
385
# 0.03473293649420271
382
386
# 0.03473293649420282
383
387
#
384
- ######################################################################
388
+
389
+ ##############################################################################
385
390
# **Measuring** :math:`|0,1,0,1\rangle` **at the output**
386
391
387
392
A = (np .dot (U , U .T ) * np .tanh (1 ))[:, [1 , 3 ]][[1 , 3 ]]
@@ -397,7 +402,8 @@ def gbs_circuit():
397
402
# 0.011870900427255558
398
403
# 0.011870900427255589
399
404
#
400
- ######################################################################
405
+
406
+ ##############################################################################
401
407
# **Measuring** :math:`|1,1,1,1\rangle` **at the output**
402
408
#
403
409
# This corresponds to the hafnian of the full matrix :math:`A=UU^T\mathrm{tanh}(r):`
@@ -415,7 +421,8 @@ def gbs_circuit():
415
421
# 0.005957399165336081
416
422
# 0.005957399165336106
417
423
#
418
- ######################################################################
424
+
425
+ ##############################################################################
419
426
# **Measuring** :math:`|2,0,0,0\rangle` **at the output**
420
427
#
421
428
# Since we have two photons in mode ``q[0]``, we take two copies of the
0 commit comments