Commit b045984
Add PEP 484 type hints to transpiler analysis and utility passes (#15832)
* docs: add PEP 484 type hints to transpiler analysis and utility passes
Add `from __future__ import annotations` and PEP 484 type annotations to all 9 analysis passes (CountOps, Depth, Size, Width, NumQubits, NumTensorFactors, CountOpsLongestPath, DAGLongestPath, ResourceEstimation) and 3 utility passes (DAGFixedPoint, FixedPoint, ContainsInstruction).
Changes include:
- Type-annotate __init__ parameters and run() method signatures with DAGCircuit, bool, str, and -> None return types
- Expand sparse docstrings with Args blocks where missing
- Fix copy-paste module docstring in contains_instruction.py (was incorrectly 'Check if a property reached a fixed point')
- Rename placeholder parameter '_' to 'dag' in ResourceEstimation.run() for clarity
* Refactor import statements in count_ops.py
* Refactor imports and update docstring formatting
* Refactor import statements and update docstring
* Refactor imports and update docstring formatting
* Refactor import statement for TYPE_CHECKING
* Apply suggestion from @Cryoris
Co-authored-by: Julien Gacon <gaconju@gmail.com>
* Refactor imports and docstring formatting
* Refactor import statements and docstring formatting
* Refactor imports and update docstring format
* Refactor import statements in width.py
* Update instruction_name type to Iterable in ContainsInstruction
* Update dag_fixed_point.py
* Refactor imports and docstrings in fixed_point.py
* Add copyright notice and docstring to count_ops.py
* Add docstring for counting operations in DAGCircuit
* Add type checking for DAGCircuit import
* Add copyright notice and docstring to depth.py
* Add copyright notice and docstring to num_qubits.py
* Import DAGCircuit for type checking
Add import statement for DAGCircuit in num_tensor_factors.py
* Update resource_estimation.py for type checking
* Add copyright notice and docstring to size.py
* Update width.py
* Update copyright notice in contains_instruction.py
* Update copyright notice in dag_fixed_point.py
* Add copyright notice and docstring to fixed_point.py
* Update fixed point tracking in DAG utility
* Fix fixed point property update logic
* Remove unnecessary blank line in fixed_point.py
* Remove unnecessary blank line in dag_fixed_point.py
* fix: use from __future__ import annotations with TYPE_CHECKING guard
Add from __future__ import annotations to all 12 files so that
type hints are treated as strings at runtime (fixing Python 3.10
NameError). Keep TYPE_CHECKING guard for DAGCircuit import to
satisfy ruff F821. This matches the pattern used in basepasses.py
and layout.py.
Also fixes contains_instruction.py module docstring (was copy-paste
from fixed_point.py).
---------
Co-authored-by: Julien Gacon <gaconju@gmail.com>1 parent ac20c33 commit b045984
12 files changed
Lines changed: 126 additions & 39 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
15 | 22 | | |
16 | 23 | | |
17 | 24 | | |
| |||
21 | 28 | | |
22 | 29 | | |
23 | 30 | | |
24 | | - | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
25 | 37 | | |
26 | 38 | | |
27 | 39 | | |
28 | | - | |
29 | | - | |
| 40 | + | |
| 41 | + | |
30 | 42 | | |
Lines changed: 9 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
15 | 22 | | |
16 | 23 | | |
17 | 24 | | |
| |||
21 | 28 | | |
22 | 29 | | |
23 | 30 | | |
24 | | - | |
25 | | - | |
| 31 | + | |
| 32 | + | |
26 | 33 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
15 | 22 | | |
16 | 23 | | |
17 | 24 | | |
18 | 25 | | |
19 | 26 | | |
20 | 27 | | |
21 | 28 | | |
22 | | - | |
23 | | - | |
| 29 | + | |
| 30 | + | |
24 | 31 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
15 | 22 | | |
16 | 23 | | |
17 | 24 | | |
18 | 25 | | |
19 | 26 | | |
20 | 27 | | |
21 | | - | |
| 28 | + | |
22 | 29 | | |
23 | 30 | | |
24 | 31 | | |
| |||
28 | 35 | | |
29 | 36 | | |
30 | 37 | | |
31 | | - | |
32 | | - | |
| 38 | + | |
| 39 | + | |
33 | 40 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
15 | 22 | | |
16 | 23 | | |
17 | 24 | | |
| |||
21 | 28 | | |
22 | 29 | | |
23 | 30 | | |
24 | | - | |
25 | | - | |
| 31 | + | |
| 32 | + | |
26 | 33 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
15 | 22 | | |
16 | 23 | | |
17 | 24 | | |
| |||
21 | 28 | | |
22 | 29 | | |
23 | 30 | | |
24 | | - | |
25 | | - | |
| 31 | + | |
| 32 | + | |
26 | 33 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
15 | 22 | | |
16 | 23 | | |
17 | 24 | | |
| |||
25 | 32 | | |
26 | 33 | | |
27 | 34 | | |
| 35 | + | |
28 | 36 | | |
29 | 37 | | |
30 | 38 | | |
31 | 39 | | |
32 | 40 | | |
| 41 | + | |
33 | 42 | | |
34 | 43 | | |
35 | | - | |
| 44 | + | |
36 | 45 | | |
37 | 46 | | |
38 | 47 | | |
39 | | - | |
40 | | - | |
| 48 | + | |
| 49 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
15 | 22 | | |
16 | 23 | | |
17 | 24 | | |
| |||
21 | 28 | | |
22 | 29 | | |
23 | 30 | | |
24 | | - | |
| 31 | + | |
25 | 32 | | |
26 | 33 | | |
27 | 34 | | |
| |||
31 | 38 | | |
32 | 39 | | |
33 | 40 | | |
34 | | - | |
35 | | - | |
| 41 | + | |
| 42 | + | |
36 | 43 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
15 | 22 | | |
16 | 23 | | |
17 | 24 | | |
| |||
22 | 29 | | |
23 | 30 | | |
24 | 31 | | |
25 | | - | |
26 | | - | |
| 32 | + | |
| 33 | + | |
27 | 34 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
14 | 22 | | |
15 | 23 | | |
16 | 24 | | |
| |||
23 | 31 | | |
24 | 32 | | |
25 | 33 | | |
26 | | - | |
27 | | - | |
28 | | - | |
| 34 | + | |
| 35 | + | |
29 | 36 | | |
30 | | - | |
| 37 | + | |
31 | 38 | | |
32 | 39 | | |
33 | | - | |
| 40 | + | |
34 | 41 | | |
35 | 42 | | |
36 | 43 | | |
37 | 44 | | |
38 | 45 | | |
39 | 46 | | |
40 | 47 | | |
41 | | - | |
42 | | - | |
| 48 | + | |
| 49 | + | |
43 | 50 | | |
44 | 51 | | |
45 | 52 | | |
0 commit comments