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

Update LightningBaseFallBack to raise an error instead of falling back to default.qubit #689

Merged
merged 61 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 59 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
50d08d1
Initial commit.
vincentmr Apr 18, 2024
178d88e
Update changelog
vincentmr Apr 18, 2024
9903d01
Merge branch 'master' into feature/raise_fallback
vincentmr Apr 18, 2024
5984f8d
Auto update version
github-actions[bot] Apr 18, 2024
db6c00a
trigger ci
vincentmr Apr 18, 2024
8035ddb
Unused import.
vincentmr Apr 18, 2024
153af42
Merge branch 'master' into feature/raise_fallback
vincentmr Apr 18, 2024
3a460d4
Auto update version
github-actions[bot] Apr 18, 2024
b29e06e
trigger ci
vincentmr Apr 18, 2024
ad2c477
Fix imports.
vincentmr Apr 19, 2024
d7b66db
Auto update version
github-actions[bot] Apr 19, 2024
26e898c
Merge branch 'master' into feature/raise_fallback
vincentmr Apr 19, 2024
36ce3ae
Fix LightningException
vincentmr Apr 19, 2024
77448c9
make format
vincentmr Apr 19, 2024
54bb29e
Merge remote-tracking branch 'origin/master' into feature/raise_fallback
vincentmr Apr 22, 2024
e35f0c1
Auto update version from '0.36.0-dev34' to '0.36.0-dev35'
ringo-but-quantum Apr 22, 2024
eacceb9
Merge branch 'master' into feature/raise_fallback
vincentmr Apr 22, 2024
30f4dd3
Auto update version from '0.36.0-dev35' to '0.36.0-dev36'
ringo-but-quantum Apr 22, 2024
80b4acd
Merge branch 'master' into feature/raise_fallback
vincentmr Apr 24, 2024
7fe81e3
Auto update version from '0.36.0-dev36' to '0.36.0-dev37'
ringo-but-quantum Apr 24, 2024
5e889b2
Make python -m pip install consistent.
vincentmr Apr 24, 2024
0006afe
Fix ImportError
vincentmr Apr 24, 2024
4624a05
Auto update version from '0.36.0-dev37' to '0.36.0-dev38'
ringo-but-quantum Apr 24, 2024
cdd6cf0
Merge branch 'master' into feature/raise_fallback
vincentmr Apr 24, 2024
d25c4de
--force-reinstall
vincentmr Apr 24, 2024
9921702
Auto update version from '0.36.0-dev38' to '0.36.0-dev39'
ringo-but-quantum Apr 24, 2024
81f883b
Merge branch 'master' into feature/raise_fallback
vincentmr Apr 24, 2024
eddba64
Remove --force-reinstall
vincentmr Apr 24, 2024
6c4dcf4
Merge branch 'master' into feature/raise_fallback
vincentmr Apr 24, 2024
61b0f76
Auto update version from '0.36.0-dev39' to '0.36.0-dev40'
ringo-but-quantum Apr 24, 2024
545c9a5
Merge branch 'master' into feature/raise_fallback
vincentmr Apr 26, 2024
3ddfc6d
Auto update version from '0.36.0-dev42' to '0.36.0-dev43'
ringo-but-quantum Apr 26, 2024
b9d40bb
Merge branch 'master' into feature/raise_fallback
vincentmr Apr 26, 2024
3e78a96
Auto update version from '0.36.0-dev43' to '0.36.0-dev44'
ringo-but-quantum Apr 26, 2024
584b927
Spec CMAKE_CXX_COMPILER
vincentmr Apr 26, 2024
820fd28
Fix quotes.
vincentmr Apr 26, 2024
567b1af
Remove quotes
vincentmr Apr 26, 2024
b90405d
Hardcode g++-11
vincentmr Apr 26, 2024
3906ec1
use env.COMPILER
vincentmr Apr 26, 2024
cfb5475
which g++
vincentmr Apr 26, 2024
fddc376
Revert
vincentmr Apr 26, 2024
3f9ea7f
Downgrade pip
vincentmr Apr 26, 2024
7966bfc
Pin libomp.
vincentmr Apr 26, 2024
977210c
Revert wheel_linux
vincentmr Apr 26, 2024
9a0887e
Upload artifacts.
vincentmr Apr 26, 2024
af5bd27
Comment upload trigger
vincentmr Apr 26, 2024
88dc45f
Install pip==23
vincentmr Apr 26, 2024
393db5d
Revert libomp
vincentmr Apr 26, 2024
99a1720
Merge branch 'feature/raise_fallback' of https://github.com/PennyLane…
AmintorDusko Apr 26, 2024
4a09e52
try testing outside cibuildwheel
AmintorDusko Apr 26, 2024
efdf913
yum install devtools
vincentmr Apr 26, 2024
7967675
yum install devtools
vincentmr Apr 26, 2024
67fbc10
Do not install python
vincentmr Apr 26, 2024
b20c153
Revert changes
vincentmr Apr 26, 2024
6108e8a
Don't editable install.
vincentmr Apr 26, 2024
2f253d8
Not edit install
vincentmr Apr 26, 2024
d20ccaf
Not edit install
vincentmr Apr 26, 2024
9a0f780
Fix cov path
vincentmr Apr 27, 2024
a4a2736
Explicit mcm tests path
vincentmr Apr 27, 2024
52b5c0d
Merge branch 'v0.36.0_rc' into feature/raise_fallback
vincentmr Apr 29, 2024
27fbfcb
Fix qml.QuantumFunctionError error messages.
vincentmr Apr 30, 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 @@ -41,6 +41,9 @@

