quantax 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. quantax/__init__.py +21 -0
  2. quantax/global_defs.py +112 -0
  3. quantax/model/__init__.py +17 -0
  4. quantax/model/fermion_mf.py +588 -0
  5. quantax/model/neural_fermion.py +611 -0
  6. quantax/model/prod_nets.py +328 -0
  7. quantax/model/sign_nets.py +146 -0
  8. quantax/model/sum_nets.py +323 -0
  9. quantax/model/transformer.py +258 -0
  10. quantax/model/triangular_nets.py +198 -0
  11. quantax/nn/__init__.py +32 -0
  12. quantax/nn/activation.py +204 -0
  13. quantax/nn/initializers.py +110 -0
  14. quantax/nn/modules.py +212 -0
  15. quantax/nn/nqs_layers.py +115 -0
  16. quantax/operator/__init__.py +28 -0
  17. quantax/operator/common_operators.py +131 -0
  18. quantax/operator/operator.py +537 -0
  19. quantax/operator/site_operator.py +320 -0
  20. quantax/optimizer/__init__.py +18 -0
  21. quantax/optimizer/driver.py +98 -0
  22. quantax/optimizer/exact.py +41 -0
  23. quantax/optimizer/minsr.py +255 -0
  24. quantax/optimizer/solver.py +242 -0
  25. quantax/optimizer/supervised.py +111 -0
  26. quantax/optimizer/tdvp.py +404 -0
  27. quantax/sampler/__init__.py +10 -0
  28. quantax/sampler/metropolis.py +631 -0
  29. quantax/sampler/sampler.py +154 -0
  30. quantax/sampler/samples.py +97 -0
  31. quantax/sites/__init__.py +13 -0
  32. quantax/sites/cluster.py +69 -0
  33. quantax/sites/common_lattices.py +136 -0
  34. quantax/sites/lattice.py +218 -0
  35. quantax/sites/sites.py +301 -0
  36. quantax/state/__init__.py +4 -0
  37. quantax/state/fermion_mf.py +304 -0
  38. quantax/state/lanczos.py +52 -0
  39. quantax/state/state.py +275 -0
  40. quantax/state/variational.py +570 -0
  41. quantax/symmetry/__init__.py +17 -0
  42. quantax/symmetry/common_symmetries.py +307 -0
  43. quantax/symmetry/symmetry.py +398 -0
  44. quantax/utils/__init__.py +32 -0
  45. quantax/utils/array.py +184 -0
  46. quantax/utils/data.py +112 -0
  47. quantax/utils/function.py +192 -0
  48. quantax/utils/linalg.py +342 -0
  49. quantax/utils/measure.py +28 -0
  50. quantax/utils/sharding.py +14 -0
  51. quantax/utils/spins.py +159 -0
  52. quantax/utils/tree.py +80 -0
  53. quantax-0.1.0.dist-info/METADATA +20 -0
  54. quantax-0.1.0.dist-info/RECORD +57 -0
  55. quantax-0.1.0.dist-info/WHEEL +5 -0
  56. quantax-0.1.0.dist-info/licenses/LICENSE +21 -0
  57. quantax-0.1.0.dist-info/top_level.txt +1 -0
