Skip to content

Commit

Permalink
Fix incorrect exception message for unknown interfaces (PennyLaneAI#930)
Browse files Browse the repository at this point in the history
* Fix incorrect exception message for unknown interfaces

* changelog
  • Loading branch information
josh146 authored and alejomonbar committed Dec 1, 2020
1 parent c28e66c commit 576429d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,9 @@
being set if this is not the case.
[(#923)](https://github.com/PennyLaneAI/pennylane/pull/923)

* Fixes broken error message if a QNode is instantiated with an unknown exception.
[(#930)](https://github.com/PennyLaneAI/pennylane/pull/930)

<h3>Contributors</h3>

This release contains contributions from (in alphabetical order):
Expand Down
2 changes: 1 addition & 1 deletion pennylane/tape/qnode.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def __init__(self, func, device, interface="autograd", diff_method="best", **dif
if interface is not None and interface not in self.INTERFACE_MAP:
raise qml.QuantumFunctionError(
f"Unknown interface {interface}. Interface must be "
f"one of {self.INTERFACE_MAP.values()}."
f"one of {list(self.INTERFACE_MAP.keys())}."
)

if not isinstance(device, Device):
Expand Down
7 changes: 6 additions & 1 deletion tests/tape/tapes/test_qnode.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ class TestValidation:
def test_invalid_interface(self):
"""Test that an exception is raised for an invalid interface"""
dev = qml.device("default.qubit", wires=1)
test_interface = "something"
expected_error = (
fr"Unknown interface {test_interface}\. Interface must be "
r"one of \['autograd', 'torch', 'tf'\]\."
)

with pytest.raises(qml.QuantumFunctionError, match="Unknown interface"):
with pytest.raises(qml.QuantumFunctionError, match=expected_error):
QNode(None, dev, interface="something")

def test_invalid_device(self):
Expand Down

0 comments on commit 576429d

Please sign in to comment.