Skip to content

Commit

Permalink
Fix qml.QuantumFunctionError error messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentmr committed Apr 30, 2024
1 parent 52b5c0d commit 27fbfcb
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 37 deletions.
55 changes: 28 additions & 27 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
venv/
kokkos/
prototypes/
doc/_build/
doc/code/api/
PennyLane_Lightning.egg-info/
PennyLane_Lightning_Kokkos.egg-info/
build/
build_lightning_*/
Build/
BuildCov/
BuildGBench/
BuildTests/
BuildTidy/
dist/
tests/__pycache__/
.idea
*.ipynp
*.ipynb_checkpoints
__pycache__
.pytest_cache/
coverage_html_report/
.cache/*
.coverage
*.so
cpptests
*.o
.DS_Store
.cache/*
.idea
.pytest_cache/
.vscode/
.ycm_extra_conf.py
*.ipynb_checkpoints
*.ipynp
*.o
*.so
/.vs
/PennyLane_Lightning*
/pennylane_lightning/.vs
/pennylane_lightning/*.pyd
/pennylane_lightning/src/Kokkos/
/pennylane_lightning/src/GBenchmarks/
/PennyLane_Lightning*
/pennylane_lightning/src/Kokkos/
build_lightning_*/
build/
Build/
BuildCov/
BuildGBench/
BuildTests/
BuildTidy/
coverage_html_report/
cpptests
dist/
doc/_build/
doc/code/api/
kokkos/
PennyLane_Lightning_Kokkos.egg-info/
PennyLane_Lightning.egg-info/
pennylane_lightning/core/src/utils/config.h
prototypes/
tests/__pycache__/
venv/
4 changes: 2 additions & 2 deletions mpitests/test_adjoint_jacobian.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def test_not_expval(self, dev):
if device_name == "lightning.gpu":
message = "Adjoint differentiation does not support State measurements."
else:
message = "This method does not support statevector return type."
message = "Adjoint differentiation method does not support measurement StateMP."
with pytest.raises(
qml.QuantumFunctionError,
match=message,
Expand Down Expand Up @@ -630,7 +630,7 @@ def test_state_return_type(self, dev):

with pytest.raises(
qml.QuantumFunctionError,
match="This method does not support statevector return type.",
match="Adjoint differentiation method does not support measurement StateMP.",
):
dev.adjoint_jacobian(tape)

Expand Down
2 changes: 1 addition & 1 deletion pennylane_lightning/lightning_gpu/lightning_gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ def adjoint_jacobian(self, tape, starting_state=None, use_device_state=False):

if tape_return_type is State: # pragma: no cover
raise QuantumFunctionError(
"This method does not support statevector return type. "
"Adjoint differentiation method does not support measurement StateMP."
"Use vjp method instead for this purpose."
)

Expand Down
2 changes: 1 addition & 1 deletion pennylane_lightning/lightning_kokkos/lightning_kokkos.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ def adjoint_jacobian(self, tape, starting_state=None, use_device_state=False):

if tape_return_type is State: # pragma: no cover
raise QuantumFunctionError(
"This method does not support statevector return type. "
"Adjoint differentiation method does not support measurement StateMP."
"Use vjp method instead for this purpose."
)

Expand Down
4 changes: 3 additions & 1 deletion pennylane_lightning/lightning_qubit/_adjoint_jacobian.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@ def calculate_jacobian(self, tape: QuantumTape):
return np.array([], dtype=self._dtype)

if tape_return_type is State:
raise QuantumFunctionError("This method does not support statevector return type. ")
raise QuantumFunctionError(
"Adjoint differentiation method does not support measurement StateMP."
)

if any(m.return_type is not Expectation for m in tape.measurements):
raise QuantumFunctionError(
Expand Down
2 changes: 1 addition & 1 deletion tests/lightning_qubit/test_adjoint_jacobian_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def test_not_supported_state(self, lightning_sv):

with pytest.raises(
qml.QuantumFunctionError,
match="This method does not support statevector return type",
match="Adjoint differentiation method does not support measurement StateMP.",
):
self.calculate_jacobian(lightning_sv(num_wires=3), tape)

Expand Down
6 changes: 4 additions & 2 deletions tests/new_api/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,12 +714,14 @@ def test_state_jacobian_not_supported(self, dev, batch_obs):
config = ExecutionConfig(gradient_method="adjoint", device_options={"batch_obs": batch_obs})

with pytest.raises(
qml.QuantumFunctionError, match="This method does not support statevector return type"
qml.QuantumFunctionError,
match="Adjoint differentiation method does not support measurement StateMP.",
):
_ = dev.compute_derivatives(qs, config)

with pytest.raises(
qml.QuantumFunctionError, match="This method does not support statevector return type"
qml.QuantumFunctionError,
match="Adjoint differentiation method does not support measurement StateMP.",
):
_ = dev.execute_and_compute_derivatives(qs, config)

Expand Down
5 changes: 3 additions & 2 deletions tests/test_adjoint_jacobian.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def test_not_expval(self, dev):
elif device_name == "lightning.gpu":
message = "Adjoint differentiation does not support State measurements."
else:
message = "This method does not support statevector return type."
message = "Adjoint differentiation method does not support measurement StateMP."
with pytest.raises(
qml.QuantumFunctionError,
match=message,
Expand Down Expand Up @@ -683,7 +683,8 @@ def test_state_return_type(self, dev):
method = self.get_derivatives_method(dev)

with pytest.raises(
qml.QuantumFunctionError, match="This method does not support statevector return type."
qml.QuantumFunctionError,
match="Adjoint differentiation method does not support measurement StateMP.",
):
method(tape)

Expand Down

0 comments on commit 27fbfcb

Please sign in to comment.