quantax 0.1.1__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 (58) hide show
  1. docs/source/conf.py +39 -0
  2. quantax/__init__.py +22 -0
  3. quantax/global_defs.py +131 -0
  4. quantax/model/__init__.py +11 -0
  5. quantax/model/fermion_mf.py +588 -0
  6. quantax/model/neural_fermion.py +615 -0
  7. quantax/model/prod_nets.py +328 -0
  8. quantax/model/sign_nets.py +146 -0
  9. quantax/model/sum_nets.py +325 -0
  10. quantax/model/transformer.py +258 -0
  11. quantax/model/triangular_nets.py +200 -0
  12. quantax/nn/__init__.py +39 -0
  13. quantax/nn/activation.py +204 -0
  14. quantax/nn/initializers.py +110 -0
  15. quantax/nn/modules.py +212 -0
  16. quantax/nn/nqs_layers.py +201 -0
  17. quantax/operator/__init__.py +23 -0
  18. quantax/operator/common_operators.py +190 -0
  19. quantax/operator/operator.py +538 -0
  20. quantax/operator/site_operator.py +299 -0
  21. quantax/optimizer/__init__.py +18 -0
  22. quantax/optimizer/driver.py +98 -0
  23. quantax/optimizer/exact.py +41 -0
  24. quantax/optimizer/minsr.py +255 -0
  25. quantax/optimizer/solver.py +242 -0
  26. quantax/optimizer/supervised.py +111 -0
  27. quantax/optimizer/tdvp.py +404 -0
  28. quantax/sampler/__init__.py +10 -0
  29. quantax/sampler/metropolis.py +649 -0
  30. quantax/sampler/sampler.py +154 -0
  31. quantax/sampler/samples.py +97 -0
  32. quantax/sites/__init__.py +13 -0
  33. quantax/sites/cluster.py +70 -0
  34. quantax/sites/common_lattices.py +138 -0
  35. quantax/sites/lattice.py +221 -0
  36. quantax/sites/sites.py +324 -0
  37. quantax/state/__init__.py +4 -0
  38. quantax/state/fermion_mf.py +437 -0
  39. quantax/state/lanczos.py +52 -0
  40. quantax/state/state.py +275 -0
  41. quantax/state/variational.py +570 -0
  42. quantax/symmetry/__init__.py +17 -0
  43. quantax/symmetry/common_symmetries.py +321 -0
  44. quantax/symmetry/symmetry.py +422 -0
  45. quantax/utils/__init__.py +29 -0
  46. quantax/utils/array.py +161 -0
  47. quantax/utils/data.py +145 -0
  48. quantax/utils/function.py +213 -0
  49. quantax/utils/linalg.py +354 -0
  50. quantax/utils/measure.py +28 -0
  51. quantax/utils/sharding.py +22 -0
  52. quantax/utils/spins.py +182 -0
  53. quantax/utils/tree.py +105 -0
  54. quantax-0.1.1.dist-info/METADATA +15 -0
  55. quantax-0.1.1.dist-info/RECORD +58 -0
  56. quantax-0.1.1.dist-info/WHEEL +5 -0
  57. quantax-0.1.1.dist-info/licenses/LICENSE +21 -0
  58. quantax-0.1.1.dist-info/top_level.txt +2 -0
