New features since last release
* A new device, `strawberryfields.tf`, provides support for using Strawberry Fields TensorFlow backend from within PennyLane. [(50)](https://github.com/PennyLaneAI/pennylane-sf/pull/50)
python
dev = qml.device('strawberryfields.tf', wires=2, cutoff_dim=10)
This device supports classical backpropagation when using the TensorFlow interface:
python
qml.qnode(dev, interface="tf", diff_method="backprop")
def circuit(x, theta):
qml.Displacement(x, 0, wires=0)
qml.Beamsplitter(theta, 0, wires=[0, 1])
return qml.probs(wires=0)
Gradients will be computed using TensorFlow backpropagation:
pycon
>>> x = tf.Variable(1.0)
>>> theta = tf.Variable(0.543)
>>> with tf.GradientTape() as tape:
... res = circuit(x, theta)
>>> jac = tape.jacobian(res, x)
>>> print(jac)
<tf.Tensor: shape=(1, 10), dtype=float32, numpy=
array([[-7.0436597e-01, 1.8805575e-01, 3.2707882e-01, 1.4299491e-01,
3.7763387e-02, 7.2306832e-03, 1.0900890e-03, 1.3535164e-04,
1.3895189e-05, 9.9099987e-07]], dtype=float32)>
For more details, please see the [TF device documentation](https://pennylane-sf.readthedocs.io/en/latest/devices/tf.html)
* A new device, `strawberryfields.gbs`, provides support for training of the Gaussian boson sampling (GBS) distribution. [(47)](https://github.com/PennyLaneAI/pennylane-sf/pull/47)
python
dev = qml.device('strawberryfields.gbs', wires=4, cutoff_dim=4)
This device allows the adjacency matrix ``A`` of a graph to be trained. The QNode must have a fixed structure:
python
from pennylane_sf.ops import ParamGraphEmbed
import numpy as np
A = np.array([
[0.0, 1.0, 1.0, 1.0],
[1.0, 0.0, 1.0, 0.0],
[1.0, 1.0, 0.0, 0.0],
[1.0, 0.0, 0.0, 0.0]])
n_mean = 2.5
qml.qnode(dev)
def quantum_function(x):
ParamGraphEmbed(x, A, n_mean, wires=range(4))
return qml.probs(wires=range(4))
Here, ``n_mean`` is the initial mean number of photons in the output GBS samples. The GBS probability distribution for a choice of trainable parameters ``x`` can then be accessed:
pycon
>>> x = 0.9 * np.ones(4)
>>> quantum_function(x)
For more details, please see the [gbs device documentation](https://pennylane-sf.readthedocs.io/en/latest/devices/gbs.html)
Improvements
* Adds the ability for the `StrawberryFieldsGBS` device to use the reparametrization trick in sampling mode. [(55)](https://github.com/PennyLaneAI/pennylane-sf/pull/55)
Bug fixes
* Applies minor fixes to `RemoteEngine`. [(53)](https://github.com/PennyLaneAI/pennylane-sf/pull/53)
* Sets a fixed cutoff dimension for `RemoteEngine`. [(54)](https://github.com/PennyLaneAI/pennylane-sf/pull/54)
* Adds unwrapping for operation parameters as indexing into NumPy arrays was added to PennyLane. [(56)](https://github.com/PennyLaneAI/pennylane-sf/pull/56)
Contributors
This release contains contributions from (in alphabetical order):
Juan Miguel Arrazola, Thomas Bromley, Josh Izaac.