Trajectree 0.0.1__py3-none-any.whl → 0.0.3__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 (124) hide show
  1. trajectree/__init__.py +0 -3
  2. trajectree/fock_optics/devices.py +1 -1
  3. trajectree/fock_optics/light_sources.py +2 -2
  4. trajectree/fock_optics/measurement.py +9 -9
  5. trajectree/fock_optics/outputs.py +10 -6
  6. trajectree/fock_optics/utils.py +9 -6
  7. trajectree/sequence/swap.py +5 -4
  8. trajectree/trajectory.py +5 -4
  9. {trajectree-0.0.1.dist-info → trajectree-0.0.3.dist-info}/METADATA +2 -3
  10. trajectree-0.0.3.dist-info/RECORD +16 -0
  11. trajectree/quimb/docs/_pygments/_pygments_dark.py +0 -118
  12. trajectree/quimb/docs/_pygments/_pygments_light.py +0 -118
  13. trajectree/quimb/docs/conf.py +0 -158
  14. trajectree/quimb/docs/examples/ex_mpi_expm_evo.py +0 -62
  15. trajectree/quimb/quimb/__init__.py +0 -507
  16. trajectree/quimb/quimb/calc.py +0 -1491
  17. trajectree/quimb/quimb/core.py +0 -2279
  18. trajectree/quimb/quimb/evo.py +0 -712
  19. trajectree/quimb/quimb/experimental/__init__.py +0 -0
  20. trajectree/quimb/quimb/experimental/autojittn.py +0 -129
  21. trajectree/quimb/quimb/experimental/belief_propagation/__init__.py +0 -109
  22. trajectree/quimb/quimb/experimental/belief_propagation/bp_common.py +0 -397
  23. trajectree/quimb/quimb/experimental/belief_propagation/d1bp.py +0 -316
  24. trajectree/quimb/quimb/experimental/belief_propagation/d2bp.py +0 -653
  25. trajectree/quimb/quimb/experimental/belief_propagation/hd1bp.py +0 -571
  26. trajectree/quimb/quimb/experimental/belief_propagation/hv1bp.py +0 -775
  27. trajectree/quimb/quimb/experimental/belief_propagation/l1bp.py +0 -316
  28. trajectree/quimb/quimb/experimental/belief_propagation/l2bp.py +0 -537
  29. trajectree/quimb/quimb/experimental/belief_propagation/regions.py +0 -194
  30. trajectree/quimb/quimb/experimental/cluster_update.py +0 -286
  31. trajectree/quimb/quimb/experimental/merabuilder.py +0 -865
  32. trajectree/quimb/quimb/experimental/operatorbuilder/__init__.py +0 -15
  33. trajectree/quimb/quimb/experimental/operatorbuilder/operatorbuilder.py +0 -1631
  34. trajectree/quimb/quimb/experimental/schematic.py +0 -7
  35. trajectree/quimb/quimb/experimental/tn_marginals.py +0 -130
  36. trajectree/quimb/quimb/experimental/tnvmc.py +0 -1483
  37. trajectree/quimb/quimb/gates.py +0 -36
  38. trajectree/quimb/quimb/gen/__init__.py +0 -2
  39. trajectree/quimb/quimb/gen/operators.py +0 -1167
  40. trajectree/quimb/quimb/gen/rand.py +0 -713
  41. trajectree/quimb/quimb/gen/states.py +0 -479
  42. trajectree/quimb/quimb/linalg/__init__.py +0 -6
  43. trajectree/quimb/quimb/linalg/approx_spectral.py +0 -1109
  44. trajectree/quimb/quimb/linalg/autoblock.py +0 -258
  45. trajectree/quimb/quimb/linalg/base_linalg.py +0 -719
  46. trajectree/quimb/quimb/linalg/mpi_launcher.py +0 -397
  47. trajectree/quimb/quimb/linalg/numpy_linalg.py +0 -244
  48. trajectree/quimb/quimb/linalg/rand_linalg.py +0 -514
  49. trajectree/quimb/quimb/linalg/scipy_linalg.py +0 -293
  50. trajectree/quimb/quimb/linalg/slepc_linalg.py +0 -892
  51. trajectree/quimb/quimb/schematic.py +0 -1518
  52. trajectree/quimb/quimb/tensor/__init__.py +0 -401
  53. trajectree/quimb/quimb/tensor/array_ops.py +0 -610
  54. trajectree/quimb/quimb/tensor/circuit.py +0 -4824
  55. trajectree/quimb/quimb/tensor/circuit_gen.py +0 -411
  56. trajectree/quimb/quimb/tensor/contraction.py +0 -336
  57. trajectree/quimb/quimb/tensor/decomp.py +0 -1255
  58. trajectree/quimb/quimb/tensor/drawing.py +0 -1646
  59. trajectree/quimb/quimb/tensor/fitting.py +0 -385
  60. trajectree/quimb/quimb/tensor/geometry.py +0 -583
  61. trajectree/quimb/quimb/tensor/interface.py +0 -114
  62. trajectree/quimb/quimb/tensor/networking.py +0 -1058
  63. trajectree/quimb/quimb/tensor/optimize.py +0 -1818
  64. trajectree/quimb/quimb/tensor/tensor_1d.py +0 -4778
  65. trajectree/quimb/quimb/tensor/tensor_1d_compress.py +0 -1854
  66. trajectree/quimb/quimb/tensor/tensor_1d_tebd.py +0 -662
  67. trajectree/quimb/quimb/tensor/tensor_2d.py +0 -5954
  68. trajectree/quimb/quimb/tensor/tensor_2d_compress.py +0 -96
  69. trajectree/quimb/quimb/tensor/tensor_2d_tebd.py +0 -1230
  70. trajectree/quimb/quimb/tensor/tensor_3d.py +0 -2869
  71. trajectree/quimb/quimb/tensor/tensor_3d_tebd.py +0 -46
  72. trajectree/quimb/quimb/tensor/tensor_approx_spectral.py +0 -60
  73. trajectree/quimb/quimb/tensor/tensor_arbgeom.py +0 -3237
  74. trajectree/quimb/quimb/tensor/tensor_arbgeom_compress.py +0 -565
  75. trajectree/quimb/quimb/tensor/tensor_arbgeom_tebd.py +0 -1138
  76. trajectree/quimb/quimb/tensor/tensor_builder.py +0 -5411
  77. trajectree/quimb/quimb/tensor/tensor_core.py +0 -11179
  78. trajectree/quimb/quimb/tensor/tensor_dmrg.py +0 -1472
  79. trajectree/quimb/quimb/tensor/tensor_mera.py +0 -204
  80. trajectree/quimb/quimb/utils.py +0 -892
  81. trajectree/quimb/tests/__init__.py +0 -0
  82. trajectree/quimb/tests/test_accel.py +0 -501
  83. trajectree/quimb/tests/test_calc.py +0 -788
  84. trajectree/quimb/tests/test_core.py +0 -847
  85. trajectree/quimb/tests/test_evo.py +0 -565
  86. trajectree/quimb/tests/test_gen/__init__.py +0 -0
  87. trajectree/quimb/tests/test_gen/test_operators.py +0 -361
  88. trajectree/quimb/tests/test_gen/test_rand.py +0 -296
  89. trajectree/quimb/tests/test_gen/test_states.py +0 -261
  90. trajectree/quimb/tests/test_linalg/__init__.py +0 -0
  91. trajectree/quimb/tests/test_linalg/test_approx_spectral.py +0 -368
  92. trajectree/quimb/tests/test_linalg/test_base_linalg.py +0 -351
  93. trajectree/quimb/tests/test_linalg/test_mpi_linalg.py +0 -127
  94. trajectree/quimb/tests/test_linalg/test_numpy_linalg.py +0 -84
  95. trajectree/quimb/tests/test_linalg/test_rand_linalg.py +0 -134
  96. trajectree/quimb/tests/test_linalg/test_slepc_linalg.py +0 -283
  97. trajectree/quimb/tests/test_tensor/__init__.py +0 -0
  98. trajectree/quimb/tests/test_tensor/test_belief_propagation/__init__.py +0 -0
  99. trajectree/quimb/tests/test_tensor/test_belief_propagation/test_d1bp.py +0 -39
  100. trajectree/quimb/tests/test_tensor/test_belief_propagation/test_d2bp.py +0 -67
  101. trajectree/quimb/tests/test_tensor/test_belief_propagation/test_hd1bp.py +0 -64
  102. trajectree/quimb/tests/test_tensor/test_belief_propagation/test_hv1bp.py +0 -51
  103. trajectree/quimb/tests/test_tensor/test_belief_propagation/test_l1bp.py +0 -142
  104. trajectree/quimb/tests/test_tensor/test_belief_propagation/test_l2bp.py +0 -101
  105. trajectree/quimb/tests/test_tensor/test_circuit.py +0 -816
  106. trajectree/quimb/tests/test_tensor/test_contract.py +0 -67
  107. trajectree/quimb/tests/test_tensor/test_decomp.py +0 -40
  108. trajectree/quimb/tests/test_tensor/test_mera.py +0 -52
  109. trajectree/quimb/tests/test_tensor/test_optimizers.py +0 -488
  110. trajectree/quimb/tests/test_tensor/test_tensor_1d.py +0 -1171
  111. trajectree/quimb/tests/test_tensor/test_tensor_2d.py +0 -606
  112. trajectree/quimb/tests/test_tensor/test_tensor_2d_tebd.py +0 -144
  113. trajectree/quimb/tests/test_tensor/test_tensor_3d.py +0 -123
  114. trajectree/quimb/tests/test_tensor/test_tensor_arbgeom.py +0 -226
  115. trajectree/quimb/tests/test_tensor/test_tensor_builder.py +0 -441
  116. trajectree/quimb/tests/test_tensor/test_tensor_core.py +0 -2066
  117. trajectree/quimb/tests/test_tensor/test_tensor_dmrg.py +0 -388
  118. trajectree/quimb/tests/test_tensor/test_tensor_spectral_approx.py +0 -63
  119. trajectree/quimb/tests/test_tensor/test_tensor_tebd.py +0 -270
  120. trajectree/quimb/tests/test_utils.py +0 -85
  121. trajectree-0.0.1.dist-info/RECORD +0 -126
  122. {trajectree-0.0.1.dist-info → trajectree-0.0.3.dist-info}/WHEEL +0 -0
  123. {trajectree-0.0.1.dist-info → trajectree-0.0.3.dist-info}/licenses/LICENSE +0 -0
  124. {trajectree-0.0.1.dist-info → trajectree-0.0.3.dist-info}/top_level.txt +0 -0
@@ -1,565 +0,0 @@
1
- """Generic methods for compressing arbitrary geometry tensor networks, where
2
- the tensor network can locally have arbitrary structure and outer indices.
3
-
4
- - [x] projector
5
- - [x] l2bp
6
- - [x] local early
7
- - [x] local late
8
- - [x] superorthogonal
9
-
10
- """
11
-
12
- from ..utils import ensure_dict
13
- from .tensor_arbgeom import create_lazy_edge_map
14
- from .tensor_core import choose_local_compress_gauge_settings
15
-
16
-
17
- def tensor_network_ag_compress_projector(
18
- tn,
19
- max_bond=None,
20
- cutoff=1e-10,
21
- site_tags=None,
22
- canonize=True,
23
- canonize_opts=None,
24
- lazy=False,
25
- optimize="auto-hq",
26
- equalize_norms=False,
27
- inplace=False,
28
- **compress_opts,
29
- ):
30
- """Compress an arbtrary geometry tensor network, with potentially multiple
31
- tensors per site, using locally computed projectors.
32
-
33
- Very loosely, this is like a generalization HOTRG.
34
-
35
- Parameters
36
- ----------
37
- tn : TensorNetwork
38
- The tensor network to compress. Every tensor should have exactly one of
39
- the site tags. Each site can have multiple tensors and output indices.
40
- max_bond : int
41
- The maximum bond dimension to compress to.
42
- cutoff : float, optional
43
- A dynamic threshold for discarding singular values when compressing.
44
- site_tags : sequence of str, optional
45
- The tags to use to group the tensors from ``tn``. If not
46
- given, uses ``tn.site_tags``. The tensor network built will have one
47
- tensor per site.
48
- canonize : bool, optional
49
- Whether to pseudo canonicalize the initial tensor network.
50
- canonize_opts
51
- Supplied to :meth:`~quimb.tensor.tensor_core.TensorNetwork.gauge_all`.
52
- lazy : bool, optional
53
- Whether to leave the computed projectors uncontracted, default: False.
54
- optimize : str, optional
55
- The contraction path optimizer to use.
56
- equalize_norms : bool or float, optional
57
- Whether to equalize the norms of the tensors after compression. If an
58
- explicit value is give, then the norms will be set to that value, and
59
- the overall scaling factor will be accumulated into `.exponent`.
60
- inplace : bool, optional
61
- Whether to perform the compression inplace.
62
- compress_opts
63
- Supplied to :func:`~quimb.tensor.tensor_split`.
64
-
65
- Returns
66
- -------
67
- TensorNetwork
68
- """
69
- tn = tn if inplace else tn.copy()
70
-
71
- if site_tags is None:
72
- site_tags = tn.site_tags
73
-
74
- edges, _ = create_lazy_edge_map(tn, site_tags)
75
-
76
- if canonize:
77
- # optionally precondition the uncontracted network
78
- canonize_opts = ensure_dict(canonize_opts)
79
- tn.gauge_all_(
80
- equalize_norms=equalize_norms,
81
- **canonize_opts
82
- )
83
-
84
- # then compute projectors using local information
85
- tn_calc = tn.copy()
86
- for taga, tagb in edges:
87
- tn_calc.insert_compressor_between_regions_(
88
- [taga],
89
- [tagb],
90
- max_bond=max_bond,
91
- cutoff=cutoff,
92
- insert_into=tn,
93
- new_ltags=[taga],
94
- new_rtags=[tagb],
95
- optimize=optimize,
96
- **compress_opts,
97
- )
98
-
99
- if not lazy:
100
- # then contract each site with all surrounding projectors
101
- for st in site_tags:
102
- tn.contract_(st, optimize=optimize)
103
-
104
- # XXX: do better than simply waiting til the end to equalize norms
105
- if equalize_norms is True:
106
- tn.equalize_norms_()
107
- elif equalize_norms:
108
- tn.equalize_norms_(value=equalize_norms)
109
-
110
- return tn
111
-
112
-
113
- def tensor_network_ag_compress_local_early(
114
- tn,
115
- max_bond=None,
116
- cutoff=1e-10,
117
- site_tags=None,
118
- canonize=True,
119
- tree_gauge_distance=None,
120
- canonize_distance=None,
121
- canonize_after_distance=None,
122
- mode="auto",
123
- optimize="auto-hq",
124
- equalize_norms=False,
125
- inplace=False,
126
- **compress_opts,
127
- ):
128
- """Compress an arbtrary geometry tensor network, with potentially multiple
129
- tensors per site, using explicit contraction followed by immediate
130
- ('early') compression. In other words, contractions are interleaved with
131
- compressions.
132
-
133
- Very loosely, this is like a generalization of the 'zip-up' algorithm in
134
- 1D, but for arbitrary geometry.
135
-
136
-
137
- Parameters
138
- ----------
139
- tn : TensorNetwork
140
- The tensor network to compress. Every tensor should have exactly one of
141
- the site tags. Each site can have multiple tensors and output indices.
142
- max_bond : int
143
- The maximum bond dimension to compress to.
144
- cutoff : float, optional
145
- A dynamic threshold for discarding singular values when compressing.
146
- site_tags : sequence of str, optional
147
- The tags to use to group the tensors from ``tn``. If not
148
- given, uses ``tn.site_tags``. The tensor network built will have one
149
- tensor per site.
150
- canonize : bool, optional
151
- Whether to locally gauge before each compression, defaults to True.
152
- tree_gauge_distance : int, optional
153
- The distance to locally gauge to before each compression. Defaults to
154
- 3.
155
- canonize_distance : int, optional
156
- The distance to canonize to before each compression, by default this
157
- is set by ``tree_gauge_distance``.
158
- canonize_after_distance : int, optional
159
- The distance to canonize to after each compression, by default this
160
- is set by ``tree_gauge_distance``, depending on ``mode``.
161
- mode : {'auto', 'basic', 'virtual-tree', ...}, optional
162
- The mode to use for the local gauging. If 'auto' will default to
163
- virtual tree gauging, or basic if `tree_gauge_distance` is 0.
164
- optimize : str, optional
165
- The contraction path optimizer to use.
166
- equalize_norms : bool or float, optional
167
- Whether to equalize the norms of the tensors after compression. If an
168
- explicit value is give, then the norms will be set to that value, and
169
- the overall scaling factor will be accumulated into `.exponent`.
170
- inplace : bool, optional
171
- Whether to perform the compression inplace.
172
- compress_opts
173
- Supplied to
174
- :meth:`~quimb.tensor.tensor_core.TensorNetwork.compress_between`.
175
-
176
- Returns
177
- -------
178
- TensorNetwork
179
- """
180
- tnc = tn if inplace else tn.copy()
181
-
182
- if site_tags is None:
183
- site_tags = tnc.site_tags
184
-
185
- _, neighbors = create_lazy_edge_map(tnc, site_tags)
186
-
187
- canonize_distance, canonize_after_distance, mode = (
188
- choose_local_compress_gauge_settings(
189
- canonize,
190
- tree_gauge_distance,
191
- canonize_distance,
192
- canonize_after_distance,
193
- mode,
194
- )
195
- )
196
-
197
- st0 = next(iter(site_tags))
198
- seen = {st0}
199
- queue = [st0]
200
-
201
- while queue:
202
- # process sites in a breadth-first manner
203
- taga = queue.pop(0)
204
-
205
- for tagb in neighbors[taga]:
206
- if tagb not in seen:
207
- queue.append(tagb)
208
- seen.add(tagb)
209
-
210
- # contract this site
211
- tnc.contract_(taga, optimize=optimize)
212
-
213
- # then immediately compress around it
214
- (tida,) = tnc._get_tids_from_tags(taga)
215
- for tidb in tnc._get_neighbor_tids(tida):
216
- tnc._compress_between_tids(
217
- tida,
218
- tidb,
219
- max_bond=max_bond,
220
- cutoff=cutoff,
221
- canonize_distance=canonize_distance,
222
- canonize_after_distance=canonize_after_distance,
223
- mode=mode,
224
- **compress_opts,
225
- )
226
-
227
- if equalize_norms is True:
228
- tnc.equalize_norms_()
229
- elif equalize_norms:
230
- tnc.equalize_norms_(value=equalize_norms)
231
-
232
- return tnc
233
-
234
-
235
- def tensor_network_ag_compress_local_late(
236
- tn,
237
- max_bond=None,
238
- cutoff=1e-10,
239
- site_tags=None,
240
- canonize=True,
241
- tree_gauge_distance=None,
242
- canonize_distance=None,
243
- canonize_after_distance=None,
244
- mode="auto",
245
- optimize="auto-hq",
246
- equalize_norms=False,
247
- inplace=False,
248
- **compress_opts,
249
- ):
250
- """Compress an arbtrary geometry tensor network, with potentially multiple
251
- tensors per site, by explicitly contracting all sites first and then
252
- ('late') locally compressing. In other words, all contractions happen, then
253
- all compressions happen.
254
-
255
- Very loosely, this is like a generalization of the 'direct' algorithm in
256
- 1D, but for arbitrary geometry.
257
-
258
- Parameters
259
- ----------
260
- tn : TensorNetwork
261
- The tensor network to compress. Every tensor should have exactly one of
262
- the site tags. Each site can have multiple tensors and output indices.
263
- max_bond : int
264
- The maximum bond dimension to compress to.
265
- cutoff : float, optional
266
- A dynamic threshold for discarding singular values when compressing.
267
- site_tags : sequence of str, optional
268
- The tags to use to group the tensors from ``tn``. If not
269
- given, uses ``tn.site_tags``. The tensor network built will have one
270
- tensor per site.
271
- canonize : bool, optional
272
- Whether to locally gauge before each compression, defaults to True.
273
- tree_gauge_distance : int, optional
274
- The distance to locally gauge to before each compression. Defaults to
275
- 3.
276
- canonize_distance : int, optional
277
- The distance to canonize to before each compression, by default this
278
- is set by ``tree_gauge_distance``.
279
- canonize_after_distance : int, optional
280
- The distance to canonize to after each compression, by default this
281
- is set by ``tree_gauge_distance``, depending on ``mode``.
282
- mode : {'auto', 'basic', 'virtual-tree', ...}, optional
283
- The mode to use for the local gauging. If 'auto' will default to
284
- virtual tree gauging, or basic if `tree_gauge_distance` is 0.
285
- optimize : str, optional
286
- The contraction path optimizer to use.
287
- equalize_norms : bool or float, optional
288
- Whether to equalize the norms of the tensors after compression. If an
289
- explicit value is give, then the norms will be set to that value, and
290
- the overall scaling factor will be accumulated into `.exponent`.
291
- inplace : bool, optional
292
- Whether to perform the compression inplace.
293
- compress_opts
294
- Supplied to
295
- :meth:`~quimb.tensor.tensor_core.TensorNetwork.compress_between`.
296
-
297
- Returns
298
- -------
299
- TensorNetwork
300
- """
301
- tnc = tn if inplace else tn.copy()
302
-
303
- if site_tags is None:
304
- site_tags = tnc.site_tags
305
-
306
- for st in site_tags:
307
- tnc.contract_(st, optimize=optimize)
308
-
309
- tnc.compress_all_(
310
- max_bond=max_bond,
311
- cutoff=cutoff,
312
- canonize=canonize,
313
- tree_gauge_distance=tree_gauge_distance,
314
- canonize_distance=canonize_distance,
315
- canonize_after_distance=canonize_after_distance,
316
- mode=mode,
317
- **compress_opts,
318
- )
319
-
320
- if equalize_norms is True:
321
- tnc.equalize_norms_()
322
- elif equalize_norms:
323
- tnc.equalize_norms_(value=equalize_norms)
324
-
325
- return tnc
326
-
327
-
328
- def tensor_network_ag_compress_superorthogonal(
329
- tn,
330
- max_bond=None,
331
- cutoff=1e-10,
332
- site_tags=None,
333
- canonize=True,
334
- optimize="auto-hq",
335
- equalize_norms=False,
336
- inplace=False,
337
- **compress_opts,
338
- ):
339
- """Compress an arbtrary geometry tensor network, with potentially multiple
340
- tensors per site, using the 'superorthogonal' / 'Vidal' / quasi-canonical
341
- / 'simple update' gauge for compression. This is the same gauge as used in
342
- L2BP, but the intermediate tensor network is explicitly constructed.
343
-
344
- Parameters
345
- ----------
346
- tn : TensorNetwork
347
- The tensor network to compress. Every tensor should have exactly one of
348
- the site tags. Each site can have multiple tensors and output indices.
349
- max_bond : int
350
- The maximum bond dimension to compress to.
351
- cutoff : float, optional
352
- A dynamic threshold for discarding singular values when compressing.
353
- site_tags : sequence of str, optional
354
- The tags to use to group the tensors from ``tn``. If not
355
- given, uses ``tn.site_tags``. The tensor network built will have one
356
- tensor per site.
357
- canonize : bool, optional
358
- Whether to locally gauge before each compression, defaults to True.
359
- optimize : str, optional
360
- The contraction path optimizer to use.
361
- equalize_norms : bool or float, optional
362
- Whether to equalize the norms of the tensors after compression. If an
363
- explicit value is give, then the norms will be set to that value, and
364
- the overall scaling factor will be accumulated into `.exponent`.
365
- inplace : bool, optional
366
- Whether to perform the compression inplace.
367
- compress_opts
368
- Supplied to
369
- :meth:`~quimb.tensor.tensor_core.TensorNetwork.compress_all_simple`.
370
-
371
- Returns
372
- -------
373
- TensorNetwork
374
- """
375
- tnc = tn if inplace else tn.copy()
376
-
377
- if site_tags is None:
378
- site_tags = tnc.site_tags
379
-
380
- for st in site_tags:
381
- tnc.contract_(st, optimize=optimize)
382
-
383
- tnc.fuse_multibonds_()
384
-
385
- if not canonize:
386
- # turn off gauging effect
387
- compress_opts.setdefault("max_iterations", 1)
388
- compress_opts.setdefault("tol", 0.0)
389
- else:
390
- compress_opts.setdefault("max_iterations", 1000)
391
- compress_opts.setdefault("tol", 5e-6)
392
-
393
- tnc.compress_all_simple_(
394
- max_bond=max_bond,
395
- cutoff=cutoff,
396
- **compress_opts,
397
- )
398
-
399
- if equalize_norms is True:
400
- tnc.equalize_norms_()
401
- elif equalize_norms:
402
- tnc.equalize_norms_(value=equalize_norms)
403
-
404
- return tnc
405
-
406
-
407
- def tensor_network_ag_compress_l2bp(
408
- tn,
409
- max_bond=None,
410
- cutoff=1e-10,
411
- site_tags=None,
412
- canonize=True,
413
- damping=0.0,
414
- local_convergence=True,
415
- update="sequential",
416
- optimize="auto-hq",
417
- equalize_norms=False,
418
- inplace=False,
419
- **compress_opts,
420
- ):
421
- """Compress an arbitrary geometry tensor network, with potentially multiple
422
- tensors per site, using lazy 2-norm belief propagation.
423
-
424
- Parameters
425
- ----------
426
- tn : TensorNetwork
427
- The tensor network to compress. Every tensor should have exactly one of
428
- the site tags. Each site can have multiple tensors and output indices.
429
- max_bond : int
430
- The maximum bond dimension to compress to.
431
- cutoff : float, optional
432
- A dynamic threshold for discarding singular values when compressing.
433
- site_tags : sequence of str, optional
434
- The tags to use to group the tensors from ``tn``. If not
435
- given, uses ``tn.site_tags``. The tensor network built will have one
436
- tensor per site.
437
- canonize : bool, optional
438
- Whether to locally gauge before each compression, defaults to True.
439
- damping : float, optional
440
- How much to dampen message updates, to help convergence, defaults to 0.
441
- local_convergence : bool, optional
442
- Whether to use local convergence criteria, defaults to True.
443
- update : {'parallel', 'sequential'}, optional
444
- Whether to update all messages in parallel or sequentially, defaults to
445
- 'parallel'.
446
- optimize : str, optional
447
- The contraction path optimizer to use.
448
- equalize_norms : bool or float, optional
449
- Whether to equalize the norms of the tensors after compression. If an
450
- explicit value is give, then the norms will be set to that value, and
451
- the overall scaling factor will be accumulated into `.exponent`.
452
- inplace : bool, optional
453
- Whether to perform the compression inplace.
454
- compress_opts
455
- Supplied to
456
- :func:`~quimb.experimental.belief_propagation.l2bp.compress_l2bp`.
457
-
458
- Returns
459
- -------
460
- TensorNetwork
461
- """
462
- from quimb.experimental.belief_propagation.l2bp import compress_l2bp
463
-
464
- if not canonize:
465
- compress_opts.setdefault("max_iterations", 1)
466
-
467
- tnc = compress_l2bp(
468
- tn,
469
- max_bond=max_bond,
470
- cutoff=cutoff,
471
- site_tags=site_tags,
472
- damping=damping,
473
- local_convergence=local_convergence,
474
- update=update,
475
- optimize=optimize,
476
- inplace=inplace,
477
- **compress_opts,
478
- )
479
-
480
- if equalize_norms is True:
481
- tnc.equalize_norms_()
482
- elif equalize_norms:
483
- tnc.equalize_norms_(value=equalize_norms)
484
-
485
- return tnc
486
-
487
-
488
- _TNAG_COMPRESS_METHODS = {
489
- "local-early": tensor_network_ag_compress_local_early,
490
- "local-late": tensor_network_ag_compress_local_late,
491
- "projector": tensor_network_ag_compress_projector,
492
- "su": tensor_network_ag_compress_superorthogonal,
493
- "superorthogonal": tensor_network_ag_compress_superorthogonal,
494
- "l2bp": tensor_network_ag_compress_l2bp,
495
- }
496
-
497
-
498
- def tensor_network_ag_compress(
499
- tn,
500
- max_bond,
501
- cutoff=1e-10,
502
- method="local-early",
503
- site_tags=None,
504
- canonize=True,
505
- optimize="auto-hq",
506
- equalize_norms=False,
507
- inplace=False,
508
- **kwargs,
509
- ):
510
- """Compress an arbitrary geometry tensor network, with potentially multiple
511
- tensors per site.
512
-
513
- Parameters
514
- ----------
515
- tn : TensorNetwork
516
- The tensor network to compress. Every tensor should have exactly one of
517
- the site tags. Each site can have multiple tensors and output indices.
518
- max_bond : int
519
- The maximum bond dimension to compress to.
520
- cutoff : float, optional
521
- A dynamic threshold for discarding singular values when compressing.
522
- method : {'local-early', 'local-late', 'projector', 'superorthogonal', 'l2bp'}, optional
523
- The compression method to use:
524
-
525
- - 'local-early': explicitly contract each site and interleave with
526
- immediate compression, see
527
- :func:`~quimb.tensor.tensor_arbgeom_compress.tensor_network_ag_compress_local_early`.
528
- - 'local-late': explicitly contract all sites and then compress, see
529
- :func:`~quimb.tensor.tensor_arbgeom_compress.tensor_network_ag_compress_local_late`.
530
- - 'projector': use locally computed projectors, see
531
- :func:`~quimb.tensor.tensor_arbgeom_compress.tensor_network_ag_compress_projector`.
532
- - 'superorthogonal': use the 'superorthogonal' gauge, see
533
- :func:`~quimb.tensor.tensor_arbgeom_compress.tensor_network_ag_compress_superorthogonal`.
534
- - 'l2bp': use lazy 2-norm belief propagation, see
535
- :func:`~quimb.tensor.tensor_arbgeom_compress.tensor_network_ag_compress_l2bp`.
536
-
537
- site_tags : sequence of str, optional
538
- The tags to use to group the tensors from ``tn``. If not
539
- given, uses ``tn.site_tags``. The tensor network built will have one
540
- tensor per site.
541
- canonize : bool, optional
542
- Whether to perform canonicalization, pseudo or otherwise depending on
543
- the method, before compressing.
544
- optimize : str, optional
545
- The contraction path optimizer to use.
546
- equalize_norms : bool or float, optional
547
- Whether to equalize the norms of the tensors after compression. If an
548
- explicit value is give, then the norms will be set to that value, and
549
- the overall scaling factor will be accumulated into `.exponent`.
550
- inplace : bool, optional
551
- Whether to perform the compression inplace.
552
- kwargs
553
- Supplied to the chosen compression method.
554
- """
555
- return _TNAG_COMPRESS_METHODS[method](
556
- tn,
557
- max_bond=max_bond,
558
- cutoff=cutoff,
559
- site_tags=site_tags,
560
- canonize=canonize,
561
- optimize=optimize,
562
- equalize_norms=equalize_norms,
563
- inplace=inplace,
564
- **kwargs,
565
- )