scope
scope
¤
Scope
¤
Bases: Collection[int], Hashable
An immutable container for a set of int to represent the scope of a node in the region graph or a layer in the circuit. Currently, it is implemented on top of a Python frozenset of integers.
Source code in cirkit/utils/scope.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 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 70 71 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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
__and__(other)
¤
Get the intersection of two scopes, for & operator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Scope
|
The other scope to take intersection with. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Scope |
Scope
|
The intersection. |
Source code in cirkit/utils/scope.py
131 132 133 134 135 136 137 138 139 140 | |
__contains__(var)
¤
Test whether a variable is in the scope, for in and not in operators.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
var
|
object
|
The variable non-negative ID to test. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
Whether the variable is in this scope. |
Source code in cirkit/utils/scope.py
31 32 33 34 35 36 37 38 39 40 41 42 | |
__eq__(other)
¤
Test equality between scopes, for == and != operators.
Two scopes are equal when they contain the same set of variables, with hash also the same.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
object
|
The other scope to compare with. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
Whether self == other. |
Source code in cirkit/utils/scope.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
__ge__(other)
¤
Test whether self is a superset (or equal) of other.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Scope
|
The other scope to test. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
Whether self ⊇ other. |
Source code in cirkit/utils/scope.py
120 121 122 123 124 125 126 127 128 129 | |
__gt__(other)
¤
Test whether self is a superset (strictly) of other.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Scope
|
The other scope to test. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
Whether self ⊇ other. |
Source code in cirkit/utils/scope.py
96 97 98 99 100 101 102 103 104 105 | |
__hash__()
¤
Get the hash value of the scope, for use as dict/set keys.
The same scope (same set of variables) always has the same hash value.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The hash value. |
Source code in cirkit/utils/scope.py
60 61 62 63 64 65 66 67 68 | |
__init__(scope=None)
¤
Initializes a scope object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scope
|
Iterable[int] | None
|
The scope as an iterable of variable non-negative integer IDs. It can be None as to construct an empty scope. |
None
|
Source code in cirkit/utils/scope.py
10 11 12 13 14 15 16 17 | |
__iter__()
¤
Iterate over the scope variables in the order of id, for conversion to other containers.
Returns:
| Type | Description |
|---|---|
Iterator[int]
|
Iterator[int]: The iterator over the scope, that is sorted. |
Source code in cirkit/utils/scope.py
44 45 46 47 48 49 50 | |
__le__(other)
¤
Test whether self is a subset (or equal) of other.
It is guaranteed that (a == b) <=> (a <= b and a >= b).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Scope
|
The other scope to test. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
Whether self ⊆ other. |
Source code in cirkit/utils/scope.py
107 108 109 110 111 112 113 114 115 116 117 118 | |
__len__()
¤
Get the length, i.e., the number of variables) of the scope.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The number of variables in the scope. |
Source code in cirkit/utils/scope.py
52 53 54 55 56 57 58 | |
__lt__(other)
¤
Test whether self is a subset (strictly) of other.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Scope
|
The other scope to test. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
Whether self ⊆ other. |
Source code in cirkit/utils/scope.py
85 86 87 88 89 90 91 92 93 94 | |
__or__(other)
¤
Get the union of two scopes, for | operator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Scope
|
The other scope to take union with. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Scope |
Scope
|
The union. |
Source code in cirkit/utils/scope.py
142 143 144 145 146 147 148 149 150 151 | |
__repr__()
¤
Generate the repr string of the scope, for repr().
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The str representation of the scope. |
Source code in cirkit/utils/scope.py
19 20 21 22 23 24 25 | |
__sub__(other)
¤
Take the difference w.r.t. another scope, i.e., the scope containing the variables that are not in the other scope.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Scope
|
The other scope to take the difference with. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Scope |
Scope
|
The difference between scopes. |
Source code in cirkit/utils/scope.py
182 183 184 185 186 187 188 189 190 191 192 | |
difference(other)
¤
Take the difference w.r.t. another scope, i.e., the scope containing the variables that are not in the other scope.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Scope
|
The other scope to take the difference with. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Scope |
Scope
|
The difference between scopes. |
Source code in cirkit/utils/scope.py
170 171 172 173 174 175 176 177 178 179 180 | |
union(*scopes)
¤
Take the union over multiple scopes, for use as reduction with n-ary | operator.
Can be used as either self.union(...) or Scope.union(...).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*scopes
|
Scope
|
The other scope to take union with. |
()
|
Returns:
| Name | Type | Description |
|---|---|---|
Scope |
Scope
|
The union. |
Source code in cirkit/utils/scope.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |