utils
Utils
Ec_to_inv_pF(Ec)
GHz -> 1/picoFarad
Source code in jaxquantum/utils/units.py
81 82 83 84 85 86 87 88 | |
as_series(*arrs)
Return arguments as a list of 1-d arrays.
The returned list contains array(s) of dtype double, complex double, or
object. A 1-d argument of shape (N,) is parsed into N arrays of
size one; a 2-d argument of shape (M,N) is parsed into M arrays
of size N (i.e., is "parsed by row"); and a higher dimensional array
raises a Value Error if it is not first reshaped into either a 1-d or 2-d
array.
Parameters
arrs : array_like 1- or 2-d array_like trim : boolean, optional When True, trailing zeros are removed from the inputs. When False, the inputs are passed through intact.
Returns
a1, a2,... : 1-D arrays A copy of the input data as 1-d arrays.
Source code in jaxquantum/utils/hermgauss.py
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 | |
benchmark_jax_function(function, *args, iterations=25, warmup=1, clear_caches=True, include_hlo=False, compare_precision=False, jit_kwargs=None, call_kwargs=None)
Collect synchronized JAX timing, memory, HLO, cost, and precision stats.
Source code in jaxquantum/utils/benchmarking.py
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 | |
benchmark_precision(function, *args, iterations=25, warmup=1, clear_caches=True, include_hlo=False, jit_kwargs=None, call_kwargs=None)
Compare double and single precision performance and output accuracy.
Source code in jaxquantum/utils/benchmarking.py
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | |
block_until_ready(tree)
Synchronize every array leaf in a PyTree.
Source code in jaxquantum/utils/benchmarking.py
28 29 30 31 32 | |
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 | |
hermcompanion(c)
Return the scaled companion matrix of c.
The basis polynomials are scaled so that the companion matrix is
symmetric when c is an Hermite basis polynomial. This provides
better eigenvalue estimates than the unscaled case and for basis
polynomials the eigenvalues are guaranteed to be real if
jax.numpy.linalg.eigvalsh is used to obtain them.
Parameters
c : array_like 1-D array of Hermite series coefficients ordered from low to high degree.
Returns
mat : ndarray Scaled companion matrix of dimensions (deg, deg).
Source code in jaxquantum/utils/hermgauss.py
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 | |
inductance_to_inductive_energy(L)
Convert inductance to inductive energy E_L.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
L
|
float
|
Inductance in nH. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
Inductive energy in GHz. |
Source code in jaxquantum/utils/units.py
57 58 59 60 61 62 63 64 65 66 67 68 69 | |
inductive_energy_to_inductance(El)
Convert inductive energy E_L to inductance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
El
|
float
|
inductive energy in GHz. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
Inductance in nH. |
Source code in jaxquantum/utils/units.py
44 45 46 47 48 49 50 51 52 53 54 55 | |
inv_pF_to_Ec(inv_pfarad)
1/picoFarad -> GHz
Source code in jaxquantum/utils/units.py
72 73 74 75 76 77 78 | |
jax_device_memory_stats()
Return allocator statistics reported by each JAX device.
Source code in jaxquantum/utils/benchmarking.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
jax_hlo(function, *args, jit_kwargs=None, call_kwargs=None)
Return lowered StableHLO text for a function call.
Source code in jaxquantum/utils/benchmarking.py
73 74 75 76 77 78 79 80 81 82 83 84 85 | |
jax_memory_stats(compiled)
Return XLA's compiled buffer-size estimates.
Source code in jaxquantum/utils/benchmarking.py
48 49 50 51 52 53 | |
lower_jax_function(function, *args, jit_kwargs=None, call_kwargs=None)
Lower a function with the supplied JIT and call arguments.
Source code in jaxquantum/utils/benchmarking.py
35 36 37 38 39 40 41 42 43 44 45 | |
n_thermal(frequency, temperature)
Calculate the average thermal photon number for a given frequency and temperature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frequency
|
float
|
Frequency in GHz. |
required |
temperature
|
float
|
Temperature in Kelvin. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Average thermal photon number. |
Source code in jaxquantum/utils/units.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | |
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 | |