Closed renovate[bot] closed 1 year ago
:exclamation: No coverage uploaded for pull request base (
main@8f6f6d9
). Click here to learn what that means. The diff coverage isn/a
.:exclamation: Current head 992403a differs from pull request most recent head 4aea15a. Consider uploading reports for the commit 4aea15a to get more accurate results
@@ Coverage Diff @@
## main #228 +/- ##
=======================================
Coverage ? 92.54%
=======================================
Files ? 12
Lines ? 993
Branches ? 191
=======================================
Hits ? 919
Misses ? 41
Partials ? 33
:mega: Weโre building smart automated test selection to slash your CI/CD build times. Learn more
Renovate failed to update an artifact related to this branch. You probably do not want to merge this PR as-is.
โป Renovate will retry this branch, including artifacts, only when one of the following happens:
The artifact failure details are included below:
installing v2 tool python v3.11.1
linking tool python v3.11.1
Python 3.11.1
pip 23.0 from /opt/buildpack/tools/python/3.11.1/lib/python3.11/site-packages/pip (python 3.11)
Installed v2 /usr/local/buildpack/tools/v2/python.sh in 9 seconds
skip cleanup, not a docker build: d9339759cb9c
Collecting poetry
Downloading poetry-1.3.2-py3-none-any.whl (218 kB)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 218.9/218.9 kB 7.1 MB/s eta 0:00:00
Collecting cachecontrol[filecache]<0.13.0,>=0.12.9
Downloading CacheControl-0.12.11-py2.py3-none-any.whl (21 kB)
Collecting cleo<3.0.0,>=2.0.0
Downloading cleo-2.0.1-py3-none-any.whl (77 kB)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 77.3/77.3 kB 19.2 MB/s eta 0:00:00
Collecting crashtest<0.5.0,>=0.4.1
Downloading crashtest-0.4.1-py3-none-any.whl (7.6 kB)
Collecting dulwich<0.21.0,>=0.20.46
Downloading dulwich-0.20.50-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (501 kB)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 501.7/501.7 kB 27.0 MB/s eta 0:00:00
Requirement already satisfied: filelock<4.0.0,>=3.8.0 in /opt/buildpack/tools/python/3.11.1/lib/python3.11/site-packages (from poetry) (3.9.0)
Collecting html5lib<2.0,>=1.0
Downloading html5lib-1.1-py2.py3-none-any.whl (112 kB)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 112.2/112.2 kB 24.8 MB/s eta 0:00:00
Collecting jsonschema<5.0.0,>=4.10.0
Downloading jsonschema-4.17.3-py3-none-any.whl (90 kB)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 90.4/90.4 kB 19.4 MB/s eta 0:00:00
Collecting keyring<24.0.0,>=23.9.0
Downloading keyring-23.13.1-py3-none-any.whl (37 kB)
Collecting lockfile<0.13.0,>=0.12.2
Downloading lockfile-0.12.2-py2.py3-none-any.whl (13 kB)
Collecting packaging>=20.4
Downloading packaging-23.0-py3-none-any.whl (42 kB)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 42.7/42.7 kB 9.9 MB/s eta 0:00:00
Collecting pexpect<5.0.0,>=4.7.0
Downloading pexpect-4.8.0-py2.py3-none-any.whl (59 kB)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 59.0/59.0 kB 13.0 MB/s eta 0:00:00
Collecting pkginfo<2.0,>=1.5
Downloading pkginfo-1.9.6-py3-none-any.whl (30 kB)
Requirement already satisfied: platformdirs<3.0.0,>=2.5.2 in /opt/buildpack/tools/python/3.11.1/lib/python3.11/site-packages (from poetry) (2.6.2)
Collecting poetry-core==1.4.0
Downloading poetry_core-1.4.0-py3-none-any.whl (546 kB)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 546.4/546.4 kB 52.2 MB/s eta 0:00:00
Collecting poetry-plugin-export<2.0.0,>=1.2.0
Downloading poetry_plugin_export-1.3.0-py3-none-any.whl (10 kB)
Collecting requests<3.0,>=2.18
Downloading requests-2.28.2-py3-none-any.whl (62 kB)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 62.8/62.8 kB 15.0 MB/s eta 0:00:00
Collecting requests-toolbelt<0.11.0,>=0.9.1
Downloading requests_toolbelt-0.10.1-py2.py3-none-any.whl (54 kB)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 54.5/54.5 kB 12.7 MB/s eta 0:00:00
Collecting shellingham<2.0,>=1.5
Downloading shellingham-1.5.0.post1-py2.py3-none-any.whl (9.4 kB)
Collecting tomlkit!=0.11.2,!=0.11.3,<1.0.0,>=0.11.1
Downloading tomlkit-0.11.6-py3-none-any.whl (35 kB)
Collecting trove-classifiers>=2022.5.19
Downloading trove_classifiers-2023.1.20-py3-none-any.whl (13 kB)
Collecting urllib3<2.0.0,>=1.26.0
Downloading urllib3-1.26.14-py2.py3-none-any.whl (140 kB)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 140.6/140.6 kB 25.5 MB/s eta 0:00:00
Requirement already satisfied: virtualenv!=20.4.5,!=20.4.6,<21.0.0,>=20.4.3 in /opt/buildpack/tools/python/3.11.1/lib/python3.11/site-packages (from poetry) (20.17.1)
Collecting msgpack>=0.5.2
Downloading msgpack-1.0.4.tar.gz (128 kB)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 128.1/128.1 kB 27.7 MB/s eta 0:00:00
Installing build dependencies: started
Installing build dependencies: finished with status 'done'
Getting requirements to build wheel: started
Getting requirements to build wheel: finished with status 'done'
Installing backend dependencies: started
Installing backend dependencies: finished with status 'done'
Preparing metadata (pyproject.toml): started
Preparing metadata (pyproject.toml): finished with status 'done'
Collecting rapidfuzz<3.0.0,>=2.2.0
Downloading rapidfuzz-2.13.7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.2 MB)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 2.2/2.2 MB 52.7 MB/s eta 0:00:00
Collecting six>=1.9
Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)
Collecting webencodings
Downloading webencodings-0.5.1-py2.py3-none-any.whl (11 kB)
Collecting attrs>=17.4.0
Downloading attrs-22.2.0-py3-none-any.whl (60 kB)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 60.0/60.0 kB 11.3 MB/s eta 0:00:00
Collecting pyrsistent!=0.17.0,!=0.17.1,!=0.17.2,>=0.14.0
Downloading pyrsistent-0.19.3-py3-none-any.whl (57 kB)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 57.5/57.5 kB 12.2 MB/s eta 0:00:00
Collecting jaraco.classes
Downloading jaraco.classes-3.2.3-py3-none-any.whl (6.0 kB)
Collecting importlib-metadata>=4.11.4
Downloading importlib_metadata-6.0.0-py3-none-any.whl (21 kB)
Collecting SecretStorage>=3.2
Downloading SecretStorage-3.3.3-py3-none-any.whl (15 kB)
Collecting jeepney>=0.4.2
Downloading jeepney-0.8.0-py3-none-any.whl (48 kB)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 48.4/48.4 kB 10.1 MB/s eta 0:00:00
Collecting ptyprocess>=0.5
Downloading ptyprocess-0.7.0-py2.py3-none-any.whl (13 kB)
Collecting charset-normalizer<4,>=2
Downloading charset_normalizer-3.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (196 kB)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 196.8/196.8 kB 34.5 MB/s eta 0:00:00
Collecting idna<4,>=2.5
Downloading idna-3.4-py3-none-any.whl (61 kB)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 61.5/61.5 kB 14.6 MB/s eta 0:00:00
Collecting certifi>=2017.4.17
Downloading certifi-2022.12.7-py3-none-any.whl (155 kB)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 155.3/155.3 kB 27.0 MB/s eta 0:00:00
Requirement already satisfied: distlib<1,>=0.3.6 in /opt/buildpack/tools/python/3.11.1/lib/python3.11/site-packages (from virtualenv!=20.4.5,!=20.4.6,<21.0.0,>=20.4.3->poetry) (0.3.6)
Collecting zipp>=0.5
Downloading zipp-3.12.0-py3-none-any.whl (6.6 kB)
Collecting cryptography>=2.0
Downloading cryptography-39.0.0-cp36-abi3-manylinux_2_28_x86_64.whl (4.2 MB)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 4.2/4.2 MB 60.5 MB/s eta 0:00:00
Collecting more-itertools
Downloading more_itertools-9.0.0-py3-none-any.whl (52 kB)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 52.8/52.8 kB 13.2 MB/s eta 0:00:00
Collecting cffi>=1.12
Downloading cffi-1.15.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (462 kB)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 462.6/462.6 kB 51.7 MB/s eta 0:00:00
Collecting pycparser
Downloading pycparser-2.21-py2.py3-none-any.whl (118 kB)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 118.7/118.7 kB 26.3 MB/s eta 0:00:00
Building wheels for collected packages: msgpack
Building wheel for msgpack (pyproject.toml): started
Building wheel for msgpack (pyproject.toml): finished with status 'done'
Created wheel for msgpack: filename=msgpack-1.0.4-cp311-cp311-linux_x86_64.whl size=330799 sha256=9d9500013501c6491d38961aa335a63d6df9ca29611920ab0dde600d81d0a732
Stored in directory: /tmp/renovate-cache/others/pip/wheels/55/e6/d3/5defbcadbaa60a8bc20e1d233aa52941a1fbe2707b11f9066d
Successfully built msgpack
Installing collected packages: webencodings, trove-classifiers, ptyprocess, msgpack, lockfile, charset-normalizer, zipp, urllib3, tomlkit, six, shellingham, rapidfuzz, pyrsistent, pycparser, poetry-core, pkginfo, pexpect, packaging, more-itertools, jeepney, idna, crashtest, certifi, attrs, requests, jsonschema, jaraco.classes, importlib-metadata, html5lib, dulwich, cleo, cffi, requests-toolbelt, cryptography, cachecontrol, SecretStorage, keyring, poetry-plugin-export, poetry
Successfully installed SecretStorage-3.3.3 attrs-22.2.0 cachecontrol-0.12.11 certifi-2022.12.7 cffi-1.15.1 charset-normalizer-3.0.1 cleo-2.0.1 crashtest-0.4.1 cryptography-39.0.0 dulwich-0.20.50 html5lib-1.1 idna-3.4 importlib-metadata-6.0.0 jaraco.classes-3.2.3 jeepney-0.8.0 jsonschema-4.17.3 keyring-23.13.1 lockfile-0.12.2 more-itertools-9.0.0 msgpack-1.0.4 packaging-23.0 pexpect-4.8.0 pkginfo-1.9.6 poetry-1.3.2 poetry-core-1.4.0 poetry-plugin-export-1.3.0 ptyprocess-0.7.0 pycparser-2.21 pyrsistent-0.19.3 rapidfuzz-2.13.7 requests-2.28.2 requests-toolbelt-0.10.1 shellingham-1.5.0.post1 six-1.16.0 tomlkit-0.11.6 trove-classifiers-2023.1.20 urllib3-1.26.14 webencodings-0.5.1 zipp-3.12.0
Updating dependencies
Resolving dependencies...
Creating virtualenv skqulacs in /mnt/renovate/gh/Qulacs-Osaka/scikit-qulacs/.venv
Because no versions of pennylane match >0.28.0,<0.29.0
and pennylane (0.28.0) depends on numpy (<1.24), pennylane (>=0.28.0,<0.29.0) requires numpy (<1.24).
So, because skqulacs depends on both numpy (~1.24.0) and PennyLane (^0.28.0), version solving failed.
As this PR has been closed unmerged, Renovate will now ignore this update (^0.28.0). You will still receive a PR once a newer version is released, so if you wish to permanently ignore this dependency, please add it to the ignoreDeps
array of your renovate config.
If this PR was closed by mistake or you changed your mind, you can simply rename this PR and you will soon get a fresh replacement PR opened.
This PR contains the following updates:
^0.24.0
->^0.28.0
Release Notes
XanaduAI/pennylane
### [`v0.28.0`](https://togithub.com/PennyLaneAI/pennylane/releases/tag/v0.28.0): Release 0.28.0 [Compare Source](https://togithub.com/XanaduAI/pennylane/compare/v0.27.0...v0.28.0)New features since last release
Custom measurement processes ๐
- Custom measurements can now be facilitated with the addition of the `qml.measurements` module. [(#3286)](https://togithub.com/PennyLaneAI/pennylane/pull/3286) [(#3343)](https://togithub.com/PennyLaneAI/pennylane/pull/3343) [(#3288)](https://togithub.com/PennyLaneAI/pennylane/pull/3288) [(#3312)](https://togithub.com/PennyLaneAI/pennylane/pull/3312) [(#3287)](https://togithub.com/PennyLaneAI/pennylane/pull/3287) [(#3292)](https://togithub.com/PennyLaneAI/pennylane/pull/3292) [(#3287)](https://togithub.com/PennyLaneAI/pennylane/pull/3287) [(#3326)](https://togithub.com/PennyLaneAI/pennylane/pull/3326) [(#3327)](https://togithub.com/PennyLaneAI/pennylane/pull/3327) [(#3388)](https://togithub.com/PennyLaneAI/pennylane/pull/3388) [(#3439)](https://togithub.com/PennyLaneAI/pennylane/pull/3439) [(#3466)](https://togithub.com/PennyLaneAI/pennylane/pull/3466) Within `qml.measurements` are new subclasses that allow for the possibility to create *custom* measurements: - `SampleMeasurement`: represents a sample-based measurement - `StateMeasurement`: represents a state-based measurement - `MeasurementTransform`: represents a measurement process that requires the application of a batch transform Creating a custom measurement involves making a class that inherits from one of the classes above. An example is given below. Here, the measurement computes the number of samples obtained of a given state: ```python from pennylane.measurements import SampleMeasurement class CountState(SampleMeasurement): def __init__(self, state: str): self.state = state # string identifying the state, e.g. "0101" wires = list(range(len(state))) super().__init__(wires=wires) def process_samples(self, samples, wire_order, shot_range, bin_size): counts_mp = qml.counts(wires=self._wires) counts = counts_mp.process_samples(samples, wire_order, shot_range, bin_size) return counts.get(self.state, 0) def __copy__(self): return CountState(state=self.state) ``` We can now execute the new measurement in a QNode as follows. ```python dev = qml.device("default.qubit", wires=1, shots=10000) @qml.qnode(dev) def circuit(x): qml.RX(x, wires=0) return CountState(state="1") ``` ```pycon >>> circuit(1.23) tensor(3303., requires_grad=True) ``` Differentiability is also supported for this new measurement process: ```pycon >>> x = qml.numpy.array(1.23, requires_grad=True) >>> qml.grad(circuit)(x) 4715.000000000001 ``` For more information about these new features, see the documentation for [`qml.measurements`](https://docs.pennylane.ai/en/stable/code/qml_measurements.html).ZX Calculus ๐งฎ
- QNodes can now be converted into ZX diagrams via the PyZX framework. [(#3446)](https://togithub.com/PennyLaneAI/pennylane/pull/3446) ZX diagrams are the medium for which we can envision a quantum circuit as a graph in the ZX-calculus language, showing properties of quantum protocols in a visually compact and logically complete fashion. QNodes decorated with `@qml.transforms.to_zx` will return a PyZX graph that represents the computation in the ZX-calculus language. ```python dev = qml.device("default.qubit", wires=2) @qml.transforms.to_zx @qml.qnode(device=dev) def circuit(p): qml.RZ(p[0], wires=1), qml.RZ(p[1], wires=1), qml.RX(p[2], wires=0), qml.PauliZ(wires=0), qml.RZ(p[3], wires=1), qml.PauliX(wires=1), qml.CNOT(wires=[0, 1]), qml.CNOT(wires=[1, 0]), qml.SWAP(wires=[0, 1]), return qml.expval(qml.PauliZ(0) @ qml.PauliZ(1)) ``` ```pycon >>> params = [5 / 4 * np.pi, 3 / 4 * np.pi, 0.1, 0.3] >>> circuit(params) Graph(20 vertices, 23 edges) ``` Information about PyZX graphs can be found in the [PyZX Graphs API](https://pyzx.readthedocs.io/en/stable/api.html).QChem databases and basis sets โ๏ธ
- The symbols and geometry of a compound from the PubChem database can now be accessed via `qchem.mol_data()`. [(#3289)](https://togithub.com/PennyLaneAI/pennylane/pull/3289) [(#3378)](https://togithub.com/PennyLaneAI/pennylane/pull/3378) ```pycon >>> import pennylane as qml >>> from pennylane.qchem import mol_data >>> mol_data("BeH2") (['Be', 'H', 'H'], tensor([[ 4.79404621, 0.29290755, 0. ], [ 3.77945225, -0.29290755, 0. ], [ 5.80882913, -0.29290755, 0. ]], requires_grad=True)) >>> mol_data(223, "CID") (['N', 'H', 'H', 'H', 'H'], tensor([[ 0. , 0. , 0. ], [ 1.82264085, 0.52836742, 0.40402345], [ 0.01417295, -1.67429735, -0.98038991], [-0.98927163, -0.22714508, 1.65369933], [-0.84773114, 1.373075 , -1.07733286]], requires_grad=True)) ``` - Perform quantum chemistry calculations with two new basis sets: `6-311g` and `CC-PVDZ`. [(#3279)](https://togithub.com/PennyLaneAI/pennylane/pull/3279) ```pycon >>> symbols = ["H", "He"] >>> geometry = np.array([[1.0, 0.0, 0.0], [0.0, 0.0, 0.0]], requires_grad=False) >>> charge = 1 >>> basis_names = ["6-311G", "CC-PVDZ"] >>> for basis_name in basis_names: ... mol = qml.qchem.Molecule(symbols, geometry, charge=charge, basis_name=basis_name) ... print(qml.qchem.hf_energy(mol)()) [-2.84429531] [-2.84061284] ```A bunch of new operators ๐
- The controlled CZ gate and controlled Hadamard gate are now available via `qml.CCZ` and `qml.CH`, respectively. [(#3408)](https://togithub.com/PennyLaneAI/pennylane/pull/3408) ```pycon >>> ccz = qml.CCZ(wires=[0, 1, 2]) >>> qml.matrix(ccz) [[ 1 0 0 0 0 0 0 0] [ 0 1 0 0 0 0 0 0] [ 0 0 1 0 0 0 0 0] [ 0 0 0 1 0 0 0 0] [ 0 0 0 0 1 0 0 0] [ 0 0 0 0 0 1 0 0] [ 0 0 0 0 0 0 1 0] [ 0 0 0 0 0 0 0 -1]] >>> ch = qml.CH(wires=[0, 1]) >>> qml.matrix(ch) [[ 1. 0. 0. 0. ] [ 0. 1. 0. 0. ] [ 0. 0. 0.70710678 0.70710678] [ 0. 0. 0.70710678 -0.70710678]] ``` - Three new parametric operators, `qml.CPhaseShift00`, `qml.CPhaseShift01`, and `qml.CPhaseShift10`, are now available. Each of these operators performs a phase shift akin to `qml.ControlledPhaseShift` but on different positions of the state vector. [(#2715)](https://togithub.com/PennyLaneAI/pennylane/pull/2715) ```pycon >>> dev = qml.device("default.qubit", wires=2) >>> @qml.qnode(dev) >>> def circuit(): ... qml.PauliX(wires=1) ... qml.CPhaseShift01(phi=1.23, wires=[0,1]) ... return qml.state() ... >>> circuit() tensor([0. +0.j , 0.33423773+0.9424888j, 1. +0.j , 0. +0.j ], requires_grad=True) ``` - A new gate operation called `qml.FermionicSWAP` has been added. This implements the exchange of spin orbitals representing fermionic-modes while maintaining proper anti-symmetrization. [(#3380)](https://togithub.com/PennyLaneAI/pennylane/pull/3380) ```python dev = qml.device('default.qubit', wires=2) @qml.qnode(dev) def circuit(phi): qml.BasisState(np.array([0, 1]), wires=[0, 1]) qml.FermionicSWAP(phi, wires=[0, 1]) return qml.state() ``` ```pycon >>> circuit(0.1) tensor([0. +0.j , 0.99750208+0.04991671j, 0.00249792-0.04991671j, 0. +0.j ], requires_grad=True) ``` - Create operators defined from a generator via `qml.ops.op_math.Evolution`. [(#3375)](https://togithub.com/PennyLaneAI/pennylane/pull/3375) `qml.ops.op_math.Evolution` defines the exponential of an operator $\hat{O}$ of the form $e^{ix\hat{O}}$, with a single trainable parameter, $x$. Limiting to a single trainable parameter allows the use of `qml.gradients.param_shift` to find the gradient with respect to the parameter $x$. ```python dev = qml.device('default.qubit', wires=2) @qml.qnode(dev, diff_method=qml.gradients.param_shift) def circuit(phi): qml.ops.op_math.Evolution(qml.PauliX(0), -.5 * phi) return qml.expval(qml.PauliZ(0)) ``` ```pycon >>> phi = np.array(1.2) >>> circuit(phi) tensor(0.36235775, requires_grad=True) >>> qml.grad(circuit)(phi) -0.9320390495504149 ``` - The qutrit Hadamard gate, `qml.THadamard`, is now available. [(#3340)](https://togithub.com/PennyLaneAI/pennylane/pull/3340) The operation accepts a `subspace` keyword argument which determines which variant of the qutrit Hadamard to use. ```pycon >>> th = qml.THadamard(wires=0, subspace=[0, 1]) >>> qml.matrix(th) array([[ 0.70710678+0.j, 0.70710678+0.j, 0. +0.j], [ 0.70710678+0.j, -0.70710678+0.j, 0. +0.j], [ 0. +0.j, 0. +0.j, 1. +0.j]]) ```New transforms, functions, and more ๐ฏ
- Calculating the purity of arbitrary quantum states is now supported. [(#3290)](https://togithub.com/PennyLaneAI/pennylane/pull/3290) The purity can be calculated in an analogous fashion to, say, the Von Neumann entropy: - `qml.math.purity` can be used as an in-line function: ```pycon >>> x = [1, 0, 0, 1] / np.sqrt(2) >>> qml.math.purity(x, [0, 1]) 1.0 >>> qml.math.purity(x, [0]) 0.5 >>> x = [[1 / 2, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 1 / 2]] >>> qml.math.purity(x, [0, 1]) 0.5 ``` - `qml.qinfo.transforms.purity` can transform a QNode returning a state to a function that returns the purity: ```python3 dev = qml.device("default.mixed", wires=2) @qml.qnode(dev) def circuit(x): qml.IsingXX(x, wires=[0, 1]) return qml.state() ``` ```pycon >>> qml.qinfo.transforms.purity(circuit, wires=[0])(np.pi / 2) 0.5 >>> qml.qinfo.transforms.purity(circuit, wires=[0, 1])(np.pi / 2) 1.0 ``` As with the other methods in `qml.qinfo`, the purity is fully differentiable: ```pycon >>> param = np.array(np.pi / 4, requires_grad=True) >>> qml.grad(qml.qinfo.transforms.purity(circuit, wires=[0]))(param) -0.5 ``` - A new gradient transform, `qml.gradients.spsa_grad`, that is based on the idea of SPSA is now available. [(#3366)](https://togithub.com/PennyLaneAI/pennylane/pull/3366) This new transform allows users to compute a single estimate of a quantum gradient using simultaneous perturbation of parameters and a stochastic approximation. A QNode that takes, say, an argument `x`, the approximate gradient can be computed as follows. ```pycon >>> dev = qml.device("default.qubit", wires=2) >>> x = np.array(0.4, requires_grad=True) >>> @qml.qnode(dev) ... def circuit(x): ... qml.RX(x, 0) ... qml.RX(x, 1) ... return qml.expval(qml.PauliZ(0)) >>> grad_fn = qml.gradients.spsa_grad(circuit, h=0.1, num_directions=1) >>> grad_fn(x) array(-0.38876964) ``` The argument `num_directions` determines how many directions of simultaneous perturbation are used, which is proportional to the number of circuit evaluations. See the [SPSA gradient transform documentation](https://docs.pennylane.ai/en/stable/code/api/pennylane.gradients.spsa_grad.html) for details. Note that the full SPSA optimizer is already available as `qml.SPSAOptimizer`. - Multiple mid-circuit measurements can now be combined arithmetically to create new conditionals. [(#3159)](https://togithub.com/PennyLaneAI/pennylane/pull/3159) ```python dev = qml.device("default.qubit", wires=3) @qml.qnode(dev) def circuit(): qml.Hadamard(wires=0) qml.Hadamard(wires=1) m0 = qml.measure(wires=0) m1 = qml.measure(wires=1) combined = 2 * m1 + m0 qml.cond(combined == 2, qml.RX)(1.3, wires=2) return qml.probs(wires=2) ``` ```pycon >>> circuit() [0.90843735 0.09156265] ``` - A new method called `pauli_decompose()` has been added to the `qml.pauli` module, which takes a hermitian matrix, decomposes it in the Pauli basis, and returns it either as a `qml.Hamiltonian` or `qml.PauliSentence` instance. [(#3384)](https://togithub.com/PennyLaneAI/pennylane/pull/3384) - `Operation` or `Hamiltonian` instances can now be generated from a `qml.PauliSentence` or `qml.PauliWord` via the new `operation()` and `hamiltonian()` methods. [(#3391)](https://togithub.com/PennyLaneAI/pennylane/pull/3391) ```pycon >>> pw = qml.pauli.PauliWord({0: 'X', 1: 'Y'}) >>> print(pw.operation()) PauliX(wires=[0]) @ PauliY(wires=[1]) >>> print(pw.hamiltonian()) (1) [X0 Y1] >>> ps = qml.pauli.PauliSentence({pw: -1.23}) >>> print(ps.operation()) -1.23*(PauliX(wires=[0]) @ PauliY(wires=[1])) >>> print(ps.hamiltonian()) (-1.23) [X0 Y1] ``` - A `sum_expand` function has been added for tapes, which splits a tape measuring a `Sum` expectation into mutliple tapes of summand expectations, and provides a function to recombine the results. [(#3230)](https://togithub.com/PennyLaneAI/pennylane/pull/3230)(Experimental) More interface support for multi-measurement and gradient output types ๐งช
- The autograd and Tensorflow interfaces now support devices with shot vectors when `qml.enable_return()` has been called. [(#3374)](https://togithub.com/PennyLaneAI/pennylane/pull/3374) [(#3400)](https://togithub.com/PennyLaneAI/pennylane/pull/3400) Here is an example using Tensorflow: ```python import tensorflow as tf qml.enable_return() dev = qml.device("default.qubit", wires=2, shots=[1000, 2000, 3000]) @qml.qnode(dev, diff_method="parameter-shift", interface="tf") def circuit(a): qml.RY(a, wires=0) qml.RX(0.2, wires=0) qml.CNOT(wires=[0, 1]) return qml.expval(qml.PauliZ(0)), qml.probs([0, 1]) ``` ```pycon >>> a = tf.Variable(0.4) >>> with tf.GradientTape() as tape: ... res = circuit(a) ... res = tf.stack([tf.experimental.numpy.hstack(r) for r in res]) ... >>> resImprovements ๐
- `qml.pauli.is_pauli_word` now supports instances of `qml.Hamiltonian`. [(#3389)](https://togithub.com/PennyLaneAI/pennylane/pull/3389) - When `qml.probs`, `qml.counts`, and `qml.sample` are called with no arguments, they measure all wires. Calling any of the aforementioned measurements with an empty wire list (e.g., `qml.sample(wires=[])`) will raise an error. [(#3299)](https://togithub.com/PennyLaneAI/pennylane/pull/3299) - Made `qml.gradients.finite_diff` more convenient to use with custom data type observables/devices by reducing the number of magic methods that need to be defined in the custom data type to support `finite_diff`. [(#3426)](https://togithub.com/PennyLaneAI/pennylane/pull/3426) - The `qml.ISWAP` gate is now natively supported on `default.mixed`, improving on its efficiency. [(#3284)](https://togithub.com/PennyLaneAI/pennylane/pull/3284) - Added more input validation to `qml.transforms.hamiltonian_expand` such that Hamiltonian objects with no terms raise an error. [(#3339)](https://togithub.com/PennyLaneAI/pennylane/pull/3339) - Continuous integration checks are now performed for Python 3.11 and Torch v1.13. Python 3.7 is dropped. [(#3276)](https://togithub.com/PennyLaneAI/pennylane/pull/3276) - `qml.Tracker` now also logs results in `tracker.history` when tracking the execution of a circuit. [(#3306)](https://togithub.com/PennyLaneAI/pennylane/pull/3306) - The execution time of `Wires.all_wires` has been improved by avoiding data type changes and making use of `itertools.chain`. [(#3302)](https://togithub.com/PennyLaneAI/pennylane/pull/3302) - Printing an instance of `qml.qchem.Molecule` is now more concise and informational. [(#3364)](https://togithub.com/PennyLaneAI/pennylane/pull/3364) - The error message for `qml.transforms.insert` when it fails to diagonalize non-qubit-wise-commuting observables is now more detailed. [(#3381)](https://togithub.com/PennyLaneAI/pennylane/pull/3381) - Extended the `qml.equal` function to `qml.Hamiltonian` and `Tensor` objects. [(#3390)](https://togithub.com/PennyLaneAI/pennylane/pull/3390) - `QuantumTape._process_queue` has been moved to `qml.queuing.process_queue` to disentangle its functionality from the `QuantumTape` class. [(#3401)](https://togithub.com/PennyLaneAI/pennylane/pull/3401) - QPE can now accept a target operator instead of a matrix and target wires pair. [(#3373)](https://togithub.com/PennyLaneAI/pennylane/pull/3373) - The `qml.ops.op_math.Controlled.map_wires` method now uses `base.map_wires` internally instead of the private `_wires` property setter. [(#3405)](https://togithub.com/PennyLaneAI/pennylane/pull/3405) - A new function called `qml.tape.make_qscript` has been created for converting a quantum function into a quantum script. This replaces `qml.transforms.make_tape`. [(#3429)](https://togithub.com/PennyLaneAI/pennylane/pull/3429) - Add a `_pauli_rep` attribute to operators to integrate the new Pauli arithmetic classes with native PennyLane objects. [(#3443)](https://togithub.com/PennyLaneAI/pennylane/pull/3443) - Extended the functionality of `qml.matrix` to qutrits. [(#3508)](https://togithub.com/PennyLaneAI/pennylane/pull/3508) - The `qcut.py` file in `pennylane/transforms/` has been reorganized into multiple files that are now in `pennylane/transforms/qcut/`. [(#3413)](https://togithub.com/PennyLaneAI/pennylane/pull/3413) - A warning now appears when creating a `Tensor` object with overlapping wires, informing that this can lead to undefined behaviour. [(#3459)](https://togithub.com/PennyLaneAI/pennylane/pull/3459) - Extended the `qml.equal` function to `qml.ops.op_math.Controlled` and `qml.ops.op_math.ControlledOp` objects. [(#3463)](https://togithub.com/PennyLaneAI/pennylane/pull/3463) - Nearly every instance of `with QuantumTape()` has been replaced with `QuantumScript` construction. [(#3454)](https://togithub.com/PennyLaneAI/pennylane/pull/3454) - Added `validate_subspace` static method to `qml.Operator` to check the validity of the subspace of certain qutrit operations. [(#3340)](https://togithub.com/PennyLaneAI/pennylane/pull/3340) - `qml.equal` now supports operators created via `qml.s_prod`, `qml.pow`, `qml.exp`, and `qml.adjoint`. [(#3471)](https://togithub.com/PennyLaneAI/pennylane/pull/3471) - Devices can now disregard observable grouping indices in Hamiltonians through the optional `use_grouping` attribute. [(#3456)](https://togithub.com/PennyLaneAI/pennylane/pull/3456) - Add the optional argument `lazy=True` to functions `qml.s_prod`, `qml.prod` and `qml.op_sum` to allow simplification. [(#3483)](https://togithub.com/PennyLaneAI/pennylane/pull/3483) - Updated the `qml.transforms.zyz_decomposition` function such that it now supports broadcast operators. This means that single-qubit `qml.QubitUnitary` operators, instantiated from a batch of unitaries, can now be decomposed. [(#3477)](https://togithub.com/PennyLaneAI/pennylane/pull/3477) - The performance of executing circuits under the `jax.vmap` transformation has been improved by being able to leverage the batch-execution capabilities of some devices. [(#3452)](https://togithub.com/PennyLaneAI/pennylane/pull/3452) - The tolerance for converting openfermion Hamiltonian complex coefficients to real ones has been modified to prevent conversion errors. [(#3367)](https://togithub.com/PennyLaneAI/pennylane/pull/3367) - `OperationRecorder` now inherits from `AnnotatedQueue` and `QuantumScript` instead of `QuantumTape`. [(#3496)](https://togithub.com/PennyLaneAI/pennylane/pull/3496) - Updated `qml.transforms.split_non_commuting` to support the new return types. [(#3414)](https://togithub.com/PennyLaneAI/pennylane/pull/3414) - Updated `qml.transforms.mitigate_with_zne` to support the new return types. [(#3415)](https://togithub.com/PennyLaneAI/pennylane/pull/3415) - Updated `qml.transforms.metric_tensor`, `qml.transforms.adjoint_metric_tensor`, `qml.qinfo.classical_fisher`, and `qml.qinfo.quantum_fisher` to support the new return types. [(#3449)](https://togithub.com/PennyLaneAI/pennylane/pull/3449) - Updated `qml.transforms.batch_params` and `qml.transforms.batch_input` to support the new return types. [(#3431)](https://togithub.com/PennyLaneAI/pennylane/pull/3431) - Updated `qml.transforms.cut_circuit` and `qml.transforms.cut_circuit_mc` to support the new return types. [(#3346)](https://togithub.com/PennyLaneAI/pennylane/pull/3346) - Limit NumPy version to `<1.24`. [(#3346)](https://togithub.com/PennyLaneAI/pennylane/pull/3346)Breaking changes ๐
- Python 3.7 support is no longer maintained. PennyLane will be maintained for versions 3.8 and up. [(#3276)](https://togithub.com/PennyLaneAI/pennylane/pull/3276) - The `log_base` attribute has been moved from `MeasurementProcess` to the new `VnEntropyMP` and `MutualInfoMP` classes, which inherit from `MeasurementProcess`. [(#3326)](https://togithub.com/PennyLaneAI/pennylane/pull/3326) - `qml.utils.decompose_hamiltonian()` has been removed. Please use `qml.pauli.pauli_decompose()` instead. [(#3384)](https://togithub.com/PennyLaneAI/pennylane/pull/3384) - The `return_type` attribute of `MeasurementProcess` has been removed where possible. Use `isinstance` checks instead. [(#3399)](https://togithub.com/PennyLaneAI/pennylane/pull/3399) - Instead of having an `OrderedDict` attribute called `_queue`, `AnnotatedQueue` now inherits from `OrderedDict` and encapsulates the queue. Consequentially, this also applies to the `QuantumTape` class which inherits from `AnnotatedQueue`. [(#3401)](https://togithub.com/PennyLaneAI/pennylane/pull/3401) - The `ShadowMeasurementProcess` class has been renamed to `ClassicalShadowMP`. [(#3388)](https://togithub.com/PennyLaneAI/pennylane/pull/3388) - The `qml.Operation.get_parameter_shift` method has been removed. The `gradients` module should be used for general parameter-shift rules instead. [(#3419)](https://togithub.com/PennyLaneAI/pennylane/pull/3419) - The signature of the `QubitDevice.statistics` method has been changed from ```python def statistics(self, observables, shot_range=None, bin_size=None, circuit=None): ``` to ```python def statistics(self, circuit: QuantumTape, shot_range=None, bin_size=None): ``` [(#3421)](https://togithub.com/PennyLaneAI/pennylane/pull/3421) - The `MeasurementProcess` class is now an abstract class and `return_type` is now a property of the class. [(#3434)](https://togithub.com/PennyLaneAI/pennylane/pull/3434)Deprecations ๐
Deprecations cycles are tracked at [doc/developement/deprecations.rst](https://docs.pennylane.ai/en/stable/development/deprecations.html). - The following methods are deprecated: [(#3281)](https://togithub.com/PennyLaneAI/pennylane/pull/3281/) - `qml.tape.get_active_tape`: Use `qml.QueuingManager.active_context()` instead - `qml.transforms.qcut.remap_tape_wires`: Use `qml.map_wires` instead - `qml.tape.QuantumTape.inv()`: Use `qml.tape.QuantumTape.adjoint()` instead - `qml.tape.stop_recording()`: Use `qml.QueuingManager.stop_recording()` instead - `qml.tape.QuantumTape.stop_recording()`: Use `qml.QueuingManager.stop_recording()` instead - `qml.QueuingContext` is now `qml.QueuingManager` - `QueuingManager.safe_update_info` and `AnnotatedQueue.safe_update_info`: Use `update_info` instead. - `qml.transforms.measurement_grouping` has been deprecated. Use `qml.transforms.hamiltonian_expand` instead. [(#3417)](https://togithub.com/PennyLaneAI/pennylane/pull/3417) - The `observables` argument in `QubitDevice.statistics` is deprecated. Please use `circuit` instead. [(#3433)](https://togithub.com/PennyLaneAI/pennylane/pull/3433) - The `seed_recipes` argument in `qml.classical_shadow` and `qml.shadow_expval` is deprecated. A new argument `seed` has been added, which defaults to None and can contain an integer with the wanted seed. [(#3388)](https://togithub.com/PennyLaneAI/pennylane/pull/3388) - `qml.transforms.make_tape` has been deprecated. Please use `qml.tape.make_qscript` instead. [(#3478)](https://togithub.com/PennyLaneAI/pennylane/pull/3478)Documentation ๐
- Added documentation on parameter broadcasting regarding both its usage and technical aspects. [(#3356)](https://togithub.com/PennyLaneAI/pennylane/pull/3356) The [quickstart guide on circuits](https://docs.pennylane.ai/en/stable/introduction/circuits.html#parameter-broadcasting-in-qnodes) as well as the the documentation of [QNodes](https://docs.pennylane.ai/en/stable/code/api/pennylane.QNode.html) and [Operators](https://docs.pennylane.ai/en/stable/code/api/pennylane.operation.Operator.html) now contain introductions and details on parameter broadcasting. The QNode documentation mostly contains usage details, the Operator documentation is concerned with implementation details and a guide to support broadcasting in custom operators. - The return type statements of gradient and Hessian transforms and a series of other functions that are a `batch_transform` have been corrected. [(#3476)](https://togithub.com/PennyLaneAI/pennylane/pull/3476) - Developer documentation for the queuing module has been added. [(#3268)](https://togithub.com/PennyLaneAI/pennylane/pull/3268) - More mentions of diagonalizing gates for all relevant operations have been corrected. [(#3409)](https://togithub.com/PennyLaneAI/pennylane/pull/3409) The docstrings for `compute_eigvals` used to say that the diagonalizing gates implemented $U$, the unitary such that $O = U \Sigma U^{\dagger}$, where $O$ is the original observable and $\Sigma$ a diagonal matrix. However, the diagonalizing gates actually implement $U^{\dagger}$, since $\langle \psi | O | \psi \rangle = \langle \psi | U \Sigma U^{\dagger} | \psi \rangle$, making $U^{\dagger} | \psi \rangle$ the actual state being measured in the $Z$-basis. - A warning about using `dill` to pickle and unpickle datasets has been added. [(#3505)](https://togithub.com/PennyLaneAI/pennylane/pull/3505)Bug fixes ๐
- Fixed a bug that prevented `qml.gradients.param_shift` from being used for broadcasted tapes. [(#3528)](https://togithub.com/PennyLaneAI/pennylane/pull/3528) - Fixed a bug where `qml.transforms.hamiltonian_expand` didn't preserve the type of the input results in its output. [(#3339)](https://togithub.com/PennyLaneAI/pennylane/pull/3339) - Fixed a bug that made `qml.gradients.param_shift` raise an error when used with unshifted terms only in a custom recipe, and when using any unshifted terms at all under the new return type system. [(#3177)](https://togithub.com/PennyLaneAI/pennylane/pull/3177) - The original tape `_obs_sharing_wires` attribute is updated during its expansion. [(#3293)](https://togithub.com/PennyLaneAI/pennylane/pull/3293) - An issue with `drain=False` in the adaptive optimizer has been fixed. Before the fix, the operator pool needed to be reconstructed inside the optimization pool when `drain=False`. With this fix, this reconstruction is no longer needed. [(#3361)](https://togithub.com/PennyLaneAI/pennylane/pull/3361) - If the device originally has no shots but finite shots are dynamically specified, Hamiltonian expansion now occurs. [(#3369)](https://togithub.com/PennyLaneAI/pennylane/pull/3369) - `qml.matrix(op)` now fails if the operator truly has no matrix (e.g., `qml.Barrier`) to match `op.matrix()`. [(#3386)](https://togithub.com/PennyLaneAI/pennylane/pull/3386) - The `pad_with` argument in the `qml.AmplitudeEmbedding` template is now compatible with all interfaces. [(#3392)](https://togithub.com/PennyLaneAI/pennylane/pull/3392) - `Operator.pow` now queues its constituents by default. [(#3373)](https://togithub.com/PennyLaneAI/pennylane/pull/3373) - Fixed a bug where a QNode returning `qml.sample` would produce incorrect results when run on a device defined with a shot vector. [(#3422)](https://togithub.com/PennyLaneAI/pennylane/pull/3422) - The `qml.data` module now works as expected on Windows. [(#3504)](https://togithub.com/PennyLaneAI/pennylane/pull/3504)Contributors โ๏ธ
This release contains contributions from (in alphabetical order): Guillermo Alonso, Juan Miguel Arrazola, Utkarsh Azad, Samuel Banning, Thomas Bromley, Astral Cai, Albert Mitjans Coma, Ahmed Darwish, Isaac De Vlugt, Olivia Di Matteo, Amintor Dusko, Pieter Eendebak, Lillian M. A. Frederiksen, Diego Guala, Katharine Hyatt, Josh Izaac, Soran Jahangiri, Edward Jiang, Korbinian Kottmann, Christina Lee, Romain Moyard, Lee James O'Riordan, Mudit Pandey, Kevin Shen, Matthew Silverman, Jay Soni, Antal Szรกva, David Wierichs, Moritz Willmann, and Filippo Vicentini. ### [`v0.27.0`](https://togithub.com/PennyLaneAI/pennylane/releases/tag/v0.27.0): Release 0.27.0 [Compare Source](https://togithub.com/XanaduAI/pennylane/compare/v0.26.0...v0.27.0)New features since last release
An all-new data module ๐พ
- The `qml.data` module is now available, allowing users to download, load, and create quantum datasets. [(#3156)](https://togithub.com/PennyLaneAI/pennylane/pull/3156) Datasets are hosted on Xanadu Cloud and can be downloaded by using `qml.data.load()`: ```pycon >>> H2_datasets = qml.data.load( ... data_name="qchem", molname="H2", basis="STO-3G", bondlength=1.1 ... ) >>> H2data = H2_datasets[0] >>> H2dataAdaptive optimization ๐๐๏ธ๐
- Optimizing quantum circuits can now be done *adaptively* with `qml.AdaptiveOptimizer`. [(#3192)](https://togithub.com/PennyLaneAI/pennylane/pull/3192) The `qml.AdaptiveOptimizer` takes an initial circuit and a collection of operators as input and adds a selected gate to the circuit at each optimization step. The process of growing the circuit can be repeated until the circuit gradients converge to zero within a given threshold. The adaptive optimizer can be used to implement algorithms such as ADAPT-VQE as shown in the following example. Firstly, we define some preliminary variables needed for VQE: ```python symbols = ["H", "H", "H"] geometry = np.array([[0.01076341, 0.04449877, 0.0], [0.98729513, 1.63059094, 0.0], [1.87262415, -0.00815842, 0.0]], requires_grad=False) H, qubits = qml.qchem.molecular_hamiltonian(symbols, geometry, charge = 1) ``` The collection of gates to grow the circuit is built to contain all single and double excitations: ```python n_electrons = 2 singles, doubles = qml.qchem.excitations(n_electrons, qubits) singles_excitations = [qml.SingleExcitation(0.0, x) for x in singles] doubles_excitations = [qml.DoubleExcitation(0.0, x) for x in doubles] operator_pool = doubles_excitations + singles_excitations ``` Next, an initial circuit that prepares a Hartree-Fock state and returns the expectation value of the Hamiltonian is defined: ```python hf_state = qml.qchem.hf_state(n_electrons, qubits) dev = qml.device("default.qubit", wires=qubits) @qml.qnode(dev) def circuit(): qml.BasisState(hf_state, wires=range(qubits)) return qml.expval(H) ``` Finally, the optimizer is instantiated and then the circuit is created and optimized adaptively: ```python opt = qml.optimize.AdaptiveOptimizer() for i in range(len(operator_pool)): circuit, energy, gradient = opt.step_and_cost(circuit, operator_pool, drain_pool=True) print('Energy:', energy) print(qml.draw(circuit)()) print('Largest Gradient:', gradient) print() if gradient < 1e-3: break ``` ```pycon Energy: -1.246549938420637 0: โโญBasisState(M0)โโญGยฒ(0.20)โโค โญ<๐> 1: โโBasisState(M0)โโGยฒ(0.20)โโค โ<๐> 2: โโBasisState(M0)โโโโโโโโโโโโค โ<๐> 3: โโBasisState(M0)โโโโโโโโโโโโค โ<๐> 4: โโBasisState(M0)โโGยฒ(0.20)โโค โ<๐> 5: โโฐBasisState(M0)โโฐGยฒ(0.20)โโค โฐ<๐> Largest Gradient: 0.14399872776755085 Energy: -1.2613740231529604 0: โโญBasisState(M0)โโญGยฒ(0.20)โโญGยฒ(0.19)โโค โญ<๐> 1: โโBasisState(M0)โโGยฒ(0.20)โโGยฒ(0.19)โโค โ<๐> 2: โโBasisState(M0)โโโโโโโโโโโโGยฒ(0.19)โโค โ<๐> 3: โโBasisState(M0)โโโโโโโโโโโโฐGยฒ(0.19)โโค โ<๐> 4: โโBasisState(M0)โโGยฒ(0.20)โโโโโโโโโโโโค โ<๐> 5: โโฐBasisState(M0)โโฐGยฒ(0.20)โโโโโโโโโโโโค โฐ<๐> Largest Gradient: 0.1349349562423238 Energy: -1.2743971719780331 0: โโญBasisState(M0)โโญGยฒ(0.20)โโญGยฒ(0.19)โโโโโโโโโโโค โญ<๐> 1: โโBasisState(M0)โโGยฒ(0.20)โโGยฒ(0.19)โโญG(0.00)โโค โ<๐> 2: โโBasisState(M0)โโโโโโโโโโโโGยฒ(0.19)โโโโโโโโโโโค โ<๐> 3: โโBasisState(M0)โโโโโโโโโโโโฐGยฒ(0.19)โโฐG(0.00)โโค โ<๐> 4: โโBasisState(M0)โโGยฒ(0.20)โโโโโโโโโโโโโโโโโโโโโค โ<๐> 5: โโฐBasisState(M0)โโฐGยฒ(0.20)โโโโโโโโโโโโโโโโโโโโโค โฐ<๐> Largest Gradient: 0.00040841755397108586 ``` For a detailed breakdown of its implementation, check out the [Adaptive circuits for quantum chemistry demo](https://pennylane.ai/qml/demos/tutorial_adaptive_circuits.html).Automatic interface detection ๐งฉ
- QNodes now accept an `auto` interface argument which automatically detects the machine learning library to use. [(#3132)](https://togithub.com/PennyLaneAI/pennylane/pull/3132) ```python from pennylane import numpy as np import torch import tensorflow as tf from jax import numpy as jnp dev = qml.device("default.qubit", wires=2) @qml.qnode(dev, interface="auto") def circuit(weight): qml.RX(weight[0], wires=0) qml.RY(weight[1], wires=1) return qml.expval(qml.PauliZ(0)) interface_tensors = [[0, 1], np.array([0, 1]), torch.Tensor([0, 1]), tf.Variable([0, 1], dtype=float), jnp.array([0, 1])] for tensor in interface_tensors: res = circuit(weight=tensor) print(f"Result value: {res:.2f}; Result type: {type(res)}") ``` ```pycon Result value: 1.00; Result type:Upgraded JAX-JIT gradient support ๐
- JAX-JIT support for computing the gradient of QNodes that return a single vector of probabilities or multiple expectation values is now available. [(#3244)](https://togithub.com/PennyLaneAI/pennylane/pull/3244) [(#3261)](https://togithub.com/PennyLaneAI/pennylane/pull/3261) ```python import jax from jax import numpy as jnp from jax.config import config config.update("jax_enable_x64", True) dev = qml.device("lightning.qubit", wires=2) @jax.jit @qml.qnode(dev, diff_method="parameter-shift", interface="jax") def circuit(x, y): qml.RY(x, wires=0) qml.RY(y, wires=1) qml.CNOT(wires=[0, 1]) return qml.expval(qml.PauliZ(0)), qml.expval(qml.PauliZ(1)) x = jnp.array(1.0) y = jnp.array(2.0) ``` ```pycon >>> jax.jacobian(circuit, argnums=[0, 1])(x, y) (DeviceArray([-0.84147098, 0.35017549], dtype=float64, weak_type=True), DeviceArray([ 4.47445479e-18, -4.91295496e-01], dtype=float64, weak_type=True)) ``` Note that this change depends on `jax.pure_callback`, which requires `jax>=0.3.17`.Construct Pauli words and sentences ๐ค
- We've reorganized and grouped everything in PennyLane responsible for manipulating Pauli operators into a `pauli` module. The `grouping` module has been deprecated as a result, and logic was moved from `pennylane/grouping` to `pennylane/pauli/grouping`. [(#3179)](https://togithub.com/PennyLaneAI/pennylane/pull/3179) - `qml.pauli.PauliWord` and `qml.pauli.PauliSentence` can be used to represent tensor products and linear combinations of Pauli operators, respectively. These provide a more performant method to compute sums and products of Pauli operators. [(#3195)](https://togithub.com/PennyLaneAI/pennylane/pull/3195) - `qml.pauli.PauliWord` represents tensor products of Pauli operators. We can efficiently multiply and extract the matrix of these operators using this representation. ```pycon >>> pw1 = qml.pauli.PauliWord({0:"X", 1:"Z"}) >>> pw2 = qml.pauli.PauliWord({0:"Y", 1:"Z"}) >>> pw1, pw2 (X(0) @ Z(1), Y(0) @ Z(1)) >>> pw1 * pw2 (Z(0), 1j) >>> pw1.to_mat(wire_order=[0,1]) array([[ 0, 0, 1, 0], [ 0, 0, 0, -1], [ 1, 0, 0, 0], [ 0, -1, 0, 0]]) ``` - `qml.pauli.PauliSentence` represents linear combinations of Pauli words. We can efficiently add, multiply and extract the matrix of these operators in this representation. ```pycon >>> ps1 = qml.pauli.PauliSentence({pw1: 1.2, pw2: 0.5j}) >>> ps2 = qml.pauli.PauliSentence({pw1: -1.2}) >>> ps1 1.2 * X(0) @ Z(1) + 0.5j * Y(0) @ Z(1) >>> ps1 + ps2 0.0 * X(0) @ Z(1) + 0.5j * Y(0) @ Z(1) >>> ps1 * ps2 -1.44 * I + (-0.6+0j) * Z(0) >>> (ps1 + ps2).to_mat(wire_order=[0,1]) array([[ 0. +0.j, 0. +0.j, 0.5+0.j, 0. +0.j], [ 0. +0.j, 0. +0.j, 0. +0.j, -0.5+0.j], [-0.5+0.j, 0. +0.j, 0. +0.j, 0. +0.j], [ 0. +0.j, 0.5+0.j, 0. +0.j, 0. +0.j]]) ```(Experimental) More support for multi-measurement and gradient output types ๐งช
- `qml.enable_return()` now supports QNodes returning multiple measurements, including shots vectors, and gradient output types. [(#2886)](https://togithub.com/PennyLaneAI/pennylane/pull/2886) [(#3052)](https://togithub.com/PennyLaneAI/pennylane/pull/3052) [(#3041)](https://togithub.com/PennyLaneAI/pennylane/pull/3041) [(#3090)](https://togithub.com/PennyLaneAI/pennylane/pull/3090) [(#3069)](https://togithub.com/PennyLaneAI/pennylane/pull/3069) [(#3137)](https://togithub.com/PennyLaneAI/pennylane/pull/3137) [(#3127)](https://togithub.com/PennyLaneAI/pennylane/pull/3127) [(#3099)](https://togithub.com/PennyLaneAI/pennylane/pull/3099) [(#3098)](https://togithub.com/PennyLaneAI/pennylane/pull/3098) [(#3095)](https://togithub.com/PennyLaneAI/pennylane/pull/3095) [(#3091)](https://togithub.com/PennyLaneAI/pennylane/pull/3091) [(#3176)](https://togithub.com/PennyLaneAI/pennylane/pull/3176) [(#3170)](https://togithub.com/PennyLaneAI/pennylane/pull/3170) [(#3194)](https://togithub.com/PennyLaneAI/pennylane/pull/3194) [(#3267)](https://togithub.com/PennyLaneAI/pennylane/pull/3267) [(#3234)](https://togithub.com/PennyLaneAI/pennylane/pull/3234) [(#3232)](https://togithub.com/PennyLaneAI/pennylane/pull/3232) [(#3223)](https://togithub.com/PennyLaneAI/pennylane/pull/3223) [(#3222)](https://togithub.com/PennyLaneAI/pennylane/pull/3222) [(#3315)](https://togithub.com/PennyLaneAI/pennylane/pull/3315) In v0.25, we introduced `qml.enable_return()`, which separates measurements into their own tensors. The motivation of this change is the deprecation of ragged `ndarray` creation in NumPy. With this release, we're continuing to elevate this feature by adding support for: - Execution (`qml.execute`) - Jacobian vector product (JVP) computation - Gradient transforms (`qml.gradients.param_shift`, `qml.gradients.finite_diff`, `qml.gradients.hessian_transform`, `qml.gradients.param_shift_hessian`). - Interfaces (Autograd, TensorFlow, and JAX, although without JIT) With this added support, the JAX interface can handle multiple shots (shots vectors), measurements, and gradient output types with `qml.enable_return()`: ```python import jax qml.enable_return() dev = qml.device("default.qubit", wires=2, shots=(1, 10000)) params = jax.numpy.array([0.1, 0.2]) @qml.qnode(dev, interface="jax", diff_method="parameter-shift", max_diff=2) def circuit(x): qml.RX(x[0], wires=[0]) qml.RY(x[1], wires=[1]) qml.CNOT(wires=[0, 1]) return qml.var(qml.PauliZ(0) @ qml.PauliX(1)), qml.probs(wires=[0]) ``` ```pycon >>> jax.hessian(circuit)(params) ((DeviceArray([[ 0., 0.], [ 2., -3.]], dtype=float32), DeviceArray([[[-0.5, 0. ], [ 0. , 0. ]], [[ 0.5, 0. ], [ 0. , 0. ]]], dtype=float32)), (DeviceArray([[ 0.07677898, 0.0563341 ], [ 0.07238522, -1.830669 ]], dtype=float32), DeviceArray([[[-4.9707499e-01, 2.9999996e-04], [-6.2500127e-04, 1.2500001e-04]], [[ 4.9707499e-01, -2.9999996e-04], [ 6.2500127e-04, -1.2500001e-04]]], dtype=float32))) ``` For more details, please [refer to the documentation](https://docs.pennylane.ai/en/stable/code/api/pennylane.enable_return.html?highlight=enable_return#pennylane.enable_return).New basis rotation and tapering features in qml.qchem ๐ค
- Grouped coefficients, observables, and basis rotation transformation matrices needed to construct a qubit Hamiltonian in the rotated basis of molecular orbitals are now calculable via `qml.qchem.basis_rotation()`. ([#3011](https://togithub.com/PennyLaneAI/pennylane/pull/3011)) ```pycon >>> symbols = ['H', 'H'] >>> geometry = np.array([[0.0, 0.0, 0.0], [1.398397361, 0.0, 0.0]], requires_grad = False) >>> mol = qml.qchem.Molecule(symbols, geometry) >>> core, one, two = qml.qchem.electron_integrals(mol)() >>> coeffs, ops, unitaries = qml.qchem.basis_rotation(one, two, tol_factor=1.0e-5) >>> unitaries [tensor([[-1.00000000e+00, -5.46483514e-13], [ 5.46483514e-13, -1.00000000e+00]], requires_grad=True), tensor([[-1.00000000e+00, 3.17585063e-14], [-3.17585063e-14, -1.00000000e+00]], requires_grad=True), tensor([[-0.70710678, -0.70710678], [-0.70710678, 0.70710678]], requires_grad=True), tensor([[ 2.58789009e-11, 1.00000000e+00], [-1.00000000e+00, 2.58789009e-11]], requires_grad=True)] ``` - Any gate operation can now be tapered according to :math:`\mathbb{Z}_2` symmetries of the Hamiltonian via `qml.qchem.taper_operation`. [(#3002)](https://togithub.com/PennyLaneAI/pennylane/pull/3002) [(#3121)](https://togithub.com/PennyLaneAI/pennylane/pull/3121) ```pycon >>> symbols = ['He', 'H'] >>> geometry = np.array([[0.0, 0.0, 0.0], [0.0, 0.0, 1.4589]]) >>> mol = qml.qchem.Molecule(symbols, geometry, charge=1) >>> H, n_qubits = qml.qchem.molecular_hamiltonian(symbols, geometry) >>> generators = qml.qchem.symmetry_generators(H) >>> paulixops = qml.qchem.paulix_ops(generators, n_qubits) >>> paulix_sector = qml.qchem.optimal_sector(H, generators, mol.n_electrons) >>> tap_op = qml.qchem.taper_operation(qml.SingleExcitation, generators, paulixops, ... paulix_sector, wire_order=H.wires, op_wires=[0, 2]) >>> tap_op(3.14159) [Exp(1.5707949999999993j PauliY)] ``` Moreover, the obtained tapered operation can be used directly within a QNode. ```pycon >>> dev = qml.device('default.qubit', wires=[0, 1]) >>> @qml.qnode(dev) ... def circuit(params): ... tap_op(params[0]) ... return qml.expval(qml.PauliZ(0) @ qml.PauliZ(1)) >>> drawer = qml.draw(circuit, show_all_wires=True) >>> print(drawer(params=[3.14159])) 0: โโExp(0.00+1.57j Y)โโค โญNew functions, operations, and observables ๐คฉ
- Wires of operators or entire QNodes can now be mapped to other wires via `qml.map_wires()`. [(#3143)](https://togithub.com/PennyLaneAI/pennylane/pull/3143) [(#3145)](https://togithub.com/PennyLaneAI/pennylane/pull/3145) The `qml.map_wires()` function requires a dictionary representing a wire map. Use it with - arbitrary operators: ```pycon >>> op = qml.RX(0.54, wires=0) + qml.PauliX(1) + (qml.PauliZ(2) @ qml.RY(1.23, wires=3)) >>> op (RX(0.54, wires=[0]) + PauliX(wires=[1])) + (PauliZ(wires=[2]) @ RY(1.23, wires=[3])) >>> wire_map = {0: 10, 1: 11, 2: 12, 3: 13} >>> qml.map_wires(op, wire_map) (RX(0.54, wires=[10]) + PauliX(wires=[11])) + (PauliZ(wires=[12]) @ RY(1.23, wires=[13])) ``` A `map_wires` method has also been added to operators, which returns a copy of the operator with its wires changed according to the given wire map. - entire QNodes: ```python dev = qml.device("default.qubit", wires=["A", "B", "C", "D"]) wire_map = {0: "A", 1: "B", 2: "C", 3: "D"} @qml.qnode(dev) def circuit(): qml.RX(0.54, wires=0) qml.PauliX(1) qml.PauliZ(2) qml.RY(1.23, wires=3) return qml.probs(wires=0) ``` ```pycon >>> mapped_circuit = qml.map_wires(circuit, wire_map) >>> mapped_circuit() tensor([0.92885434, 0.07114566], requires_grad=True) >>> print(qml.draw(mapped_circuit)()) A: โโRX(0.54)โโค Probs B: โโXโโโโโโโโโค C: โโZโโโโโโโโโค D: โโRY(1.23)โโค ``` - The `qml.IntegerComparator` arithmetic operation is now available. [(#3113)](https://togithub.com/PennyLaneAI/pennylane/pull/3113) Given a basis state :math:`\vert n \rangle`, where :math:`n` is a positive integer, and a fixed positive integer :math:`L`, `qml.IntegerComparator` flips a target qubit if :math:`n \geq L`. Alternatively, the flipping condition can be :math:`n < L` as demonstrated below: ```python dev = qml.device("default.qubit", wires=2) @qml.qnode(dev) def circuit(): qml.BasisState(np.array([0, 1]), wires=range(2)) qml.broadcast(qml.Hadamard, wires=range(2), pattern='single') qml.IntegerComparator(2, geq=False, wires=[0, 1]) return qml.state() ``` ```pycon >>> circuit() [-0.5+0.j 0.5+0.j -0.5+0.j 0.5+0.j] ``` - The `qml.GellMann` qutrit observable, the ternary generalization of the Pauli observables, is now available. [(#3035)](https://togithub.com/PennyLaneAI/pennylane/pull/3035) When using `qml.GellMann`, the `index` keyword argument determines which of the 8 Gell-Mann matrices is used. ```python dev = qml.device("default.qutrit", wires=2) @qml.qnode(dev) def circuit(): qml.TClock(wires=0) qml.TShift(wires=1) qml.TAdd(wires=[0, 1]) return qml.expval(qml.GellMann(wires=0, index=8) + qml.GellMann(wires=1, index=3)) ``` ```pycon >>> circuit() -0.42264973081037416 ``` - Controlled qutrit operations can now be performed with `qml.ControlledQutritUnitary`. ([#2844](https://togithub.com/PennyLaneAI/pennylane/pull/2844)) The control wires and values that define the operation are defined analogously to the qubit operation. ```python dev = qml.device("default.qutrit", wires=3) @qml.qnode(dev) def circuit(U): qml.TShift(wires=0) qml.TAdd(wires=[0, 1]) qml.ControlledQutritUnitary(U, control_wires=[0, 1], control_values='12', wires=2) return qml.state() ``` ```pycon >>> U = np.array([[1, 1, 0], [1, -1, 0], [0, 0, np.sqrt(2)]]) / np.sqrt(2) >>> circuit(U) tensor([0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], requires_grad=True) ```Improvements
- PennyLane now supports Python 3.11! [(#3297)](https://togithub.com/PennyLaneAI/pennylane/pull/3297) - `qml.sample` and `qml.counts` work more efficiently and track if computational basis samples are being generated when they are called without specifying an observable. [(#3207)](https://togithub.com/PennyLaneAI/pennylane/pull/3207) - The parameters of a basis set containing a different number of Gaussian functions are now easier to differentiate. [(#3213)](https://togithub.com/PennyLaneAI/pennylane/pull/3213) - Printing a `qml.MultiControlledX` operator now shows the `control_values` keyword argument. [(#3113)](https://togithub.com/PennyLaneAI/pennylane/pull/3113) - `qml.simplify` and transforms like `qml.matrix`, `batch_transform`, `hamiltonian_expand`, and `split_non_commuting` now work with `QuantumScript` as well as `QuantumTape`. [(#3209)](https://togithub.com/PennyLaneAI/pennylane/pull/3209) - A redundant flipping of the initial state in the UCCSD and kUpCCGSD templates has been removed. [(#3148)](https://togithub.com/PennyLaneAI/pennylane/pull/3148) - `qml.adjoint` now supports batching if the base operation supports batching. [(#3168)](https://togithub.com/PennyLaneAI/pennylane/pull/3168) - `qml.OrbitalRotation` is now decomposed into two `qml.SingleExcitation` operations for faster execution and more efficient parameter-shift gradient calculations on devices that natively support `qml.SingleExcitation`. [(#3171)](https://togithub.com/PennyLaneAI/pennylane/pull/3171) - The `Exp` class decomposes into a `PauliRot` class if the coefficient is imaginary and the base operator is a Pauli Word. [(#3249)](https://togithub.com/PennyLaneAI/pennylane/pull/3249) - Added the operator attributes `has_decomposition` and `has_adjoint` that indicate whether a corresponding `decomposition` or `adjoint` method is available. [(#2986)](https://togithub.com/PennyLaneAI/pennylane/pull/2986) - Structural improvements are made to `QueuingManager`, formerly `QueuingContext`, and `AnnotatedQueue`. [(#2794)](https://togithub.com/PennyLaneAI/pennylane/pull/2794) [(#3061)](https://togithub.com/PennyLaneAI/pennylane/pull/3061) [(#3085)](https://togithub.com/PennyLaneAI/pennylane/pull/3085) - `QueuingContext` is renamed to `QueuingManager`. - `QueuingManager` should now be the global communication point for putting queuable oConfiguration
๐ Schedule: Branch creation - "after 10pm every weekday,before 5am every weekday,every weekend" in timezone Asia/Tokyo, Automerge - At any time (no schedule defined).
๐ฆ Automerge: Disabled by config. Please merge this manually once you are satisfied.
โป Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
๐ Ignore: Close this PR and you won't be reminded about this update again.
This PR has been generated by Mend Renovate. View repository job log here.