utils
utils
¤
HyperCube = tuple[tuple[int, ...], tuple[int, ...]]
module-attribute
¤
A hypercube represented by "top-left" and "bottom-right" coordinates (cut points).
HypercubeToScope
¤
Helper class to map sub-hypercubes to scopes with caching for variables arranged in a hypercube.
This is implemented as a dict subclass with customized missing, so that: - If a hypercube is already queried, the corresponding scope is retrieved the dict; - If it's not in the dict yet, the scope is calculated and cached to the dict.
Source code in cirkit/templates/region_graph/algorithms/utils.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
hypercube = np.arange(math.prod(shape), dtype=np.int64).reshape(shape)
instance-attribute
¤
ndims = len(shape)
instance-attribute
¤
shape = tuple(shape)
instance-attribute
¤
__init__(shape)
¤
Init class.
Note that this does not accept initial elements and is initialized empty.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
Sequence[int]
|
The shape of the whole hypercube. |
required |
Source code in cirkit/templates/region_graph/algorithms/utils.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |
__missing__(key)
¤
Construct the item when not exist in the dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
HyperCube
|
The key that is missing from the dict, i.e., a hypercube that is visited for the first time. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Scope |
Scope
|
The value for the key, i.e., the corresponding scope. |
Source code in cirkit/templates/region_graph/algorithms/utils.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
tree2rg(tree)
¤
Convert a tree structure into a region graph. Useful to convert CLTs into HCLT region graphs. More details in https://arxiv.org/abs/2409.07953.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tree
|
ndarray
|
A tree in form of list of predecessors, i.e. tree[i] is the parent of i, and is equal to -1 when i is root. |
required |
Returns:
| Type | Description |
|---|---|
RegionGraph
|
A region graph. |
Source code in cirkit/templates/region_graph/algorithms/utils.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |