-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Add PEP 484 type hints to transpiler analysis and utility passes #15832
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
Changes from all commits
13592cc
dd4df44
8c5662d
f53935c
57e984d
2b6a512
f953847
5962863
0d614bc
e9572cf
9680725
0bc1b34
74a9466
66ee428
3507ba7
ce141dd
5dd8d15
2d5814a
467e5f4
fbf4347
1090259
5c44af7
5c40f3c
2f6dd11
4a7a027
9438f0d
46127b0
e6b3e69
5b0d5fb
6a38dd8
573b959
f18a82f
ecc51c2
7d5a06c
b86fbd1
c8021f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,13 @@ | |
|
|
||
| """Automatically require analysis passes for resource estimation.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import TYPE_CHECKING | ||
|
|
||
| if TYPE_CHECKING: | ||
| from qiskit.dagcircuit import DAGCircuit | ||
|
|
||
| from qiskit.transpiler.basepasses import AnalysisPass | ||
| from qiskit.transpiler.passes.analysis.depth import Depth | ||
| from qiskit.transpiler.passes.analysis.width import Width | ||
|
|
@@ -25,16 +32,18 @@ class ResourceEstimation(AnalysisPass): | |
| """Automatically require analysis passes for resource estimation. | ||
|
|
||
| An analysis pass for automatically running: | ||
|
|
||
| * Depth() | ||
| * Width() | ||
| * Size() | ||
| * CountOps() | ||
| * NumTensorFactors() | ||
| * NumQubits() | ||
|
Collaborator
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. Oh nice catch 👍🏻
Contributor
Author
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. Thanks! 😊 |
||
| """ | ||
|
|
||
| def __init__(self): | ||
| def __init__(self) -> None: | ||
| super().__init__() | ||
| self.requires += [Depth(), Width(), Size(), CountOps(), NumTensorFactors(), NumQubits()] | ||
|
|
||
| def run(self, _): | ||
| """Run the ResourceEstimation pass on `dag`.""" | ||
| def run(self, dag: DAGCircuit) -> None: | ||
| """Run the ResourceEstimation pass on ``dag``.""" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,13 @@ | |
|
|
||
| """Check if a property reached a fixed point.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from copy import deepcopy | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| if TYPE_CHECKING: | ||
| from qiskit.dagcircuit import DAGCircuit | ||
|
|
||
| from qiskit.transpiler.basepasses import AnalysisPass | ||
|
|
||
|
|
@@ -25,20 +31,18 @@ class FixedPoint(AnalysisPass): | |
| as a boolean. | ||
| """ | ||
|
|
||
| def __init__(self, property_to_check): | ||
| """FixedPoint initializer. | ||
|
|
||
| def __init__(self, property_to_check: str) -> None: | ||
| """ | ||
| Args: | ||
| property_to_check (str): The property to check if a fixed point was reached. | ||
| property_to_check: The property to check if a fixed point was reached. | ||
| """ | ||
| super().__init__() | ||
| self._property = property_to_check | ||
|
|
||
| def run(self, dag): | ||
| """Run the FixedPoint pass on `dag`.""" | ||
| def run(self, dag: DAGCircuit) -> None: | ||
| """Run the FixedPoint pass on ``dag``.""" | ||
| current_value = self.property_set[self._property] | ||
| fixed_point_previous_property = f"_fixed_point_previous_{self._property}" | ||
|
|
||
|
Collaborator
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. Maybe it'd be best to just revert all these line removals generally 😄
Contributor
Author
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. Sorry about that! Restored the blank lines ,will keep whitespace as in the originals going forward. |
||
| if self.property_set[fixed_point_previous_property] is None: | ||
| self.property_set[f"{self._property}_fixed_point"] = False | ||
| else: | ||
|
|
||
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.
IMO it's much easier to see the module docstring with this whitespace, could you leave these as they were?
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.
Sorry about that! Restored the blank lines , will keep whitespace as in the originals going forward.