PennyLane v0.7.0 Released

Hi everyone, we’re excited to announce PennyLane version 0.7.0 :fireworks: :champagne: :strawberry:

This is a major release, that contains some great new features and improvements. These include:

New operations

  • The parametrized single-qubit unitaries U2 and U3 are now supported natively in PennyLane, via qml.U2, qml.U3. Support for the S, T, CSWAP, and Toffoli gates have also been added

  • You can now specify inverse operations via the .inv() method, for example, qml.S(wires=0).inv(). Currently, this is supported by default.qubit, PennyLane-Cirq, and PennyLane-Qiskit.

  • If the device you are using doesn’t support a particular operation, PennyLane can now smartly determine the best decomposition to allow the device to execute it.

Load Qiskit/QASM circuits into PennyLane template

You can now load (parametrized) Qiskit circuits and QASM files in PennyLane, and they are automatically converted into PennyLane templates, with full support for automatic differentiation! Not only that, but the converted templates are now hardware independent, and can be run on other devices (for example, Rigetti’s QPUs).

Code example
from qiskit import QuantumCircuit
from qiskit.circuit import Parameter
import numpy as np

dev = qml.device('default.qubit', wires=2)

theta = Parameter('θ')

qc = QuantumCircuit(2)
qc.rz(theta, [0])
qc.rx(theta, [0])
qc.cx(0, 1)

@qml.qnode(dev)
def quantum_circuit_with_loaded_subcircuit(x):
    qml.from_qiskit(qc)({theta: x})
    return qml.expval(qml.PauliZ(0))

angle = np.pi/2
result = quantum_circuit_with_loaded_subcircuit(angle)

Templates refactor

The templates are now easier to use, with clearer docstrings, and numerous bug fixes. In addition, two new state preparation templates have been added — BasisStatePreparation and MottonenStatePreparation — allowing you to prepare a given quantum state, by decomposing it into elementary operations.

Experimental TensorNetwork device

An experimental TensorNetwork device, expt.tensornet.tf has been added, which uses TensorFlow for backpropagation. When optimizing a large number of parameters, this device can be significantly faster than other simulators!

See here for a small example on how to use this new device.

Note: this device is considered experimental — if you discover any bugs, please let us know on our GitHub page.

Debugging tools

PennyLane now features an OperationRecorder() context manager, that allows templates and quantum functions to be executed while recording events:

Code Example
>>> from pennylane.init import strong_ent_layers_normal
>>> from pennylane.templates import StronglyEntanglingLayers
>>>
>>> params = strong_ent_layers_normal(n_wires=2, n_layers=3)
>>> with qml.utils.OperationRecorder() as rec:
>>>     StronglyEntanglingLayers(weights=params, wires=[0, 2])
>>>
>>> print(rec)

Operations
==========
Rot(0.0007921340370760937, -0.11679998018150295, -0.11769329813630634, wires=[0])
Rot(-0.03831877439284849, -0.04366868467700882, 0.017691880535405487, wires=[2])
CNOT(wires=[0, 2])
CNOT(wires=[2, 0])
Rot(0.03450305137767042, -0.02317782996305706, 0.015922616214334502, wires=[0])
Rot(0.0021489309826849606, 0.05777840434563987, 0.0008014966136134486, wires=[2])
CNOT(wires=[0, 2])
CNOT(wires=[2, 0])
Rot(-0.01996469240851956, 0.011499683549602291, -0.10634881064808129, wires=[0])
Rot(0.03542747988415599, 0.08974706943141819, -0.04372804731753166, wires=[2])
CNOT(wires=[0, 2])
CNOT(wires=[2, 0])


See the full release notes for more details on the latest PennyLane release.

As always, this release would not have been possible without all the help from our contributors:

Ville Bergholm, @nathan, Angus Lowe, @johannesjmeyer , Oluwatobi Ogunbayo, @Maria_Schuld , @antalszava