Skip to content

Commit 2236e5f

Browse files
committed
Merge branch 'v0.36.0_rc' of https://github.com/PennyLaneAI/pennylane-lightning into v0.36.0_rc
2 parents 0412295 + 34877ff commit 2236e5f

28 files changed

+1599
-1732
lines changed

.github/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141

4242
### Breaking changes
4343

44+
* Update `lightning.gpu` and `lightning.kokkos` to raise an error instead of falling back to `default.qubit`.
45+
[(#689)](https://github.com/PennyLaneAI/pennylane-lightning/pull/689)
46+
4447
* Add `paths` directives to test workflows to avoid running tests that cannot be impacted by changes.
4548
[(#699)](https://github.com/PennyLaneAI/pennylane-lightning/pull/699)
4649
[(#695)](https://github.com/PennyLaneAI/pennylane-lightning/pull/695)

.github/workflows/tests_linux_python.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ jobs:
364364
mv .coverage .coverage-${{ github.job }}-${{ matrix.pl_backend }}
365365
# TODO: Remove this if-cond with release v0.36.0
366366
if [ -f tests/test_native_mcm.py ]; then
367-
OMP_NUM_THREADS=1 PL_DEVICE=${DEVICENAME} python -m pytest -n auto tests/ -k "test_native_mcm" $COVERAGE_FLAGS --cov-append
367+
OMP_NUM_THREADS=1 PL_DEVICE=${DEVICENAME} python -m pytest -n auto tests/test_native_mcm.py $COVERAGE_FLAGS --cov-append
368368
fi
369369
370370
- name: Install all backend devices
@@ -418,7 +418,7 @@ jobs:
418418
- name: Combine coverage files
419419
run: |
420420
python -m pip install coverage
421-
python -m coverage combine .coverage-python*
421+
python -m coverage combine .coverage*
422422
# Added cov xml -i to ignore "No source for code" random errors
423423
# https://stackoverflow.com/questions/2386975/no-source-for-code-message-in-coverage-py
424424
python -m coverage xml -i -o coverage-${{ github.job }}.xml

.github/workflows/wheel_linux_aarch64.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ jobs:
141141

142142
CIBW_BEFORE_TEST: |
143143
python -m pip install -r requirements-tests.txt
144-
if ${{ matrix.pl_backend == 'lightning_kokkos'}}; then SKIP_COMPILATION=True PL_BACKEND="lightning_qubit" pip install -e . -vv; fi
144+
if ${{ matrix.pl_backend == 'lightning_kokkos'}}; then SKIP_COMPILATION=True PL_BACKEND="lightning_qubit" python -m pip install . -vv; fi
145145
146146
CIBW_TEST_COMMAND: |
147147
DEVICENAME=`echo ${{ matrix.pl_backend }} | sed "s/_/./g"`

.github/workflows/wheel_linux_x86_64.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ jobs:
156156
157157
CIBW_BEFORE_TEST: |
158158
python -m pip install -r requirements-tests.txt
159-
if ${{ matrix.pl_backend == 'lightning_kokkos'}}; then SKIP_COMPILATION=True PL_BACKEND="lightning_qubit" pip install -e . -vv; fi
159+
if ${{ matrix.pl_backend == 'lightning_kokkos'}}; then SKIP_COMPILATION=True PL_BACKEND="lightning_qubit" python -m pip install . -vv; fi
160160
161161
CIBW_TEST_COMMAND: |
162162
DEVICENAME=`echo ${{ matrix.pl_backend }} | sed "s/_/./g"`

.github/workflows/wheel_macos_arm64.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ jobs:
9696
9797
CIBW_BEFORE_TEST: |
9898
python -m pip install -r requirements-tests.txt
99-
if ${{ matrix.pl_backend == 'lightning_kokkos'}}; then SKIP_COMPILATION=True PL_BACKEND="lightning_qubit" pip install -e . -vv; fi
99+
if ${{ matrix.pl_backend == 'lightning_kokkos'}}; then SKIP_COMPILATION=True PL_BACKEND="lightning_qubit" python -m pip install . -vv; fi
100100
101101
CIBW_TEST_COMMAND: |
102102
DEVICENAME=`echo ${{ matrix.pl_backend }} | sed "s/_/./g"`

.github/workflows/wheel_macos_x86_64.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ jobs:
144144

145145
CIBW_BEFORE_TEST: |
146146
python -m pip install -r requirements-tests.txt
147-
if ${{ matrix.pl_backend == 'lightning_kokkos'}}; then SKIP_COMPILATION=True PL_BACKEND="lightning_qubit" pip install -e . -vv; fi
147+
if ${{ matrix.pl_backend == 'lightning_kokkos'}}; then SKIP_COMPILATION=True PL_BACKEND="lightning_qubit" python -m pip install . -vv; fi
148148
149149
CIBW_TEST_COMMAND: |
150150
DEVICENAME=`echo ${{ matrix.pl_backend }} | sed "s/_/./g"`

.github/workflows/wheel_win_x86_64.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ jobs:
173173
python -m pip install setuptools
174174
python -m pip install -r requirements-tests.txt
175175
if (${{ matrix.pl_backend == 'lightning_kokkos'}}) {
176-
SKIP_COMPILATION=True PL_BACKEND="lightning_qubit" python -m pip install -e . -vv
176+
SKIP_COMPILATION=True PL_BACKEND="lightning_qubit" python -m pip install . -vv
177177
}
178178
pushd wheelhouse
179179
$wheels = Get-ChildItem "./" -Filter *.whl

.gitignore

+28-27
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,37 @@
1-
venv/
2-
kokkos/
3-
prototypes/
4-
doc/_build/
5-
doc/code/api/
6-
PennyLane_Lightning.egg-info/
7-
PennyLane_Lightning_Kokkos.egg-info/
8-
build/
9-
build_lightning_*/
10-
Build/
11-
BuildCov/
12-
BuildGBench/
13-
BuildTests/
14-
BuildTidy/
15-
dist/
16-
tests/__pycache__/
17-
.idea
18-
*.ipynp
19-
*.ipynb_checkpoints
201
__pycache__
21-
.pytest_cache/
22-
coverage_html_report/
2+
.cache/*
233
.coverage
24-
*.so
25-
cpptests
26-
*.o
274
.DS_Store
28-
.cache/*
5+
.idea
6+
.pytest_cache/
297
.vscode/
308
.ycm_extra_conf.py
9+
*.ipynb_checkpoints
10+
*.ipynp
11+
*.o
12+
*.so
3113
/.vs
14+
/PennyLane_Lightning*
3215
/pennylane_lightning/.vs
3316
/pennylane_lightning/*.pyd
34-
/pennylane_lightning/src/Kokkos/
3517
/pennylane_lightning/src/GBenchmarks/
36-
/PennyLane_Lightning*
18+
/pennylane_lightning/src/Kokkos/
19+
build_lightning_*/
20+
build/
21+
Build/
22+
BuildCov/
23+
BuildGBench/
24+
BuildTests/
25+
BuildTidy/
26+
coverage_html_report/
27+
cpptests
28+
dist/
29+
doc/_build/
30+
doc/code/api/
31+
kokkos/
32+
PennyLane_Lightning_Kokkos.egg-info/
33+
PennyLane_Lightning.egg-info/
34+
pennylane_lightning/core/src/utils/config.h
35+
prototypes/
36+
tests/__pycache__/
37+
venv/

mpitests/test_adjoint_jacobian.py

+6-13
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
from pennylane import qnode
2929
from scipy.stats import unitary_group
3030

31+
if not ld._CPP_BINARY_AVAILABLE:
32+
pytest.skip("No binary module found. Skipping.", allow_module_level=True)
33+
3134
I, X, Y, Z = (
3235
np.eye(2),
3336
qml.PauliX.compute_matrix(),
@@ -109,12 +112,10 @@ def test_not_expval(self, dev):
109112
qml.RX(0.1, wires=0)
110113
qml.state()
111114

112-
if device_name == "lightning.gpu" and ld._CPP_BINARY_AVAILABLE:
115+
if device_name == "lightning.gpu":
113116
message = "Adjoint differentiation does not support State measurements."
114-
elif ld._CPP_BINARY_AVAILABLE:
115-
message = "This method does not support statevector return type."
116117
else:
117-
message = "Adjoint differentiation method does not support measurement StateMP"
118+
message = "Adjoint differentiation method does not support measurement StateMP."
118119
with pytest.raises(
119120
qml.QuantumFunctionError,
120121
match=message,
@@ -144,7 +145,6 @@ def test_empty_measurements(self, dev):
144145
jac = dev.adjoint_jacobian(tape)
145146
assert len(jac) == 0
146147

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

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

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

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

604-
@pytest.mark.skipif(not ld._CPP_BINARY_AVAILABLE, reason="Lightning binary required")
605601
def test_provide_wrong_starting_state(self, dev):
606602
"""Tests raise an exception when provided starting state mismatches."""
607603
x, y, z = [0.5, 0.3, -0.7]
@@ -624,7 +620,6 @@ def test_provide_wrong_starting_state(self, dev):
624620
device_name == "lightning.gpu",
625621
reason="Adjoint differentiation does not support State measurements.",
626622
)
627-
@pytest.mark.skipif(not ld._CPP_BINARY_AVAILABLE, reason="Lightning binary required")
628623
def test_state_return_type(self, dev):
629624
"""Tests raise an exception when the return type is State"""
630625
with qml.tape.QuantumTape() as tape:
@@ -635,7 +630,7 @@ def test_state_return_type(self, dev):
635630

636631
with pytest.raises(
637632
qml.QuantumFunctionError,
638-
match="This method does not support statevector return type.",
633+
match="Adjoint differentiation method does not support measurement StateMP.",
639634
):
640635
dev.adjoint_jacobian(tape)
641636

@@ -675,7 +670,6 @@ def circ(x):
675670
):
676671
qml.grad(circ)(0.1)
677672

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

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

769-
@pytest.mark.skipif(not ld._CPP_BINARY_AVAILABLE, reason="Lightning binary required")
770763
def test_gradient_repeated_gate_parameters(self, mocker, dev):
771764
"""Tests that repeated use of a free parameter in a multi-parameter gate yields correct
772765
gradients."""

pennylane_lightning/core/lightning_base.py

+6-29
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import numpy as np
2323
import pennylane as qml
2424
from pennylane import BasisState, QubitDevice, StatePrep
25-
from pennylane.devices import DefaultQubitLegacy
2625
from pennylane.measurements import Expectation, MeasurementProcess, State
2726
from pennylane.operation import Operation, Tensor
2827
from pennylane.ops import Prod, Projector, SProd, Sum
@@ -71,6 +70,12 @@ def __init__(
7170
shots=None,
7271
batch_obs=False,
7372
):
73+
if not self._CPP_BINARY_AVAILABLE:
74+
raise ImportError(
75+
f"Pre-compiled binaries for {self.short_name} are not available. "
76+
"To manually compile from source, follow the instructions at "
77+
"https://pennylane-lightning.readthedocs.io/en/latest/installation.html."
78+
)
7479
if c_dtype is np.complex64:
7580
r_dtype = np.float32
7681
self.use_csingle = True
@@ -446,31 +451,3 @@ def processing_fns(tapes):
446451
return vjps
447452

448453
return processing_fns
449-
450-
451-
class LightningBaseFallBack(DefaultQubitLegacy): # pragma: no cover
452-
# pylint: disable=missing-class-docstring, too-few-public-methods
453-
pennylane_requires = ">=0.34"
454-
version = __version__
455-
author = "Xanadu Inc."
456-
_CPP_BINARY_AVAILABLE = False
457-
_new_API = False
458-
459-
def __init__(self, wires, *, c_dtype=np.complex128, **kwargs):
460-
if c_dtype is np.complex64:
461-
r_dtype = np.float32
462-
elif c_dtype is np.complex128:
463-
r_dtype = np.float64
464-
else:
465-
raise TypeError(f"Unsupported complex type: {c_dtype}")
466-
super().__init__(wires, r_dtype=r_dtype, c_dtype=c_dtype, **kwargs)
467-
468-
@property
469-
def state_vector(self):
470-
"""Returns a handle to the statevector."""
471-
return self._state
472-
473-
@property
474-
def dtype(self):
475-
"""State vector complex data type."""
476-
return self.C_DTYPE

0 commit comments

Comments
 (0)