PennyLane
  • Why PennyLane
  • Getting Started
  • Documentation
  • Ecosystem
Install
Install
  1. Blog/
  2. Releases/
  3. PennyLane v0.33 released

October 31, 2023

PennyLane v0.33 released

Isaac De Vlugt

Isaac De Vlugt

Thomas Bromley

Thomas Bromley

PennyLane v0.33 just dropped in time for Halloween, and itโ€™s scary good ๐Ÿ‘น! Check out the terrifyingly terrific new functionality below.

Contents

  • Postselection and statistics in mid-circuit measurements ๐Ÿ“Œ
  • Flexible Trotter products ๐Ÿ–
  • Pulse programming with OQC hardware โš›๏ธ๐Ÿ”ฌ
  • Modular Quantum Phase Estimation ๐Ÿงฉ
  • New device capabilities, Catalyst integration, and more! โš—๏ธ
  • Improvements ๐Ÿ› ๏ธ
  • Deprecations and breaking changes ๐Ÿ’”
  • Contributors โœ๏ธ

Postselection and statistics in mid-circuit measurements ๐Ÿ“Œ

Trick or treat? You decide ๐ŸŽƒ๐Ÿฌ. Postselecting qubits and gathering statistics of mid-circuit measurements are now available in v0.33 ๐Ÿ™Œ

In the last release, we introduced reusing and resetting qubits after a mid-circuit measurement. With this release, we've added more features to mid-circuit measurements:

  • Postselection after mid-circuit measurements can now be performed by specifying
    the postselect keyword argument in qml.measure as either 0 or 1, corresponding to the basis states.

    import pennylane as qml dev = qml.device("default.qubit", wires=1) @qml.qnode(dev) def circuit(): qml.Hadamard(0) m = qml.measure(0, postselect=1) return qml.probs(wires=0)
    >>> circuit() tensor([0., 1.], requires_grad=True)
  • Mid-circuit measurement statistics can be obtained from QNode returns:

    dev = qml.device("default.qubit") @qml.qnode(dev) def circ(x, y): qml.RX(x, wires=0) qml.RY(y, wires=1) m0 = qml.measure(1) return qml.expval(qml.PauliZ(0)), qml.expval(m0), qml.sample(m0)
    >>> circ(1.0, 2.0, shots=10000) (0.5606, 0.7089, array([0, 1, 1, ..., 1, 1, 1]))

    Support is provided for both finite-shot and analytic modes and devices default to using the deferred measurement principle to enact the mid-circuit measurements.

In future releases, we will be exploring the ability to combine and manipulate mid-circuit measurements such as qml.expval(m0 @ m1) or qml.expval(m0 @ qml.PauliZ(0)). Stay tuned!

Flexible Trotter products ๐Ÿ–

Want better Trotter decomposition functionality? Fright this way ๐Ÿ˜ฑ

With this release, we're putting some points into Hamiltonian simulation techniques that are based on Trotterization.

  • Higher-order Suzukiโ€“Trotter methods are now easily accessible through a new operation called TrotterProduct. The Suzukiโ€“Trotter product formula allows for the ability to express higher-order approximations to the matrix exponential of a Hamiltonian, letting you use Trotterization techniques as an effective route towards accurate and efficient Hamiltonian simulation. Simply specify the order of the approximation and the evolution time:

    coeffs = [0.25, 0.75] ops = [qml.PauliX(0), qml.PauliZ(0)] H = qml.dot(coeffs, ops) dev = qml.device("default.qubit", wires=2) @qml.qnode(dev) def circuit(): qml.Hadamard(0) qml.TrotterProduct(H, time=2.4, order=2) return qml.state()
    >>> circuit() [-0.13259524+0.59790098j 0. +0.j -0.13259524-0.77932754j 0. +0.j ]
  • The quantum stochastic drift protocol for approximating matrix exponentiation with random product formulas, qDrift, is now available with the new QDrift operation. As shown in 1811.08017, qDrift is a Markovian process that can provide a speedup in Hamiltonian simulation. At a high level, qDrift works by randomly sampling from the Hamiltonian terms with a probability that depends on the Hamiltonian coefficients. This method for Hamiltonian simulation is now ready to use in PennyLane with the QDrift operator. Simply specify the evolution time and the number of samples drawn from the Hamiltonian, n:

    coeffs = [0.25, 0.75] ops = [qml.PauliX(0), qml.PauliZ(0)] H = qml.dot(coeffs, ops) dev = qml.device("default.qubit", wires=2) @qml.qnode(dev) def circuit(): qml.Hadamard(0) qml.QDrift(H, time=1.2, n = 10) return qml.probs()
    >>> circuit() array([0.61814334, 0. , 0.38185666, 0. ])

