-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite singleton handling including
SingletonInstruction
(#11014)
* Rewrite singleton handling including `SingletonInstruction` This is a large rewrite of the singleton gate handling, building off the work done across the library to make the initial implementation work. There are two main purposes to this commit: * Make `SingletonInstruction` available in addition to `SingletonGate`, and have these be easy to maintain in conjunction, not need to duplicate overrides between them, and not require inheritors to do any nasty multiple inheritance or the like. * Fix regressions in the construction time of `SingletonGate` instances. In the end, this turned into a fairly complete rewrite that completely switches out the method of defining the classes; it transpires that the previous way of having the "immutable overrides" on _all_ instances of the classes was the main source of slowdown, with `__setattr__` being a large problem. The previous method was far easier from an implementation perspective, but the runtime costs ended up being too high. This new form takes a vastly different strategy, explained in detail in `qiskit/circuit/singleton.py`. The gist is that we instead make the singleton instance a _subclass_ of the class object we're creating, and only it contains the overrides to make itself immutable. We get around the instantiation problem (`__init__` isn't special and doesn't skip the forbidden `__setattr__`) by constructing an instance of the _base_ class, and then dynamically switching in the overrides afterwards. Since the overrides and the dynamic singleton type of the instance are designed to be co-operative (including in `__slots__` layout), this can be done safely. * Make singleton documentation public * Add tests of new singleton behaviour * Fix typos Co-authored-by: Matthew Treinish <[email protected]> --------- Co-authored-by: Matthew Treinish <[email protected]>
- Loading branch information
1 parent
a1927bd
commit bcf5ce4
Showing
32 changed files
with
581 additions
and
363 deletions.
There are no files selected for viewing
This file contains 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,6 @@ | ||
.. _qiskit-circuit-singleton: | ||
|
||
.. automodule:: qiskit.circuit.singleton | ||
:no-members: | ||
:no-inherited-members: | ||
:no-special-members: |
This file contains 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 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 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 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 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 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 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 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 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 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 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 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
Oops, something went wrong.