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

[WIP] MPI support of mid-measurement #944

Draft
wants to merge 27 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
29cf4f0
Initial commit
multiphaseCFD Oct 2, 2024
0c449bf
Auto update version from '0.39.0-dev34' to '0.39.0-dev36'
ringo-but-quantum Oct 2, 2024
1582064
Merge branch 'master' into add_collapse_lgpu
multiphaseCFD Oct 7, 2024
6c36e5c
Auto update version from '0.39.0-dev39' to '0.39.0-dev40'
ringo-but-quantum Oct 7, 2024
80c3a62
tidy up code and add mpi support
multiphaseCFD Oct 8, 2024
b2a3758
Auto update version from '0.39.0-dev40' to '0.39.0-dev41'
ringo-but-quantum Oct 8, 2024
960dc84
Add native `setStateVector` support to `lightning.gpu` (#930)
multiphaseCFD Oct 8, 2024
c7ea1a8
Auto update version from '0.39.0-dev40' to '0.39.0-dev41'
ringo-but-quantum Oct 8, 2024
208782f
Merge branch 'master' into add_collapse_lgpu
multiphaseCFD Oct 8, 2024
829f8eb
Auto update version from '0.39.0-dev40' to '0.39.0-dev41'
ringo-but-quantum Oct 8, 2024
2493260
update collapse with custatevec apis
multiphaseCFD Oct 8, 2024
4238aeb
Auto update version from '0.39.0-dev41' to '0.39.0-dev42'
ringo-but-quantum Oct 8, 2024
15c7e2f
add python layer
multiphaseCFD Oct 8, 2024
6dc7c03
update changelog
multiphaseCFD Oct 8, 2024
5294b59
Merge branch 'master' into add_collapse_lgpu
multiphaseCFD Oct 8, 2024
a57b5ee
Auto update version from '0.39.0-dev41' to '0.39.0-dev42'
ringo-but-quantum Oct 8, 2024
d608f06
make format
multiphaseCFD Oct 9, 2024
63facdd
drop mpi support for mid-measurement
multiphaseCFD Oct 9, 2024
53ec72b
make format
multiphaseCFD Oct 9, 2024
410d694
test mpi support
multiphaseCFD Oct 10, 2024
7d631f5
Merge branch 'master' into add_collapse_lgpu
multiphaseCFD Oct 10, 2024
6a010f1
tidy up the code
multiphaseCFD Oct 10, 2024
7f4c97f
revert mpi support
multiphaseCFD Oct 10, 2024
85dc575
Auto update version from '0.39.0-dev42' to '0.39.0-dev43'
ringo-but-quantum Oct 10, 2024
0e9f1db
tidy up code
multiphaseCFD Oct 10, 2024
3b809fa
initial commit
multiphaseCFD Oct 15, 2024
ddc74f2
update conftest
multiphaseCFD Oct 15, 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 @@ -2,6 +2,9 @@

### New features since last release

* Add `mid-circuit measurements` support to `lightning.gpu`'s single-GPU backend.
[(#931)](https://github.com/PennyLaneAI/pennylane-lightning/pull/931)

* Add Matrix Product Operator (MPO) for all gates support to `lightning.tensor`. Note current C++ implementation only works for MPO sites data provided by users.
[(#859)](https://github.com/PennyLaneAI/pennylane-lightning/pull/859)

Expand Down
79 changes: 78 additions & 1 deletion mpitests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
Pytest configuration file for PennyLane-Lightning-GPU test suite.
"""
# pylint: disable=missing-function-docstring,wrong-import-order,unused-import

import itertools
import os
from functools import reduce
from typing import Sequence

import pennylane as qml
import pytest
Expand Down Expand Up @@ -125,3 +126,79 @@ def _device(wires):
)

return _device


#######################################################################


def validate_counts(shots, results1, results2):
"""Compares two counts.
If the results are ``Sequence``s, loop over entries.
Fails if a key of ``results1`` is not found in ``results2``.
Passes if counts are too low, chosen as ``100``.
Otherwise, fails if counts differ by more than ``20`` plus 20 percent.
"""
if isinstance(results1, Sequence):
assert isinstance(results2, Sequence)
assert len(results1) == len(results2)
for r1, r2 in zip(results1, results2):
validate_counts(shots, r1, r2)
return
for key1, val1 in results1.items():
val2 = results2[key1]
if abs(val1 + val2) > 100:
assert np.allclose(val1, val2, rtol=20, atol=0.2)


def validate_samples(shots, results1, results2):
"""Compares two samples.
If the results are ``Sequence``s, loop over entries.
Fails if the results do not have the same shape, within ``20`` entries plus 20 percent.
This is to handle cases when post-selection yields variable shapes.
Otherwise, fails if the sums of samples differ by more than ``20`` plus 20 percent.
"""
if isinstance(shots, Sequence):
assert isinstance(results1, Sequence)
assert isinstance(results2, Sequence)
assert len(results1) == len(results2)
for s, r1, r2 in zip(shots, results1, results2):
validate_samples(s, r1, r2)
else:
sh1, sh2 = results1.shape[0], results2.shape[0]
assert np.allclose(sh1, sh2, rtol=20, atol=0.2)
assert results1.ndim == results2.ndim
if results2.ndim > 1:
assert results1.shape[1] == results2.shape[1]
np.allclose(np.sum(results1), np.sum(results2), rtol=20, atol=0.2)


def validate_others(shots, results1, results2):
"""Compares two expval, probs or var.
If the results are ``Sequence``s, validate the average of items.
If ``shots is None``, validate using ``np.allclose``'s default parameters.
Otherwise, fails if the results do not match within ``0.01`` plus 20 percent.
"""
if isinstance(results1, Sequence):
assert isinstance(results2, Sequence)
assert len(results1) == len(results2)
results1 = reduce(lambda x, y: x + y, results1) / len(results1)
results2 = reduce(lambda x, y: x + y, results2) / len(results2)
validate_others(shots, results1, results2)
return
if shots is None:
assert np.allclose(results1, results2)
return
assert np.allclose(results1, results2, atol=0.01, rtol=0.2)


def validate_measurements(func, shots, results1, results2):
"""Calls the correct validation function based on measurement type."""
if func is qml.counts:
validate_counts(shots, results1, results2)
return

if func is qml.sample:
validate_samples(shots, results1, results2)
return

validate_others(shots, results1, results2)
Loading