From 9badedfc5d092754d19883324b670739aa6ef0ed Mon Sep 17 00:00:00 2001 From: Isaac De Vlugt Date: Mon, 6 Jan 2025 11:36:33 -0500 Subject: [PATCH 01/21] changelog From 422acb542d2ac79226d02d8d2b1f3a01814ff600 Mon Sep 17 00:00:00 2001 From: Isaac De Vlugt Date: Mon, 6 Jan 2025 12:15:26 -0500 Subject: [PATCH 02/21] breaking changes, docs, deps, bug fixes --- doc/releases/changelog-0.40.0.md | 138 ++++++++++++++++--------------- 1 file changed, 72 insertions(+), 66 deletions(-) diff --git a/doc/releases/changelog-0.40.0.md b/doc/releases/changelog-0.40.0.md index b381ea18ed0..89ca6a6e2d7 100644 --- a/doc/releases/changelog-0.40.0.md +++ b/doc/releases/changelog-0.40.0.md @@ -435,6 +435,15 @@ such as `shots`, `rng` and `prng_key`. * Added support `qml.Snapshot` operation in `qml.devices.qubit_mixed.apply_operation`. [(#6659)](https://github.com/PennyLaneAI/pennylane/pull/6659) +* Add reporting of test warnings as failures. + [(#6217)](https://github.com/PennyLaneAI/pennylane/pull/6217) + +* Add a warning message to Gradients and training documentation about ComplexWarnings. + [(#6543)](https://github.com/PennyLaneAI/pennylane/pull/6543) + +* Added `opengraph.png` asset and configured `opengraph` metadata image. Overrode the documentation landing page `meta-description`. + [(#6696)](https://github.com/PennyLaneAI/pennylane/pull/6696) +

Labs: a place for unified and rapid prototyping of research software ๐Ÿงช

Resource estimation

@@ -495,63 +504,68 @@ such as `shots`, `rng` and `prng_key`.

Breaking changes ๐Ÿ’”

-* The default graph coloring method of `qml.dot`, `qml.sum`, and `qml.pauli.optimize_measurements` for grouping observables was changed - from `"rlf"` to `"lf"`. Internally, `qml.pauli.group_observables` has been replaced with `qml.pauli.compute_partition_indices` - in several places to improve efficiency. +* The default graph coloring method of `qml.dot`, `qml.sum`, and `qml.pauli.optimize_measurements` + for grouping observables was changed from `"rlf"` to `"lf"`. Internally, + `qml.pauli.group_observables` has been replaced with `qml.pauli.compute_partition_indices` in + several places to improve efficiency. [(#6706)](https://github.com/PennyLaneAI/pennylane/pull/6706) -* `qml.fourier.qnode_spectrum` no longer automatically converts pure numpy parameters to the +* `qml.fourier.qnode_spectrum` no longer automatically converts pure Numpy parameters to the Autograd framework. As the function uses automatic differentiation for validation, parameters - from an autodiff framework have to be used. + from such a framework have to be used. [(#6622)](https://github.com/PennyLaneAI/pennylane/pull/6622) -* `qml.math.jax_argnums_to_tape_trainable` is moved and made private to avoid a qnode dependency - in the math module. +* `qml.math.jax_argnums_to_tape_trainable` has been moved and made private to avoid an unecessary + QNode dependency in the `qml.math` module. [(#6609)](https://github.com/PennyLaneAI/pennylane/pull/6609) -* Gradient transforms are now applied after the user's transform program. +* Gradient transforms are now applied after the user's transform program. This ensures user + transforms work as expected on initial structures (e.g., embeddings or entangling layers), + guarantees that gradient transforms only process compatible operations, aligns transform order + with user expectations, and avoids confusion. [(#6590)](https://github.com/PennyLaneAI/pennylane/pull/6590) -* Legacy operator arithmetic has been removed. This includes `qml.ops.Hamiltonian`, `qml.operation.Tensor`, - `qml.operation.enable_new_opmath`, `qml.operation.disable_new_opmath`, and `qml.operation.convert_to_legacy_H`. - Note that `qml.Hamiltonian` will continue to dispatch to `qml.ops.LinearCombination`. For more information, - check out the [updated operator troubleshooting page](https://docs.pennylane.ai/en/stable/news/new_opmath.html). +* Legacy operator arithmetic has been removed. This includes `qml.ops.Hamiltonian`, + `qml.operation.Tensor`, `qml.operation.enable_new_opmath`, `qml.operation.disable_new_opmath`, and + `qml.operation.convert_to_legacy_H`. Note that `qml.Hamiltonian` will continue to dispatch to + `qml.ops.LinearCombination`. For more information, check out the + [updated operator troubleshooting page](https://docs.pennylane.ai/en/stable/news/new_opmath.html). [(#6548)](https://github.com/PennyLaneAI/pennylane/pull/6548) [(#6602)](https://github.com/PennyLaneAI/pennylane/pull/6602) [(#6589)](https://github.com/PennyLaneAI/pennylane/pull/6589) -* The developer-facing `qml.utils` module has been removed. Specifically, the -following 4 sets of functions have been either moved or removed[(#6588)](https://github.com/PennyLaneAI/pennylane/pull/6588): - - * `qml.utils._flatten`, `qml.utils.unflatten` has been moved and renamed to `qml.optimize.qng._flatten_np` and `qml.optimize.qng._unflatten_np` respectively. - - * `qml.utils._inv_dict` and `qml._get_default_args` have been removed. +* The developer-facing `qml.utils` module has been removed. + [(#6588)](https://github.com/PennyLaneAI/pennylane/pull/6588): - * `qml.utils.pauli_eigs` has been moved to `qml.pauli.utils`. + Specifically, the following 4 sets of functions have been either moved or removed: + * `qml.utils._flatten`, `qml.utils.unflatten` has been moved and renamed to `qml.optimize.qng._flatten_np` and `qml.optimize.qng._unflatten_np` respectively. + * `qml.utils._inv_dict` and `qml._get_default_args` have been removed. + * `qml.utils.pauli_eigs` has been moved to `qml.pauli.utils`. + * `qml.utils.expand_vector` has been moved to `qml.math.expand_vector`. - * `qml.utils.expand_vector` has been moved to `qml.math.expand_vector`. - -* The `qml.qinfo` module has been removed. Please see the respective functions in the `qml.math` and `qml.measurements` - modules instead. +* The `qml.qinfo` module has been removed. Please use the corresponding functions in the `qml.math` + and `qml.measurements` modules instead. [(#6584)](https://github.com/PennyLaneAI/pennylane/pull/6584) * Top level access to `Device`, `QubitDevice`, and `QutritDevice` have been removed. Instead, they - are available as `qml.devices.LegacyDevice`, `qml.devices.QubitDevice`, and `qml.devices.QutritDevice` - respectively. + are available as `qml.devices.LegacyDevice`, `qml.devices.QubitDevice`, and + `qml.devices.QutritDevice`, respectively. [(#6537)](https://github.com/PennyLaneAI/pennylane/pull/6537) -* The `'ancilla'` argument for `qml.iterative_qpe` has been removed. Instead, use the `'aux_wire'` argument. +* The `'ancilla'` argument for `qml.iterative_qpe` has been removed. Instead, use the `'aux_wire'` + argument. [(#6532)](https://github.com/PennyLaneAI/pennylane/pull/6532) * The `qml.BasisStatePreparation` template has been removed. Instead, use `qml.BasisState`. [(#6528)](https://github.com/PennyLaneAI/pennylane/pull/6528) -* The `qml.workflow.set_shots` helper function has been removed. We no longer interact with the legacy device interface in our code. - Instead, shots should be specified on the tape, and the device should use these shots. +* The `qml.workflow.set_shots` helper function has been removed. We no longer interact with the + legacy device interface in our code. Instead, shots should be specified on the tape, and the + device should use these shots. [(#6534)](https://github.com/PennyLaneAI/pennylane/pull/6534) -* `QNode.gradient_fn` has been removed. Please use `QNode.diff_method` instead. `QNode.get_gradient_fn` can also be used to - process the diff method. +* `QNode.gradient_fn` has been removed. Please use `QNode.diff_method` instead. + `QNode.get_gradient_fn` can also be used to process the differentiation method. [(#6535)](https://github.com/PennyLaneAI/pennylane/pull/6535) * The `qml.QubitStateVector` template has been removed. Instead, use `qml.StatePrep`. @@ -573,51 +587,42 @@ following 4 sets of functions have been either moved or removed[(#6588)](https:/

Deprecations ๐Ÿ‘‹

-* The `tape` and `qtape` properties of `QNode` have been deprecated. - Instead, use the `qml.workflow.construct_tape` function. +* The `tape` and `qtape` properties of `QNode` have been deprecated. Instead, use the + `qml.workflow.construct_tape` function. [(#6583)](https://github.com/PennyLaneAI/pennylane/pull/6583) [(#6650)](https://github.com/PennyLaneAI/pennylane/pull/6650) -* The `max_expansion` argument in `qml.devices.preprocess.decompose` is deprecated and will be removed in v0.41. +* The `max_expansion` argument in `qml.devices.preprocess.decompose` is deprecated and will be + removed in v0.41. [(#6400)](https://github.com/PennyLaneAI/pennylane/pull/6400) -* The `decomp_depth` argument in `qml.transforms.set_decomposition` is deprecated and will be removed in v0.41. +* The `decomp_depth` argument in `qml.transforms.set_decomposition` is deprecated and will be + removed in v0.41. [(#6400)](https://github.com/PennyLaneAI/pennylane/pull/6400) -* The `output_dim` property of `qml.tape.QuantumScript` has been deprecated. -Instead, use method `shape` of `QuantumScript` or `MeasurementProcess` to get the -same information. +* The `output_dim` property of `qml.tape.QuantumScript` has been deprecated. Instead, use method + `shape` of `QuantumScript` or `MeasurementProcess` to get the same information. [(#6577)](https://github.com/PennyLaneAI/pennylane/pull/6577) -* The `QNode.get_best_method` and `QNode.best_method_str` methods have been deprecated. - Instead, use the `qml.workflow.get_best_diff_method` function. +* The `QNode.get_best_method` and `QNode.best_method_str` methods have been deprecated. Instead, use + the `qml.workflow.get_best_diff_method` function. [(#6418)](https://github.com/PennyLaneAI/pennylane/pull/6418) -* The `qml.execute` `gradient_fn` keyword argument has been renamed `diff_method`, - to better align with the termionology used by the `QNode`. - `gradient_fn` will be removed in v0.41. +* The `qml.execute` `gradient_fn` keyword argument has been renamed to `diff_method` to better + align with the termionology used by the QNode. `gradient_fn` will be removed in v0.41. [(#6549)](https://github.com/PennyLaneAI/pennylane/pull/6549)

Documentation ๐Ÿ“

-* The docstrings for `qml.qchem.Molecule` and `qml.qchem.molecular_hamiltonian` have been updated to include a - note that says that they are not compatible with qjit or jit. +* The docstrings for `qml.qchem.Molecule` and `qml.qchem.molecular_hamiltonian` have been updated to + include a note that says that they are not compatible with `qjit` or `jit`. [(#6702)](https://github.com/PennyLaneAI/pennylane/pull/6702) -* Updated the documentation of `TrotterProduct` to include the impact of the operands in the - Hamiltonian on the strucutre of the created circuit. Included an illustrative example on this. +* The documentation of `TrotterProduct` has been updated to include the impact of the operands in + the Hamiltonian on the strucutre of the created circuit. [(#6629)](https://github.com/PennyLaneAI/pennylane/pull/6629) -* Add reporting of test warnings as failures. - [(#6217)](https://github.com/PennyLaneAI/pennylane/pull/6217) - -* Add a warning message to Gradients and training documentation about ComplexWarnings. - [(#6543)](https://github.com/PennyLaneAI/pennylane/pull/6543) - -* Added `opengraph.png` asset and configured `opengraph` metadata image. Overrode the documentation landing page `meta-description`. - [(#6696)](https://github.com/PennyLaneAI/pennylane/pull/6696) - -* Updated the documentation of `QSVT` to include examples for different block encodings. +* The documentation of `QSVT` has been updated to include examples for different block encodings. [(#6673)](https://github.com/PennyLaneAI/pennylane/pull/6673) * The link to `qml.ops.one_qubit_transform` was fixed in the `QubitUnitary` docstring. @@ -625,7 +630,8 @@ same information.

Bug fixes ๐Ÿ›

-* `qml.counts` returns all outcomes when the `all_outcomes` argument is `True` and mid-circuit measurements are present. +* `qml.counts` now returns all outcomes when the `all_outcomes` argument is `True` and mid-circuit + measurements are present. [(#6732)](https://github.com/PennyLaneAI/pennylane/pull/6732) * `qml.ControlledQubitUnitary` has consistent behaviour with program capture enabled. @@ -635,29 +641,29 @@ same information. [(#6713)](https://github.com/PennyLaneAI/pennylane/pull/6713) [(#6720)](https://github.com/PennyLaneAI/pennylane/pull/6720) -* The `qml.Hermitian` class no longer checks that the provided matrix is hermitian. - The reason for this removal is to allow for faster execution and avoid incompatibilities with `jax.jit`. +* The `qml.Hermitian` class no longer checks that the provided matrix is hermitian. The reason for + this removal is to allow for faster execution and avoid incompatibilities with `jax.jit`. [(#6642)](https://github.com/PennyLaneAI/pennylane/pull/6642) -* Subclasses of `qml.ops.Controlled` no longer bind the primitives of their base operators when program capture - is enabled. +* Subclasses of `qml.ops.Controlled` no longer bind the primitives of their base operators when + program capture is enabled. [(#6672)](https://github.com/PennyLaneAI/pennylane/pull/6672) * The `qml.HilbertSchmidt` and `qml.LocalHilbertSchmidt` templates now apply the complex conjugate of the unitaries instead of the adjoint, providing the correct result. [(#6604)](https://github.com/PennyLaneAI/pennylane/pull/6604) -* `QNode` return behaviour is now consistent for lists and tuples. +* QNode return behaviour is now consistent for lists and tuples. [(#6568)](https://github.com/PennyLaneAI/pennylane/pull/6568) -* `qml.QNode` now accepts arguments with types defined in libraries that are not necessarily - in the list of supported interfaces, such as the `Graph` class defined in `networkx`. +* QNode now accepts arguments with types defined in libraries that are not necessarily in the list + of supported interfaces, such as the `Graph` class defined in `networkx`. [(#6600)](https://github.com/PennyLaneAI/pennylane/pull/6600) -* `qml.math.get_deep_interface` now works properly for autograd arrays. +* `qml.math.get_deep_interface` now works properly for Autograd arrays. [(#6557)](https://github.com/PennyLaneAI/pennylane/pull/6557) -* Fixed `Identity.__repr__` to return correct wires list. +* Fixed `Identity.__repr__` to return the correct wires list. [(#6506)](https://github.com/PennyLaneAI/pennylane/pull/6506)

Contributors โœ๏ธ

From f9d35d2689b8e5e508eaa01eff5350f098120b0a Mon Sep 17 00:00:00 2001 From: Isaac De Vlugt Date: Mon, 6 Jan 2025 12:15:56 -0500 Subject: [PATCH 03/21] minor --- doc/releases/changelog-0.40.0.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/releases/changelog-0.40.0.md b/doc/releases/changelog-0.40.0.md index 89ca6a6e2d7..a6011a434c7 100644 --- a/doc/releases/changelog-0.40.0.md +++ b/doc/releases/changelog-0.40.0.md @@ -637,7 +637,7 @@ such as `shots`, `rng` and `prng_key`. * `qml.ControlledQubitUnitary` has consistent behaviour with program capture enabled. [(#6719)](https://github.com/PennyLaneAI/pennylane/pull/6719) -* The `Wires` object throws a `TypeError` if `wires=None`. +* The `Wires` object now throws a `TypeError` if `wires=None`. [(#6713)](https://github.com/PennyLaneAI/pennylane/pull/6713) [(#6720)](https://github.com/PennyLaneAI/pennylane/pull/6720) From 8fa123f87fd3bffc0eddb2ae6304dac6045abe25 Mon Sep 17 00:00:00 2001 From: Mudit Pandey Date: Tue, 7 Jan 2025 16:23:21 -0500 Subject: [PATCH 04/21] Fix small issue with default.mixed related changelog entry --- doc/releases/changelog-0.40.0.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/releases/changelog-0.40.0.md b/doc/releases/changelog-0.40.0.md index a6011a434c7..773751009a0 100644 --- a/doc/releases/changelog-0.40.0.md +++ b/doc/releases/changelog-0.40.0.md @@ -403,10 +403,11 @@ * Improved documentation for the `dynamic_one_shot` transform, and a warning is raised when a user-applied `dynamic_one_shot` transform is ignored in favour of the existing transform in a device's preprocessing transform program. [(#6701)](https://github.com/PennyLaneAI/pennylane/pull/6701) -* Added `qml.devices.qubit_mixed` module for mixed-state qubit device support [(#6379)](https://github.com/PennyLaneAI/pennylane/pull/6379). This module introduces an `apply_operation` helper function that features: +* Added `qml.devices.qubit_mixed` module for mixed-state qubit device support. This module introduces an `apply_operation` helper function that features: * Two density matrix contraction methods using `einsum` and `tensordot` * Optimized handling of special cases including: Diagonal operators, Identity operators, CX (controlled-X), Multi-controlled X gates, Grover operators + [(#6379)](https://github.com/PennyLaneAI/pennylane/pull/6379) * Added submodule 'initialize_state' featuring a `create_initial_state` function for initializing a density matrix from `qml.StatePrep` operations or `qml.QubitDensityMatrix` operations. [(#6503)](https://github.com/PennyLaneAI/pennylane/pull/6503) From dbadfba9573dca0f1d64a473d5dfc8e9f5c7e1ce Mon Sep 17 00:00:00 2001 From: Isaac De Vlugt <34751083+isaacdevlugt@users.noreply.github.com> Date: Thu, 9 Jan 2025 13:44:43 -0500 Subject: [PATCH 05/21] v0.40.0 changelog - Bosonic ops (#6764) Co-authored-by: ANTH0NY <39093564+AntonNI8@users.noreply.github.com> --- doc/releases/changelog-0.40.0.md | 59 ++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 7 deletions(-) diff --git a/doc/releases/changelog-0.40.0.md b/doc/releases/changelog-0.40.0.md index 773751009a0..c95728f79b8 100644 --- a/doc/releases/changelog-0.40.0.md +++ b/doc/releases/changelog-0.40.0.md @@ -79,17 +79,62 @@

Bosonic operators ๐ŸŽˆ

-* Added `unary_mapping()` function to map `BoseWord` and `BoseSentence` to qubit operators, using unary mapping. - [(#6576)](https://github.com/PennyLaneAI/pennylane/pull/6576) +A new module, :mod:`qml.bose `, has been added to PennyLane that includes support +for constructing and manipulating Bosonic operators and converting between Bosonic operators and +qubit operators. -* Added `binary_mapping()` function to map `BoseWord` and `BoseSentence` to qubit operators, using standard-binary mapping. - [(#6564)](https://github.com/PennyLaneAI/pennylane/pull/6564) +* Bosonic operators analogous to `qml.FermiWord` and `qml.FermiSentence` are now available with + :class:`qml.BoseWord ` and :class:`qml.BoseSentence `. + [(#6518)](https://github.com/PennyLaneAI/pennylane/pull/6518) + + :class:`qml.BoseWord ` and :class:`qml.BoseSentence ` + operate similarly to their fermionic counterparts. To create a Bose word, a dictionary + is required as input, where the keys are tuples of boson indicies and values are `'+/-'` (denoting + the bosonic creation/annihilation operators). For example, the :math:`b^{\dagger}_0 b_1` can be + constructed as follows. + + ```pycon + >>> w = qml.BoseWord({(0, 0) : '+', (1, 1) : '-'}) + >>> print(w) + bโบ(0) b(1) + ``` + + Multiple Bose words can then be combined to form a Bose sentence: + + ```pycon + >>> w1 = qml.BoseWord({(0, 0) : '+', (1, 1) : '-'}) + >>> w2 = qml.BoseWord({(0, 1) : '+', (1, 2) : '-'}) + >>> s = qml.BoseSentence({w1 : 1.2, w2: 3.1}) + >>> print(s) + 1.2 * bโบ(0) b(1) + + 3.1 * bโบ(1) b(2) + ``` -* Added `christiansen_mapping()` function to map `BoseWord` and `BoseSentence` to qubit operators, using christiansen mapping. +* Functionality for converting bosonic operators to qubit operators is available with + :func:`qml.unary_mapping `, :func:`qml.binary_mapping `, + and :func:`qml.christiansen_mapping `. [(#6623)](https://github.com/PennyLaneAI/pennylane/pull/6623) + [(#6576)](https://github.com/PennyLaneAI/pennylane/pull/6576) + [(#6564)](https://github.com/PennyLaneAI/pennylane/pull/6564) -* Added support for constructing `BoseWord` and `BoseSentence`, similar to `FermiWord` and `FermiSentence`. - [(#6518)](https://github.com/PennyLaneAI/pennylane/pull/6518) + All three mappings follow the same syntax, where a :class:`qml.BoseWord ` or + :class:`qml.BoseSentence ` is required as input. + + ```python + >>> w = qml.BoseWord({(0, 0): "+"}) + >>> qml.binary_mapping(w, n_states=4) + 0.6830127018922193 * X(0) + + -0.1830127018922193 * X(0) @ Z(1) + + -0.6830127018922193j * Y(0) + + 0.1830127018922193j * Y(0) @ Z(1) + + 0.3535533905932738 * X(0) @ X(1) + + -0.3535533905932738j * X(0) @ Y(1) + + 0.3535533905932738j * Y(0) @ X(1) + + (0.3535533905932738+0j) * Y(0) @ Y(1) + ``` + + Additional fine-tuning is available within each function, such as the maximum number of allowed + bosonic states and a tolerance for discarding imaginary parts of the coefficients.

Construct vibrational Hamiltonians ๐Ÿซจ

From 2f67f7fde97872800803e6d04b8dfaf4d10f745b Mon Sep 17 00:00:00 2001 From: Isaac De Vlugt Date: Thu, 9 Jan 2025 15:03:13 -0500 Subject: [PATCH 06/21] changelog --- doc/releases/changelog-0.40.0.md | 155 ++++++++++++++++++------------- 1 file changed, 93 insertions(+), 62 deletions(-) diff --git a/doc/releases/changelog-0.40.0.md b/doc/releases/changelog-0.40.0.md index c95728f79b8..41522335beb 100644 --- a/doc/releases/changelog-0.40.0.md +++ b/doc/releases/changelog-0.40.0.md @@ -168,94 +168,118 @@ qubit operators. [(#6573)](https://github.com/PennyLaneAI/pennylane/pull/6573) [(#6611)](https://github.com/PennyLaneAI/pennylane/pull/6611) -* Added `qml.qchem.symmetry_shift` function to perform the - [block-invariant symmetry shift](https://arxiv.org/pdf/2304.13772) on the electronic integrals. +* A new function for performing the [block-invariant symmetry shift](https://arxiv.org/pdf/2304.13772) + on electronic integrals has been added with `qml.qchem.symmetry_shift`. [(#6574)](https://github.com/PennyLaneAI/pennylane/pull/6574) -* Added JAX support for the differentiable Hartree-Fock workflow. +* The differentiable Hartree-Fock workflow is now compatible with JAX. [(#6096)](https://github.com/PennyLaneAI/pennylane/pull/6096) [(#6707)](https://github.com/PennyLaneAI/pennylane/pull/6707)

Transform for combining GlobalPhase instances

-* Added a new `qml.transforms.combine_global_phases` transform to combine all `qml.GlobalPhase` gates in a circuit into a single one applied at the end. - This can be useful for circuits that include a lot of `qml.GlobalPhase` gates, which can be introduced directly during circuit creation, - decompositions that include `qml.GlobalPhase` gates, etc. +* A new transform called `qml.transforms.combine_global_phases` has been added. It combines all + `qml.GlobalPhase` gates in a circuit into a single one applied at the end. This can be useful for + circuits that include a lot of `qml.GlobalPhase` gates that are introduced directly during + circuit creation, decompositions that include `qml.GlobalPhase` gates, etc. [(#6686)](https://github.com/PennyLaneAI/pennylane/pull/6686)

Better drawing functionality

-* Added support for the `wire_options` dictionary to customize wire line formatting in `qml.draw_mpl` circuit - visualizations, allowing global and per-wire customization with options like `color`, `linestyle`, and `linewidth`. +* `qml.draw_mpl` now has a `wire_options` keyword argument, which allows for global- and per-wire + customization with options like `color`, `linestyle`, and `linewidth`. [(#6486)](https://github.com/PennyLaneAI/pennylane/pull/6486) + Here is an example that would make all wires cyan and bold except for wires 2 and 6, which are + dashed and a different colour. + + ```python + @qml.qnode(qml.device("default.qubit")) + def circuit(x): + for w in range(5): + qml.Hadamard(w) + return qml.expval(qml.PauliZ(0) @ qml.PauliY(1)) + + wire_options = {"color": "cyan", + "linewidth": 5, + 2: {"linestyle": "--", "color": "red"}, + 6: {"linestyle": "--", "color": "orange"} + } + print(qml.draw_mpl(circuit, wire_options=wire_options)(0.52)) + ``` +

New device capabilities ๐Ÿ’พ

-* Two new methods: `setup_execution_config` and `preprocess_transforms` are added to the `Device` - class. Device developers are encouraged to override these two methods separately instead of the +* Two new methods, `setup_execution_config` and `preprocess_transforms`, have been added to the + `Device` class. Device developers are encouraged to override these two methods separately instead of the `preprocess` method. For now, to avoid ambiguity, a device is allowed to override either these two methods or `preprocess`, but not both. In the long term, we will slowly phase out the use of `preprocess` in favour of these two methods for better separation of concerns. [(#6617)](https://github.com/PennyLaneAI/pennylane/pull/6617) * Developers of plugin devices now have the option of providing a TOML-formatted configuration file - to declare the capabilities of the device. See [Device Capabilities](https://docs.pennylane.ai/en/latest/development/plugins.html#device-capabilities) for details. + to declare the capabilities of the device. See + [Device Capabilities](https://docs.pennylane.ai/en/latest/development/plugins.html#device-capabilities) + for details. -* An internal module `pennylane.devices.capabilities` is added that defines a new `DeviceCapabilites` - data class, as well as functions that load and parse the TOML-formatted configuration files. +* An internal module called `qml.devices.capabilities` has been added that defines a new + `DeviceCapabilites` data class, as well as functions that load and parse the TOML-formatted + configuration files. [(#6407)](https://github.com/PennyLaneAI/pennylane/pull/6407) ```pycon - >>> from pennylane.devices.capabilities import DeviceCapabilities - >>> capabilities = DeviceCapabilities.from_toml_file("my_device.toml") - >>> isinstance(capabilities, DeviceCapabilities) - True + >>> from pennylane.devices.capabilities import DeviceCapabilities + >>> capabilities = DeviceCapabilities.from_toml_file("my_device.toml") + >>> isinstance(capabilities, DeviceCapabilities) + True ``` -* Devices that extends `qml.devices.Device` now has an optional class attribute `capabilities` - that is an instance of the `DeviceCapabilities` data class, constructed from the configuration - file if it exists. Otherwise, it is set to `None`. +* Devices that extend `qml.devices.Device` now have an optional class attribute called + `capabilities`, which is an instance of the `DeviceCapabilities` data class constructed from the + configuration file if it exists. Otherwise, it is set to `None`. [(#6433)](https://github.com/PennyLaneAI/pennylane/pull/6433) ```python from pennylane.devices import Device class MyDevice(Device): - config_filepath = "path/to/config.toml" - ... ``` + ```pycon >>> isinstance(MyDevice.capabilities, DeviceCapabilities) True ``` * Default implementations of `Device.setup_execution_config` and `Device.preprocess_transforms` - are added to the device API for devices that provides a TOML configuration file and thus have - a `capabilities` property. + have been added to the device API for devices that provide a TOML configuration file and, thus, + have a `capabilities` property. [(#6632)](https://github.com/PennyLaneAI/pennylane/pull/6632) [(#6653)](https://github.com/PennyLaneAI/pennylane/pull/6653)

Capturing and representing hybrid programs

-* Support is added for `if`/`else` statements and `for` and `while` loops in circuits executed with `qml.capture.enabled`, via Autograph. - Autograph conversion is now used by default in `make_plxpr`, but can be skipped with the keyword arg `autograph=False`. +* Support has been added for `if`/`else` statements and `for` and `while` loops in circuits executed + with `qml.capture.enabled`, via Autograph. Autograph conversion is now used by default in + `make_plxpr`, but can be skipped with `autograph=False`. [(#6406)](https://github.com/PennyLaneAI/pennylane/pull/6406) [(#6413)](https://github.com/PennyLaneAI/pennylane/pull/6413) [(#6426)](https://github.com/PennyLaneAI/pennylane/pull/6426) [(#6645)](https://github.com/PennyLaneAI/pennylane/pull/6645) [(#6685)](https://github.com/PennyLaneAI/pennylane/pull/6685) -* `qml.transform` now accepts a `plxpr_transform` argument. This argument must be a function that can transform plxpr. - Note that executing a transformed function will currently raise a `NotImplementedError`. To see more details, check - out the documentation of `qml.transform`. +* `qml.transform` now accepts a `plxpr_transform` argument. This argument must be a function that + can transform plxpr. Note that executing a transformed function will currently raise a + `NotImplementedError`. To see more details, check out the + :func:`documentation of qml.transform `. [(#6633)](https://github.com/PennyLaneAI/pennylane/pull/6633) [(#6722)](https://github.com/PennyLaneAI/pennylane/pull/6722) -* Users can now apply transforms with program capture enabled. Transformed functions cannot be executed by default. To apply - the transforms (and be able to execute the function), it must be decorated with the new `qml.capture.expand_plxpr_transforms` - function, which accepts a callable as input and returns a new function to which all present transforms have been applied. +* Users can now apply transforms with program capture enabled. Transformed functions cannot be + executed by default. To apply the transforms (and to be able to execute the function), it must be + decorated with the new `qml.capture.expand_plxpr_transforms` function, which accepts a callable as + input and returns a new function for which all present transforms have been applied. [(#6722)](https://github.com/PennyLaneAI/pennylane/pull/6722) ```python @@ -300,29 +324,31 @@ qubit operators. in (d,) } ``` -* The `qml.iterative_qpe` function can now be compactly captured into jaxpr. +* The `qml.iterative_qpe` function can now be compactly captured into plxpr. [(#6680)](https://github.com/PennyLaneAI/pennylane/pull/6680) -* Functions and plxpr can now be natively transformed using the new `qml.capture.transforms.CancelInterpreter` - when program capture is enabled. This class cancels operators appearing consecutively that are adjoints of each - other, and follows the same API as `qml.transforms.cancel_inverses`. - [(#6692)](https://github.com/PennyLaneAI/pennylane/pull/6692) +* Three new plxpr interpreters have been added that allow for functions and plxpr to be natively + transformed with the same API as the corresponding existing transforms in PennyLane when program + capture is enabled: + + * `qml.capture.transforms.CancelInterpreter`:this class cancels operators appearing consecutively + that are adjoints of each other following the same API as `qml.transforms.cancel_inverses`. + [(#6692)](https://github.com/PennyLaneAI/pennylane/pull/6692) -* Functions and plxpr can now be natively transformed using the new `qml.capture.transforms.DecomposeInterpreter` - when program capture is enabled. This class decomposes pennylane operators following the same API as - `qml.transforms.decompose`. - [(#6691)](https://github.com/PennyLaneAI/pennylane/pull/6691) + * `qml.capture.transforms.DecomposeInterpreter`: this class decomposes pennylane operators + following the same API as `qml.transforms.decompose`. + [(#6691)](https://github.com/PennyLaneAI/pennylane/pull/6691) -* Implemented a `MapWiresInterpreter` class that can be used as a quantum transform to map - operator and measurement wires with capture enabled. - [(#6697)](https://github.com/PennyLaneAI/pennylane/pull/6697) + * `qml.capture.transforms.MapWiresInterpreter`: this class maps wires to new values following the + same API as `qml.map_wires`. + [(#6697)](https://github.com/PennyLaneAI/pennylane/pull/6697) -* A `qml.tape.plxpr_to_tape` function can now convert plxpr to a tape. +* A `qml.tape.plxpr_to_tape` function is now available that converts plxpr to a tape. [(#6343)](https://github.com/PennyLaneAI/pennylane/pull/6343) * Execution with capture enabled now follows a new execution pipeline and natively passes the - captured jaxpr to the device. Since it no longer falls back to the old pipeline, execution - only works with a reduced feature set. + captured plxpr to the device. Since it no longer falls back to the old pipeline, execution only + works with a reduced feature set. [(#6655)](https://github.com/PennyLaneAI/pennylane/pull/6655) [(#6596)](https://github.com/PennyLaneAI/pennylane/pull/6596) @@ -334,16 +360,17 @@ qubit operators. [(#6422)](https://github.com/PennyLaneAI/pennylane/pull/6422) [(#6668)](https://github.com/PennyLaneAI/pennylane/pull/6668) -* `qml.capture.PlxprInterpreter` base class has been added for easy transformation and execution of - pennylane variant jaxpr. +* A `qml.capture.PlxprInterpreter` base class has been added for easy transformation and execution + of plxpr. [(#6141)](https://github.com/PennyLaneAI/pennylane/pull/6141) -* A `DefaultQubitInterpreter` class has been added to provide plxpr execution using python based tools, - and the `DefaultQubit.eval_jaxpr` method is now implemented. +* A `DefaultQubitInterpreter` class has been added to provide plxpr execution using python based + tools, and the `DefaultQubit.eval_jaxpr` method has been implemented. [(#6594)](https://github.com/PennyLaneAI/pennylane/pull/6594) [(#6328)](https://github.com/PennyLaneAI/pennylane/pull/6328) -* An optional method `eval_jaxpr` is added to the device API for native execution of plxpr programs. +* An optional method, `eval_jaxpr`, has been added to the device API for native execution of plxpr + programs. [(#6580)](https://github.com/PennyLaneAI/pennylane/pull/6580) * `qml.capture.qnode_call` has been made private and moved to the `workflow` module. @@ -351,37 +378,41 @@ qubit operators.

Other Improvements

-* `qml.math.grad` and `qml.math.jacobian` added to differentiate a function with inputs of any - interface in a jax-like manner. +* `qml.math.grad` and `qml.math.jacobian` have been added to differentiate a function with inputs of + any interface in a JAX-like manner. [(#6741)](https://github.com/PennyLaneAI/pennylane/pull/6741) * `qml.GroverOperator` now has a `work_wires` property. [(#6738)](https://github.com/PennyLaneAI/pennylane/pull/6738) -* `Wires` object usage across Pennylane source code has been tidied up. +* The `Wires` object's usage across Pennylane source code has been tidied up for internal + consistency. [(#6689)](https://github.com/PennyLaneAI/pennylane/pull/6689) -* `qml.equal` now supports `PauliWord` and `PauliSentence` instances. +* `qml.equal` now supports `qml.PauliWord` and `qml.PauliSentence` instances. [(#6703)](https://github.com/PennyLaneAI/pennylane/pull/6703) -* Remove redundant commutator computations from `qml.lie_closure`. +* Redundant commutator computations from `qml.lie_closure` have been removed. [(#6724)](https://github.com/PennyLaneAI/pennylane/pull/6724) -* Raises a comprehensive error when using `qml.fourier.qnode_spectrum` with standard numpy +* A comprehensive error is now raised when using `qml.fourier.qnode_spectrum` with standard Numpy arguments and `interface="auto"`. [(#6622)](https://github.com/PennyLaneAI/pennylane/pull/6622) -* Added Pauli String representations for the gates X, Y, Z, S, T, SX, SWAP, ISWAP, ECR, SISWAP. Fixed a shape error in the matrix conversion of `PauliSentence`s with list or array input. +* Pauli string representations for the gates `{X, Y, Z, S, T, SX, SWAP, ISWAP, ECR, SISWAP}` have + been added, and a shape error in the matrix conversion of `qml.PauliSentence`s with `list` or + `array` inputs has been fixed. [(#6562)](https://github.com/PennyLaneAI/pennylane/pull/6562) [(#6587)](https://github.com/PennyLaneAI/pennylane/pull/6587) -* `QNode` and `qml.execute` now forbid certain keyword arguments from being passed positionally. +* `qml.QNode` and `qml.execute` now forbid certain keyword arguments from being passed positionally. [(#6610)](https://github.com/PennyLaneAI/pennylane/pull/6610) -* Shortened the string representation for the `qml.S`, `qml.T`, and `qml.SX` operators. +* The string representations for the `qml.S`, `qml.T`, and `qml.SX` have been shortened. [(#6542)](https://github.com/PennyLaneAI/pennylane/pull/6542) -* Added functions and dunder methods to add and multiply Resources objects in series and in parallel. +* Internal class functions and dunder methods have been added to allow for multiplying Resources + objects in series and in parallel. [(#6567)](https://github.com/PennyLaneAI/pennylane/pull/6567) * The `diagonalize_measurements` transform no longer raises an error for unknown observables. Instead, From d0cdc5115970c64e0ad44e7adba671720dd08d5d Mon Sep 17 00:00:00 2001 From: Austin Huang <65315367+austingmhuang@users.noreply.github.com> Date: Fri, 10 Jan 2025 09:36:55 -0500 Subject: [PATCH 07/21] move labs functionality in changelog (#6794) **Context:** Some entries in the changelog belong in the labs section instead **Description of the Change:** Moved to labs section of changelog --------- Co-authored-by: Isaac De Vlugt <34751083+isaacdevlugt@users.noreply.github.com> --- doc/releases/changelog-0.40.0.md | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/doc/releases/changelog-0.40.0.md b/doc/releases/changelog-0.40.0.md index 41522335beb..2c87d66b38b 100644 --- a/doc/releases/changelog-0.40.0.md +++ b/doc/releases/changelog-0.40.0.md @@ -143,10 +143,6 @@ qubit operators. and normal-mode localization. [(#6453)](https://github.com/PennyLaneAI/pennylane/pull/6453) [(#6666)](https://github.com/PennyLaneAI/pennylane/pull/6666) - * Implemented helper functions for calculating one-mode PES, two-mode PES, and - three-mode PES. - [(#6616)](https://github.com/PennyLaneAI/pennylane/pull/6616) - [(#6676)](https://github.com/PennyLaneAI/pennylane/pull/6676) * Implemented wrapper function for vibrational Hamiltonian calculation and dataclass for storing the data. [(#6652)](https://github.com/PennyLaneAI/pennylane/pull/6652) @@ -156,9 +152,6 @@ qubit operators. * Added support to build a vibrational Hamiltonian in Taylor form. [(#6523)](https://github.com/PennyLaneAI/pennylane/pull/6523) -* Added support to build a vibrational Hamiltonian in the Christiansen form. - [(#6560)](https://github.com/PennyLaneAI/pennylane/pull/6560) -

Improvements ๐Ÿ› 

QChem improvements

@@ -579,6 +572,16 @@ such as `shots`, `rng` and `prng_key`. for the horizontal Cartan subalgebra instead of `$\mathfrak{h}$`. [(#6747)](https://github.com/PennyLaneAI/pennylane/pull/6747) +

Vibrational Hamiltonians

+ +* Implemented helper functions for calculating one-mode PES, two-mode PES, and +three-mode PES. + [(#6616)](https://github.com/PennyLaneAI/pennylane/pull/6616) + [(#6676)](https://github.com/PennyLaneAI/pennylane/pull/6676) + +* Added support to build a vibrational Hamiltonian in the Christiansen form. + [(#6560)](https://github.com/PennyLaneAI/pennylane/pull/6560) +

Breaking changes ๐Ÿ’”

* The default graph coloring method of `qml.dot`, `qml.sum`, and `qml.pauli.optimize_measurements` From c353b77651d97c26a7550e5f814e027f284c4b37 Mon Sep 17 00:00:00 2001 From: Isaac De Vlugt Date: Fri, 10 Jan 2025 15:50:43 -0500 Subject: [PATCH 08/21] wording --- doc/releases/changelog-0.40.0.md | 98 +++++++++++++++++--------------- 1 file changed, 53 insertions(+), 45 deletions(-) diff --git a/doc/releases/changelog-0.40.0.md b/doc/releases/changelog-0.40.0.md index 2c87d66b38b..56f064beddc 100644 --- a/doc/releases/changelog-0.40.0.md +++ b/doc/releases/changelog-0.40.0.md @@ -421,13 +421,15 @@ qubit operators. [(#6630)](https://github.com/PennyLaneAI/pennylane/pull/6630) [(#6736)](https://github.com/PennyLaneAI/pennylane/pull/6736) -* Add developer focused `run` function to `qml.workflow` module. +* A developer focused `run` function has been added to the `qml.workflow` module for a cleaner and + standardized approach to executing tapes on an ML interface. [(#6657)](https://github.com/PennyLaneAI/pennylane/pull/6657) -* Standardize supported interfaces to an internal `Enum` object. +* Internal changes have been made to standardize execution interfaces, which resolves ambiguities in + how the `interface` value is handled during execution. [(#6643)](https://github.com/PennyLaneAI/pennylane/pull/6643) -* Moved all interface handling logic to `interface_utils.py` in the `qml.math` module. +* All interface handling logic has been moved to `interface_utils.py` in the `qml.math` module. [(#6649)](https://github.com/PennyLaneAI/pennylane/pull/6649) * `qml.execute` can now be used with `diff_method="best"`. @@ -435,7 +437,7 @@ qubit operators. validation and program setup is now handled inside of `qml.execute`, instead of in `QNode`. [(#6716)](https://github.com/PennyLaneAI/pennylane/pull/6716) -* Added PyTree support for measurements in a circuit. +* PyTree support for measurements in a circuit has been added. [(#6378)](https://github.com/PennyLaneAI/pennylane/pull/6378) ```python @@ -452,66 +454,72 @@ qubit operators. {'Probabilities': array([0.5, 0. , 0. , 0.5]), 'State': array([0.70710678+0.j, 0. +0.j, 0. +0.j, 0.70710678+0.j])} ``` -* `_cache_transform` transform has been moved to its own file located - at `qml.workflow._cache_transform.py`. +* The `_cache_transform` transform has been moved to its own file located in + `pennylane/workflow/_cache_transform.py`. [(#6624)](https://github.com/PennyLaneAI/pennylane/pull/6624) -* `qml.BasisRotation` template is now JIT compatible. +* The `qml.BasisRotation` template is now JIT compatible. [(#6019)](https://github.com/PennyLaneAI/pennylane/pull/6019) * The Jaxpr primitives for `for_loop`, `while_loop` and `cond` now store slices instead of - numbers of args. + numbers of arguments. This helps with keeping track of what order the arguments come in. [(#6521)](https://github.com/PennyLaneAI/pennylane/pull/6521) -* Expand `ExecutionConfig.gradient_method` to store `TransformDispatcher` type. +* The `ExecutionConfig.gradient_method` function has been expanded to store `TransformDispatcher` + type. [(#6455)](https://github.com/PennyLaneAI/pennylane/pull/6455) -* Fix the string representation of `Resources` instances to match the attribute names. +* The string representation of `Resources` instances has been improved to match the attribute names. [(#6581)](https://github.com/PennyLaneAI/pennylane/pull/6581) -* Improved documentation for the `dynamic_one_shot` transform, and a warning is raised when a user-applied `dynamic_one_shot` transform is ignored in favour of the existing transform in a device's preprocessing transform program. +* The documentation for the `dynamic_one_shot` transform has been improved, and a warning is raised + when a user-applied `dynamic_one_shot` transform is ignored in favour of the existing transform in + a device's preprocessing transform program. [(#6701)](https://github.com/PennyLaneAI/pennylane/pull/6701) -* Added `qml.devices.qubit_mixed` module for mixed-state qubit device support. This module introduces an `apply_operation` helper function that features: - +* A `qml.devices.qubit_mixed` module has been added for mixed-state qubit device support. This + module introduces an `apply_operation` helper function that features: * Two density matrix contraction methods using `einsum` and `tensordot` - * Optimized handling of special cases including: Diagonal operators, Identity operators, CX (controlled-X), Multi-controlled X gates, Grover operators + * Optimized handling of special cases including: Diagonal operators, Identity operators, CX + (controlled-X), Multi-controlled X gates, Grover operators [(#6379)](https://github.com/PennyLaneAI/pennylane/pull/6379) -* Added submodule 'initialize_state' featuring a `create_initial_state` function for initializing a density matrix from `qml.StatePrep` operations or `qml.QubitDensityMatrix` operations. +* A function called `create_initial_state` has been added to allow for initializing a circuit with a + density matrix using `qml.StatePrep` or `qml.QubitDensityMatrix`. [(#6503)](https://github.com/PennyLaneAI/pennylane/pull/6503) - -* Added method `preprocess` to the `QubitMixed` device class to preprocess the quantum circuit before execution. Necessary non-intrusive interfaces changes to class init method were made along the way to the `QubitMixed` device class to support new API feature. - [(#6601)](https://github.com/PennyLaneAI/pennylane/pull/6601) - -* Added a second class `DefaultMixedNewAPI` to the `qml.devices.qubit_mixed` module, which is to be the replacement of legacy `DefaultMixed` which for now to hold the implementations of `preprocess` and `execute` methods. - [(#6607)](https://github.com/PennyLaneAI/pennylane/pull/6607) - -* Added submodule `devices.qubit_mixed.measure` as a necessary step for the new API, featuring a `measure` function for measuring qubits in mixed-state devices. - [(#6637)](https://github.com/PennyLaneAI/pennylane/pull/6637) - -* Added submodule `devices.qubit_mixed.simulate` as a necessary step for the new API, -featuring a `simulate` function for simulating mixed states in analytic mode. - [(#6618)](https://github.com/PennyLaneAI/pennylane/pull/6618) - -* Added submodule `devices.qubit_mixed.sampling` as a necessary step for the new API, featuring functions `sample_state`, `measure_with_samples` and `sample_probs` for sampling qubits in mixed-state devices. - [(#6639)](https://github.com/PennyLaneAI/pennylane/pull/6639) - -* Implemented the finite-shot branch of `devices.qubit_mixed.simulate`. Now, the -new device API of `default_mixed` should be able to take the stochastic arguments -such as `shots`, `rng` and `prng_key`. -[(#6665)](https://github.com/PennyLaneAI/pennylane/pull/6665) - -* Added support `qml.Snapshot` operation in `qml.devices.qubit_mixed.apply_operation`. - [(#6659)](https://github.com/PennyLaneAI/pennylane/pull/6659) -* Add reporting of test warnings as failures. +* Several additions have been made to eventually migrate the `"default.mixed"` device to the new + device API: + * A `preprocess` method has been added to the `QubitMixed` device class to preprocess the quantum + circuit before execution. + [(#6601)](https://github.com/PennyLaneAI/pennylane/pull/6601) + * A new class called `DefaultMixedNewAPI` has been addded to the `qml.devices.qubit_mixed` module, + which will replace the legacy `DefaultMixed`. + [(#6607)](https://github.com/PennyLaneAI/pennylane/pull/6607) + * A new submodule called `devices.qubit_mixed.measure` has been added, featuring a `measure` + function for measuring qubits in mixed-state devices. + [(#6637)](https://github.com/PennyLaneAI/pennylane/pull/6637) + * A new submodule called `devices.qubit_mixed.simulate` has been added, featuring a `simulate` + function for simulating mixed states in analytic mode. + [(#6618)](https://github.com/PennyLaneAI/pennylane/pull/6618) + * A new submodule called `devices.qubit_mixed.sampling` has been added, featuring functions + `sample_state`, `measure_with_samples` and `sample_probs` for sampling qubits in mixed-state + devices. + [(#6639)](https://github.com/PennyLaneAI/pennylane/pull/6639) + * The finite-shot branch of `devices.qubit_mixed.simulate` has been added, which allows for + accepting stochastic arguments such as `shots`, `rng` and `prng_key`. + [(#6665)](https://github.com/PennyLaneAI/pennylane/pull/6665) + * Support for `qml.Snapshot` has been added. + [(#6659)](https://github.com/PennyLaneAI/pennylane/pull/6659) + +* Reporting of test warnings as failures has been added [(#6217)](https://github.com/PennyLaneAI/pennylane/pull/6217) -* Add a warning message to Gradients and training documentation about ComplexWarnings. +* A warning message in the Gradients and training documentation has been added that pertains to + `ComplexWarning`s. [(#6543)](https://github.com/PennyLaneAI/pennylane/pull/6543) -* Added `opengraph.png` asset and configured `opengraph` metadata image. Overrode the documentation landing page `meta-description`. +* A new figure was added to the landing page of the PennyLane website. [(#6696)](https://github.com/PennyLaneAI/pennylane/pull/6696)

Labs: a place for unified and rapid prototyping of research software ๐Ÿงช

@@ -714,7 +722,7 @@ three-mode PES. measurements are present. [(#6732)](https://github.com/PennyLaneAI/pennylane/pull/6732) -* `qml.ControlledQubitUnitary` has consistent behaviour with program capture enabled. +* `qml.ControlledQubitUnitary` now has consistent behaviour with program capture enabled. [(#6719)](https://github.com/PennyLaneAI/pennylane/pull/6719) * The `Wires` object now throws a `TypeError` if `wires=None`. @@ -736,14 +744,14 @@ three-mode PES. * QNode return behaviour is now consistent for lists and tuples. [(#6568)](https://github.com/PennyLaneAI/pennylane/pull/6568) -* QNode now accepts arguments with types defined in libraries that are not necessarily in the list +* QNodes now accept arguments with types defined in libraries that are not necessarily in the list of supported interfaces, such as the `Graph` class defined in `networkx`. [(#6600)](https://github.com/PennyLaneAI/pennylane/pull/6600) * `qml.math.get_deep_interface` now works properly for Autograd arrays. [(#6557)](https://github.com/PennyLaneAI/pennylane/pull/6557) -* Fixed `Identity.__repr__` to return the correct wires list. +* Printing instances of `qml.Identity` now returns the correct wires list. [(#6506)](https://github.com/PennyLaneAI/pennylane/pull/6506)

Contributors โœ๏ธ

From f56abd271f82768f49ec9430dccb2b0da76180c2 Mon Sep 17 00:00:00 2001 From: Isaac De Vlugt <34751083+isaacdevlugt@users.noreply.github.com> Date: Fri, 10 Jan 2025 15:59:56 -0500 Subject: [PATCH 09/21] v0.40 changelog - QSVT (#6762) Co-authored-by: ANTH0NY <39093564+AntonNI8@users.noreply.github.com> Co-authored-by: AntonNI8 --- doc/releases/changelog-0.40.0.md | 91 +++++++++++++++++++++++++++++--- 1 file changed, 84 insertions(+), 7 deletions(-) diff --git a/doc/releases/changelog-0.40.0.md b/doc/releases/changelog-0.40.0.md index df582b44cc7..b217b30a426 100644 --- a/doc/releases/changelog-0.40.0.md +++ b/doc/releases/changelog-0.40.0.md @@ -30,18 +30,90 @@

Enhanced QSVT functionality ๐Ÿคฉ

-* New functionality to calculate angles for QSP and QSVT has been added. This includes the function `qml.poly_to_angles` - to obtain angles directly and the function `qml.transform_angles` to convert angles from one subroutine to another. +* New functionality to calculate and convert phase angles for QSP and QSVT has been added + with :func:`qml.poly_to_angles ` and + :func:`qml.transform_angles `. [(#6483)](https://github.com/PennyLaneAI/pennylane/pull/6483) -* The `qml.qsvt` function has been improved to be more user-friendly. Old functionality is moved to `qml.qsvt_legacy` - and it will be deprecated in release v0.40. - [(#6520)](https://github.com/PennyLaneAI/pennylane/pull/6520/) + The :func:`qml.poly_to_angles ` function calculates phase angles + directly given polynomial coefficients and the routine in which the angles will be used (`"QSVT"`, + `"QSP"`, or `"GQSP"`): + ```pycon + >>> poly = [0, 1.0, 0, -1/2, 0, 1/3] + >>> qsvt_angles = qml.poly_to_angles(poly, "QSVT") + >>> print(qsvt_angles) + [-5.49778714 1.57079633 1.57079633 0.5833829 1.61095884 0.74753829] + ``` + + The :func:`qml.transform_angles ` function can be used to convert + angles from one routine to another: + ```pycon + >>> qsp_angles = np.array([0.2, 0.3, 0.5]) + >>> qsvt_angles = qml.transform_angles(qsp_angles, "QSP", "QSVT") + >>> print(qsvt_angles) + [-6.86858347 1.87079633 -0.28539816] + ``` + +* The :func:`qml.qsvt ` function has been improved to be more user-friendly, +with enhanced capabilities. + [(#6520)](https://github.com/PennyLaneAI/pennylane/pull/6520) [(#6693)](https://github.com/PennyLaneAI/pennylane/pull/6693) -* New `qml.GQSP` template has been added to perform Generalized Quantum Signal Processing (GQSP). - The functionality `qml.poly_to_angles` has been also extended to support GQSP. + Block encoding and phase angle computation are now handled automatically, + given a matrix to encode, polynomial coefficients, and a block encoding method + (`"prepselprep"`, `"qubitization"`, `"embedding"`, or `"fable"`, all implemented with their + corresponding operators in PennyLane). + ```python + # P(x) = -x + 0.5 x^3 + 0.5 x^5 + poly = np.array([0, -1, 0, 0.5, 0, 0.5]) + hamiltonian = qml.dot([0.3, 0.7], [qml.Z(1), qml.X(1) @ qml.Z(2)]) + + dev = qml.device("default.qubit") + @qml.qnode(dev) + def circuit(): + qml.qsvt(hamiltonian, poly, encoding_wires=[0], block_encoding="prepselprep") + return qml.state() + + matrix = qml.matrix(circuit, wire_order=[0, 1, 2])() + ``` + ```pycon + >>> print(matrix[:4, :4].real) + [[-0.1625 0. -0.3793 0. ] + [ 0. -0.1625 0. 0.3793] + [-0.3793 0. 0.1625 0. ] + [ 0. 0.3793 0. 0.1625]] + ``` + The old functionality can be still be accessed with :func:`qml.qsvt_legacy `. + +* A new :class:`qml.GQSP ` template has been added to perform Generalized Quantum Signal Processing (GQSP). [(#6565)](https://github.com/PennyLaneAI/pennylane/pull/6565) + Similar to QSVT, GQSP is an algorithm that polynomially transforms an input unitary operator, + but with fewer restrictions on the chosen polynomial. + + You can also use :func:`qml.poly_to_angles ` to obtain angles for GQSP! + + ```python + # P(x) = 0.1 + 0.2j x + 0.3 x^2 + poly = [0.1, 0.2j, 0.3] + angles = qml.poly_to_angles(poly, "GQSP") + + @qml.prod # transforms the qfunc into an Operator + def unitary(wires): + qml.RX(0.3, wires) + + dev = qml.device("default.qubit") + @qml.qnode(dev) + def circuit(angles): + qml.GQSP(unitary(wires = 1), angles, control = 0) + return qml.state() + + matrix = qml.matrix(circuit, wire_order=[0, 1])(angles) + ``` + ```pycon + >>> print(np.round(matrix,3)[:2, :2]) + [[0.387+0.198j 0.03 -0.089j] + [0.03 -0.089j 0.387+0.198j]] + ```

Generalized Trotter products ๐Ÿ–

@@ -701,6 +773,11 @@ three-mode PES. align with the termionology used by the QNode. `gradient_fn` will be removed in v0.41. [(#6549)](https://github.com/PennyLaneAI/pennylane/pull/6549) +* The old `qml.qsvt` functionality is moved to `qml.qsvt_legacy` + and is now deprecated. It will be removed in v0.41. + [(#6520)](https://github.com/PennyLaneAI/pennylane/pull/6520) + +

Documentation ๐Ÿ“

* The docstrings for `qml.qchem.Molecule` and `qml.qchem.molecular_hamiltonian` have been updated to From 4b5d796d32c04234dcaa92ac9da588d48a58ee90 Mon Sep 17 00:00:00 2001 From: Isaac De Vlugt <34751083+isaacdevlugt@users.noreply.github.com> Date: Fri, 10 Jan 2025 16:00:32 -0500 Subject: [PATCH 10/21] v0.40 changelog - efficient state prep (#6761) --- doc/releases/changelog-0.40.0.md | 66 +++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 6 deletions(-) diff --git a/doc/releases/changelog-0.40.0.md b/doc/releases/changelog-0.40.0.md index b217b30a426..0a095235ede 100644 --- a/doc/releases/changelog-0.40.0.md +++ b/doc/releases/changelog-0.40.0.md @@ -6,27 +6,81 @@

Efficient state preparation methods ๐Ÿฆพ

-* Added new ``MPSPrep`` template to prepare quantum states in tensor network simulators. +* State preparation tailored for matrix product states (MPS) is now supported with + :class:`qml.MPSPrep ` on the `lightning.tensor` device. [(#6431)](https://github.com/PennyLaneAI/pennylane/pull/6431) -* Users can prepare a linear combination of basis states using `qml.Superposition`. + Given a list of :math:`n` tensors that represents an MPS, :math:`[A^{(0)}, ..., A^{(n-1)}]`, + :class:`qml.MPSPrep ` lets you directly inject the MPS into a QNode as the initial + state of the circuit without any need for pre-processing. The first and last tensors in the list + must be rank-2, while all intermediate tensors should be rank-3. + + ```python + import pennylane as qml + import numpy as np + + mps = [ + np.array([[0.0, 0.107], [0.994, 0.0]]), + np.array( + [ + [[0.0, 0.0, 0.0, -0.0], [1.0, 0.0, 0.0, -0.0]], + [[0.0, 1.0, 0.0, -0.0], [0.0, 0.0, 0.0, -0.0]], + ] + ), + np.array( + [ + [[-1.0, 0.0], [0.0, 0.0]], + [[0.0, 0.0], [0.0, 1.0]], + [[0.0, -1.0], [0.0, 0.0]], + [[0.0, 0.0], [1.0, 0.0]], + ] + ), + np.array([[-1.0, -0.0], [-0.0, -1.0]]), + ] + + dev = qml.device("lightning.tensor", wires = [0, 1, 2, 3]) + @qml.qnode(dev) + def circuit(): + qml.MPSPrep(mps, wires = [0,1,2]) + return qml.state() + ``` + + ```pycon + >>> print(circuit()) + [ 0. +0.j 0. +0.j 0. +0.j -0.1066+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.9943+0.j 0. +0.j 0. +0.j 0. +0.j] + ``` + + At this time, :class:`qml.MPSPrep ` is only supported on the `lightning.tensor` device. + +* Custom-made state preparation for linear combinations of quantum states is now available with + :class:`qml.Superposition `. [(#6670)](https://github.com/PennyLaneAI/pennylane/pull/6670) + Given a list of :math:`m` coefficients :math:`c_i` and basic states :math:`|b_i\rangle`, + :class:`qml.Superposition ` prepares + :math:`|\phi\rangle = \sum_i^m c_i |b_i\rangle`. Here is a simple example showing how to use + :class:`qml.Superposition ` to prepare + :math:`\tfrac{1}{\sqrt{2}} |00\rangle + \tfrac{1}{\sqrt{2}} |10\rangle`. + ```python coeffs = np.array([0.70710678, 0.70710678]) basis = np.array([[0, 0], [1, 0]]) - @qml.qnode(qml.device('default.qubit', wires=2)) + @qml.qnode(qml.device('default.qubit')) def circuit(): - qml.Superposition(coeffs, basis) + qml.Superposition(coeffs, basis, wires=[0, 1], work_wire=[2]) return qml.state() ``` + ``` >>> circuit() - tensor([0.70710678+0.j, 0.+0.j, 0.70710678+0.j, 0.+0.j], requires_grad=True) + Array([0.7071068 +0.j, 0. +0.j, 0. +0.j, 0. +0.j, + 0.70710677+0.j, 0. +0.j, 0. +0.j, 0. +0.j], dtype=complex64) ``` - This template is also JAX-jit compatible! + Note that specification of one `work_wire` is required.

Enhanced QSVT functionality ๐Ÿคฉ

From 4e3b45f51b7c9c4a6a347d4435ae0e103835893b Mon Sep 17 00:00:00 2001 From: Isaac De Vlugt <34751083+isaacdevlugt@users.noreply.github.com> Date: Fri, 10 Jan 2025 17:37:11 -0500 Subject: [PATCH 11/21] v0.40 changelog - Generalized Trotter products (#6763) Co-authored-by: ANTH0NY <39093564+AntonNI8@users.noreply.github.com> --- doc/releases/changelog-0.40.0.md | 50 ++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/doc/releases/changelog-0.40.0.md b/doc/releases/changelog-0.40.0.md index 921d1789776..7d1f27ded35 100644 --- a/doc/releases/changelog-0.40.0.md +++ b/doc/releases/changelog-0.40.0.md @@ -171,22 +171,50 @@ with enhanced capabilities.

Generalized Trotter products ๐Ÿ–

-* Added a function `qml.trotterize` to generalize the Suzuki-Trotter product to arbitrary quantum functions. +* Trotter products that work on exponentiated operators directly instead of full system hamiltonians + can now be encoded into circuits with the addition of + :class:`qml.TrotterizedQfunc ` and :func:`qml.trotterize `. This + allows for custom specification of the first-order expansion of the Suzuki-Trotter product formula + and extrapolating it to the :math:`n^{\text{th}}` order. [(#6627)](https://github.com/PennyLaneAI/pennylane/pull/6627) + If the first-order of the Suzuki-Trotter product formula for a given problem is known, + :class:`qml.TrotterizedQfunc ` and :func:`qml.trotterize ` + let you implement the :math:`n^{\text{th}}`-order product formula while only specifying the + first-order term as a quantum function. + ```python def my_custom_first_order_expansion(time, theta, phi, wires, flip): - "This is the first order expansion (U_1)." - qml.RX(time*theta, wires[0]) - qml.RY(time*phi, wires[1]) + qml.RX(time * theta, wires[0]) + qml.RY(time * phi, wires[1]) if flip: qml.CNOT(wires=wires[:2]) + ``` + + :func:`qml.trotterize ` requires the quantum function representing the first-order + product formula, the number of Trotter steps, and the desired order. It returns a function with + the same call signature as the first-order product formula quantum function: + + ```python + @qml.qnode(qml.device("default.qubit")) + def my_circuit(time, theta, phi, num_trotter_steps): + qml.trotterize( + first_order_expansion, + n=num_trotter_steps, + order=2, + )(time, theta, phi, wires=['a', 'b'], flip=True) + return qml.state() + ``` + + Alternatively, :class:`qml.TrotterizedQfunc ` can be used as follows: + ```python @qml.qnode(qml.device("default.qubit")) - def my_circuit(time, angles, num_trotter_steps): - TrotterizedQfunc( + def my_circuit(time, theta, phi, num_trotter_steps): + qml.TrotterizedQfunc( time, - *angles, + theta, + phi, qfunc=my_custom_first_order_expansion, n=num_trotter_steps, order=2, @@ -195,14 +223,18 @@ with enhanced capabilities. ) return qml.state() ``` + ```pycon >>> time = 0.1 - >>> angles = (0.12, -3.45) - >>> print(qml.draw(my_circuit, level=3)(time, angles, num_trotter_steps=1)) + >>> theta, phi = (0.12, -3.45) + >>> print(qml.draw(my_circuit, level="device")(time, theta, phi, num_trotter_steps=1)) a: โ”€โ”€RX(0.01)โ”€โ”€โ•ญโ—โ”€โ•ญโ—โ”€โ”€RX(0.01)โ”€โ”€โ”ค State b: โ”€โ”€RY(-0.17)โ”€โ•ฐXโ”€โ•ฐXโ”€โ”€RY(-0.17)โ”€โ”ค State ``` + Both methods produce the same results, but offer different interfaces based on the application or overall + preference. +

Bosonic operators ๐ŸŽˆ

A new module, :mod:`qml.bose `, has been added to PennyLane that includes support From 91bbcf9efd7e51c22d055acf493405b570c13896 Mon Sep 17 00:00:00 2001 From: Isaac De Vlugt <34751083+isaacdevlugt@users.noreply.github.com> Date: Fri, 10 Jan 2025 18:59:18 -0500 Subject: [PATCH 12/21] v0.40.0 changelog - Vibrational Hamiltonians (#6765) Co-authored-by: Diego Co-authored-by: Diego <67476785+DSGuala@users.noreply.github.com> --- doc/releases/changelog-0.40.0.md | 72 +++++++++++++++++++++++++++----- 1 file changed, 61 insertions(+), 11 deletions(-) diff --git a/doc/releases/changelog-0.40.0.md b/doc/releases/changelog-0.40.0.md index 7d1f27ded35..87bba6e6137 100644 --- a/doc/releases/changelog-0.40.0.md +++ b/doc/releases/changelog-0.40.0.md @@ -294,21 +294,71 @@ qubit operators. Additional fine-tuning is available within each function, such as the maximum number of allowed bosonic states and a tolerance for discarding imaginary parts of the coefficients. -

Construct vibrational Hamiltonians ๐Ÿซจ

+

Construct vibrational Hamiltonians ๐Ÿ”จ

-* Added submodule for calculating vibrational Hamiltonians - * Implemented helper functions for geometry optimization, harmonic analysis, - and normal-mode localization. +* Several new features are available in the +:mod:`qml.qchem ` module to help with the construction of vibrational +Hamiltonians. This includes: + * The :class:`~.qchem.VibrationalPES` class to store potential energy surface information. + [(#6652)](https://github.com/PennyLaneAI/pennylane/pull/6652) + + ```python + pes_onemode = np.array([[0.309, 0.115, 0.038, 0.008, 0.000, 0.006, 0.020, 0.041, 0.070]]) + pes_twomode = np.zeros((1, 1, 9, 9)) + dipole_onemode = np.zeros((1, 9, 3)) + gauss_weights = np.array([3.96e-05, 4.94e-03, 8.85e-02, + 4.33e-01, 7.20e-01, 4.33e-01, + 8.85e-02, 4.94e-03, 3.96e-05]) + grid = np.array([-3.19, -2.27, -1.47, -0.72, 0.0, 0.72, 1.47, 2.27, 3.19]) + pes_object = qml.qchem.VibrationalPES( + freqs=np.array([0.025]), + grid=grid, + uloc=np.array([[1.0]]), + gauss_weights=gauss_weights, + pes_data=[pes_onemode, pes_twomode], + dipole_data=[dipole_onemode], + localized=False, + dipole_level=1, + ) + ``` + + * The :func:`~.qchem.taylor_hamiltonian` function to build a Taylor Hamiltonian from a + :class:`~.VibrationalPES` object. + [(#6523)](https://github.com/PennyLaneAI/pennylane/pull/6523) + + ```pycon + >>> qml.qchem.taylor_hamiltonian(pes_object, 4, 2) + ( + 0.016867926879358452 * I(0) + + -0.007078617919572303 * Z(0) + + 0.0008679410939323631 * X(0) + ) + ``` + + * The :func:`~.qchem.taylor_bosonic` function to build a Taylor Hamiltonian in terms of Bosonic + operators. + [(#6523)](https://github.com/PennyLaneAI/pennylane/pull/6523) + + ```pycon + >>> coeffs_arr = qml.qchem.taylor_coeffs(pes_object) + >>> bose_op = qml.qchem.taylor_bosonic(coeffs_arr, pes_object.freqs, is_local=pes_object.localized, uloc=pes_object.uloc) + >>> type(bose_op) + pennylane.bose.bosonic.BoseSentence + ``` + + Additional functionality is also available to optimize molecular geometries and convert between + representations: + * Convert Christiansen Hamiltonian integrals in the harmonic oscillator basis to + integrals in the vibrational self-consistent field (VSCF) basis with the :func:`~.qchem.vscf_integrals` + function. + [(#6688)](https://github.com/PennyLaneAI/pennylane/pull/6688) + + * Find the lowest energy configuration of molecules with :func:`~.qchem.optimize_geometry`. [(#6453)](https://github.com/PennyLaneAI/pennylane/pull/6453) [(#6666)](https://github.com/PennyLaneAI/pennylane/pull/6666) - * Implemented wrapper function for vibrational Hamiltonian calculation and dataclass - for storing the data. - [(#6652)](https://github.com/PennyLaneAI/pennylane/pull/6652) - * Implemented functions for generating the vibrational Hamiltonian in VSCF basis - [(#6688)](https://github.com/PennyLaneAI/pennylane/pull/6688) -* Added support to build a vibrational Hamiltonian in Taylor form. - [(#6523)](https://github.com/PennyLaneAI/pennylane/pull/6523) + * Separate normal mode frequencies and localize them with :func:`~.qchem.localize_normal_modes`. + [(#6453)](https://github.com/PennyLaneAI/pennylane/pull/6453)

Improvements ๐Ÿ› 

From 78f540b85c69a2e10a83b4e77c14b781f8613984 Mon Sep 17 00:00:00 2001 From: Isaac De Vlugt <34751083+isaacdevlugt@users.noreply.github.com> Date: Fri, 10 Jan 2025 19:32:32 -0500 Subject: [PATCH 13/21] v0.40.0 changelog - Labs (#6766) Co-authored-by: ANTH0NY <39093564+AntonNI8@users.noreply.github.com> Co-authored-by: Diego Co-authored-by: Diego <67476785+DSGuala@users.noreply.github.com> Co-authored-by: Jay Soni Co-authored-by: qottmann Co-authored-by: Josh Izaac --- doc/releases/changelog-0.40.0.md | 234 ++++++++++++++++++++++--------- 1 file changed, 166 insertions(+), 68 deletions(-) diff --git a/doc/releases/changelog-0.40.0.md b/doc/releases/changelog-0.40.0.md index 87bba6e6137..13822238055 100644 --- a/doc/releases/changelog-0.40.0.md +++ b/doc/releases/changelog-0.40.0.md @@ -360,6 +360,172 @@ Hamiltonians. This includes: * Separate normal mode frequencies and localize them with :func:`~.qchem.localize_normal_modes`. [(#6453)](https://github.com/PennyLaneAI/pennylane/pull/6453) +

Labs: a place for unified and rapid prototyping of research software ๐Ÿง‘โ€๐Ÿ”ฌ

+ +The new :mod:`qml.labs ` module will house experimental research software ๐Ÿ”ฌ. Features here may be useful +for state-of-the-art research, beta testing, or getting a sneak peek into *potential* new features before +they are added to PennyLane. + +The experimental nature of this module means features may not integrate well with other +PennyLane staples like differentiability, JAX, or JIT compatibility. There may also be unexpected +sharp bits ๐Ÿ”ช and errors โŒ. + +.. warning:: + This module is **experimental**! Breaking changes and removals will happen without warning. + Please use these features carefully and let us know your thoughts. Your feedback will inform + how these features become a part of mainline PennyLane. + +

Resource estimation

+ +* Resource estimation functionality in Labs is focused on being light-weight and flexible. +The Labs :mod:`qml.labs.resource_estimation ` module involves modifications to core PennyLane that reduce the +memory requirements and computational time of resource estimation. These include new or modified +base classes and one new function: + * :class:`~.labs.resource_estimation.Resources` - This class is simplified in `labs`, removing the arguments: `gate_sizes`, `depth`, + and `shots`. [(#6428)](https://github.com/PennyLaneAI/pennylane/pull/6428) + * :class:`~.labs.resource_estimation.ResourceOperator` - Replaces :class:`~.resource.ResourceOperation`, expanded to include decompositions. [(#6428)](https://github.com/PennyLaneAI/pennylane/pull/6428) + * :class:`~.labs.resource_estimation.CompressedResourceOp` - A new class with the minimum information to estimate resources: + the operator type and the parameters needed to decompose it. [(#6428)](https://github.com/PennyLaneAI/pennylane/pull/6428) + * :class:`~.labs.resource_estimation.ResourceOperator` versions of many existing PennyLane operations, like Pauli operators, + :class:`~.labs.resource_estimation.ResourceHadamard`, and :class:`~.labs.resource_estimation.ResourceCNOT`. [(#6447)](https://github.com/PennyLaneAI/pennylane/pull/6447) + [(#6579)](https://github.com/PennyLaneAI/pennylane/pull/6579) + [(#6538)](https://github.com/PennyLaneAI/pennylane/pull/6538) + [(#6592)](https://github.com/PennyLaneAI/pennylane/pull/6592). + * :func:`~.labs.resource_estimation.get_resources()` - The new entry point to efficiently obtain the resources of quantum circuits. + [(#6500)](https://github.com/PennyLaneAI/pennylane/pull/6500) + + Using new Resource versions of existing operations and :func:`~.labs.resource_estimation.get_resources`, we can estimate + resources quickly: + ```python + import pennylane.labs.resource_estimation as re + + def my_circuit(): + for w in range(2): + re.ResourceHadamard(w) + re.ResourceCNOT([0, 1]) + re.ResourceRX(1.23, 0) + re.ResourceRY(-4.56, 1) + re.ResourceQFT(wires=[0, 1, 2]) + return qml.expval(re.ResourceHadamard(2)) + ``` + ```pycon + >>> res = re.get_resources(my_circuit)() + >>> print(res) + wires: 3 + gates: 202 + gate_types: + {'Hadamard': 5, 'CNOT': 10, 'T': 187} + ``` + + We can also set custom gate sets for decompositions: + + ````pycon + >>> gate_set={"Hadamard","CNOT","RZ", "RX", "RY", "SWAP"} + >>> res = re.get_resources(my_circuit, gate_set=gate_set)() + >>> print(res) + wires: 3 + gates: 24 + gate_types: + {'Hadamard': 5, 'CNOT': 7, 'RX': 1, 'RY': 1, 'SWAP': 1, 'RZ': 9} + ```` + + Alternatively, it is possible to manually substitute associated resources: + + ```pycon + >>> new_resources = re.substitute(res, "SWAP", re.Resources(2, 3, {"CNOT":3})) + >>> print(new_resources) + {'Hadamard': 5, 'CNOT': 10, 'RX': 1, 'RY': 1, 'RZ': 9} + ``` + +

Experimental functionality for handling dynamical Lie algebras (DLAs)

+ +* Use the :mod:`qml.labs.dla ` module to perform the + [KAK decomposition](https://pennylane.ai/qml/demos/tutorial_kak_decomposition): + * :func:`~.labs.dla.cartan_decomp`: obtain a **Cartan decomposition** of an input **Lie algebra** via an **involution**. + [(#6392)](https://github.com/PennyLaneAI/pennylane/pull/6392) + * We provide a variety of **involutions** like :func:`~.labs.dla.concurrence_involution`, :func:`~.labs.dla.even_odd_involution` and canonical Cartan involutions. + [(#6392)](https://github.com/PennyLaneAI/pennylane/pull/6392) + [(#6396)](https://github.com/PennyLaneAI/pennylane/pull/6396) + * :func:`~.labs.dla.cartan_subalgebra`: compute a horizontal **Cartan subalgebra**. + [(#6403)](https://github.com/PennyLaneAI/pennylane/pull/6403) + * :func:`~.labs.dla.variational_kak_adj` : compute a [variational KAK decomposition](https://pennylane.ai/qml/demos/tutorial_fixed_depth_hamiltonian_simulation_via_cartan_decomposition) of a Hermitian operator using a **Cartan decomposition** and the adjoint + representation of a horizontal **Cartan subalgebra**. + [(#6446)](https://github.com/PennyLaneAI/pennylane/pull/6446) + + To use this functionality we start with a set of Hermitian operators. + + ```pycon + >>> n = 3 + >>> gens = [qml.X(i) @ qml.X(i + 1) for i in range(n - 1)] + >>> gens += [qml.Z(i) for i in range(n)] + >>> H = qml.sum(*gens) + ``` + + We then generate its Lie algebra by computing the Lie closure. + + ```pycon + >>> g = qml.lie_closure(gens) + >>> g = [op.pauli_rep for op in g] + >>> print(g) + [1 * X(0) @ X(1), 1 * X(1) @ X(2), 1.0 * Z(0), ...] + ``` + + We then choose an involution (e.g. :func:`~.labs.dla.concurrence_involution`) that defines a Cartan decomposition `g = k + m`. `k` is the vertical subalgebra, and `m` its horizontal complement (not a subalgebra). + + ```pycon + >>> from pennylane.labs.dla import concurrence_involution, cartan_decomp + >>> involution = concurrence_involution + >>> k, m = cartan_decomp(g, involution=involution) + ``` + + The next step is just re-ordering the basis elements in `g` and computing its `structure_constants`. + + ```pycon + >>> g = k + m + >>> adj = qml.structure_constants(g) + ``` + + We can then compute a (horizontal) Cartan subalgebra `a`, that is, a maximal Abelian subalgebra of `m`. + ```pycon + >>> from pennylane.labs.dla import cartan_subalgebra + >>> g, k, mtilde, a, adj = cartan_subalgebra(g, k, m, adj) + ``` + + Having determined both subalgebras `k` and `a`, we can compute the KAK decomposition variationally like in [2104.00728](https://arxiv.org/abs/2104.00728), see our [demo on KAK decomposition in practice](https://pennylane.ai/qml/demos/tutorial_fixed_depth_hamiltonian_simulation_via_cartan_decomposition). + + ```pycon + >>> from pennylane.labs.dla import variational_kak_adj + >>> dims = (len(k), len(mtilde), len(a)) + >>> adjvec_a, theta_opt = variational_kak_adj(H, g, dims, adj, opt_kwargs={"n_epochs": 3000}) + ``` + +* We also provide some additional features that are useful for handling dynamical Lie algebras. + * :func:`~.labs.dla.recursive_cartan_decomp`: perform consecutive recursive Cartan decompositions. + [(#6396)](https://github.com/PennyLaneAI/pennylane/pull/6396) + * :func:`~.labs.dla.lie_closure_dense`: extension of `qml.lie_closure` using dense matrices. + [(#6371)](https://github.com/PennyLaneAI/pennylane/pull/6371) + [(#6695)](https://github.com/PennyLaneAI/pennylane/pull/6695) + * :func:`~.labs.dla.structure_constants_dense`: extension of `qml.structure_constants` using dense matrices. + [(#6396)](https://github.com/PennyLaneAI/pennylane/pull/6396) [(#6376)](https://github.com/PennyLaneAI/pennylane/pull/6376) + + +

Vibrational Hamiltonians

+ +* New functionality in labs helps with the construction of vibrational Hamiltonians. + * Generate potential energy surfaces (PES) with `qml.labs.vibrational.vibrational_pes`. + [(#6616)](https://github.com/PennyLaneAI/pennylane/pull/6616) + [(#6676)](https://github.com/PennyLaneAI/pennylane/pull/6676) + + ```pycon + >>> symbols = ['H', 'F'] + >>> geometry = np.array([[0.0, 0.0, 0.0], [0.0, 0.0, 1.0]]) + >>> mol = qml.qchem.Molecule(symbols, geometry) + >>> pes = vibrational_pes(mol) + ``` + * Use the `qml.labs.vibrational.christiansen_hamiltonian` function and potential energy surfaces + to generate Hamiltonians in the Christiansen form. + [(#6560)](https://github.com/PennyLaneAI/pennylane/pull/6560) +

Improvements ๐Ÿ› 

QChem improvements

@@ -731,74 +897,6 @@ Hamiltonians. This includes: * A new figure was added to the landing page of the PennyLane website. [(#6696)](https://github.com/PennyLaneAI/pennylane/pull/6696) -

Labs: a place for unified and rapid prototyping of research software ๐Ÿงช

- -

Resource estimation

- -* Added base class `Resources`, `CompressedResourceOp`, `ResourceOperator` for advanced resource estimation. - [(#6428)](https://github.com/PennyLaneAI/pennylane/pull/6428) - -* Added `get_resources()` functionality which allows users to extract resources from a quantum function, tape or - resource operation. Additionally added some standard gatesets `DefaultGateSet` to track resources with respect to. - [(#6500)](https://github.com/PennyLaneAI/pennylane/pull/6500) - -* Added `ResourceOperator` classes for QFT and all operators in QFT's decomposition. - [(#6447)](https://github.com/PennyLaneAI/pennylane/pull/6447) - -* Added native `ResourceOperator` subclasses for each of the controlled operators. - [(#6579)](https://github.com/PennyLaneAI/pennylane/pull/6579) - -* Added native `ResourceOperator` subclasses for each of the multi qubit operators. - [(#6538)](https://github.com/PennyLaneAI/pennylane/pull/6538) - -* Added abstract `ResourceOperator` subclasses for Adjoint, Controlled, and Pow - symbolic operation classes. - [(#6592)](https://github.com/PennyLaneAI/pennylane/pull/6592) - -

Experimental functionality for handling dynamical Lie algebras (DLAs)

- -* Added a dense implementation of computing the Lie closure in a new function - `lie_closure_dense` in `pennylane.labs.dla`. - [(#6371)](https://github.com/PennyLaneAI/pennylane/pull/6371) - [(#6695)](https://github.com/PennyLaneAI/pennylane/pull/6695) - -* Added a dense implementation of computing the structure constants in a new function - `structure_constants_dense` in `pennylane.labs.dla`. - [(#6376)](https://github.com/PennyLaneAI/pennylane/pull/6376) - -* Added utility functions for handling dense matrices and advanced functionality in the Lie theory context. - [(#6563)](https://github.com/PennyLaneAI/pennylane/pull/6563) - [(#6392)](https://github.com/PennyLaneAI/pennylane/pull/6392) - [(#6396)](https://github.com/PennyLaneAI/pennylane/pull/6396) - -* Added a ``cartan_decomp`` function along with two standard involutions ``even_odd_involution`` and ``concurrence_involution``. - [(#6392)](https://github.com/PennyLaneAI/pennylane/pull/6392) - -* Added a `recursive_cartan_decomp` function and all canonical Cartan involutions. - [(#6396)](https://github.com/PennyLaneAI/pennylane/pull/6396) - -* Added a `cartan_subalgebra` function to compute the (horizontal) Cartan subalgebra of a Cartan decomposition. - [(#6403)](https://github.com/PennyLaneAI/pennylane/pull/6403) - [(#6396)](https://github.com/PennyLaneAI/pennylane/pull/6396) - -* Added a `variational_kak_adj` function to compute a KaK decomposition of a Hamiltonian given a Cartan - decomposition and the ordered adjoint representation of the Lie algebra. - [(#6446)](https://github.com/PennyLaneAI/pennylane/pull/6446) - -* Improved documentation by fixing broken links and latex issues. Also consistently use `$\mathfrak{a}$` - for the horizontal Cartan subalgebra instead of `$\mathfrak{h}$`. - [(#6747)](https://github.com/PennyLaneAI/pennylane/pull/6747) - -

Vibrational Hamiltonians

- -* Implemented helper functions for calculating one-mode PES, two-mode PES, and -three-mode PES. - [(#6616)](https://github.com/PennyLaneAI/pennylane/pull/6616) - [(#6676)](https://github.com/PennyLaneAI/pennylane/pull/6676) - -* Added support to build a vibrational Hamiltonian in the Christiansen form. - [(#6560)](https://github.com/PennyLaneAI/pennylane/pull/6560) -

Breaking changes ๐Ÿ’”

* The default graph coloring method of `qml.dot`, `qml.sum`, and `qml.pauli.optimize_measurements` From d37b3e38a85e255479ba74511dd7aaee9121513b Mon Sep 17 00:00:00 2001 From: Isaac De Vlugt Date: Fri, 10 Jan 2025 20:00:47 -0500 Subject: [PATCH 14/21] minor --- doc/releases/changelog-0.40.0.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/doc/releases/changelog-0.40.0.md b/doc/releases/changelog-0.40.0.md index 13822238055..fc56a5d76ec 100644 --- a/doc/releases/changelog-0.40.0.md +++ b/doc/releases/changelog-0.40.0.md @@ -651,7 +651,6 @@ base classes and one new function: ```python from functools import partial - import jax qml.capture.enable() wire_map = {0: 3, 1: 6, 2: 9} @@ -815,8 +814,6 @@ base classes and one new function: [(#6378)](https://github.com/PennyLaneAI/pennylane/pull/6378) ```python - import pennylane as qml - @qml.qnode(qml.device("default.qubit")) def circuit(): qml.Hadamard(0) From 24725caa1b7e5c7733d44e56988d43638df261d2 Mon Sep 17 00:00:00 2001 From: Isaac De Vlugt <34751083+isaacdevlugt@users.noreply.github.com> Date: Fri, 10 Jan 2025 20:02:01 -0500 Subject: [PATCH 15/21] Apply suggestions from code review Co-authored-by: Diego <67476785+DSGuala@users.noreply.github.com> --- doc/releases/changelog-0.40.0.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/releases/changelog-0.40.0.md b/doc/releases/changelog-0.40.0.md index fc56a5d76ec..36e7044e8df 100644 --- a/doc/releases/changelog-0.40.0.md +++ b/doc/releases/changelog-0.40.0.md @@ -247,7 +247,7 @@ qubit operators. :class:`qml.BoseWord ` and :class:`qml.BoseSentence ` operate similarly to their fermionic counterparts. To create a Bose word, a dictionary - is required as input, where the keys are tuples of boson indicies and values are `'+/-'` (denoting + is required as input, where the keys are tuples of boson indices and values are `'+/-'` (denoting the bosonic creation/annihilation operators). For example, the :math:`b^{\dagger}_0 b_1` can be constructed as follows. From e765ed8b7054f1dbdeb37a0d1ecd59945f2fe4f0 Mon Sep 17 00:00:00 2001 From: Isaac De Vlugt <34751083+isaacdevlugt@users.noreply.github.com> Date: Fri, 10 Jan 2025 20:03:39 -0500 Subject: [PATCH 16/21] Update doc/releases/changelog-0.40.0.md --- doc/releases/changelog-0.40.0.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/releases/changelog-0.40.0.md b/doc/releases/changelog-0.40.0.md index 36e7044e8df..a468b1b4517 100644 --- a/doc/releases/changelog-0.40.0.md +++ b/doc/releases/changelog-0.40.0.md @@ -386,7 +386,7 @@ base classes and one new function: * :class:`~.labs.resource_estimation.ResourceOperator` - Replaces :class:`~.resource.ResourceOperation`, expanded to include decompositions. [(#6428)](https://github.com/PennyLaneAI/pennylane/pull/6428) * :class:`~.labs.resource_estimation.CompressedResourceOp` - A new class with the minimum information to estimate resources: the operator type and the parameters needed to decompose it. [(#6428)](https://github.com/PennyLaneAI/pennylane/pull/6428) - * :class:`~.labs.resource_estimation.ResourceOperator` versions of many existing PennyLane operations, like Pauli operators, + * :class:`~.labs.resource_estimation.ResourceOperator` - versions of many existing PennyLane operations, like Pauli operators, :class:`~.labs.resource_estimation.ResourceHadamard`, and :class:`~.labs.resource_estimation.ResourceCNOT`. [(#6447)](https://github.com/PennyLaneAI/pennylane/pull/6447) [(#6579)](https://github.com/PennyLaneAI/pennylane/pull/6579) [(#6538)](https://github.com/PennyLaneAI/pennylane/pull/6538) From b6ab649aabde760072f90d7357557a9d8ccdb0d9 Mon Sep 17 00:00:00 2001 From: Isaac De Vlugt <34751083+isaacdevlugt@users.noreply.github.com> Date: Fri, 10 Jan 2025 20:03:47 -0500 Subject: [PATCH 17/21] Update doc/releases/changelog-0.40.0.md Co-authored-by: Diego <67476785+DSGuala@users.noreply.github.com> --- doc/releases/changelog-0.40.0.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/releases/changelog-0.40.0.md b/doc/releases/changelog-0.40.0.md index a468b1b4517..07b9c8ae014 100644 --- a/doc/releases/changelog-0.40.0.md +++ b/doc/releases/changelog-0.40.0.md @@ -137,7 +137,7 @@ with enhanced capabilities. [-0.3793 0. 0.1625 0. ] [ 0. 0.3793 0. 0.1625]] ``` - The old functionality can be still be accessed with :func:`qml.qsvt_legacy `. + The old functionality can still be accessed with :func:`qml.qsvt_legacy `. * A new :class:`qml.GQSP ` template has been added to perform Generalized Quantum Signal Processing (GQSP). [(#6565)](https://github.com/PennyLaneAI/pennylane/pull/6565) From d9e80e6efe2bffbc44ba09cf4c1748a91a5b6e86 Mon Sep 17 00:00:00 2001 From: Isaac De Vlugt <34751083+isaacdevlugt@users.noreply.github.com> Date: Fri, 10 Jan 2025 20:03:59 -0500 Subject: [PATCH 18/21] Update doc/releases/changelog-0.40.0.md Co-authored-by: Diego <67476785+DSGuala@users.noreply.github.com> --- doc/releases/changelog-0.40.0.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/releases/changelog-0.40.0.md b/doc/releases/changelog-0.40.0.md index 07b9c8ae014..b8d1683449d 100644 --- a/doc/releases/changelog-0.40.0.md +++ b/doc/releases/changelog-0.40.0.md @@ -865,7 +865,7 @@ base classes and one new function: * A `preprocess` method has been added to the `QubitMixed` device class to preprocess the quantum circuit before execution. [(#6601)](https://github.com/PennyLaneAI/pennylane/pull/6601) - * A new class called `DefaultMixedNewAPI` has been addded to the `qml.devices.qubit_mixed` module, + * A new class called `DefaultMixedNewAPI` has been added to the `qml.devices.qubit_mixed` module, which will replace the legacy `DefaultMixed`. [(#6607)](https://github.com/PennyLaneAI/pennylane/pull/6607) * A new submodule called `devices.qubit_mixed.measure` has been added, featuring a `measure` From 5739207c13b21a49c3d324a471c6f5791ea166a3 Mon Sep 17 00:00:00 2001 From: Isaac De Vlugt <34751083+isaacdevlugt@users.noreply.github.com> Date: Fri, 10 Jan 2025 20:04:09 -0500 Subject: [PATCH 19/21] Update doc/releases/changelog-0.40.0.md Co-authored-by: Diego <67476785+DSGuala@users.noreply.github.com> --- doc/releases/changelog-0.40.0.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/releases/changelog-0.40.0.md b/doc/releases/changelog-0.40.0.md index b8d1683449d..13c5acf7f63 100644 --- a/doc/releases/changelog-0.40.0.md +++ b/doc/releases/changelog-0.40.0.md @@ -1021,7 +1021,7 @@ base classes and one new function: [(#6702)](https://github.com/PennyLaneAI/pennylane/pull/6702) * The documentation of `TrotterProduct` has been updated to include the impact of the operands in - the Hamiltonian on the strucutre of the created circuit. + the Hamiltonian on the structure of the created circuit. [(#6629)](https://github.com/PennyLaneAI/pennylane/pull/6629) * The documentation of `QSVT` has been updated to include examples for different block encodings. From 36504b82817a4ce7bfa04e7b654169803af8ccd8 Mon Sep 17 00:00:00 2001 From: Isaac De Vlugt <34751083+isaacdevlugt@users.noreply.github.com> Date: Fri, 10 Jan 2025 20:04:23 -0500 Subject: [PATCH 20/21] Apply suggestions from code review Co-authored-by: Diego <67476785+DSGuala@users.noreply.github.com> --- doc/releases/changelog-0.40.0.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/releases/changelog-0.40.0.md b/doc/releases/changelog-0.40.0.md index 13c5acf7f63..38089669f3a 100644 --- a/doc/releases/changelog-0.40.0.md +++ b/doc/releases/changelog-0.40.0.md @@ -907,7 +907,7 @@ base classes and one new function: from such a framework have to be used. [(#6622)](https://github.com/PennyLaneAI/pennylane/pull/6622) -* `qml.math.jax_argnums_to_tape_trainable` has been moved and made private to avoid an unecessary +* `qml.math.jax_argnums_to_tape_trainable` has been moved and made private to avoid an unnecessary QNode dependency in the `qml.math` module. [(#6609)](https://github.com/PennyLaneAI/pennylane/pull/6609) From 5f14caf26384b4460c012c9f0640ac5495afe1ae Mon Sep 17 00:00:00 2001 From: Isaac De Vlugt <34751083+isaacdevlugt@users.noreply.github.com> Date: Fri, 10 Jan 2025 20:15:37 -0500 Subject: [PATCH 21/21] Apply suggestions from code review Co-authored-by: ANTH0NY <39093564+AntonNI8@users.noreply.github.com> --- doc/releases/changelog-0.40.0.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/releases/changelog-0.40.0.md b/doc/releases/changelog-0.40.0.md index 38089669f3a..8f8683564f7 100644 --- a/doc/releases/changelog-0.40.0.md +++ b/doc/releases/changelog-0.40.0.md @@ -390,7 +390,7 @@ base classes and one new function: :class:`~.labs.resource_estimation.ResourceHadamard`, and :class:`~.labs.resource_estimation.ResourceCNOT`. [(#6447)](https://github.com/PennyLaneAI/pennylane/pull/6447) [(#6579)](https://github.com/PennyLaneAI/pennylane/pull/6579) [(#6538)](https://github.com/PennyLaneAI/pennylane/pull/6538) - [(#6592)](https://github.com/PennyLaneAI/pennylane/pull/6592). + [(#6592)](https://github.com/PennyLaneAI/pennylane/pull/6592) * :func:`~.labs.resource_estimation.get_resources()` - The new entry point to efficiently obtain the resources of quantum circuits. [(#6500)](https://github.com/PennyLaneAI/pennylane/pull/6500) @@ -884,7 +884,7 @@ base classes and one new function: * Support for `qml.Snapshot` has been added. [(#6659)](https://github.com/PennyLaneAI/pennylane/pull/6659) -* Reporting of test warnings as failures has been added +* Reporting of test warnings as failures has been added. [(#6217)](https://github.com/PennyLaneAI/pennylane/pull/6217) * A warning message in the Gradients and training documentation has been added that pertains to