Skip to content

Commit

Permalink
Merge branch 'master' into measured_wires_on_qscript
Browse files Browse the repository at this point in the history
  • Loading branch information
comp-phys-marc committed Jun 19, 2024
2 parents ad23512 + 248a808 commit 67279c4
Show file tree
Hide file tree
Showing 23 changed files with 1,380 additions and 296 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
42 changes: 33 additions & 9 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,41 @@
* 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)

* A new `qml.noise` module which contains utililty functions for building `NoiseModels`.
* 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)

```python
fcond = qml.noise.op_eq(qml.X) | qml.noise.op_eq(qml.Y)
noise = qml.noise.partial_wires(qml.AmplitudeDamping, 0.4)
```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
>>> qml.NoiseModel({fcond: noise}, t1=0.04)
NoiseModel({
OpEq(PauliX) | OpEq(PauliY) = AmplitudeDamping(gamma=0.4)
}, t1 = 0.04)
>>> @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>
```

* The ``from_openfermion`` and ``to_openfermion`` functions are added to convert between
Expand All @@ -72,8 +93,8 @@
of_op = openfermion.FermionOperator('0^ 2')
pl_op = qml.from_openfermion(of_op)
of_op_new = qml.to_openfermion(pl_op)

```

```pycon
>>> print(pl_op)
a⁺(0) a(2)
Expand Down Expand Up @@ -307,6 +328,9 @@
* `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 Down
1 change: 1 addition & 0 deletions pennylane/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
pattern_matching,
pattern_matching_optimization,
clifford_t_decomposition,
add_noise,
)
from pennylane.ops.functions import (
dot,
Expand Down
Loading

0 comments on commit 67279c4

Please sign in to comment.