Skip to content

Commit

Permalink
Merge branch 'master' into ad/shot-allocation-split-non-commuting
Browse files Browse the repository at this point in the history
  • Loading branch information
Shiro-Raven committed Jun 19, 2024
2 parents ea94f5f + 248a808 commit ce6d58e
Show file tree
Hide file tree
Showing 156 changed files with 3,497 additions and 1,362 deletions.
23 changes: 22 additions & 1 deletion doc/_static/draw_mpl/draw_mpl_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def rcparams(circuit):

def use_style(circuit):

fig, ax = qml.draw_mpl(circuit, style='sketch')(1.2345, 1.2345)
fig, ax = qml.draw_mpl(circuit, style="sketch")(1.2345, 1.2345)

plt.savefig(folder / "sketch_style.png")
plt.close()
Expand All @@ -128,6 +128,26 @@ def circuit():
plt.close()


@qml.transforms.merge_rotations
@qml.transforms.cancel_inverses
@qml.qnode(qml.device("default.qubit"), diff_method="parameter-shift")
def _levels_circ():
qml.RandomLayers([[1.0, 20]], wires=(0, 1))
qml.Permute([2, 1, 0], wires=(0, 1, 2))
qml.PauliX(0)
qml.PauliX(0)
qml.RX(0.1, wires=0)
qml.RX(-0.1, wires=0)
return qml.expval(qml.PauliX(0))


def levels():
for level in ("top", "user", None, slice(1, 2)):
draw_mpl(_levels_circ, level=level)()
plt.savefig(folder / f"level_{str(level).split('(')[0].lower()}.png")
plt.close


if __name__ == "__main__":

dev = qml.device("lightning.qubit", wires=(0, 1, 2, 3))
Expand All @@ -151,3 +171,4 @@ def circuit(x, z):
rcparams(circuit)
wires_labels(circuit)
mid_measure()
levels()
Binary file added doc/_static/draw_mpl/level_none.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/_static/draw_mpl/level_slice.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/_static/draw_mpl/level_top.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/_static/draw_mpl/level_user.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 9 additions & 1 deletion doc/code/qml_noise.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ qml.noise
This module contains the functionality for building and manipulating insertion-based noise models,
where noisy gates and channels are inserted based on the target operations.

.. _intro_noise_model:

Overview
--------

Expand All @@ -22,7 +24,13 @@ noise-related metadata can also be supplied to construct a noise model using:
Each conditional in the ``model_map`` evaluates the gate operations in the quantum circuit based on
some condition of its attributes (e.g., type, parameters, wires, etc.) and use the corresponding
callable to apply the noise operations, using the user-provided metadata (e.g., hardware topologies
or relaxation times), whenever the condition results true.
or relaxation times), whenever the condition results true. A noise model once built can be attached
to a circuit or device via the following transform:

.. autosummary::
:toctree: api

~add_noise

.. _intro_boolean_fn:

