-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Operation abstract base class #7087
Conversation
first pass on adding CircuitElement mixin to Clifford by @alexanderivrii
adding @Property to funcs in instruction.py related to CircuitElement
For Instruction class: fixes related to @Property decorator
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.
This looks great so far! One comment on the .setter
s for Instruction
, which relates to whether or not we can or should use CircuitElement
for QuantumCircuit
: once these elements are added to a circuit (and in some cases even before), these properties should effectively be fixed.
While e.g. it is currently possible to change Instruction.name
or Instruction.num_qubits
(because it's python and we haven't taken the steps extra to make them read-only), this will only lead to confusion or an invalid circuit in 99% of the cases (as in @nkanazawa1989 's issue from the other day). I'd have to think a bit about how this could be implemented through the CircuitElement
mixin.
…antumCircuit classes
Circuit element
I agree with Chris that we should use a better way than overriding the |
From the meeting: we decided that "something that can be added to a circuit" is a description of an interface, not an implementation, and consequently we should just look to define the interface. This means:
In general, the reasons for these all stem from how we plan to use this as an interface attached to other objects. This means that it needs to be well-behaved in a multiple-inheritance context. The primary implication is that the class should be as lightweight as absolutely possible, which means removing all concrete behaviour and leaving only the required interface for children to fill in. More detailRequiring the underlying data to be stored in a certain name (here set by The original reason for having |
…ynthesis team; adding tests to test_operation
Updating the Operation class following review comments
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 for the updates @ShellyGarion . Few minor comments, otherwise looks good!
These objects include :class:`~qiskit.circuit.Gate`, :class:`~qiskit.circuit.Reset`, | ||
:class:`~qiskit.circuit.Barrier`, :class:`~qiskit.circuit.Measure`, | ||
and operators such as :class:`~qiskit.quantum_info.Clifford`. | ||
""" |
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.
Here and in the release note, it would be good to have a simple example of how users should expect to use this class and some details on its motivation. e.g. Clifford
is probably a more representative example than Reset
.
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 for the updates here @ShellyGarion and @alexanderivrii ! I think there are still a few open questions around how we ultimately want to build around Operation
(like how we want to define and handle params
/operands
, and how to set a deprecation path for Instruction
) but I think these can be discussed separately. This is sufficient to unblock e.g. #7238 and the related https://github.com/Qiskit/qiskit-terra/labels/synthesis work so this LGTM.
Summary
Add
Operation
mixin class and refactor the other classes accordingly.#5811
co-authored by @alexanderivrii
Details and comments
Operation
classGate
classBarrier, Reset, Measure
classesQuantumCircuit
class - this will be done in a separate PR (deprecatingcircuit.to_instruction
)In
quantum_info
:Clifford
classCNOTDihedral
classpauli
classIn
extension
: need to update classes which areInstruction
and notGate
Initialize
Isometry
In
circuit.library.standard_gates
: all areGate
so no update is neededIn
circuit.library.generalized_gates
: all areQuantumCircuit
so no update is neededIn future PR -
deprecate Instruction
!