Pulse programming with OQC hardware โš›๏ธ๐Ÿ”ฌ

PennyLane-Braket is creepinโ€™ it real ๐Ÿ’€

Now you can run pulse-level circuits on the 8-qubit Lucy device from Oxford Quantum Circuits (OQC). This new hardware support is provided through the Amazon Braket service, so you'll need to install the PennyLane-Braket plugin to get it up and running. Once you're ready, head on over to our hot-off-the-press Pulse programming demo to learn more!

This release of PennyLane concludes our year-long push to add pulse-level support to PennyLane ๐ŸŽ‰. We started in v0.29 with pulse-based circuits and simulation and then unlocked hardware support on QuEra in v0.30. Have you enjoyed working with pulse programs in PennyLane or has it been a nightmare? ๐Ÿ˜ฑ Would you like to see more pulse support in 2024? Let us know by filling out our PennyLane user survey!

Modular Quantum Phase Estimation ๐Ÿงฉ

Create zombified QPE algorithms by stitching together these new features ๐ŸงŸ

Quantum phase estimation (QPE) is a staple quantum algorithm, and recent research has delivered some new ways of looking at it by way of modifications to bits and pieces of the algorithm at large. Motivated by these advancements, we've added two new operators that facilitate the modularization of QPE and more!

  • Controlled gate sequences raised to decreasing powers, a sub-block in QPE, can now be created with the new ControlledSequence operator. Applying sequences of controlled unitary operations raised to decreasing powers is a key part in QPE. The new ControlledSequence operator allows for the ability to create just this part of the algorithm.

    To use ControlledSequence, specify the controlled unitary operator and the control wires, control:

    dev = qml.device("default.qubit", wires = 4) @qml.qnode(dev) def circuit(): for i in range(3): qml.Hadamard(wires = i) qml.ControlledSequence(qml.RX(0.25, wires = 3), control = [0, 1, 2]) qml.adjoint(qml.QFT)(wires = range(3)) return qml.probs(wires = range(3))
    >>> print(circuit()) [0.92059345 0.02637178 0.00729619 0.00423258 0.00360545 0.00423258 0.00729619 0.02637178]
  • A new operator called CosineWindow has been added to prepare an initial state based on a cosine wave function. As outlined in 2110.09590, the cosine tapering window is part of a modification to QPE that can provide a cubic improvement to the algorithm's error rate. Using CosineWindow will prepare a state whose amplitudes follow a cosinusoidal distribution over the computational basis.

    import matplotlib.pyplot as plt dev = qml.device('default.qubit', wires=4) @qml.qnode(dev) def example_circuit(): qml.CosineWindow(wires=range(4)) return qml.state() output = example_circuit() plt.style.use("pennylane.drawer.plot") plt.bar(range(len(output)), output) plt.show()

New device capabilities, Catalyst integration, and more! โš—๏ธ

We think these new device changes are fang-tastic ๐Ÿฆท

With this v0.33 release, default.qubit has been totally revamped to use our new qml.devices.Device API and functionality in qml.devices.qubit. This change has several benefits, most notably that the number of wires is now optional โ€” simply having qml.device("default.qubit") is valid! If wires are not provided at instantiation, the device automatically infers the required number of wires for each circuit provided for execution.

dev = qml.device("default.qubit") # no wires specified! @qml.qnode(dev) def circuit(): qml.PauliZ(0) qml.RZ(0.1, wires=1) qml.Hadamard(2) return qml.state()
>>> print(qml.draw(circuit)()) 0: โ”€โ”€Zโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค State 1: โ”€โ”€RZ(0.10)โ”€โ”ค State 2: โ”€โ”€Hโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค State

If you experience any issues with the updated default.qubit, please let us know by posting an issue. The old version of the device is still accessible by the short name default.qubit.legacy, or directly via qml.devices.DefaultQubitLegacy.

Improvements ๐Ÿ› ๏ธ

In addition to the new features listed above, the release contains a wide array of improvements and optimizations:

  • A QNode that has been decorated with qjit from PennyLane's Catalyst library for just-in-time hybrid compilation is now compatible with qml.draw.

  • qml.qchem.import_state has been extended to import more quantum chemistry wavefunctions, from MPS, DMRG and SHCI classical calculations performed with the Block2 and Dice libraries.

    Check out our how-to guide to learn more about how PennyLane integrates with your favourite quantum chemistry libraries.

  • MeasurementProcess and QuantumScript objects are now registered as JAX PyTrees. It is now possible to JIT-compile functions with arguments that are a MeasurementProcess or a QuantumScript.

  • qml.cut_circuit is now compatible with circuits that compute the expectation values of Hamiltonians with two or more terms.

Deprecations and breaking changes ๐Ÿ’”

As new things are added, outdated features are removed. To keep track of things in the deprecation pipeline, check out the deprecations page.

Here's a summary of what has changed in this release:

  • The old return type and associated functions qml.enable_return and qml.disable_return have been removed.

  • qml.defer_measurements now raises an error if a transformed circuit measures qml.probs, qml.sample, or qml.counts without any wires or observable, or if it measures qml.state.

  • Using == with operators and measurement processes will now behave the same as qml.equal.

    op1 = qml.PauliX(0) op2 = qml.PauliX(0) op3 = op1
    >>> op1 == op2 True >>> op1 == op3 True

These highlights are just scratching the surface โ€” check out the full release notes for more details, and let us know how you're liking the new release in the PennyLane v0.33 survey.

Contributors โœ๏ธ

As always, this release would not have been possible without the hard work of our development team and contributors:

Guillermo Alonso, Ali Asadi, Utkarsh Azad, Thomas Bromley, Isaac De Vlugt, Jack Brown, Amintor Dusko, Tarik El-Khateeb, Stepan Fomichev, Joana Fraxanet, Diego Guala, Soran Jahangiri, Edward Jiang, Korbinian Kottmann, Ivana Kureฤiฤ‡, Christina Lee, Lillian M. A. Frederiksen, Vincent Michaud-Rioux, Romain Moyard, Daniel F. Nino, Lee James O'Riordan, Mudit Pandey, Shuli Shu, Matthew Silverman, Jay Soni.

About the authors

Isaac De Vlugt
Isaac De Vlugt

Isaac De Vlugt

My job is to help manage the PennyLane and Catalyst feature roadmap... and spam lots of emojis in the chat ๐Ÿค 

Thomas Bromley
Thomas Bromley

Thomas Bromley

Last modified:ย August 14, 2024

Related Blog Posts

PennyLane

PennyLane is an open-source software framework for quantum machine learning, quantum chemistry, and quantum computing, with the ability to run on all hardware. Built with โค๏ธ by Xanadu.

Stay updated with our newsletter

For researchers

  • Research
  • Features
  • Demos
  • Compilation
  • Datasets
  • Performance
  • Learn
  • Videos
  • Documentation
  • Teach

For learners

  • Learn
  • Codebook
  • Teach
  • Videos
  • Challenges
  • Demos
  • Compilation
  • Glossary

For developers

  • Features
  • Documentation
  • API
  • GitHub
  • Datasets
  • Demos
  • Compilation
  • Performance
  • Devices
  • Catalyst

ยฉ Copyright 2025 | Xanadu | All rights reserved

TensorFlow, the TensorFlow logo and any related marks are trademarks of Google Inc.

Privacy Policy|Terms of Service|Cookie Policy|Code of Conduct