Expand Down
86 changes: 67 additions & 19 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,34 +47,59 @@
* The `default.tensor` device is introduced to perform tensor network simulations of quantum circuits using the `mps` (Matrix Product State) method.
[(#5699)](https://github.com/PennyLaneAI/pennylane/pull/5699)

* Added `from_openfermion` to convert openfermion `FermionOperator` objects to PennyLane `FermiWord` or
`FermiSentence` objects.
[(#5808)](https://github.com/PennyLaneAI/pennylane/pull/5808)

```python
of_op = openfermion.FermionOperator('0^ 2')
pl_op = qml.from_openfermion(of_op)
* A new `qml.noise` module which contains utility function for building `NoiseModels`
and an `add_noise` tranform for addding it to quantum circuits.
[(#5674)](https://github.com/PennyLaneAI/pennylane/pull/5674)
[(#5684)](https://github.com/PennyLaneAI/pennylane/pull/5684)
[(#5718)](https://github.com/PennyLaneAI/pennylane/pull/5718)

```pycon
>>> fcond1 = qml.noise.op_eq(qml.RX) & qml.noise.wires_in([0, 1])
>>> noise1 = qml.noise.partial_wires(qml.PhaseDamping, 0.4)
>>> fcond2 = qml.noise.op_in([qml.RY, qml.RZ])
>>> def noise2(op, **kwargs):
... qml.ThermalRelaxationError(op.parameters[0] * 0.05, kwargs["t1"], 0.2, 0.6, op.wires)
>>> noise_model = qml.NoiseModel({fcond1: noise1, fcond2: noise2}, t1=2.0)
>>> noise_model
NoiseModel({
OpEq(RX) & WiresIn([0, 1]) = PhaseDamping(gamma=0.4)
OpIn(['RY', 'RZ']) = noise2
}, t1 = 2.0)
```

```pycon
>>> print(pl_op)
a⁺(0) a(2)
>>> @partial(qml.transforms.add_noise, noise_model=noise_model)
... @qml.qnode(dev)
... def circuit(w, x, y, z):
... qml.RX(w, wires=0)
... qml.RY(x, wires=1)
... qml.CNOT(wires=[0, 1])
... qml.RY(y, wires=0)
... qml.RX(z, wires=1)
... return qml.expval(qml.Z(0) @ qml.Z(1))
>>> print(qml.draw(circuit)(0.9, 0.4, 0.5, 0.6))
0: ──RX(0.90)──PhaseDamping(0.40)──────────────────────────╭●──RY(0.50)
1: ──RY(0.40)──ThermalRelaxationError(0.02,2.00,0.20,0.60)─╰X──RX(0.60)
───ThermalRelaxationError(0.03,2.00,0.20,0.60)─┤ ╭<Z@Z>
───PhaseDamping(0.40)──────────────────────────┤ ╰<Z@Z>
```

* A new `qml.noise` module which contains utililty functions for building `NoiseModels`.
[(#5674)](https://github.com/PennyLaneAI/pennylane/pull/5674)
[(#5684)](https://github.com/PennyLaneAI/pennylane/pull/5684)
* The ``from_openfermion`` and ``to_openfermion`` functions are added to convert between
OpenFermion and PennyLane objects.
[(#5773)](https://github.com/PennyLaneAI/pennylane/pull/5773)
[(#5808)](https://github.com/PennyLaneAI/pennylane/pull/5808)

```python
fcond = qml.noise.op_eq(qml.X) | qml.noise.op_eq(qml.Y)
noise = qml.noise.partial_wires(qml.AmplitudeDamping, 0.4)
of_op = openfermion.FermionOperator('0^ 2')
pl_op = qml.from_openfermion(of_op)
of_op_new = qml.to_openfermion(pl_op)
```

```pycon
>>> qml.NoiseModel({fcond: noise}, t1=0.04)
NoiseModel({
OpEq(PauliX) | OpEq(PauliY) = AmplitudeDamping(gamma=0.4)
}, t1 = 0.04)
>>> print(pl_op)
a⁺(0) a(2)
>>> print(of_op_new)
1.0 [0^ 2]
```

<h3>Improvements 🛠</h3>
Expand Down Expand Up @@ -230,6 +255,7 @@

* Sets up the framework for the development of an `assert_equal` function for testing operator comparison.
[(#5634)](https://github.com/PennyLaneAI/pennylane/pull/5634)
[(#5858)](https://github.com/PennyLaneAI/pennylane/pull/5858)

* `qml.sample` can now be used on Boolean values representing mid-circuit measurement results in
traced quantum functions. This feature is used with Catalyst to enable the pattern
Expand Down Expand Up @@ -291,12 +317,20 @@
* `specs()` can now be requested at any specific point of the transform program through the `level` keyword argument.
[(#5781)](https://github.com/PennyLaneAI/pennylane/pull/5781/)

* The `qml.snapshots` transform now supports arbitrary devices by running a separate tape for each snapshot for unsupported devices.
[(#5805)](https://github.com/PennyLaneAI/pennylane/pull/5805)

* The `qml.Snapshot` operator now accepts sample-based measurements for finite-shot devices.
[(#5805)](https://github.com/PennyLaneAI/pennylane/pull/5805)
* Device preprocess transforms now happen inside the ml boundary.
[(#5791)](https://github.com/PennyLaneAI/pennylane/pull/5791)

* `qml.qchem.molecular_dipole` function is added for calculating the dipole operator using "dhf" and "openfermion" backends.
[(#5764)](https://github.com/PennyLaneAI/pennylane/pull/5764)

* Circuits can now be plotted at any specific point of the transform program through the `level` keyword argument in `draw()` and `draw_mpl()`.
[(#5855)](https://github.com/PennyLaneAI/pennylane/pull/5855)

* Transforms applied to callables now use `functools.wraps` to preserve the docstring and call signature of the original function.
[(#5857)](https://github.com/PennyLaneAI/pennylane/pull/5857)

Expand All @@ -309,7 +343,8 @@
[(#5502)](https://github.com/PennyLaneAI/pennylane/pull/5502)

* Implement support in `assert_equal` for `Operator`, `Controlled`, `Adjoint`, `Pow`, `Exp`, `SProd`, `ControlledSequence`, `Prod`, `Sum`, `Tensor` and `Hamiltonian`
[(#5780)](https://github.com/PennyLaneAI/pennylane/pull/5780)
[(#5780)](https://github.com/PennyLaneAI/pennylane/pull/5780)
[(#5877)](https://github.com/PennyLaneAI/pennylane/pull/5877)

* `qml.QutritChannel` has been added, enabling the specification of noise using a collection of (3x3) Kraus matrices on the `default.qutrit.mixed` device.
[(#5793)](https://github.com/PennyLaneAI/pennylane/issues/5793)
Expand Down Expand Up @@ -472,6 +507,15 @@
* `qml.matrix` is now compatible with qnodes compiled by catalyst.qjit.
[(#5753)](https://github.com/PennyLaneAI/pennylane/pull/5753)

* `qml.snapshots` raises an error when a measurement other than `qml.state` is requested from `default.qubit.legacy` instead of silently returning the statevector.
[(#5805)](https://github.com/PennyLaneAI/pennylane/pull/5805)

* Fixes a bug where `default.qutrit` is falsely determined to be natively compatible with `qml.snapshots`.
[(#5805)](https://github.com/PennyLaneAI/pennylane/pull/5805)

* Fixes a bug where the measurement of a `qml.Snapshot` instance is not passed on during the `qml.adjoint` and `qml.ctrl` operations.
[(#5805)](https://github.com/PennyLaneAI/pennylane/pull/5805)

* `CNOT` and `Toffoli` now have an `arithmetic_depth` of `1`, as they are controlled operations.
[(#5797)](https://github.com/PennyLaneAI/pennylane/pull/5797)

Expand All @@ -487,6 +531,9 @@
* Fix bug where `CompositeOp.overlapping_ops` sometimes puts overlapping ops in different groups, leading to incorrect results returned by `LinearCombination.eigvals()`
[(#5847)](https://github.com/PennyLaneAI/pennylane/pull/5847)

* `qml.pauli_decompose` now works in a jit-ted context, such as `jax.jit` and `catalyst.qjit`.
[(#5878)](https://github.com/PennyLaneAI/pennylane/pull/5878)

<h3>Contributors ✍️</h3>

This release contains contributions from (in alphabetical order):
Expand All @@ -503,6 +550,7 @@ Isaac De Vlugt,
Diksha Dhawan,
Pietropaolo Frisoni,
Emiliano Godinez,
Daria Van Hende,
Austin Huang,
David Ittah,
Soran Jahangiri,
Expand Down
3 changes: 3 additions & 0 deletions pennylane/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
taper_operation,
import_operator,
from_openfermion,
to_openfermion,
)
from pennylane._device import Device, DeviceError
from pennylane._grad import grad, jacobian, vjp, jvp
Expand Down Expand Up @@ -104,11 +105,13 @@
pattern_matching,
pattern_matching_optimization,
clifford_t_decomposition,
add_noise,
)
from pennylane.ops.functions import (
dot,
eigvals,
equal,
assert_equal,
evolve,
generator,
is_commuting,
Expand Down
Loading

0 comments on commit ce6d58e

Please sign in to comment.