Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions doc/releases/changelog-0.43.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,11 @@

<h4>Dynamic wire allocation 🎁</h4>

* A `DynamicRegister` can no longer be used as an individual wire itself, as this led to confusing results.

* Wires can now be dynamically allocated and deallocated in quantum functions with
:func:`~.allocate` and :func:`~.deallocate`. These features unlock many important applications
that rely on smart and efficient handling of wires, such as decompositions of gates that require
temporary auxiliary wires and logical patterns in subroutines that benefit from having dynamic
wire management.
auxiliary wires and logical patterns in subroutines that benefit from having dynamic wire
management.

[(#7718)](https://github.com/PennyLaneAI/pennylane/pull/7718)
[(#8151)](https://github.com/PennyLaneAI/pennylane/pull/8151)
Expand All @@ -81,12 +79,12 @@
The :func:`~.allocate` function can accept three arguments that dictate how dynamically allocated
wires are handled:

* `num_wires`: the number of wires to dynamically allocate.
* `state = "zero"/"any"`: the initial state that the dynamically allocated wires are requested to
be in. Currently, supported values are `"zero"` (initialize in the all-zero state) or `"any"`
(any arbitrary state).
* `restored = True/False`: a user-guarantee that the allocated wires will be restored to their
original state (`True`) or not (`False`) when those wires are deallocated.
* ``num_wires``: the number of wires to dynamically allocate.
* ``state = "zero"/"any"``: the initial state that the dynamically allocated wires are requested
to be in. Currently, supported values are ``"zero"`` (initialize in the all-zero state) or
``"any"`` (any arbitrary state).
* ``restored = True/False``: a user-guarantee that the allocated wires will be restored to their
original state (``True``) or not (``False``) when those wires are deallocated.

The recommended way to safely allocate and deallocate wires is to use :func:`~.allocate` as a
context manager:
Expand Down Expand Up @@ -127,7 +125,7 @@

For more complex dynamic allocation in circuits, PennyLane will resolve the dynamic allocation
calls in the most resource-efficient manner before sending the program to the device. Consider the
following circuit, which contains two dynamic allocations within a `for` loop.
following circuit, which contains two dynamic allocations within a ``for`` loop.

```python
@qml.qnode(qml.device("default.qubit"), mcm_method="tree-traversal")
Expand All @@ -139,7 +137,7 @@
with qml.allocate(1, state="any", restored=False) as new_qubit2:
m0 = qml.measure(new_qubit1[0], reset=True)
qml.cond(m0 == 1, qml.Z)(new_qubit2[0])
qml.CNOT((0, new_qubit2))
qml.CNOT((0, new_qubit2[0]))

return qml.expval(qml.Z(0))
```
Expand All @@ -156,9 +154,9 @@

The user-level circuit drawing shows four separate allocations and deallocations (two per loop
iteration). However, the circuit that the device receives gets automatically compiled to only use
**two** additional wires (wires labelled `1` and `2` in the diagram below). This is due to the
fact that `new_qubit1` and `new_qubit2` can both be reused after they've been deallocated in
the first iteration of the `for` loop:
**two** additional wires (wires labelled ``1`` and ``2`` in the diagram below). This is due to the
fact that ``new_qubit1`` and ``new_qubit2`` can both be reused after they've been deallocated in
the first iteration of the ``for`` loop:

```
>>> print(qml.draw(circuit, level="device")())
Expand All @@ -168,6 +166,9 @@
╚════════╝ ╚════════╝
```

Additionally, :func:`~.allocate` and :func:`~.deallocate` work with :func:`~.qjit` with
[some restrictions](https://docs.pennylane.ai/projects/catalyst/en/stable/dev/sharp_bits.html#functionality-differences-from-pennylane).

<h4>Resource tracking with Catalyst 👓</h4>

* The :func:`~.specs` function now supports programs compiled with :func:`~.qjit`.
Expand Down