Simulators with Tensorflow support#

Pure Fock Simulator and Tensorflow#

Performs photonic simulations using Fock representation with pure states.

This simulator is similar to PureFockSimulator, but it calculates with Tensorflow to enable calculating the gradient.

The simulation (when executed) results in an instance of PureFockState.


Non-deterministic operations like ParticleNumberMeasurement are non-differentiable, please use a deterministic attribute of the resulting state instead.

Example usage:

import tensorflow as tf

alpha = tf.Variable(0.43)

simulator = pq.TensorflowPureFockSimulator(d=1)

with pq.Program() as program:
    pq.Q() | pq.Vacuum()

    pq.Q(0) | pq.Displacement(alpha=alpha)

with tf.GradientTape() as tape:
    state = simulator.execute(program).state

    mean = state.mean_photon_number()

gradient = tape.gradient(mean, [alpha])
Supported preparations:

Vacuum, Create, Annihilate, StateVector.

Supported gates:

Interferometer, Beamsplitter, Phaseshifter, MachZehnder, Fourier, Kerr, CrossKerr, CubicPhase, GaussianTransform, Squeezing, QuadraticPhase, Squeezing2, ControlledX, ControlledZ, Displacement, PositionDisplacement, MomentumDisplacement.

Supported measurements:

ParticleNumberMeasurement (non-differentiable).

Supported channels:

Attenuator (non-differentiable).