-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
quantum_info.operator mixin interface refactor #5617
Conversation
04de44f
to
23b4876
Compare
23b4876
to
68c6c64
Compare
2a50232
to
c567d26
Compare
Maybe def _evolve(self, state, qargs=None):
return SuperOp(self)._evolve(state, qargs) could be moved to |
That is True, however it has cyclic import issues which is why it isn't in the base class. |
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.
Looks good overall, few small comments.
Why do private and public methods coexist? (e.g. |
The idea was user never overrides
in every subclasses compose method. But maybe thats not a good enough reason. |
I updated to remove the |
Move tolerances to mixin folder
Subclass of BaseOperator that includes LinearMixin and TolerancesMixin
deb9417
to
2dba626
Compare
In Qiskit#5617 a single usage of np.int slipped in to the clifford module. This type is deprecated in numpy 1.20.0 and is just an alias for python's stdlib int type (see Qiskit#5788 and Qiskit#5758 for the earlier fixes). This usage is causing downstream failures in other project's CI that use this module in environment's where warnings aren't allowed (mainly ignis's docs builds). This commit fixes this stray np.int usage to unblock CI and remove the deprecation warning from anything using the clifford module.
In #5617 a single usage of np.int slipped in to the clifford module. This type is deprecated in numpy 1.20.0 and is just an alias for python's stdlib int type (see #5788 and #5758 for the earlier fixes). This usage is causing downstream failures in other project's CI that use this module in environment's where warnings aren't allowed (mainly ignis's docs builds). This commit fixes this stray np.int usage to unblock CI and remove the deprecation warning from anything using the clifford module. Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
Summary
Internal API changes to BaseOperator class to simplify making operator subclasses, and reduce copy paste of API docs.
Details and comments
Refactors the quantum_info BaseOperator and subclasses to use mixins for defining the operator inferface. This allows operator subclasses to only include the mixin for interfaces they support. For example Operator and QuantumChannel operators support linear operations (addition, subtraction), but Clifford and Pauli operators do not.
Current mixins are:
GroupMixin
: this defines the basic API to be compatible with QuantumCircuits. It includescompose
,dot
,tensor
,expand
AdjointMixin
: definesconjugate
,transpose
,adjoint
methods.MultiplyMixin
: this is not part of the BaseOperator and can be used by special operators which support scalar multiplication. It defines__mul__
and__truediv__
for scalars.LinearMixin
: this defines linear operators which support addition, subtraction, and scalar multiplication. It includes theMultiplyMixin
, plus defines__add__
and__sub__
methods.ToleranceMixin
: this defines theatol
andrtol
properties for the operator for use in numeric comparisonsBaseOperator
only usesGroupMixin
for its API. Other mixins can be included by subclasses which support their interface or require their functionality. ALinearOp
abstract class was also added that includesLinearMixin
,AdjointMixin
andTolerancesMixin
with BaseOperator.This PR also refactors a lot of doc strings in the operator classes to avoid unnecessary duplication in derived classes. This is handled by the
generate_apidocs
function that must be called on a class after its definition (Due to however python handles abstractmethod doc strings I couldn't seem to get this function to work as a decorator when defining the class).