docs/source/conf.py ADDED
@@ -0,0 +1,39 @@
1
+ # Configuration file for the Sphinx documentation builder.
2
+ #
3
+ # For the full list of built-in configuration values, see the documentation:
4
+ # https://www.sphinx-doc.org/en/master/usage/configuration.html
5
+
6
+ import pathlib
7
+ import sys
8
+
9
+ sys.path.insert(0, pathlib.Path(__file__).parents[2].resolve().as_posix())
10
+
11
+ # -- Project information -----------------------------------------------------
12
+ # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
13
+
14
+ project = "Quantax"
15
+ copyright = "2024, Ao Chen"
16
+ author = "Ao Chen, Christopher Roth"
17
+ release = "0.1.1"
18
+
19
+ # -- General configuration ---------------------------------------------------
20
+ # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
21
+
22
+ extensions = ["sphinx.ext.autodoc", "sphinx.ext.autosummary"]
23
+
24
+ templates_path = ["_templates"]
25
+ exclude_patterns = []
26
+
27
+ autodoc_member_order = "bysource"
28
+ autosummary_generate = True
29
+ autosummary_generate_overwrite = False
30
+ default_role = "py:obj"
31
+
32
+
33
+ # -- Options for HTML output -------------------------------------------------
34
+ # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
35
+
36
+ html_theme = "pydata_sphinx_theme"
37
+ #html_static_path = ["_static"]
38
+ html_use_relative_urls = True
39
+ html_baseurl = 'https://chenao-phys.github.io/quantax/'
quantax/__init__.py ADDED
@@ -0,0 +1,22 @@
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
+ PARTICLE_TYPE,
8
+ get_sites,
9
+ get_lattice,
10
+ )
11
+
12
+ from . import (
13
+ sites,
14
+ symmetry,
15
+ operator,
16
+ nn,
17
+ model,
18
+ state,
19
+ sampler,
20
+ optimizer,
21
+ utils,
22
+ )
quantax/global_defs.py ADDED
@@ -0,0 +1,131 @@
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
+ import equinox as eqx
7
+
8
+
9
+ jax.config.update("jax_enable_x64", True)
10
+ jax.config.update("jax_default_matmul_precision", "float32")
11
+
12
+
13
+ DTYPE = jnp.float64
14
+
15
+
16
+ def set_default_dtype(dtype: jnp.dtype) -> None:
17
+ """
18
+ Set the default data type for the computation in quantax.
19
+ Recommended to be ``jnp.float64`` or ``jnp.complex128``. Default to ``jnp.float64``.
20
+
21
+ .. note::
22
+ This doesn't alter the computation inside `quantax.model`.
23
+ """
24
+ if not (
25
+ jnp.issubdtype(dtype, jnp.floating)
26
+ or jnp.issubdtype(dtype, jnp.complexfloating)
27
+ ):
28
+ raise ValueError("'dtype' should be float or complex types")
29
+ global DTYPE
30
+ DTYPE = dtype
31
+
32
+
33
+ def get_default_dtype() -> jnp.dtype:
34
+ """Return the default data type for the computation in quantax."""
35
+ return DTYPE
36
+
37
+
38
+ def get_real_dtype() -> jnp.dtype:
39
+ """Return the default real data type for the computation in quantax."""
40
+ return jnp.finfo(DTYPE).dtype
41
+
42
+
43
+ def is_default_cpl() -> bool:
44
+ """Return whether the default data type is complex."""
45
+ return jnp.issubdtype(DTYPE, jnp.complexfloating)
46
+
47
+
48
+ KEY = None
49
+
50
+
51
+ def set_random_seed(seed: int) -> None:
52
+ """
53
+ Set the initial random seed for the computation in jax.
54
+ Default to be a random number generated by numpy.
55
+ """
56
+ global KEY
57
+ KEY = jr.key(seed)
58
+
59
+
60
+ @partial(jax.jit, static_argnums=1)
61
+ def _gen_keys(key, num: Optional[int] = None) -> Tuple[jax.Array, jax.Array]:
62
+ nkeys = 2 if num is None else num + 1
63
+ new_keys = jr.split(key, nkeys)
64
+ key = new_keys[0]
65
+ new_keys = new_keys[1] if num is None else new_keys[1:]
66
+ return key, new_keys
67
+
68
+
69
+ def get_subkeys(num: Optional[int] = None) -> jax.Array:
70
+ """
71
+ Get a certain number of jax PRNG keys as an array.
72
+
73
+ :param num:
74
+ The number of returned keys.
75
+ If ``num is None`` (default), then return only 1 key instead of an array of keys.
76
+
77
+ .. warning::
78
+ This function is not jittable, because it reads and writes the global key
79
+ stored in quantax.
80
+ """
81
+ global KEY
82
+ if KEY is None:
83
+ set_random_seed(0)
84
+ KEY, new_keys = _gen_keys(KEY, num)
85
+ return new_keys
86
+
87
+
88
+ class PARTICLE_TYPE(eqx.Enumeration):
89
+ r"""
90
+ The enums to distinguish different particle types.
91
+
92
+ 0: spin
93
+
94
+ 1: spinful_fermion
95
+
96
+ 2: spinless_fermion
97
+
98
+ (Not implemented) 3: boson
99
+ """
100
+
101
+ spin = 0
102
+ spinful_fermion = 1
103
+ spinless_fermion = 2
104
+
105
+
106
+ from .sites import Sites, Lattice
107
+
108
+
109
+ def get_sites() -> Sites:
110
+ """
111
+ Get the `quantax.sites.Sites` used in the current program.
112
+
113
+ .. warning::
114
+ Unlike other NQS packages, in quantax the geometry graph and the hilbert space
115
+ is defined as a global constant which shouldn't be changed within a single program.
116
+ """
117
+ sites = Sites._SITES
118
+ if sites is None:
119
+ raise RuntimeError("The `Sites` hasn't been defined.")
120
+ return sites
121
+
122
+
123
+ def get_lattice() -> Lattice:
124
+ """
125
+ Get the `quantax.sites.Lattice` used in the current program. This is similar to `get_sites`,
126
+ but will raise an error if the defined `Sites` is not a `Lattice`.
127
+ """
128
+ sites = get_sites()
129
+ if not isinstance(sites, Lattice):
130
+ raise RuntimeError("Require a `Lattice`, but got a general `Sites`")
131
+ return sites
@@ -0,0 +1,11 @@
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 Triangular_Neighbor_Conv, Triangular_ResSum
6
+ from .fermion_mf import (
7
+ Determinant,
8
+ Pfaffian,
9
+ PairProduct,
10
+ )
11
+ from .neural_fermion import NeuralJastrow, HiddenPfaffian