quantax/__init__.py ADDED
@@ -0,0 +1,21 @@
1
+ from .global_defs import (
2
+ set_random_seed,
3
+ set_default_dtype,
4
+ get_default_dtype,
5
+ get_real_dtype,
6
+ get_subkeys,
7
+ get_sites,
8
+ get_lattice,
9
+ )
10
+
11
+ from . import (
12
+ sites,
13
+ symmetry,
14
+ operator,
15
+ nn,
16
+ model,
17
+ state,
18
+ sampler,
19
+ optimizer,
20
+ utils,
21
+ )
quantax/global_defs.py ADDED
@@ -0,0 +1,112 @@
1
+ from typing import Optional, Tuple
2
+ from functools import partial
3
+ import jax
4
+ import jax.numpy as jnp
5
+ import jax.random as jr
6
+
7
+
8
+ jax.config.update("jax_enable_x64", True)
9
+ jax.config.update("jax_default_matmul_precision", "float32")
10
+
11
+
12
+ DTYPE = jnp.float64
13
+
14
+
15
+ def set_default_dtype(dtype: jnp.dtype) -> None:
16
+ """
17
+ Set the default data type for the computation in quantax.
18
+ Recommended to be ``jnp.float64`` or ``jnp.complex128``. Default to ``jnp.float64``.
19
+
20
+ .. note::
21
+ This doesn't alter the computation inside `quantax.model`.
22
+ """
23
+ if not (
24
+ jnp.issubdtype(dtype, jnp.floating)
25
+ or jnp.issubdtype(dtype, jnp.complexfloating)
26
+ ):
27
+ raise ValueError("'dtype' should be float or complex types")
28
+ global DTYPE
29
+ DTYPE = dtype
30
+
31
+
32
+ def get_default_dtype() -> jnp.dtype:
33
+ """Return the default data type for the computation in quantax."""
34
+ return DTYPE
35
+
36
+
37
+ def get_real_dtype() -> jnp.dtype:
38
+ """Return the default real data type for the computation in quantax."""
39
+ return jnp.finfo(DTYPE).dtype
40
+
41
+
42
+ def is_default_cpl() -> bool:
43
+ """Return whether the default data type is complex."""
44
+ return jnp.issubdtype(DTYPE, jnp.complexfloating)
45
+
46
+
47
+ KEY = None
48
+
49
+
50
+ def set_random_seed(seed: int) -> None:
51
+ """
52
+ Set the initial random seed for the computation in jax.
53
+ Default to be a random number generated by numpy.
54
+ """
55
+ global KEY
56
+ KEY = jr.key(seed)
57
+
58
+
59
+ @partial(jax.jit, static_argnums=1)
60
+ def _gen_keys(key, num: Optional[int] = None) -> Tuple[jax.Array, jax.Array]:
61
+ nkeys = 2 if num is None else num + 1
62
+ new_keys = jr.split(key, nkeys)
63
+ key = new_keys[0]
64
+ new_keys = new_keys[1] if num is None else new_keys[1:]
65
+ return key, new_keys
66
+
67
+
68
+ def get_subkeys(num: Optional[int] = None) -> jax.Array:
69
+ """
70
+ Get a certain number of jax PRNG keys as an array.
71
+
72
+ :param num:
73
+ The number of returned keys.
74
+ If ``num is None`` (default), then return only 1 key instead of an array of keys.
75
+
76
+ .. warning::
77
+ This function is not jittable, because it reads and writes the global key
78
+ stored in quantax.
79
+ """
80
+ global KEY
81
+ if KEY is None:
82
+ set_random_seed(0)
83
+ KEY, new_keys = _gen_keys(KEY, num)
84
+ return new_keys
85
+
86
+
87
+ from .sites import Sites, Lattice
88
+
89
+
90
+ def get_sites() -> Sites:
91
+ """
92
+ Get the `quantax.sites.Sites` used in the current program.
93
+
94
+ .. warning::
95
+ Unlike other NQS packages, in quantax the geometry graph and the hilbert space
96
+ is defined as a global constant which shouldn't be changed within a single program.
97
+ """
98
+ sites = Sites._SITES
99
+ if sites is None:
100
+ raise RuntimeError("The `Sites` hasn't been defined.")
101
+ return sites
102
+
103
+
104
+ def get_lattice() -> Lattice:
105
+ """
106
+ Get the `quantax.sites.Lattice` used in the current program. This is similar to `get_sites`,
107
+ but will raise an error if the defined `Sites` is not a `Lattice`.
108
+ """
109
+ sites = get_sites()
110
+ if not isinstance(sites, Lattice):
111
+ raise RuntimeError("Require a `Lattice`, but got a general `Sites`")
112
+ return sites
@@ -0,0 +1,17 @@
1
+ from .prod_nets import SingleDense, RBM_Dense, SingleConv, RBM_Conv, ResProd, SchmittNet
2
+ from .sum_nets import ResSum, ResSumGconv
3
+ from .transformer import ConvTransformer
4
+ from .sign_nets import SgnNet, MarshallSign, StripeSign, Neel120
5
+ from .triangular_nets import (
6
+ Reshape_TriangularB,
7
+ ReshapeTo_TriangularB,
8
+ Triangular_Neighbor_Conv,
9
+ Triangular_ResSum,
10
+ )
11
+ from .fermion_mf import (
12
+ Determinant,
13
+ Pfaffian,
14
+ PairProduct,
15
+ )
16
+
17
+ from .neural_fermion import NeuralJastrow, HiddenPfaffian