Note
You can download this notebook
here.
Pure Fock simulation with Tensorflow#
[2]:
import numpy as np
import piquasso as pq
import tensorflow as tf
theta_1 = tf.Variable(np.pi / 3)
theta_2 = tf.Variable(np.pi / 5)
simulator = pq.TensorflowPureFockSimulator(d=3, config=pq.Config(cutoff=3))
with pq.Program() as program:
pq.Q(all) | pq.StateVector((1, 1, 0))
pq.Q(0, 1) | pq.Beamsplitter(theta=theta_1)
pq.Q(1, 2) | pq.Beamsplitter(theta=theta_2)
with tf.GradientTape() as tape:
state = simulator.execute(program).state
fock_probabilities = state.fock_probabilities
tape.jacobian(fock_probabilities, [theta_1, theta_2])
[2]:
[<tf.Tensor: shape=(10,), dtype=float32, numpy=
array([ 0. , 0. , 0. , 0. , -0.8660257 ,
1.1336422 , 0.59840894, -0.37098926, -0.39166376, -0.1033726 ],
dtype=float32)>,
<tf.Tensor: shape=(10,), dtype=float32, numpy=
array([ 0. , 0. , 0. , 0. , 0. ,
-0.23776424, 0.23776422, -0.46685594, 0.22041947, 0.24643645],
dtype=float32)>]