-
Notifications
You must be signed in to change notification settings - Fork 575
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
Add representation to MeasurementProcess #883
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,6 +78,16 @@ def __init__(self, return_type, obs=None, wires=None, eigvals=None): | |
# Queue the measurement process | ||
self.queue() | ||
|
||
def __repr__(self): | ||
"""Representation of this class.""" | ||
if self.obs is None: | ||
return "{}(None)".format(self.return_type.value) | ||
mariaschuld marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if self.obs.return_type is None: | ||
mariaschuld marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return "{}({})".format(self.return_type.value, self.obs) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the return type is not none, it was already added in the I am not sure if this has to do with the two cores? Shouldn't the return type be only specified in the process? I tried not to change too much here... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yep, this is to support non-tape mode, where observables are still annotated directly with the return type. Perhaps we should add a TODO to this method, to remind us to fix it when tape mode is default? |
||
|
||
return "{}".format(self.obs) | ||
|
||
def __copy__(self): | ||
cls = self.__class__ | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -199,6 +199,16 @@ def test_observable_with_no_eigvals(self): | |
m = MeasurementProcess(Expectation, obs=obs) | ||
assert m.eigvals is None | ||
|
||
def test_repr(self): | ||
"""Test the string representation of a MeasurementProcess.""" | ||
m = MeasurementProcess(Expectation, obs=qml.PauliZ(wires='a') @ qml.PauliZ(wires='b')) | ||
expected = "expval(PauliZ(wires=['a']) @ PauliZ(wires=['b']))" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😍 |
||
assert str(m) == expected | ||
|
||
m = MeasurementProcess(Probability, obs=qml.PauliZ(wires='a')) | ||
expected = "probs(PauliZ(wires=['a']))" | ||
assert str(m) == expected | ||
|
||
|
||
class TestExpansion: | ||
"""Test for measurement expansion""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