Skip to content

Commit

Permalink
renamed to PlaceholderExpectation
Browse files Browse the repository at this point in the history
  • Loading branch information
cgogolin committed Nov 30, 2018
1 parent 97c7b3a commit 7c53694
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions pennylane/expval/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,14 @@
from .cv import __all__ as _cv__all__
from .qubit import __all__ as _qubit__all__

class PlaceholderOperation:
class PlaceholderExpectation():
r"""pennylane.expval.PlaceholderExpectation()
A generic base class for constructing placeholders for operations that
exist under the same name in CV and qubit based devices.
When instantiated inside a QNode context, returns an instance
of the respective class in expval.cv or expval.qubit.
"""
def __new__(cls, *args, **kwargs):
if QNode._current_context is None:
raise QuantumFunctionError("Quantum operations can only be used inside a qfunc.")
Expand All @@ -69,14 +76,14 @@ def __new__(cls, *args, **kwargs):
elif supported_expectations.intersection([cls for cls in _qubit__all__]):
return getattr(qubit, cls.__name__)(*args, **kwargs)
else:
raise QuantumFunctionError("Unable to determine whether this device supports CV or qubit operations when constructing this "+cls.__name__+" expectation.")
raise QuantumFunctionError("Unable to determine whether this device supports CV or qubit Operations when constructing this "+cls.__name__+" Expectation.")

num_wires = 0
num_params = 0
par_domain = 'A'
grad_method = None

class Identity(PlaceholderOperation): #pylint: disable=too-few-public-methods,function-redefined
class Identity(PlaceholderExpectation): #pylint: disable=too-few-public-methods,function-redefined
r"""pennylane.expval.Identity(wires)
Expectation value of the identity observable :math:`\I`.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_expval.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_identiy_raises_exception_if_cannot_guess_device_type(self):
def circuit():
return qml.expval.Identity(wires=0)

with self.assertRaisesRegex(QuantumFunctionError, 'Unable to determine whether this device supports CV or qubit operations'):
with self.assertRaisesRegex(QuantumFunctionError, 'Unable to determine whether this device supports CV or qubit'):
circuit()


Expand Down

0 comments on commit 7c53694

Please sign in to comment.