PennyLaneAI / pennylane

PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.
https://pennylane.ai
Apache License 2.0
2.17k stars 568 forks source link

Fix wrong PaulitRot decomposition with identity as pauli word #5875

Closed EmilianoG-byte closed 1 week ago

EmilianoG-byte commented 1 week ago

Context:

Currently the decomposition of a Pauli Rotation with an identity as Pauli word returns an empty list. I.e,

qml.PauliRot(theta, Pauli_word="I").decomposition() == []

Description of the Change:

Implement the correct decomposition for this case using qml.GlobalPhase

Benefits:

The TrotterProduct for Hamiltonians with an identity using default.qubit and default.lightning now return the same correct result.

import pennylane as qml
import numpy as np

symbols = ["H", "H"]
coordinates = np.array([[0.0, 0.0, -0.6614], [0.0, 0.0, 0.6614]])
H, num_qubits = qml.qchem.molecular_hamiltonian(symbols, coordinates, basis="sto-3g")

results = []
for dev_name in ["default.qubit", "lightning.qubit"]:
    dev = qml.device(dev_name, wires=num_qubits)
    @qml.qnode(dev)
    def circuit():
        qml.TrotterProduct(H, 1.0)
        return qml.state()
    results.append(circuit())
qml.math.allclose(*results)

>> True

Related GitHub Issues: [#5859]

[sc-66115]

github-actions[bot] commented 1 week ago

Hello. You may have forgotten to update the changelog! Please edit doc/releases/changelog-dev.md with:

codecov[bot] commented 1 week ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 99.66%. Comparing base (96a3d56) to head (7832a16). Report is 1 commits behind head on master.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #5875 +/- ## ========================================== - Coverage 99.67% 99.66% -0.01% ========================================== Files 425 425 Lines 40751 40457 -294 ========================================== - Hits 40618 40323 -295 - Misses 133 134 +1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.