Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test_templates module + Fix LQ decomposition of StatePrep Ops + Fix LQ decomposition strategy of QFT and GroverOperator #684

Merged
merged 25 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
41d77fd
Add test for QSVT.
vincentmr Apr 16, 2024
e890a52
Auto update version
github-actions[bot] Apr 16, 2024
243b121
Update changelog.
vincentmr Apr 16, 2024
3a59e7e
Add tests for embedding, layer and stateprep templates.
vincentmr Apr 16, 2024
8667022
Parametrize tests over n_qubits.
vincentmr Apr 16, 2024
ca467db
Add qchem template tests.
vincentmr Apr 16, 2024
92744f3
Add a few misc template tests.
vincentmr Apr 16, 2024
31f73ea
Merge branch 'master' into feature/test_templates
vincentmr Apr 17, 2024
a776b81
Auto update version
github-actions[bot] Apr 17, 2024
369739e
trigger ci
vincentmr Apr 17, 2024
a4985de
Fix serialize.
vincentmr Apr 17, 2024
103bad1
Fix formatting.
vincentmr Apr 17, 2024
fc89d8d
Update tests/test_templates.py
vincentmr Apr 17, 2024
ecb49e0
Update tests/test_templates.py
vincentmr Apr 17, 2024
7aaef8a
Add xfail condition for AmplitudeEmbedding.
vincentmr Apr 17, 2024
1412d42
Fix pytest.skip top cond.
vincentmr Apr 17, 2024
1f9ed97
Update tests/test_templates.py
vincentmr Apr 17, 2024
3c5395c
Update pennylane_lightning/core/_serialize.py
vincentmr Apr 17, 2024
cea50c1
Add breaking tests for if not observable
vincentmr Apr 17, 2024
1a65c8f
trigger ci
vincentmr Apr 17, 2024
8dc58ab
Merge branch 'master' into feature/test_templates
vincentmr Apr 17, 2024
201d14a
Auto update version
github-actions[bot] Apr 17, 2024
50b7fa9
Fix decompositions with `LightningQubit` (#687)
mudit2812 Apr 18, 2024
b10c6fb
Merge branch 'master' into feature/test_templates
maliasadi Apr 18, 2024
a0c6265
Fix test params
vincentmr Apr 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@

### Improvements

* Add `test_templates.py` module where Grover and QSVT are tested.
[(#684)](https://github.com/PennyLaneAI/pennylane-lightning/pull/684)

* Create `cuda_utils` for common usage of CUDA related backends.
[(#676)](https://github.com/PennyLaneAI/pennylane-lightning/pull/676)

Expand Down
3 changes: 3 additions & 0 deletions pennylane_lightning/core/_serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@

def _pauli_sentence(self, observable, wires_map: dict = None):
"""Serialize a :class:`pennylane.pauli.PauliSentence` into a Hamiltonian."""
# Trivial Pauli sentences' items is empty, cannot unpack
if not observable:
return self.hamiltonian_obs(np.array([0.0]).astype(self.rtype), [self._ob(Identity(0))])

Check warning on line 260 in pennylane_lightning/core/_serialize.py

View check run for this annotation

Codecov / codecov/patch

pennylane_lightning/core/_serialize.py#L259-L260

Added lines #L259 - L260 were not covered by tests
vincentmr marked this conversation as resolved.
Show resolved Hide resolved
pwords, coeffs = zip(*observable.items())
terms = [self._pauli_word(pw, wires_map) for pw in pwords]
coeffs = np.array(coeffs).astype(self.rtype)
Expand Down
2 changes: 1 addition & 1 deletion pennylane_lightning/core/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
Version number (major.minor.patch[-label])
"""

__version__ = "0.36.0-dev29"
__version__ = "0.36.0-dev30"
37 changes: 0 additions & 37 deletions tests/test_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,40 +87,3 @@ def dev_l_execute(t):

assert np.allclose(grad_dev_l, grad_qml_l, tol)
assert np.allclose(grad_dev_l, grad_qml_d, tol)


class TestGrover:
"""Test Grover's algorithm (multi-controlled gates, decomposition, etc.)"""

@pytest.mark.parametrize("num_qubits", range(4, 8))
def test_grover(self, num_qubits):
np.random.seed(42)
omega = np.random.rand(num_qubits) > 0.5
dev = qml.device(device_name, wires=num_qubits)
wires = list(range(num_qubits))

@qml.qnode(dev, diff_method=None)
def circuit(omega):
iterations = int(np.round(np.sqrt(2**num_qubits) * np.pi / 4))

# Initial state preparation
for wire in wires:
qml.Hadamard(wires=wire)

# Grover's iterator
for _ in range(iterations):
qml.FlipSign(omega, wires=wires)
qml.templates.GroverOperator(wires)

return qml.probs(wires=wires)

prob = circuit(omega)
index = omega.astype(int)
index = functools.reduce(
lambda sum, x: sum + (1 << x[0]) * x[1],
zip([i for i in range(len(index) - 1, -1, -1)], index),
0,
)
assert np.allclose(np.sum(prob), 1.0)
assert prob[index] > 0.95
assert np.sum(prob) - prob[index] < 0.05
Loading
Loading