### Breaking changes

* Update `lightning.gpu` and `lightning.kokkos` to raise an error instead of falling back to `default.qubit`.
[(#689)](https://github.com/PennyLaneAI/pennylane-lightning/pull/689)

* Add `paths` directives to test workflows to avoid running tests that cannot be impacted by changes.
[(#699)](https://github.com/PennyLaneAI/pennylane-lightning/pull/699)
[(#695)](https://github.com/PennyLaneAI/pennylane-lightning/pull/695)
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests_linux_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ jobs:
mv .coverage .coverage-${{ github.job }}-${{ matrix.pl_backend }}
# TODO: Remove this if-cond with release v0.36.0
if [ -f tests/test_native_mcm.py ]; then
OMP_NUM_THREADS=1 PL_DEVICE=${DEVICENAME} python -m pytest -n auto tests/ -k "test_native_mcm" $COVERAGE_FLAGS --cov-append
OMP_NUM_THREADS=1 PL_DEVICE=${DEVICENAME} python -m pytest -n auto tests/test_native_mcm.py $COVERAGE_FLAGS --cov-append
fi

- name: Install all backend devices
Expand Down Expand Up @@ -418,7 +418,7 @@ jobs:
- name: Combine coverage files
run: |
python -m pip install coverage
python -m coverage combine .coverage-python*
python -m coverage combine .coverage*
# Added cov xml -i to ignore "No source for code" random errors
# https://stackoverflow.com/questions/2386975/no-source-for-code-message-in-coverage-py
python -m coverage xml -i -o coverage-${{ github.job }}.xml
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/wheel_linux_aarch64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ jobs:

CIBW_BEFORE_TEST: |
python -m pip install -r requirements-tests.txt
if ${{ matrix.pl_backend == 'lightning_kokkos'}}; then SKIP_COMPILATION=True PL_BACKEND="lightning_qubit" pip install -e . -vv; fi
if ${{ matrix.pl_backend == 'lightning_kokkos'}}; then SKIP_COMPILATION=True PL_BACKEND="lightning_qubit" python -m pip install . -vv; fi
vincentmr marked this conversation as resolved.
Show resolved Hide resolved

CIBW_TEST_COMMAND: |
DEVICENAME=`echo ${{ matrix.pl_backend }} | sed "s/_/./g"`
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/wheel_linux_x86_64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ jobs:

CIBW_BEFORE_TEST: |
python -m pip install -r requirements-tests.txt
if ${{ matrix.pl_backend == 'lightning_kokkos'}}; then SKIP_COMPILATION=True PL_BACKEND="lightning_qubit" pip install -e . -vv; fi
if ${{ matrix.pl_backend == 'lightning_kokkos'}}; then SKIP_COMPILATION=True PL_BACKEND="lightning_qubit" python -m pip install . -vv; fi

CIBW_TEST_COMMAND: |
DEVICENAME=`echo ${{ matrix.pl_backend }} | sed "s/_/./g"`
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/wheel_macos_arm64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ jobs:

CIBW_BEFORE_TEST: |
python -m pip install -r requirements-tests.txt
if ${{ matrix.pl_backend == 'lightning_kokkos'}}; then SKIP_COMPILATION=True PL_BACKEND="lightning_qubit" pip install -e . -vv; fi
if ${{ matrix.pl_backend == 'lightning_kokkos'}}; then SKIP_COMPILATION=True PL_BACKEND="lightning_qubit" python -m pip install . -vv; fi

CIBW_TEST_COMMAND: |
DEVICENAME=`echo ${{ matrix.pl_backend }} | sed "s/_/./g"`
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/wheel_macos_x86_64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ jobs:

CIBW_BEFORE_TEST: |
python -m pip install -r requirements-tests.txt
if ${{ matrix.pl_backend == 'lightning_kokkos'}}; then SKIP_COMPILATION=True PL_BACKEND="lightning_qubit" pip install -e . -vv; fi
if ${{ matrix.pl_backend == 'lightning_kokkos'}}; then SKIP_COMPILATION=True PL_BACKEND="lightning_qubit" python -m pip install . -vv; fi

CIBW_TEST_COMMAND: |
DEVICENAME=`echo ${{ matrix.pl_backend }} | sed "s/_/./g"`
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/wheel_win_x86_64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ jobs:
python -m pip install setuptools
python -m pip install -r requirements-tests.txt
if (${{ matrix.pl_backend == 'lightning_kokkos'}}) {
SKIP_COMPILATION=True PL_BACKEND="lightning_qubit" python -m pip install -e . -vv
SKIP_COMPILATION=True PL_BACKEND="lightning_qubit" python -m pip install . -vv
}
pushd wheelhouse
$wheels = Get-ChildItem "./" -Filter *.whl
Expand Down
17 changes: 5 additions & 12 deletions mpitests/test_adjoint_jacobian.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
from pennylane import qnode
from scipy.stats import unitary_group

if not ld._CPP_BINARY_AVAILABLE:
pytest.skip("No binary module found. Skipping.", allow_module_level=True)

I, X, Y, Z = (
np.eye(2),
qml.PauliX.compute_matrix(),
Expand Down Expand Up @@ -109,12 +112,10 @@ def test_not_expval(self, dev):
qml.RX(0.1, wires=0)
qml.state()

if device_name == "lightning.gpu" and ld._CPP_BINARY_AVAILABLE:
if device_name == "lightning.gpu":
message = "Adjoint differentiation does not support State measurements."
elif ld._CPP_BINARY_AVAILABLE:
message = "This method does not support statevector return type."
else:
message = "Adjoint differentiation method does not support measurement StateMP"
message = "This method does not support statevector return type."
mlxd marked this conversation as resolved.
Show resolved Hide resolved
with pytest.raises(
qml.QuantumFunctionError,
match=message,
Expand Down Expand Up @@ -144,7 +145,6 @@ def test_empty_measurements(self, dev):
jac = dev.adjoint_jacobian(tape)
assert len(jac) == 0

@pytest.mark.skipif(not ld._CPP_BINARY_AVAILABLE, reason="Lightning binary required")
def test_unsupported_op(self, dev):
"""Test if a QuantumFunctionError is raised for an unsupported operation, i.e.,
multi-parameter operations that are not qml.Rot"""
Expand All @@ -159,7 +159,6 @@ def test_unsupported_op(self, dev):
):
dev.adjoint_jacobian(tape)

@pytest.mark.skipif(not ld._CPP_BINARY_AVAILABLE, reason="Lightning binary required")
def test_proj_unsupported(self, dev):
"""Test if a QuantumFunctionError is raised for a Projector observable"""
with qml.tape.QuantumTape() as tape:
Expand Down Expand Up @@ -332,7 +331,6 @@ def test_multiple_rx_gradient_expval_hermitian(self, tol, dev):
qubit_ops = [getattr(qml, name) for name in qml.ops._qubit__ops__] # pylint: disable=no-member
ops = {qml.RX, qml.RY, qml.RZ, qml.PhaseShift, qml.CRX, qml.CRY, qml.CRZ, qml.Rot}

@pytest.mark.skipif(not ld._CPP_BINARY_AVAILABLE, reason="Lightning binary required")
def test_multiple_rx_gradient_expval_hamiltonian(self, tol, dev):
"""Tests that the gradient of multiple RX gates in a circuit yields the correct result
with Hermitian observable
Expand Down Expand Up @@ -522,7 +520,6 @@ def test_gradient_gate_with_multiple_parameters_hermitian(self, dev):
# the different methods agree
assert np.allclose(grad_D, grad_F, atol=tol, rtol=0)

@pytest.mark.skipif(not ld._CPP_BINARY_AVAILABLE, reason="Lightning binary required")
def test_gradient_gate_with_multiple_parameters_hamiltonian(self, dev):
"""Tests that gates with multiple free parameters yield correct gradients."""
x, y, z = [0.5, 0.3, -0.7]
Expand Down Expand Up @@ -601,7 +598,6 @@ def test_provide_starting_state(self, tol, dev):
dM2 = dev.adjoint_jacobian(tape, starting_state=state_vector)
assert np.allclose(dM1, dM2, atol=tol, rtol=0)

@pytest.mark.skipif(not ld._CPP_BINARY_AVAILABLE, reason="Lightning binary required")
def test_provide_wrong_starting_state(self, dev):
"""Tests raise an exception when provided starting state mismatches."""
x, y, z = [0.5, 0.3, -0.7]
Expand All @@ -624,7 +620,6 @@ def test_provide_wrong_starting_state(self, dev):
device_name == "lightning.gpu",
reason="Adjoint differentiation does not support State measurements.",
)
@pytest.mark.skipif(not ld._CPP_BINARY_AVAILABLE, reason="Lightning binary required")
def test_state_return_type(self, dev):
"""Tests raise an exception when the return type is State"""
with qml.tape.QuantumTape() as tape:
Expand Down Expand Up @@ -675,7 +670,6 @@ def circ(x):
):
qml.grad(circ)(0.1)

@pytest.mark.skipif(not ld._CPP_BINARY_AVAILABLE, reason="Lightning binary required")
def test_qnode(self, mocker, dev):
"""Test that specifying diff_method allows the adjoint method to be selected"""
args = np.array([0.54, 0.1, 0.5], requires_grad=True)
Expand Down Expand Up @@ -766,7 +760,6 @@ def cost(p1, p2):

assert np.allclose(grad_D[0], expected, atol=tol, rtol=0)

@pytest.mark.skipif(not ld._CPP_BINARY_AVAILABLE, reason="Lightning binary required")
def test_gradient_repeated_gate_parameters(self, mocker, dev):
"""Tests that repeated use of a free parameter in a multi-parameter gate yields correct
gradients."""
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-dev43"
__version__ = "0.36.0-dev44"
35 changes: 6 additions & 29 deletions pennylane_lightning/core/lightning_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import numpy as np
import pennylane as qml
from pennylane import BasisState, QubitDevice, StatePrep
from pennylane.devices import DefaultQubitLegacy
from pennylane.measurements import Expectation, MeasurementProcess, State
from pennylane.operation import Operation, Tensor
from pennylane.ops import Prod, Projector, SProd, Sum
Expand Down Expand Up @@ -71,6 +70,12 @@ def __init__(
shots=None,
batch_obs=False,
):
if not self._CPP_BINARY_AVAILABLE:
raise ImportError(
f"Pre-compiled binaries for {self.short_name} are not available. "
"To manually compile from source, follow the instructions at "
"https://pennylane-lightning.readthedocs.io/en/latest/installation.html."
)
if c_dtype is np.complex64:
r_dtype = np.float32
self.use_csingle = True
Expand Down Expand Up @@ -446,31 +451,3 @@ def processing_fns(tapes):
return vjps

return processing_fns


class LightningBaseFallBack(DefaultQubitLegacy): # pragma: no cover
# pylint: disable=missing-class-docstring, too-few-public-methods
pennylane_requires = ">=0.34"
version = __version__
author = "Xanadu Inc."
_CPP_BINARY_AVAILABLE = False
_new_API = False

def __init__(self, wires, *, c_dtype=np.complex128, **kwargs):
if c_dtype is np.complex64:
r_dtype = np.float32
elif c_dtype is np.complex128:
r_dtype = np.float64
else:
raise TypeError(f"Unsupported complex type: {c_dtype}")
super().__init__(wires, r_dtype=r_dtype, c_dtype=c_dtype, **kwargs)

@property
def state_vector(self):
"""Returns a handle to the statevector."""
return self._state

@property
def dtype(self):
"""State vector complex data type."""
return self.C_DTYPE
vincentmr marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading