Trajectree 0.0.0__py3-none-any.whl → 0.0.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.
- trajectree/__init__.py +3 -0
- trajectree/fock_optics/devices.py +1 -1
- trajectree/fock_optics/light_sources.py +2 -2
- trajectree/fock_optics/measurement.py +3 -3
- trajectree/fock_optics/utils.py +6 -6
- trajectree/quimb/docs/_pygments/_pygments_dark.py +118 -0
- trajectree/quimb/docs/_pygments/_pygments_light.py +118 -0
- trajectree/quimb/docs/conf.py +158 -0
- trajectree/quimb/docs/examples/ex_mpi_expm_evo.py +62 -0
- trajectree/quimb/quimb/__init__.py +507 -0
- trajectree/quimb/quimb/calc.py +1491 -0
- trajectree/quimb/quimb/core.py +2279 -0
- trajectree/quimb/quimb/evo.py +712 -0
- trajectree/quimb/quimb/experimental/__init__.py +0 -0
- trajectree/quimb/quimb/experimental/autojittn.py +129 -0
- trajectree/quimb/quimb/experimental/belief_propagation/__init__.py +109 -0
- trajectree/quimb/quimb/experimental/belief_propagation/bp_common.py +397 -0
- trajectree/quimb/quimb/experimental/belief_propagation/d1bp.py +316 -0
- trajectree/quimb/quimb/experimental/belief_propagation/d2bp.py +653 -0
- trajectree/quimb/quimb/experimental/belief_propagation/hd1bp.py +571 -0
- trajectree/quimb/quimb/experimental/belief_propagation/hv1bp.py +775 -0
- trajectree/quimb/quimb/experimental/belief_propagation/l1bp.py +316 -0
- trajectree/quimb/quimb/experimental/belief_propagation/l2bp.py +537 -0
- trajectree/quimb/quimb/experimental/belief_propagation/regions.py +194 -0
- trajectree/quimb/quimb/experimental/cluster_update.py +286 -0
- trajectree/quimb/quimb/experimental/merabuilder.py +865 -0
- trajectree/quimb/quimb/experimental/operatorbuilder/__init__.py +15 -0
- trajectree/quimb/quimb/experimental/operatorbuilder/operatorbuilder.py +1631 -0
- trajectree/quimb/quimb/experimental/schematic.py +7 -0
- trajectree/quimb/quimb/experimental/tn_marginals.py +130 -0
- trajectree/quimb/quimb/experimental/tnvmc.py +1483 -0
- trajectree/quimb/quimb/gates.py +36 -0
- trajectree/quimb/quimb/gen/__init__.py +2 -0
- trajectree/quimb/quimb/gen/operators.py +1167 -0
- trajectree/quimb/quimb/gen/rand.py +713 -0
- trajectree/quimb/quimb/gen/states.py +479 -0
- trajectree/quimb/quimb/linalg/__init__.py +6 -0
- trajectree/quimb/quimb/linalg/approx_spectral.py +1109 -0
- trajectree/quimb/quimb/linalg/autoblock.py +258 -0
- trajectree/quimb/quimb/linalg/base_linalg.py +719 -0
- trajectree/quimb/quimb/linalg/mpi_launcher.py +397 -0
- trajectree/quimb/quimb/linalg/numpy_linalg.py +244 -0
- trajectree/quimb/quimb/linalg/rand_linalg.py +514 -0
- trajectree/quimb/quimb/linalg/scipy_linalg.py +293 -0
- trajectree/quimb/quimb/linalg/slepc_linalg.py +892 -0
- trajectree/quimb/quimb/schematic.py +1518 -0
- trajectree/quimb/quimb/tensor/__init__.py +401 -0
- trajectree/quimb/quimb/tensor/array_ops.py +610 -0
- trajectree/quimb/quimb/tensor/circuit.py +4824 -0
- trajectree/quimb/quimb/tensor/circuit_gen.py +411 -0
- trajectree/quimb/quimb/tensor/contraction.py +336 -0
- trajectree/quimb/quimb/tensor/decomp.py +1255 -0
- trajectree/quimb/quimb/tensor/drawing.py +1646 -0
- trajectree/quimb/quimb/tensor/fitting.py +385 -0
- trajectree/quimb/quimb/tensor/geometry.py +583 -0
- trajectree/quimb/quimb/tensor/interface.py +114 -0
- trajectree/quimb/quimb/tensor/networking.py +1058 -0
- trajectree/quimb/quimb/tensor/optimize.py +1818 -0
- trajectree/quimb/quimb/tensor/tensor_1d.py +4778 -0
- trajectree/quimb/quimb/tensor/tensor_1d_compress.py +1854 -0
- trajectree/quimb/quimb/tensor/tensor_1d_tebd.py +662 -0
- trajectree/quimb/quimb/tensor/tensor_2d.py +5954 -0
- trajectree/quimb/quimb/tensor/tensor_2d_compress.py +96 -0
- trajectree/quimb/quimb/tensor/tensor_2d_tebd.py +1230 -0
- trajectree/quimb/quimb/tensor/tensor_3d.py +2869 -0
- trajectree/quimb/quimb/tensor/tensor_3d_tebd.py +46 -0
- trajectree/quimb/quimb/tensor/tensor_approx_spectral.py +60 -0
- trajectree/quimb/quimb/tensor/tensor_arbgeom.py +3237 -0
- trajectree/quimb/quimb/tensor/tensor_arbgeom_compress.py +565 -0
- trajectree/quimb/quimb/tensor/tensor_arbgeom_tebd.py +1138 -0
- trajectree/quimb/quimb/tensor/tensor_builder.py +5411 -0
- trajectree/quimb/quimb/tensor/tensor_core.py +11179 -0
- trajectree/quimb/quimb/tensor/tensor_dmrg.py +1472 -0
- trajectree/quimb/quimb/tensor/tensor_mera.py +204 -0
- trajectree/quimb/quimb/utils.py +892 -0
- trajectree/quimb/tests/__init__.py +0 -0
- trajectree/quimb/tests/test_accel.py +501 -0
- trajectree/quimb/tests/test_calc.py +788 -0
- trajectree/quimb/tests/test_core.py +847 -0
- trajectree/quimb/tests/test_evo.py +565 -0
- trajectree/quimb/tests/test_gen/__init__.py +0 -0
- trajectree/quimb/tests/test_gen/test_operators.py +361 -0
- trajectree/quimb/tests/test_gen/test_rand.py +296 -0
- trajectree/quimb/tests/test_gen/test_states.py +261 -0
- trajectree/quimb/tests/test_linalg/__init__.py +0 -0
- trajectree/quimb/tests/test_linalg/test_approx_spectral.py +368 -0
- trajectree/quimb/tests/test_linalg/test_base_linalg.py +351 -0
- trajectree/quimb/tests/test_linalg/test_mpi_linalg.py +127 -0
- trajectree/quimb/tests/test_linalg/test_numpy_linalg.py +84 -0
- trajectree/quimb/tests/test_linalg/test_rand_linalg.py +134 -0
- trajectree/quimb/tests/test_linalg/test_slepc_linalg.py +283 -0
- trajectree/quimb/tests/test_tensor/__init__.py +0 -0
- trajectree/quimb/tests/test_tensor/test_belief_propagation/__init__.py +0 -0
- trajectree/quimb/tests/test_tensor/test_belief_propagation/test_d1bp.py +39 -0
- trajectree/quimb/tests/test_tensor/test_belief_propagation/test_d2bp.py +67 -0
- trajectree/quimb/tests/test_tensor/test_belief_propagation/test_hd1bp.py +64 -0
- trajectree/quimb/tests/test_tensor/test_belief_propagation/test_hv1bp.py +51 -0
- trajectree/quimb/tests/test_tensor/test_belief_propagation/test_l1bp.py +142 -0
- trajectree/quimb/tests/test_tensor/test_belief_propagation/test_l2bp.py +101 -0
- trajectree/quimb/tests/test_tensor/test_circuit.py +816 -0
- trajectree/quimb/tests/test_tensor/test_contract.py +67 -0
- trajectree/quimb/tests/test_tensor/test_decomp.py +40 -0
- trajectree/quimb/tests/test_tensor/test_mera.py +52 -0
- trajectree/quimb/tests/test_tensor/test_optimizers.py +488 -0
- trajectree/quimb/tests/test_tensor/test_tensor_1d.py +1171 -0
- trajectree/quimb/tests/test_tensor/test_tensor_2d.py +606 -0
- trajectree/quimb/tests/test_tensor/test_tensor_2d_tebd.py +144 -0
- trajectree/quimb/tests/test_tensor/test_tensor_3d.py +123 -0
- trajectree/quimb/tests/test_tensor/test_tensor_arbgeom.py +226 -0
- trajectree/quimb/tests/test_tensor/test_tensor_builder.py +441 -0
- trajectree/quimb/tests/test_tensor/test_tensor_core.py +2066 -0
- trajectree/quimb/tests/test_tensor/test_tensor_dmrg.py +388 -0
- trajectree/quimb/tests/test_tensor/test_tensor_spectral_approx.py +63 -0
- trajectree/quimb/tests/test_tensor/test_tensor_tebd.py +270 -0
- trajectree/quimb/tests/test_utils.py +85 -0
- trajectree/trajectory.py +2 -2
- {trajectree-0.0.0.dist-info → trajectree-0.0.1.dist-info}/METADATA +2 -2
- trajectree-0.0.1.dist-info/RECORD +126 -0
- trajectree-0.0.0.dist-info/RECORD +0 -16
- {trajectree-0.0.0.dist-info → trajectree-0.0.1.dist-info}/WHEEL +0 -0
- {trajectree-0.0.0.dist-info → trajectree-0.0.1.dist-info}/licenses/LICENSE +0 -0
- {trajectree-0.0.0.dist-info → trajectree-0.0.1.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import pytest
|
|
3
|
+
from numpy.testing import assert_allclose
|
|
4
|
+
|
|
5
|
+
import quimb as qu
|
|
6
|
+
import quimb.tensor as qtn
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class TestGeometries:
|
|
10
|
+
@pytest.mark.parametrize("cyclic", [False, True])
|
|
11
|
+
@pytest.mark.parametrize(
|
|
12
|
+
"edge_fn,shape,percell,coordination",
|
|
13
|
+
[
|
|
14
|
+
(qtn.edges_2d_square, (3, 3), 1, 4),
|
|
15
|
+
(qtn.edges_2d_hexagonal, (3, 3), 2, 3),
|
|
16
|
+
(qtn.edges_2d_kagome, (3, 3), 3, 4),
|
|
17
|
+
(qtn.edges_2d_triangular, (3, 3), 1, 6),
|
|
18
|
+
(qtn.edges_2d_triangular_rectangular, (3, 3), 2, 6),
|
|
19
|
+
(qtn.edges_3d_cubic, (3, 3, 3), 1, 6),
|
|
20
|
+
(qtn.edges_3d_pyrochlore, (3, 3, 3), 4, 6),
|
|
21
|
+
(qtn.edges_3d_diamond, (3, 3, 3), 2, 4),
|
|
22
|
+
(qtn.edges_3d_diamond_cubic, (2, 2, 2), 8, 4),
|
|
23
|
+
],
|
|
24
|
+
)
|
|
25
|
+
def test_basic(self, cyclic, edge_fn, shape, percell, coordination):
|
|
26
|
+
edges = edge_fn(*shape, cyclic=cyclic)
|
|
27
|
+
tn = qtn.TN_rand_from_edges(edges, D=2)
|
|
28
|
+
assert tn.num_tensors == qu.prod(shape) * percell
|
|
29
|
+
assert max(t.ndim for t in tn) == coordination
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class TestSpinHam1D:
|
|
33
|
+
@pytest.mark.parametrize("cyclic", [False, True])
|
|
34
|
+
def test_var_terms(self, cyclic):
|
|
35
|
+
n = 8
|
|
36
|
+
Hd = qu.ham_mbl(n, dh=0.77, seed=42, cyclic=cyclic)
|
|
37
|
+
Ht = qtn.MPO_ham_mbl(n, dh=0.77, seed=42, cyclic=cyclic).to_dense()
|
|
38
|
+
assert_allclose(Hd, Ht)
|
|
39
|
+
|
|
40
|
+
@pytest.mark.parametrize("var_two", ["none", "some", "only"])
|
|
41
|
+
@pytest.mark.parametrize(
|
|
42
|
+
"var_one", ["some", "only", "only-some", "def-only", "none"]
|
|
43
|
+
)
|
|
44
|
+
def test_specials(self, var_one, var_two):
|
|
45
|
+
K1 = qu.rand_herm(2**1)
|
|
46
|
+
|
|
47
|
+
n = 10
|
|
48
|
+
HB = qtn.SpinHam1D(S=1 / 2)
|
|
49
|
+
|
|
50
|
+
if var_two == "some":
|
|
51
|
+
HB += 1, K1, K1
|
|
52
|
+
HB[4, 5] += 1, K1, K1
|
|
53
|
+
HB[7, 8] += 1, K1, K1
|
|
54
|
+
elif var_two == "only":
|
|
55
|
+
for i in range(n - 1):
|
|
56
|
+
HB[i, i + 1] += 1, K1, K1
|
|
57
|
+
else:
|
|
58
|
+
HB += 1, K1, K1
|
|
59
|
+
|
|
60
|
+
if var_one == "some":
|
|
61
|
+
HB += 1, K1
|
|
62
|
+
HB[2] += 1, K1
|
|
63
|
+
HB[3] += 1, K1
|
|
64
|
+
elif var_one == "only":
|
|
65
|
+
for i in range(n - 1):
|
|
66
|
+
HB[i] += 1, K1
|
|
67
|
+
elif var_one == "only-some":
|
|
68
|
+
HB[1] += 1, K1
|
|
69
|
+
elif var_one == "def-only":
|
|
70
|
+
HB += 1, K1
|
|
71
|
+
|
|
72
|
+
HB.build_local_ham(n)
|
|
73
|
+
H_mpo = HB.build_mpo(n)
|
|
74
|
+
H_sps = HB.build_sparse(n)
|
|
75
|
+
|
|
76
|
+
assert_allclose(H_mpo.to_dense(), H_sps.toarray())
|
|
77
|
+
|
|
78
|
+
def test_no_default_term(self):
|
|
79
|
+
N = 10
|
|
80
|
+
builder = qtn.SpinHam1D(1 / 2)
|
|
81
|
+
|
|
82
|
+
for i in range(N - 1):
|
|
83
|
+
builder[i, i + 1] += 1.0, "Z", "Z"
|
|
84
|
+
|
|
85
|
+
H = builder.build_mpo(N)
|
|
86
|
+
|
|
87
|
+
dmrg = qtn.DMRG2(H)
|
|
88
|
+
dmrg.solve(verbosity=1)
|
|
89
|
+
|
|
90
|
+
assert dmrg.energy == pytest.approx(-2.25)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class TestMPSSpecificStates:
|
|
94
|
+
def test_site_varying_phys_dim(self):
|
|
95
|
+
k = qtn.MPS_rand_state(5, 4, phys_dim=[2, 3, 3, 2, 5])
|
|
96
|
+
assert k.H @ k == pytest.approx(1.0)
|
|
97
|
+
assert k.outer_dims_inds() == (
|
|
98
|
+
(2, "k0"),
|
|
99
|
+
(3, "k1"),
|
|
100
|
+
(3, "k2"),
|
|
101
|
+
(2, "k3"),
|
|
102
|
+
(5, "k4"),
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
@pytest.mark.parametrize("dtype", ["float32", "complex64"])
|
|
106
|
+
def test_ghz_state(self, dtype):
|
|
107
|
+
mps = qtn.MPS_ghz_state(5, dtype=dtype)
|
|
108
|
+
assert mps.dtype == dtype
|
|
109
|
+
psi = qu.ghz_state(5, dtype=dtype)
|
|
110
|
+
assert mps.H @ mps == pytest.approx(1.0)
|
|
111
|
+
assert mps.bond_sizes() == [2, 2, 2, 2]
|
|
112
|
+
assert qu.fidelity(psi, mps.to_dense()) == pytest.approx(1.0)
|
|
113
|
+
|
|
114
|
+
@pytest.mark.parametrize("dtype", ["float32", "complex64"])
|
|
115
|
+
def test_w_state(self, dtype):
|
|
116
|
+
mps = qtn.MPS_w_state(5, dtype=dtype)
|
|
117
|
+
assert mps.dtype == dtype
|
|
118
|
+
psi = qu.w_state(5, dtype=dtype)
|
|
119
|
+
assert mps.H @ mps == pytest.approx(1.0)
|
|
120
|
+
assert mps.bond_sizes() == [2, 2, 2, 2]
|
|
121
|
+
assert qu.fidelity(psi, mps.to_dense()) == pytest.approx(1.0)
|
|
122
|
+
|
|
123
|
+
def test_computational_state(self):
|
|
124
|
+
mps = qtn.MPS_computational_state("01+-")
|
|
125
|
+
assert_allclose(
|
|
126
|
+
mps.to_dense(), qu.up() & qu.down() & qu.plus() & qu.minus()
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
class TestMatrixProductOperatorSpecifics:
|
|
131
|
+
def test_MPO_product_operator(self):
|
|
132
|
+
psis = [qu.rand_ket(2) for _ in range(5)]
|
|
133
|
+
ops = [qu.rand_matrix(2) for _ in range(5)]
|
|
134
|
+
psif = qu.kron(*ops) @ qu.kron(*psis)
|
|
135
|
+
mps = qtn.MPS_product_state(psis)
|
|
136
|
+
mpo = qtn.MPO_product_operator(ops)
|
|
137
|
+
assert mpo.bond_sizes() == [1, 1, 1, 1]
|
|
138
|
+
mpsf = mpo.apply(mps)
|
|
139
|
+
assert_allclose(mpsf.to_dense(), psif)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
class TestGenericTN:
|
|
143
|
+
def test_TN_rand_reg(self):
|
|
144
|
+
n = 6
|
|
145
|
+
reg = 3
|
|
146
|
+
D = 2
|
|
147
|
+
tn = qtn.TN_rand_reg(n, reg, D=D)
|
|
148
|
+
assert tn.outer_inds() == ()
|
|
149
|
+
assert tn.max_bond() == D
|
|
150
|
+
assert {t.ndim for t in tn} == {reg}
|
|
151
|
+
ket = qtn.TN_rand_reg(n, reg, D=2, phys_dim=2)
|
|
152
|
+
assert set(ket.outer_inds()) == {f"k{i}" for i in range(n)}
|
|
153
|
+
assert ket.max_bond() == D
|
|
154
|
+
|
|
155
|
+
@pytest.mark.parametrize("Lx", [3])
|
|
156
|
+
@pytest.mark.parametrize("Ly", [2, 4])
|
|
157
|
+
@pytest.mark.parametrize("beta", [0.13, 0.44])
|
|
158
|
+
@pytest.mark.parametrize("j", [-1.0, +1.0])
|
|
159
|
+
@pytest.mark.parametrize("h", [0.0, 0.1])
|
|
160
|
+
@pytest.mark.parametrize(
|
|
161
|
+
"cyclic", [False, True, (False, True), (True, False)]
|
|
162
|
+
)
|
|
163
|
+
def test_2D_classical_ising_model(self, Lx, Ly, beta, j, h, cyclic):
|
|
164
|
+
tn = qtn.TN2D_classical_ising_partition_function(
|
|
165
|
+
Lx, Ly, beta=beta, j=j, h=h, cyclic=cyclic
|
|
166
|
+
)
|
|
167
|
+
htn = qtn.HTN2D_classical_ising_partition_function(
|
|
168
|
+
Lx, Ly, beta=beta, j=j, h=h, cyclic=cyclic
|
|
169
|
+
)
|
|
170
|
+
Z1 = tn.contract(all, output_inds=())
|
|
171
|
+
Z2 = htn.contract(all, output_inds=())
|
|
172
|
+
assert Z1 == pytest.approx(Z2)
|
|
173
|
+
|
|
174
|
+
if not cyclic:
|
|
175
|
+
# skip cyclic as nx has no multibonds for L=2
|
|
176
|
+
import networkx as nx
|
|
177
|
+
|
|
178
|
+
G = nx.lattice.grid_graph((Lx, Ly))
|
|
179
|
+
Z3 = qtn.TN_classical_partition_function_from_edges(
|
|
180
|
+
G.edges, beta=beta, j=j, h=h
|
|
181
|
+
).contract(all, output_inds=())
|
|
182
|
+
assert Z2 == pytest.approx(Z3)
|
|
183
|
+
Z4 = qtn.HTN_classical_partition_function_from_edges(
|
|
184
|
+
G.edges, beta=beta, j=j, h=h
|
|
185
|
+
).contract(all, output_inds=())
|
|
186
|
+
assert Z3 == pytest.approx(Z4)
|
|
187
|
+
|
|
188
|
+
@pytest.mark.parametrize("Lx", [2])
|
|
189
|
+
@pytest.mark.parametrize("Ly", [3])
|
|
190
|
+
@pytest.mark.parametrize("Lz", [4])
|
|
191
|
+
@pytest.mark.parametrize("beta", [0.13, 1 / 4.5])
|
|
192
|
+
@pytest.mark.parametrize("j", [-1.0, +1.0])
|
|
193
|
+
@pytest.mark.parametrize("h", [0.0, 0.1])
|
|
194
|
+
@pytest.mark.parametrize(
|
|
195
|
+
"cyclic", [False, True, (False, True, False), (True, False, True)]
|
|
196
|
+
)
|
|
197
|
+
def test_3D_classical_ising_model(self, Lx, Ly, Lz, beta, j, h, cyclic):
|
|
198
|
+
tn = qtn.TN3D_classical_ising_partition_function(
|
|
199
|
+
Lx, Ly, Lz, beta=beta, j=j, h=h, cyclic=cyclic
|
|
200
|
+
)
|
|
201
|
+
htn = qtn.HTN3D_classical_ising_partition_function(
|
|
202
|
+
Lx, Ly, Lz, beta=beta, j=j, h=h, cyclic=cyclic
|
|
203
|
+
)
|
|
204
|
+
Z1 = tn.contract(all, output_inds=())
|
|
205
|
+
Z2 = htn.contract(all, output_inds=())
|
|
206
|
+
assert Z1 == pytest.approx(Z2)
|
|
207
|
+
|
|
208
|
+
if not cyclic:
|
|
209
|
+
# skip cyclic as nx has no multibonds for L=2
|
|
210
|
+
import networkx as nx
|
|
211
|
+
|
|
212
|
+
G = nx.lattice.grid_graph((Lx, Ly, Lz))
|
|
213
|
+
Z3 = qtn.TN_classical_partition_function_from_edges(
|
|
214
|
+
G.edges, beta=beta, j=j, h=h
|
|
215
|
+
).contract(all, output_inds=())
|
|
216
|
+
assert Z2 == pytest.approx(Z3)
|
|
217
|
+
Z4 = qtn.HTN_classical_partition_function_from_edges(
|
|
218
|
+
G.edges, beta=beta, j=j, h=h
|
|
219
|
+
).contract(all, output_inds=())
|
|
220
|
+
assert Z3 == pytest.approx(Z4)
|
|
221
|
+
|
|
222
|
+
def test_2d_classical_ising_varying_j(self):
|
|
223
|
+
L = 5
|
|
224
|
+
beta = 0.3
|
|
225
|
+
edges = qtn.edges_2d_square(L, L)
|
|
226
|
+
np.random.seed(666)
|
|
227
|
+
js = {edge: np.random.normal() for edge in edges}
|
|
228
|
+
tn = qtn.TN_classical_partition_function_from_edges(
|
|
229
|
+
edges, beta=beta, j=lambda i, j: js[i, j]
|
|
230
|
+
)
|
|
231
|
+
assert tn.dtype == "float64"
|
|
232
|
+
x0 = tn.contract(all, output_inds=())
|
|
233
|
+
tn = qtn.HTN_classical_partition_function_from_edges(
|
|
234
|
+
edges, beta=beta, j=lambda i, j: js[i, j]
|
|
235
|
+
)
|
|
236
|
+
assert tn.dtype == "float64"
|
|
237
|
+
x1 = tn.contract(all, output_inds=())
|
|
238
|
+
tn = qtn.TN2D_classical_ising_partition_function(
|
|
239
|
+
L, L, beta=beta, j=lambda i, j: js[i, j]
|
|
240
|
+
)
|
|
241
|
+
assert tn.dtype == "float64"
|
|
242
|
+
x2 = tn.contract(all, output_inds=())
|
|
243
|
+
tn = qtn.HTN2D_classical_ising_partition_function(
|
|
244
|
+
L, L, beta=beta, j=lambda i, j: js[i, j]
|
|
245
|
+
)
|
|
246
|
+
assert tn.dtype == "float64"
|
|
247
|
+
x3 = tn.contract(all, output_inds=())
|
|
248
|
+
assert x0 == pytest.approx(x1)
|
|
249
|
+
assert x1 == pytest.approx(x2)
|
|
250
|
+
assert x2 == pytest.approx(x3)
|
|
251
|
+
|
|
252
|
+
def test_3d_classical_ising_varying_j(self):
|
|
253
|
+
L = 3
|
|
254
|
+
beta = 0.3
|
|
255
|
+
edges = qtn.edges_3d_cubic(L, L, L)
|
|
256
|
+
np.random.seed(666)
|
|
257
|
+
js = {edge: np.random.normal() for edge in edges}
|
|
258
|
+
tn = qtn.TN_classical_partition_function_from_edges(
|
|
259
|
+
edges, beta=beta, j=lambda i, j: js[i, j]
|
|
260
|
+
)
|
|
261
|
+
assert tn.dtype == "float64"
|
|
262
|
+
x0 = tn.contract(all, output_inds=())
|
|
263
|
+
tn = qtn.HTN_classical_partition_function_from_edges(
|
|
264
|
+
edges, beta=beta, j=lambda i, j: js[i, j]
|
|
265
|
+
)
|
|
266
|
+
assert tn.dtype == "float64"
|
|
267
|
+
x1 = tn.contract(all, output_inds=())
|
|
268
|
+
tn = qtn.TN3D_classical_ising_partition_function(
|
|
269
|
+
L, L, L, beta=beta, j=lambda i, j: js[i, j]
|
|
270
|
+
)
|
|
271
|
+
assert tn.dtype == "float64"
|
|
272
|
+
x2 = tn.contract(all, output_inds=())
|
|
273
|
+
tn = qtn.HTN3D_classical_ising_partition_function(
|
|
274
|
+
L, L, L, beta=beta, j=lambda i, j: js[i, j]
|
|
275
|
+
)
|
|
276
|
+
assert tn.dtype == "float64"
|
|
277
|
+
x3 = tn.contract(all, output_inds=())
|
|
278
|
+
assert x0 == pytest.approx(x1)
|
|
279
|
+
assert x1 == pytest.approx(x2)
|
|
280
|
+
assert x2 == pytest.approx(x3)
|
|
281
|
+
|
|
282
|
+
def test_tn_dimer_covering(self):
|
|
283
|
+
edges = [(0, 1), (1, 2), (2, 3), (3, 0)]
|
|
284
|
+
tn = qtn.TN_dimer_covering_from_edges(edges, cover_count=1)
|
|
285
|
+
assert tn ^ all == pytest.approx(2.0)
|
|
286
|
+
tn = qtn.TN_dimer_covering_from_edges(edges, cover_count=2)
|
|
287
|
+
assert tn ^ all == pytest.approx(1.0)
|
|
288
|
+
edges = [(0, 1), (1, 2), (2, 0)]
|
|
289
|
+
tn = qtn.TN_dimer_covering_from_edges(edges, cover_count=1)
|
|
290
|
+
assert tn ^ all == pytest.approx(0.0)
|
|
291
|
+
|
|
292
|
+
def test_tn2d_fillers(self):
|
|
293
|
+
tn = qtn.TN2D_empty(Lx=2, Ly=2, D=2)
|
|
294
|
+
assert isinstance(tn, qtn.TensorNetwork2D)
|
|
295
|
+
assert (
|
|
296
|
+
qtn.TN2D_rand(Lx=2, Ly=2, D=2, seed=42) ^ all
|
|
297
|
+
) == pytest.approx(qtn.TN2D_rand(Lx=2, Ly=2, D=2, seed=42) ^ all)
|
|
298
|
+
tn = qtn.TN2D_with_value(1.0, Lx=2, Ly=3, D=4)
|
|
299
|
+
assert tn ^ all == pytest.approx(qu.prod(tn.ind_sizes().values()))
|
|
300
|
+
|
|
301
|
+
def test_tn3d_fillers(self):
|
|
302
|
+
tn = qtn.TN3D_empty(Lx=2, Ly=2, Lz=2, D=2)
|
|
303
|
+
assert isinstance(tn, qtn.TensorNetwork3D)
|
|
304
|
+
assert (
|
|
305
|
+
qtn.TN3D_rand(Lx=2, Ly=2, Lz=2, D=2, seed=42) ^ all
|
|
306
|
+
) == pytest.approx(qtn.TN3D_rand(Lx=2, Ly=2, Lz=2, D=2, seed=42) ^ all)
|
|
307
|
+
tn = qtn.TN3D_with_value(1.0, Lx=2, Ly=3, Lz=2, D=2)
|
|
308
|
+
assert tn ^ all == pytest.approx(qu.prod(tn.ind_sizes().values()))
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
@pytest.mark.parametrize("cyclic", [False, True, (False, True), (True, False)])
|
|
312
|
+
def test_tn2d_classical_ising_partition_function(cyclic):
|
|
313
|
+
Lx = 4
|
|
314
|
+
Ly = 5
|
|
315
|
+
coupling = {
|
|
316
|
+
(cooa, coob): float(qu.randn())
|
|
317
|
+
for cooa, coob in qtn.gen_2d_bonds(Lx, Ly, cyclic=cyclic)
|
|
318
|
+
}
|
|
319
|
+
h = qu.randn()
|
|
320
|
+
tn = qtn.TN2D_classical_ising_partition_function(
|
|
321
|
+
Lx,
|
|
322
|
+
Ly,
|
|
323
|
+
beta=0.44,
|
|
324
|
+
j=coupling,
|
|
325
|
+
h=h,
|
|
326
|
+
outputs=[(1, 2), (3, 4)],
|
|
327
|
+
cyclic=cyclic,
|
|
328
|
+
)
|
|
329
|
+
assert tn.outer_inds() == ("s1,2", "s3,4")
|
|
330
|
+
htn = qtn.HTN2D_classical_ising_partition_function(
|
|
331
|
+
Lx,
|
|
332
|
+
Ly,
|
|
333
|
+
beta=0.44,
|
|
334
|
+
j=coupling,
|
|
335
|
+
h=h,
|
|
336
|
+
cyclic=cyclic,
|
|
337
|
+
)
|
|
338
|
+
assert htn.num_indices == Lx * Ly
|
|
339
|
+
|
|
340
|
+
if not isinstance(cyclic, tuple):
|
|
341
|
+
cyclic = (cyclic, cyclic)
|
|
342
|
+
|
|
343
|
+
assert (tn.is_cyclic_x(), tn.is_cyclic_y()) == cyclic
|
|
344
|
+
|
|
345
|
+
assert_allclose(
|
|
346
|
+
tn.contract().data,
|
|
347
|
+
htn.contract(output_inds=("s1,2", "s3,4")).data,
|
|
348
|
+
)
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
@pytest.mark.parametrize("cyclic", [False, (0, 1, 1), (0, 0, 1)])
|
|
352
|
+
def test_tn3d_classical_ising_partition_function(cyclic):
|
|
353
|
+
Lx, Ly, Lz = 2, 3, 3
|
|
354
|
+
coupling = {
|
|
355
|
+
(cooa, coob): float(qu.randn())
|
|
356
|
+
for cooa, coob in qtn.gen_3d_bonds(Lx, Ly, Lz, cyclic=cyclic)
|
|
357
|
+
}
|
|
358
|
+
h = qu.randn()
|
|
359
|
+
tn = qtn.TN3D_classical_ising_partition_function(
|
|
360
|
+
Lx,
|
|
361
|
+
Ly,
|
|
362
|
+
Lz,
|
|
363
|
+
beta=0.44,
|
|
364
|
+
j=lambda cooa, coob: coupling[(cooa, coob)],
|
|
365
|
+
h=h,
|
|
366
|
+
outputs=[(1, 0, 2), (0, 2, 1)],
|
|
367
|
+
cyclic=cyclic,
|
|
368
|
+
)
|
|
369
|
+
assert tn.outer_inds() == ("s0,2,1", "s1,0,2")
|
|
370
|
+
htn = qtn.HTN3D_classical_ising_partition_function(
|
|
371
|
+
Lx,
|
|
372
|
+
Ly,
|
|
373
|
+
Lz,
|
|
374
|
+
beta=0.44,
|
|
375
|
+
j=lambda cooa, coob: coupling[(cooa, coob)],
|
|
376
|
+
h=h,
|
|
377
|
+
cyclic=cyclic,
|
|
378
|
+
)
|
|
379
|
+
assert htn.num_indices == Lx * Ly * Lz
|
|
380
|
+
|
|
381
|
+
if not isinstance(cyclic, tuple):
|
|
382
|
+
cyclic = (cyclic, cyclic, cyclic)
|
|
383
|
+
|
|
384
|
+
assert (tn.is_cyclic_x(), tn.is_cyclic_y(), tn.is_cyclic_z()) == cyclic
|
|
385
|
+
|
|
386
|
+
assert_allclose(
|
|
387
|
+
tn.contract().data,
|
|
388
|
+
htn.contract(output_inds=("s0,2,1", "s1,0,2")).data,
|
|
389
|
+
)
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
@pytest.mark.parametrize("sites_location", ["side", "diag"])
|
|
393
|
+
@pytest.mark.parametrize("outputs", [(), 2, (1, 3)])
|
|
394
|
+
def test_all_to_all_classical_partition_functions(sites_location, outputs):
|
|
395
|
+
import numpy as np
|
|
396
|
+
|
|
397
|
+
N = 5
|
|
398
|
+
rng = np.random.default_rng(42)
|
|
399
|
+
Jij = {(i, j): rng.normal() for i in range(N) for j in range(i + 1, N)}
|
|
400
|
+
htn = qtn.HTN_classical_partition_function_from_edges(
|
|
401
|
+
edges=Jij.keys(),
|
|
402
|
+
beta=0.179,
|
|
403
|
+
j=Jij,
|
|
404
|
+
)
|
|
405
|
+
Zex = htn.contract(all, output_inds=())
|
|
406
|
+
|
|
407
|
+
tn = qtn.TN2D_embedded_classical_ising_partition_function(
|
|
408
|
+
Jij,
|
|
409
|
+
beta=0.179,
|
|
410
|
+
sites_location=sites_location,
|
|
411
|
+
outputs=outputs,
|
|
412
|
+
)
|
|
413
|
+
|
|
414
|
+
sites = tuple(tn.gen_sites_present())
|
|
415
|
+
assert len(sites) == N * (N - 1) // 2
|
|
416
|
+
for i, j in sites:
|
|
417
|
+
assert i > j
|
|
418
|
+
|
|
419
|
+
if isinstance(outputs, tuple):
|
|
420
|
+
assert set(tn.outer_inds()) == {f"s{i}" for i in outputs}
|
|
421
|
+
else:
|
|
422
|
+
assert tn.outer_inds() == (f"s{outputs}",)
|
|
423
|
+
(t,) = tn._inds_get(f"s{outputs}")
|
|
424
|
+
if sites_location == "side":
|
|
425
|
+
assert "I2,0" in t.tags
|
|
426
|
+
else:
|
|
427
|
+
assert "I2,1" in t.tags
|
|
428
|
+
assert tn.contract(output_inds=()) == pytest.approx(Zex)
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
def test_tn2d_rand_symm():
|
|
432
|
+
import numpy as np
|
|
433
|
+
|
|
434
|
+
tn = qtn.TN2D_rand_symmetric(3, 4, 3)
|
|
435
|
+
ghash = tn.geometry_hash(strict_index_order=True)
|
|
436
|
+
Zex = tn.contract(all, output_inds=())
|
|
437
|
+
rng = np.random.default_rng(42)
|
|
438
|
+
for t in tn:
|
|
439
|
+
t.modify(inds=rng.permutation(t.inds))
|
|
440
|
+
assert tn.geometry_hash(strict_index_order=True) != ghash
|
|
441
|
+
assert tn.contract(all, output_inds=()) == pytest.approx(Zex)
|