# Release notes¶

This page contains the release notes for PennyLane.

## Release 0.8.1 (current release)¶

### Improvements

Beginning of support for Python 3.8, with the test suite now being run in a Python 3.8 environment. (#501)

### Documentation

Present templates as a gallery of thumbnails showing the basic circuit architecture. (#499)

### Bug fixes

Fixed a bug where multiplying a QNode parameter by 0 caused a divide by zero error when calculating the parameter shift formula. (#512)

Fixed a bug where the shape of differentiable QNode arguments was being cached on the first construction, leading to indexing errors if the QNode was re-evaluated if the argument changed shape. (#505)

### Contributors

This release contains contributions from (in alphabetical order):

Ville Bergholm, Josh Izaac, Maria Schuld, Antal Száva.

## Release 0.8.0¶

### New features since last release

Added a quantum chemistry package,

`pennylane.qchem`

, which supports integration with OpenFermion, Psi4, PySCF, and OpenBabel. (#453)Features include:

Generate the qubit Hamiltonians directly starting with the atomic structure of the molecule.

Calculate the mean-field (Hartree-Fock) electronic structure of molecules.

Allow to define an active space based on the number of active electrons and active orbitals.

Perform the fermionic-to-qubit transformation of the electronic Hamiltonian by using different functions implemented in OpenFermion.

Convert OpenFermion’s QubitOperator to a Pennylane

`Hamiltonian`

class.Perform a Variational Quantum Eigensolver (VQE) computation with this Hamiltonian in PennyLane.

Check out the quantum chemistry quickstart, as well the quantum chemistry and VQE tutorials.

PennyLane now has some functions and classes for creating and solving VQE problems. (#467)

`qml.Hamiltonian`

: a lightweight class for representing qubit Hamiltonians`qml.VQECost`

: a class for quickly constructing a differentiable cost function given a circuit ansatz, Hamiltonian, and one or more devices>>> H = qml.vqe.Hamiltonian(coeffs, obs) >>> cost = qml.VQECost(ansatz, hamiltonian, dev, interface="torch") >>> params = torch.rand([4, 3]) >>> cost(params) tensor(0.0245, dtype=torch.float64)

Added a circuit drawing feature that provides a text-based representation of a QNode instance. It can be invoked via

`qnode.draw()`

. The user can specify to display variable names instead of variable values and choose either an ASCII or Unicode charset. (#446)Consider the following circuit as an example:

@qml.qnode(dev) def qfunc(a, w): qml.Hadamard(0) qml.CRX(a, wires=[0, 1]) qml.Rot(w[0], w[1], w[2], wires=[1]) qml.CRX(-a, wires=[0, 1]) return qml.expval(qml.PauliZ(0) @ qml.PauliZ(1))

We can draw the circuit after it has been executed:

>>> result = qfunc(2.3, [1.2, 3.2, 0.7]) >>> print(qfunc.draw()) 0: ──H──╭C────────────────────────────╭C─────────╭┤ ⟨Z ⊗ Z⟩ 1: ─────╰RX(2.3)──Rot(1.2, 3.2, 0.7)──╰RX(-2.3)──╰┤ ⟨Z ⊗ Z⟩ >>> print(qfunc.draw(charset="ascii")) 0: --H--+C----------------------------+C---------+| <Z @ Z> 1: -----+RX(2.3)--Rot(1.2, 3.2, 0.7)--+RX(-2.3)--+| <Z @ Z> >>> print(qfunc.draw(show_variable_names=True)) 0: ──H──╭C─────────────────────────────╭C─────────╭┤ ⟨Z ⊗ Z⟩ 1: ─────╰RX(a)──Rot(w[0], w[1], w[2])──╰RX(-1*a)──╰┤ ⟨Z ⊗ Z⟩

Added

`QAOAEmbedding`

and its parameter initialization as a new trainable template. (#442)Added the

`qml.probs()`

measurement function, allowing QNodes to differentiate variational circuit probabilities on simulators and hardware. (#432)@qml.qnode(dev) def circuit(x): qml.Hadamard(wires=0) qml.RY(x, wires=0) qml.RX(x, wires=1) qml.CNOT(wires=[0, 1]) return qml.probs(wires=[0])

Executing this circuit gives the marginal probability of wire 1:

>>> circuit(0.2) [0.40066533 0.59933467]

QNodes that return probabilities fully support autodifferentiation.

Added the convenience load functions

`qml.from_pyquil`

,`qml.from_quil`

and`qml.from_quil_file`

that convert pyQuil objects and Quil code to PennyLane templates. This feature requires version 0.8 or above of the PennyLane-Forest plugin. (#459)Added a

`qml.inv`

method that inverts templates and sequences of Operations. Added a`@qml.template`

decorator that makes templates return the queued Operations. (#462)For example, using this function to invert a template inside a QNode:

@qml.template def ansatz(weights, wires): for idx, wire in enumerate(wires): qml.RX(weights[idx], wires=[wire]) for idx in range(len(wires) - 1): qml.CNOT(wires=[wires[idx], wires[idx + 1]]) dev = qml.device('default.qubit', wires=2) @qml.qnode(dev) def circuit(weights): qml.inv(ansatz(weights, wires=[0, 1])) return qml.expval(qml.PauliZ(0) @ qml.PauliZ(1))

Added the

`QNodeCollection`

container class, that allows independent QNodes to be stored and evaluated simultaneously. Experimental support for asynchronous evaluation of contained QNodes is provided with the`parallel=True`

keyword argument. (#466)Added a high level

`qml.map`

function, that maps a quantum circuit template over a list of observables or devices, returning a`QNodeCollection`

. (#466)For example:

>>> def my_template(params, wires, **kwargs): >>> qml.RX(params[0], wires=wires[0]) >>> qml.RX(params[1], wires=wires[1]) >>> qml.CNOT(wires=wires) >>> obs_list = [qml.PauliX(0) @ qml.PauliZ(1), qml.PauliZ(0) @ qml.PauliX(1)] >>> dev = qml.device("default.qubit", wires=2) >>> qnodes = qml.map(my_template, obs_list, dev, measure="expval") >>> qnodes([0.54, 0.12]) array([-0.06154835 0.99280864])

Added high level

`qml.sum`

,`qml.dot`

,`qml.apply`

functions that act on QNode collections. (#466)`qml.apply`

allows vectorized functions to act over the entire QNode collection:>>> qnodes = qml.map(my_template, obs_list, dev, measure="expval") >>> cost = qml.apply(np.sin, qnodes) >>> cost([0.54, 0.12]) array([-0.0615095 0.83756375])

`qml.sum`

and`qml.dot`

take the sum of a QNode collection, and a dot product of tensors/arrays/QNode collections, respectively.

### Breaking changes

Deprecated the old-style

`QNode`

such that only the new-style`QNode`

and its syntax can be used, moved all related files from the`pennylane/beta`

folder to`pennylane`

. (#440)

### Improvements

Added the

`Tensor.prune()`

method and the`Tensor.non_identity_obs`

property for extracting non-identity instances from the observables making up a`Tensor`

instance. (#498)Renamed the

`expt.tensornet`

and`expt.tensornet.tf`

devices to`default.tensor`

and`default.tensor.tf`

. (#495)Added a serialization method to the

`CircuitGraph`

class that is used to create a unique hash for each quantum circuit graph. (#470)Added the

`Observable.eigvals`

method to return the eigenvalues of observables. (#449)Added the

`Observable.diagonalizing_gates`

method to return the gates that diagonalize an observable in the computational basis. (#454)Added the

`Operator.matrix`

method to return the matrix representation of an operator in the computational basis. (#454)Added a

`QubitDevice`

class which implements common functionalities of plugin devices such that plugin devices can rely on these implementations. The new`QubitDevice`

also includes a new`execute`

method, which allows for more convenient plugin design. In addition,`QubitDevice`

also unifies the way samples are generated on qubit-based devices. (#452) (#473)Improved documentation of

`AmplitudeEmbedding`

and`BasisEmbedding`

templates. (#441) (#439)Codeblocks in the documentation now have a ‘copy’ button for easily copying examples. (#437)

### Documentation

Update the developers plugin guide to use QubitDevice. (#483)

### Bug fixes

Fixed a bug in

`CVQNode._pd_analytic`

, where non-descendant observables were not Heisenberg-transformed before evaluating the partial derivatives when using the order-2 parameter-shift method, resulting in an erroneous Jacobian for some circuits. (#433)

### Contributors

This release contains contributions from (in alphabetical order):

Juan Miguel Arrazola, Ville Bergholm, Alain Delgado Gran, Olivia Di Matteo, Theodor Isacsson, Josh Izaac, Soran Jahangiri, Nathan Killoran, Johannes Jakob Meyer, Zeyue Niu, Maria Schuld, Antal Száva.

## Release 0.7.0¶

### New features since last release

Custom padding constant in

`AmplitudeEmbedding`

is supported (see ‘Breaking changes’.) (#419)`StronglyEntanglingLayer`

and`RandomLayer`

now work with a single wire. (#409) (#413)Added support for applying the inverse of an

`Operation`

within a circuit. (#377)Added an

`OperationRecorder()`

context manager, that allows templates and quantum functions to be executed while recording events. The recorder can be used with and without QNodes as a debugging utility. (#388)Operations can now specify a decomposition that is used when the desired operation is not supported on the target device. (#396)

The ability to load circuits from external frameworks as templates has been added via the new

`qml.load()`

function. This feature requires plugin support — this initial release provides support for Qiskit circuits and QASM files when`pennylane-qiskit`

is installed, via the functions`qml.from_qiskit`

and`qml.from_qasm`

. (#418)An experimental tensor network device has been added (#416) (#395) (#394) (#380)

An experimental tensor network device which uses TensorFlow for backpropagation has been added (#427)

Custom padding constant in

`AmplitudeEmbedding`

is supported (see ‘Breaking changes’.) (#419)

### Breaking changes

The

`pad`

parameter in`AmplitudeEmbedding()`

is now either`None`

(no automatic padding), or a number that is used as the padding constant. (#419)Initialization functions now return a single array of weights per function. Utilities for multi-weight templates

`Interferometer()`

and`CVNeuralNetLayers()`

are provided. (#412)The single layer templates

`RandomLayer()`

,`CVNeuralNetLayer()`

and`StronglyEntanglingLayer()`

have been turned into private functions`_random_layer()`

,`_cv_neural_net_layer()`

and`_strongly_entangling_layer()`

. Recommended use is now via the corresponding`Layers()`

templates. (#413)

### Improvements

Added extensive input checks in templates. (#419)

Templates integration tests are rewritten - now cover keyword/positional argument passing, interfaces and combinations of templates. (#409) (#419)

State vector preparation operations in the

`default.qubit`

plugin can now be applied to subsets of wires, and are restricted to being the first operation in a circuit. (#346)The

`QNode`

class is split into a hierarchy of simpler classes. (#354) (#398) (#415) (#417) (#425)Added the gates U1, U2 and U3 parametrizing arbitrary unitaries on 1, 2 and 3 qubits and the Toffoli gate to the set of qubit operations. (#396)

Changes have been made to accomodate the movement of the main function in

`pytest._internal`

to`pytest._internal.main`

in pip 19.3. (#404)Added the templates

`BasisStatePreparation`

and`MottonenStatePreparation`

that use gates to prepare a basis state and an arbitrary state respectively. (#336)Added decompositions for

`BasisState`

and`QubitStateVector`

based on state preparation templates. (#414)Replaces the pseudo-inverse in the quantum natural gradient optimizer (which can be numerically unstable) with

`np.linalg.solve`

. (#428)

### Contributors

This release contains contributions from (in alphabetical order):

Ville Bergholm, Josh Izaac, Nathan Killoran, Angus Lowe, Johannes Jakob Meyer, Oluwatobi Ogunbayo, Maria Schuld, Antal Száva.

## Release 0.6.1¶

### New features since last release

Added a

`print_applied`

method to QNodes, allowing the operation and observable queue to be printed as last constructed. (#378)

### Improvements

A new

`Operator`

base class is introduced, which is inherited by both the`Observable`

class and the`Operation`

class. (#355)Removed deprecated

`@abstractproperty`

decorators in`_device.py`

. (#374)The

`CircuitGraph`

class is updated to deal with`Operation`

instances directly. (#344)Comprehensive gradient tests have been added for the interfaces. (#381)

### Documentation

The new restructured documentation has been polished and updated. (#387) (#375) (#372) (#370) (#369) (#367) (#364)

Added all modules, classes, and functions to the API section in the documentation. (#373)

### Bug fixes

Replaces the existing

`np.linalg.norm`

normalization with hand-coded normalization, allowing`AmplitudeEmbedding`

to be used with differentiable parameters. AmplitudeEmbedding tests have been added and improved. (#376)

### Contributors

This release contains contributions from (in alphabetical order):

Ville Bergholm, Josh Izaac, Nathan Killoran, Maria Schuld, Antal Száva

## Release 0.6.0¶

### New features since last release

The devices

`default.qubit`

and`default.gaussian`

have a new initialization parameter`analytic`

that indicates if expectation values and variances should be calculated analytically and not be estimated from data. (#317)Added C-SWAP gate to the set of qubit operations (#330)

The TensorFlow interface has been renamed from

`"tfe"`

to`"tf"`

, and now supports TensorFlow 2.0. (#337)Added the S and T gates to the set of qubit operations. (#343)

Tensor observables are now supported within the

`expval`

,`var`

, and`sample`

functions, by using the`@`

operator. (#267)

### Breaking changes

The argument

`n`

specifying the number of samples in the method`Device.sample`

was removed. Instead, the method will always return`Device.shots`

many samples. (#317)

### Improvements

The number of shots / random samples used to estimate expectation values and variances,

`Device.shots`

, can now be changed after device creation. (#317)Unified import shortcuts to be under qml in qnode.py and test_operation.py (#329)

The quantum natural gradient now uses

`scipy.linalg.pinvh`

which is more efficient for symmetric matrices than the previously used`scipy.linalg.pinv`

. (#331)The deprecated

`qml.expval.Observable`

syntax has been removed. (#267)Remainder of the unittest-style tests were ported to pytest. (#310)

The

`do_queue`

argument for operations now only takes effect within QNodes. Outside of QNodes, operations can now be instantiated without needing to specify`do_queue`

. (#359)

### Documentation

The docs are rewritten and restructured to contain a code introduction section as well as an API section. (#314)

Added Ising model example to the tutorials (#319)

Added tutorial for QAOA on MaxCut problem (#328)

Added QGAN flow chart figure to its tutorial (#333)

Added missing figures for gallery thumbnails of state-preparation and QGAN tutorials (#326)

Fixed typos in the state preparation tutorial (#321)

Fixed bug in VQE tutorial 3D plots (#327)

### Bug fixes

Fixed typo in measurement type error message in qnode.py (#341)

### Contributors

This release contains contributions from (in alphabetical order):

Shahnawaz Ahmed, Ville Bergholm, Aroosa Ijaz, Josh Izaac, Nathan Killoran, Angus Lowe, Johannes Jakob Meyer, Maria Schuld, Antal Száva, Roeland Wiersema.

## Release 0.5.0¶

### New features since last release

Adds a new optimizer,

`qml.QNGOptimizer`

, which optimizes QNodes using quantum natural gradient descent. See https://arxiv.org/abs/1909.02108 for more details. (#295) (#311)Adds a new QNode method,

`QNode.metric_tensor()`

, which returns the block-diagonal approximation to the Fubini-Study metric tensor evaluated on the attached device. (#295)Sampling support: QNodes can now return a specified number of samples from a given observable via the top-level

`pennylane.sample()`

function. To support this on plugin devices, there is a new`Device.sample`

method.Calculating gradients of QNodes that involve sampling is not possible. (#256)

`default.qubit`

has been updated to provide support for sampling. (#256)Added controlled rotation gates to PennyLane operations and

`default.qubit`

plugin. (#251)

### Breaking changes

The method

`Device.supported`

was removed, and replaced with the methods`Device.supports_observable`

and`Device.supports_operation`

. Both methods can be called with string arguments (`dev.supports_observable('PauliX')`

) and class arguments (`dev.supports_observable(qml.PauliX)`

). (#276)The following CV observables were renamed to comply with the new Operation/Observable scheme:

`MeanPhoton`

to`NumberOperator`

,`Homodyne`

to`QuadOperator`

and`NumberState`

to`FockStateProjector`

. (#254)

### Improvements

The

`AmplitudeEmbedding`

function now provides options to normalize and pad features to ensure a valid state vector is prepared. (#275)Operations can now optionally specify generators, either as existing PennyLane operations, or by providing a NumPy array. (#295) (#313)

Adds a

`Device.parameters`

property, so that devices can view a dictionary mapping free parameters to operation parameters. This will allow plugin devices to take advantage of parametric compilation. (#283)Introduces two enumerations:

`Any`

and`All`

, representing any number of wires and all wires in the system respectively. They can be imported from`pennylane.operation`

, and can be used when defining the`Operation.num_wires`

class attribute of operations. (#277)As part of this change:

`All`

is equivalent to the integer 0, for backwards compatibility with the existing test suite`Any`

is equivalent to the integer -1 to allow numeric comparison operators to continue workingAn additional validation is now added to the

`Operation`

class, which will alert the user that an operation with`num_wires = All`

is being incorrectly.

The one-qubit rotations in

`pennylane.plugins.default_qubit`

no longer depend on Scipy’s`expm`

. Instead they are calculated with Euler’s formula. (#292)Creates an

`ObservableReturnTypes`

enumeration class containing`Sample`

,`Variance`

and`Expectation`

. These new values can be assigned to the`return_type`

attribute of an`Observable`

. (#290)Changed the signature of the

`RandomLayer`

and`RandomLayers`

templates to have a fixed seed by default. (#258)`setup.py`

has been cleaned up, removing the non-working shebang, and removing unused imports. (#262)

### Documentation

A documentation refactor to simplify the tutorials and include Sphinx-Gallery. (#291)

Examples and tutorials previously split across the

`examples/`

and`doc/tutorials/`

directories, in a mixture of ReST and Jupyter notebooks, have been rewritten as Python scripts with ReST comments in a single location, the`examples/`

folder.Sphinx-Gallery is used to automatically build and run the tutorials. Rendered output is displayed in the Sphinx documentation.

Links are provided at the top of every tutorial page for downloading the tutorial as an executable python script, downloading the tutorial as a Jupyter notebook, or viewing the notebook on GitHub.

The tutorials table of contents have been moved to a single quick start page.

Fixed a typo in

`QubitStateVector`

. (#296)Fixed a typo in the

`default_gaussian.gaussian_state`

function. (#293)Fixed a typo in the gradient recipe within the

`RX`

,`RY`

,`RZ`

operation docstrings. (#248)Fixed a broken link in the tutorial documentation, as a result of the

`qml.expval.Observable`

deprecation. (#246)

### Bug fixes

Fixed a bug where a

`PolyXP`

observable would fail if applied to subsets of wires on`default.gaussian`

. (#277)

### Contributors

This release contains contributions from (in alphabetical order):

Simon Cross, Aroosa Ijaz, Josh Izaac, Nathan Killoran, Johannes Jakob Meyer, Rohit Midha, Nicolás Quesada, Maria Schuld, Antal Száva, Roeland Wiersema.

## Release 0.4.0¶

### New features since last release

`pennylane.expval()`

is now a top-level*function*, and is no longer a package of classes. For now, the existing`pennylane.expval.Observable`

interface continues to work, but will raise a deprecation warning. (#232)Variance support: QNodes can now return the variance of observables, via the top-level

`pennylane.var()`

function. To support this on plugin devices, there is a new`Device.var`

method.The following observables support analytic gradients of variances:

All qubit observables (requiring 3 circuit evaluations for involutory observables such as

`Identity`

,`X`

,`Y`

,`Z`

; and 5 circuit evals for non-involutary observables, currently only`qml.Hermitian`

)First-order CV observables (requiring 5 circuit evaluations)

Second-order CV observables support numerical variance gradients.

`pennylane.about()`

function added, providing details on current PennyLane version, installed plugins, Python, platform, and NumPy versions (#186)Removed the logic that allowed

`wires`

to be passed as a positional argument in quantum operations. This allows us to raise more useful error messages for the user if incorrect syntax is used. (#188)Adds support for multi-qubit expectation values of the

`pennylane.Hermitian()`

observable (#192)Adds support for multi-qubit expectation values in

`default.qubit`

. (#202)Organize templates into submodules (#195). This included the following improvements:

Distinguish embedding templates from layer templates.

New random initialization functions supporting the templates available in the new submodule

`pennylane.init`

.Added a random circuit template (

`RandomLayers()`

), in which rotations and 2-qubit gates are randomly distributed over the wiresAdd various embedding strategies

### Breaking changes

The

`Device`

methods`expectations`

,`pre_expval`

, and`post_expval`

have been renamed to`observables`

,`pre_measure`

, and`post_measure`

respectively. (#232)

### Improvements

`default.qubit`

plugin now uses`np.tensordot`

when applying quantum operations and evaluating expectations, resulting in significant speedup (#239), (#241)PennyLane now allows division of quantum operation parameters by a constant (#179)

Portions of the test suite are in the process of being ported to pytest. Note: this is still a work in progress.

Ported tests include:

`test_ops.py`

`test_about.py`

`test_classical_gradients.py`

`test_observables.py`

`test_measure.py`

`test_init.py`

`test_templates*.py`

`test_ops.py`

`test_variable.py`

`test_qnode.py`

(partial)

### Bug fixes

Fixed a bug in

`Device.supported`

, which would incorrectly mark an operation as supported if it shared a name with an observable (#203)Fixed a bug in

`Operation.wires`

, by explicitly casting the type of each wire to an integer (#206)Removed code in PennyLane which configured the logger, as this would clash with users’ configurations (#208)

Fixed a bug in

`default.qubit`

, in which`QubitStateVector`

operations were accidentally being cast to`np.float`

instead of`np.complex`

. (#211)

### Contributors

This release contains contributions from:

Shahnawaz Ahmed, riveSunder, Aroosa Ijaz, Josh Izaac, Nathan Killoran, Maria Schuld.

## Release 0.3.1¶

### Bug fixes

Fixed a bug where the interfaces submodule was not correctly being packaged via setup.py

## Release 0.3.0¶

### New features since last release

PennyLane now includes a new

`interfaces`

submodule, which enables QNode integration with additional machine learning libraries.Adds support for an experimental PyTorch interface for QNodes

Adds support for an experimental TensorFlow eager execution interface for QNodes

Adds a PyTorch+GPU+QPU tutorial to the documentation

Documentation now includes links and tutorials including the new PennyLane-Forest plugin.

### Improvements

Printing a QNode object, via

`print(qnode)`

or in an interactive terminal, now displays more useful information regarding the QNode, including the device it runs on, the number of wires, it’s interface, and the quantum function it uses:>>> print(qnode) <QNode: device='default.qubit', func=circuit, wires=2, interface=PyTorch>

### Contributors

This release contains contributions from:

Josh Izaac and Nathan Killoran.

## Release 0.2.0¶

### New features since last release

Added the

`Identity`

expectation value for both CV and qubit models (#135)Added the

`templates.py`

submodule, containing some commonly used QML models to be used as ansatz in QNodes (#133)Added the

`qml.Interferometer`

CV operation (#152)Wires are now supported as free QNode parameters (#151)

Added ability to update stepsizes of the optimizers (#159)

### Improvements

Removed use of hardcoded values in the optimizers, made them parameters (see #131 and #132)

Created the new

`PlaceholderExpectation`

, to be used when both CV and qubit expval modules contain expectations with the same nameProvide the plugins a way to view the operation queue

*before*applying operations. This allows for on-the-fly modifications of the queue, allowing hardware-based plugins to support the full range of qubit expectation values. (#143)QNode return values now support

*any*form of sequence, such as lists, sets, etc. (#144)CV analytic gradient calculation is now more robust, allowing for operations which may not themselves be differentiated, but have a well defined

`_heisenberg_rep`

method, and so may succeed operations that are analytically differentiable (#152)

### Bug fixes

Fixed a bug where the variational classifier example was not batching when learning parity (see #128 and #129)

Fixed an inconsistency where some initial state operations were documented as accepting complex parameters - all operations now accept real values (#146)

### Contributors

This release contains contributions from:

Christian Gogolin, Josh Izaac, Nathan Killoran, and Maria Schuld.

## Release 0.1.0¶

Initial public release.

### Contributors

This release contains contributions from:Ville Bergholm, Josh Izaac, Maria Schuld, Christian Gogolin, and Nathan Killoran.

## Contents

## Downloads