The Fock device¶
Pennylane’s Fock device gives access to
Strawberry Field’s Fock state simulator backend.
This simulator represents quantum states in the Fock basis
|0⟩,|1⟩,|2⟩,…,|D−1⟩,
where D is the user-given value for cutoff_dim
that limits the dimension of the Hilbert space.
The advantage of this representation is that any continuous-variable operation can be represented. However, the simulations are approximations, whose accuracy increases with the cutoff dimension.
Warning
It is often useful to keep track of the normalization of a quantum state during optimization, to make sure the circuit does not “learn” to push its parameters into a regime where the simulation is vastly inaccurate.
Note
For M modes or wires and a cutoff dimension of D, the Fock simulator needs to keep track of at least MD values. Hence, the simulation time and required memory grows much faster with the number of modes than in qubit-based simulators.
Usage¶
You can instantiate the Fock device in PennyLane as follows:
import pennylane as qml
dev = qml.device('strawberryfields.fock', wires=2, cutoff_dim=10)
The device can then be used just like other devices for the definition and evaluation of QNodes within PennyLane.
For instance, the following simple example defines a quantum_function
circuit that first displaces
the vacuum state, applies a beamsplitter, and then returns the photon number expectation.
This function is then converted into a QNode which is placed on the strawberryfields.fock
device:
@qml.qnode(dev)
def quantum_function(x, theta):
qml.Displacement(x, 0, wires=0)
qml.Beamsplitter(theta, 0, wires=[0, 1])
return qml.expval(qml.NumberOperator(0))
We can evaluate the QNode for arbitrary values of the circuit parameters:
>>> quantum_function(1., 0.543)
0.7330132578095255
We can also evaluate the derivative with respect to any parameter(s):
>>> dqfunc = qml.grad(quantum_function, argnum=0)
>>> dqfunc(1., 0.543)
1.4660265156190515
Note
The qml.state
, qml.sample
and qml.density_matrix
measurements
are not supported on the strawberryfields.fock
device.
The continuous-variable QNodes available via Strawberry Fields can also be combined with qubit-based QNodes and classical nodes to build up a hybrid computational model. Such hybrid models can be optimized using the built-in optimizers provided by PennyLane.
Device options¶
The Strawberry Fields Fock device accepts additional arguments beyond the PennyLane default device arguments.
cutoff_dim
the Fock basis truncation when applying quantum operations
hbar=2
The convention chosen in the canonical commutation relation [x,p]=iℏ. Default value is ℏ=2.
shots=None
The number of circuit evaluations/random samples used to estimate expectation values of observables. The default value of
None
means that the exact expectation value is returned.If shots is a positive integer or a list of integers, the Fock device calculates the variance of the expectation value(s), and use the Berry-Esseen theorem to estimate the sampled expectation value.
Supported operations¶
The Strawberry Fields Fock device supports all continuous-variable (CV) operations and observables provided by PennyLane, including both Gaussian and non-Gaussian operations.
Supported operations:
Beamsplitter interaction. |
|
Prepares a cat state. |
|
Prepares a coherent state. |
|
Controlled addition operation. |
|
Controlled phase operation. |
|
Cross-Kerr interaction. |
|
Cubic phase shift. |
|
Prepares a displaced squeezed vacuum state. |
|
Phase space displacement. |
|
Prepare subsystems using the given density matrix in the Fock basis. |
|
Prepares a single Fock state. |
|
Prepare subsystems using the given ket vector in the Fock basis. |
|
Prepare subsystems in a given Gaussian state. |
|
A linear interferometer transforming the bosonic operators according to the unitary matrix U. |
|
Kerr interaction. |
|
Quadratic phase shift. |
|
Phase space rotation. |
|
Prepares a squeezed vacuum state. |
|
Phase space squeezing. |
|
Prepares a thermal state. |
|
Phase space two-mode squeezing. |
Supported observables:
The identity observable ˆ1. |
|
The photon number observable ⟨ˆn⟩. |
|
The tensor product of the |
|
The position quadrature observable ˆx. |
|
|
The momentum quadrature observable ˆp. |
The generalized quadrature observable ˆxϕ=ˆxcosϕ+ˆpsinϕ. |
|
An arbitrary second-order polynomial observable. |
|
The tensor product of the |