utils
JAX Utils
clear_default_sharding()
Disable default sharding (return to single-device behaviour).
Source code in jaxquantum/utils/utils.py
148 149 150 151 | |
comb(N, k)
NCk
TODO: replace with jsp.special.comb once issue is closed:
https://github.com/google/jax/issues/9709
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
N
|
total items |
required | |
k
|
of items to choose |
required |
Returns:
| Name | Type | Description |
|---|---|---|
NCk |
N choose k |
Source code in jaxquantum/utils/utils.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
get_default_sharding()
Return the configured default sharding, or None if unset.
Source code in jaxquantum/utils/utils.py
142 143 144 145 | |
set_default_sharding(sharding)
Configure the global default Sharding applied to every Qarray.
Once set, every DenseImpl and SparseDiaImpl construction routes
its underlying jnp.ndarray through jax.lax.with_sharding_constraint
using sharding. SparseBCOOImpl is unsupported under sharding and
will raise from Qarray.create(..., implementation=SPARSE_BCOO).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sharding
|
Either a |
required |
Source code in jaxquantum/utils/utils.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
set_device_mesh(shape, axis_names, partition_spec=None, devices=None)
Configure default sharding from a high-level mesh description.
Convenience wrapper around :func:set_default_sharding that builds a
Mesh and NamedSharding for you. Mirrors the pattern used in
experiments/distributed/1-demo.ipynb.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
Tuple of mesh dimensions, e.g. |
required | |
axis_names
|
Tuple of mesh axis names, same length as shape, e.g.
|
required | |
partition_spec
|
Optional
Each mesh axis is greedy-bound to the first un-claimed array axis (in priority order) whose size is divisible by the mesh axis size. Mesh axes that find no binding are unused (the array replicates along them). This produces e.g.
|
None
|
|
devices
|
Optional explicit list of devices. Defaults to
|
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
Source code in jaxquantum/utils/utils.py
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 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
set_precision(precision)
Set the precision of JAX operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
precision
|
Literal['single', 'double']
|
'single' or 'double' |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
if precision is not 'single' or 'double' |
Source code in jaxquantum/utils/utils.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |