-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Wrote ObservablesArray.apply_layout
and some additional methods
#14289
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
Conversation
One or more of the following people are relevant to this code:
|
Pull Request Test Coverage Report for Build 14892081928Details
💛 - Coveralls |
for ndi, obs in np.ndenumerate(self._array): | ||
new_arr[ndi] = obs.apply_layout(layout, num_qubits) | ||
|
||
return ObservablesArray(new_arr) |
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.
I chose not to set validate
to False
, only to be on the safe side, but I actually don't see a real reason. What do you think?
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.
I think we should not validate in the constructor when making new instances in method implementations
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.
Thanks @yaelbh !
arr2 = np.atleast_1d(other._array).flat | ||
|
||
for obs1, obs2 in zip(arr1, arr2): | ||
if (obs1 - obs2).simplify(tol) != SparseObservable.zero(self.num_qubits): |
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.
nit: the creation of the zero array can be moved outside of the loop.
|
||
n_qubits = self.num_qubits | ||
if isinstance(layout, TranspileLayout): | ||
n_qubits = len(layout._output_qubit_list) |
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.
We shouldn't be using private attributes of other classes. Is there another way to fetch this information?
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.
It seems like just len(layout)
is sufficient?
for ndi, obs in np.ndenumerate(self._array): | ||
new_arr[ndi] = obs.apply_layout(layout, num_qubits) | ||
|
||
return ObservablesArray(new_arr) |
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.
I think we should not validate in the constructor when making new instances in method implementations
Co-authored-by: Ian Hincks <ian.hincks@gmail.com>
Co-authored-by: Ian Hincks <ian.hincks@gmail.com>
Co-authored-by: Ian Hincks <ian.hincks@gmail.com>
Co-authored-by: Ian Hincks <ian.hincks@gmail.com>
Co-authored-by: Ian Hincks <ian.hincks@gmail.com>
Co-authored-by: Ian Hincks <ian.hincks@gmail.com>
Co-authored-by: Ian Hincks <ian.hincks@gmail.com>
Co-authored-by: Ian Hincks <ian.hincks@gmail.com>
Summary
Addresses part of #14129
Details and comments
Added the following methods to
ObservablesArray
:apply_layout
equivalent
copy
Also added
SparseObservable
toObservableLike
and a test to verify the workflow with the estimator.