-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Operation abstract base class #7087
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
Merged
Merged
Changes from all commits
Commits
Show all changes
95 commits
Select commit
Hold shift + click to select a range
00c1030
add CircuitElement mixin class
ShellyGarion 1bb861f
update Instruction class
ShellyGarion 34317d9
reformat instruction.py
ShellyGarion ea0f117
Merge branch 'main' into circuit_element
levbishop 4d35d3c
first pass on adding CircuitElement mixin to Clifford
alexanderivrii df319e3
Merge pull request #3 from alexanderivrii/circuit_element
ShellyGarion 3dba19c
style edits
ShellyGarion a73cf37
add docstring in CircuitElement class
ShellyGarion 946a44c
remove duplicate instruction
ShellyGarion c0ac0cd
remove unused import instruction from instructionset
ShellyGarion 665efa9
adding @property to functions in instruction.py related to CircuitEle…
alexanderivrii 44ac031
Merge pull request #5 from alexanderivrii/circuit_element
ShellyGarion 16a2710
For Instruction class: fixes related to @property decorator, and addi…
alexanderivrii 2c91561
Merge pull request #6 from alexanderivrii/circuit_element
ShellyGarion ce47b1a
fix comment following review
ShellyGarion fb613fc
remove setter from Instruction
ShellyGarion 51c9a82
add name setter since CI is failing
ShellyGarion 0fca3e6
update num_params
ShellyGarion 83a1adc
making QuantumCircuit inherit QuantumElementMixin
alexanderivrii badde7c
making sure that to_instruction still gets called for Clifford and Qu…
alexanderivrii ef1c1eb
updating description for params
alexanderivrii a510115
Merge pull request #9 from alexanderivrii/circuit_element
ShellyGarion daf4a69
Merge branch 'main' into circuit_element
ShellyGarion 44eecfe
refactor CircuitElement --> Operation
ShellyGarion 37573b2
update comments
ShellyGarion 3033663
style
ShellyGarion 1a49f9b
revert to original Instruction class
ShellyGarion e1cbf4f
revert code in instructionset and quantumcircuit
ShellyGarion 9dda899
revert instructionset import
ShellyGarion 16e6b6c
make Gate an Operation Mixin
ShellyGarion f90d68c
update Gate
ShellyGarion a999d8d
remove params from gate.py
ShellyGarion 38aa966
style
ShellyGarion cbb90e3
update quantumcircuit following review
ShellyGarion 682c817
add to_instruction method to Operation
ShellyGarion 63e69a5
style
ShellyGarion f408dfe
fix to_instruction method in Operation
ShellyGarion 77be67c
fix to_instruction method in Operation
ShellyGarion 674a899
remove to_instruction method from Operation
ShellyGarion 2b714f1
style
ShellyGarion 3c47c3d
adding Operation mixing to Barrier, Measure, and Reset
alexanderivrii ee40fb4
Merge pull request #11 from alexanderivrii/circuit_element2
ShellyGarion f53c1bf
implementing name, num_qubits, num_clbits directly in Operation; remo…
alexanderivrii dd6ecc8
copy-pasting is evil
alexanderivrii 45b0a8b
Merge pull request #12 from alexanderivrii/circuit_element
ShellyGarion 4b9188b
fix conflict with main branch
ShellyGarion 4607f6f
fix clifford name to Clifford
ShellyGarion 6f08181
add super to QuantumCircuit
ShellyGarion 80f9b45
fix super in QuantumCircuit
ShellyGarion 51ac2ce
Fixing name is QuantumCircuit constructor
alexanderivrii 0af6037
Merge pull request #13 from alexanderivrii/circuit_element
ShellyGarion 1ca8db2
replace params with parameters in super
ShellyGarion 04093d7
revert super in QuantumCircuit
ShellyGarion 464487d
Merge branch 'main' into main_shelly_5
ShellyGarion 4afcc1b
add Operation mixin to CNOTDiheral class
ShellyGarion 237db1a
Adding Operation mixin to isometry and initializer
alexanderivrii 85ef076
Merge pull request #14 from alexanderivrii/circuit_element
ShellyGarion 200e549
add Operation mixin to Pauli class
ShellyGarion aecf2f3
add release notes
ShellyGarion a17e7c2
change _name to name in Gate class
ShellyGarion f3b5d72
add description to Operation docstring
ShellyGarion aeea5f4
raising CircuitError to disallow direct instantiation of Operation (b…
alexanderivrii cb6d667
Eli pointed out that calling Operation.__init__ is bad Python practic…
alexanderivrii 00f7b05
running black
alexanderivrii 10bccc9
Merge pull request #17 from alexanderivrii/circuit_element
ShellyGarion ea961e3
temporarily remove _new_ in Operation class
ShellyGarion 2b7e258
remove CircuitError import from Operation
ShellyGarion a964fd2
fix signature errors when estimating free parameters
ewinston ef87ef9
Merge pull request #18 from ewinston/shelly/circuit_element
ShellyGarion abe8187
add CircuitError back to Operation
ShellyGarion 8db4cbe
Adding pylint-disable messages for C3XGate and MCXGate (both implemen…
alexanderivrii 3b4cc6f
Disabling pylint complaints that __new__ does not use args and kwargs…
alexanderivrii 4256d7b
Fixed comparison between str and constant string
alexanderivrii aa22f38
Adding test for Operation class
alexanderivrii 6d48741
Reformatting using black
alexanderivrii 5d8a6ea
Merge pull request #19 from alexanderivrii/circuit_element
ShellyGarion 5f45ae1
remove Operation mixin from QuantumCircuit class
ShellyGarion 0c07a44
remove QuantumCircuit from documentation and release notes
ShellyGarion 4117677
update names to lower case
ShellyGarion 2aee5c7
refactor: params --> operands
ShellyGarion 1be374a
Merge branch 'main' into circuit_element
ShellyGarion e974e4c
Updating the Operation class following the meeting with the quantum s…
alexanderivrii 7cb8a11
Merge pull request #26 from alexanderivrii/circuit_element
ShellyGarion 316c6b6
style fixes
ShellyGarion bf638b6
fix lint
ShellyGarion d537fda
remove import Operation from test
ShellyGarion 052b923
minor fixes
alexanderivrii a792b8f
Merge pull request #27 from alexanderivrii/circuit_element
ShellyGarion f898e1b
Merge branch 'main' into circuit_element
ShellyGarion 3e56045
Merge branch 'main' into circuit_element
ShellyGarion cd7f373
revert line in Gate class
ShellyGarion 2b14079
revert pylint disable in x.py
ShellyGarion 54ec96e
revert changes in gate_utils in test
ShellyGarion 72f54cf
add more detailed doc and an example
ShellyGarion d005e97
Merge branch 'main' into circuit_element
mergify[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| # This code is part of Qiskit. | ||
| # | ||
| # (C) Copyright IBM 2017. | ||
| # | ||
| # This code is licensed under the Apache License, Version 2.0. You may | ||
| # obtain a copy of this license in the LICENSE.txt file in the root directory | ||
| # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. | ||
| # | ||
| # Any modifications or derivative works of this code must retain this | ||
| # copyright notice, and modified files need to carry a notice indicating | ||
| # that they have been altered from the originals. | ||
|
|
||
| """Quantum Operation Mixin.""" | ||
|
|
||
| from abc import ABC, abstractmethod | ||
|
|
||
|
|
||
| class Operation(ABC): | ||
|
ShellyGarion marked this conversation as resolved.
|
||
| """Quantum Operation Interface Class. | ||
| For objects that can be added to a :class:`~qiskit.circuit.QuantumCircuit`. | ||
| 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`. | ||
| The main purpose is to add an :class:`~qiskit.circuit.Operation` to a | ||
| :class:`~qiskit.circuit.QuantumCircuit` without synthesizing it before the transpilation. | ||
|
|
||
| Example: | ||
|
|
||
| Add a Clifford and a Toffoli gate to a QuantumCircuit. | ||
|
|
||
| .. jupyter-execute:: | ||
|
|
||
| from qiskit import QuantumCircuit | ||
| from qiskit.quantum_info import Clifford, random_clifford | ||
|
|
||
| qc = QuantumCircuit(3) | ||
| cliff = random_clifford(2) | ||
| qc.append(cliff, [0, 1]) | ||
| qc.ccx(0, 1, 2) | ||
| qc.draw() | ||
| """ | ||
|
Member
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. 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. |
||
|
|
||
| __slots__ = () | ||
|
|
||
| @property | ||
|
ShellyGarion marked this conversation as resolved.
|
||
| @abstractmethod | ||
| def name(self): | ||
| """Unique string identifier for operation type.""" | ||
| raise NotImplementedError | ||
|
|
||
| @property | ||
|
ShellyGarion marked this conversation as resolved.
|
||
| @abstractmethod | ||
| def num_qubits(self): | ||
| """Number of qubits.""" | ||
| raise NotImplementedError | ||
|
|
||
| @property | ||
| @abstractmethod | ||
| def num_clbits(self): | ||
| """Number of classical bits.""" | ||
| raise NotImplementedError | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
releasenotes/notes/Operation-abstract-base-class-99f46180c7ddaa6b.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| --- | ||
| features: | ||
| - | | ||
| A new :class:`~qiskit.circuit.Operation` base class for objects | ||
| that can be added to a :class:`~qiskit.circuit.QuantumCircuit`. | ||
| 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`. | ||
| The main purpose is to add an :class:`~qiskit.circuit.Operation` to a | ||
| :class:`~qiskit.circuit.QuantumCircuit` without synthesizing it before the transpilation. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.