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.
Files changed (122) hide show
  1. trajectree/__init__.py +3 -0
  2. trajectree/fock_optics/devices.py +1 -1
  3. trajectree/fock_optics/light_sources.py +2 -2
  4. trajectree/fock_optics/measurement.py +3 -3
  5. trajectree/fock_optics/utils.py +6 -6
  6. trajectree/quimb/docs/_pygments/_pygments_dark.py +118 -0
  7. trajectree/quimb/docs/_pygments/_pygments_light.py +118 -0
  8. trajectree/quimb/docs/conf.py +158 -0
  9. trajectree/quimb/docs/examples/ex_mpi_expm_evo.py +62 -0
  10. trajectree/quimb/quimb/__init__.py +507 -0
  11. trajectree/quimb/quimb/calc.py +1491 -0
  12. trajectree/quimb/quimb/core.py +2279 -0
  13. trajectree/quimb/quimb/evo.py +712 -0
  14. trajectree/quimb/quimb/experimental/__init__.py +0 -0
  15. trajectree/quimb/quimb/experimental/autojittn.py +129 -0
  16. trajectree/quimb/quimb/experimental/belief_propagation/__init__.py +109 -0
  17. trajectree/quimb/quimb/experimental/belief_propagation/bp_common.py +397 -0
  18. trajectree/quimb/quimb/experimental/belief_propagation/d1bp.py +316 -0
  19. trajectree/quimb/quimb/experimental/belief_propagation/d2bp.py +653 -0
  20. trajectree/quimb/quimb/experimental/belief_propagation/hd1bp.py +571 -0
  21. trajectree/quimb/quimb/experimental/belief_propagation/hv1bp.py +775 -0
  22. trajectree/quimb/quimb/experimental/belief_propagation/l1bp.py +316 -0
  23. trajectree/quimb/quimb/experimental/belief_propagation/l2bp.py +537 -0
  24. trajectree/quimb/quimb/experimental/belief_propagation/regions.py +194 -0
  25. trajectree/quimb/quimb/experimental/cluster_update.py +286 -0
  26. trajectree/quimb/quimb/experimental/merabuilder.py +865 -0
  27. trajectree/quimb/quimb/experimental/operatorbuilder/__init__.py +15 -0
  28. trajectree/quimb/quimb/experimental/operatorbuilder/operatorbuilder.py +1631 -0
  29. trajectree/quimb/quimb/experimental/schematic.py +7 -0
  30. trajectree/quimb/quimb/experimental/tn_marginals.py +130 -0
  31. trajectree/quimb/quimb/experimental/tnvmc.py +1483 -0
  32. trajectree/quimb/quimb/gates.py +36 -0
  33. trajectree/quimb/quimb/gen/__init__.py +2 -0
  34. trajectree/quimb/quimb/gen/operators.py +1167 -0
  35. trajectree/quimb/quimb/gen/rand.py +713 -0
  36. trajectree/quimb/quimb/gen/states.py +479 -0
  37. trajectree/quimb/quimb/linalg/__init__.py +6 -0
  38. trajectree/quimb/quimb/linalg/approx_spectral.py +1109 -0
  39. trajectree/quimb/quimb/linalg/autoblock.py +258 -0
  40. trajectree/quimb/quimb/linalg/base_linalg.py +719 -0
  41. trajectree/quimb/quimb/linalg/mpi_launcher.py +397 -0
  42. trajectree/quimb/quimb/linalg/numpy_linalg.py +244 -0
  43. trajectree/quimb/quimb/linalg/rand_linalg.py +514 -0
  44. trajectree/quimb/quimb/linalg/scipy_linalg.py +293 -0
  45. trajectree/quimb/quimb/linalg/slepc_linalg.py +892 -0
  46. trajectree/quimb/quimb/schematic.py +1518 -0
  47. trajectree/quimb/quimb/tensor/__init__.py +401 -0
  48. trajectree/quimb/quimb/tensor/array_ops.py +610 -0
  49. trajectree/quimb/quimb/tensor/circuit.py +4824 -0
  50. trajectree/quimb/quimb/tensor/circuit_gen.py +411 -0
  51. trajectree/quimb/quimb/tensor/contraction.py +336 -0
  52. trajectree/quimb/quimb/tensor/decomp.py +1255 -0
  53. trajectree/quimb/quimb/tensor/drawing.py +1646 -0
  54. trajectree/quimb/quimb/tensor/fitting.py +385 -0
  55. trajectree/quimb/quimb/tensor/geometry.py +583 -0
  56. trajectree/quimb/quimb/tensor/interface.py +114 -0
  57. trajectree/quimb/quimb/tensor/networking.py +1058 -0
  58. trajectree/quimb/quimb/tensor/optimize.py +1818 -0
  59. trajectree/quimb/quimb/tensor/tensor_1d.py +4778 -0
  60. trajectree/quimb/quimb/tensor/tensor_1d_compress.py +1854 -0
  61. trajectree/quimb/quimb/tensor/tensor_1d_tebd.py +662 -0
  62. trajectree/quimb/quimb/tensor/tensor_2d.py +5954 -0
  63. trajectree/quimb/quimb/tensor/tensor_2d_compress.py +96 -0
  64. trajectree/quimb/quimb/tensor/tensor_2d_tebd.py +1230 -0
  65. trajectree/quimb/quimb/tensor/tensor_3d.py +2869 -0
  66. trajectree/quimb/quimb/tensor/tensor_3d_tebd.py +46 -0
  67. trajectree/quimb/quimb/tensor/tensor_approx_spectral.py +60 -0
  68. trajectree/quimb/quimb/tensor/tensor_arbgeom.py +3237 -0
  69. trajectree/quimb/quimb/tensor/tensor_arbgeom_compress.py +565 -0
  70. trajectree/quimb/quimb/tensor/tensor_arbgeom_tebd.py +1138 -0
  71. trajectree/quimb/quimb/tensor/tensor_builder.py +5411 -0
  72. trajectree/quimb/quimb/tensor/tensor_core.py +11179 -0
  73. trajectree/quimb/quimb/tensor/tensor_dmrg.py +1472 -0
  74. trajectree/quimb/quimb/tensor/tensor_mera.py +204 -0
  75. trajectree/quimb/quimb/utils.py +892 -0
  76. trajectree/quimb/tests/__init__.py +0 -0
  77. trajectree/quimb/tests/test_accel.py +501 -0
  78. trajectree/quimb/tests/test_calc.py +788 -0
  79. trajectree/quimb/tests/test_core.py +847 -0
  80. trajectree/quimb/tests/test_evo.py +565 -0
  81. trajectree/quimb/tests/test_gen/__init__.py +0 -0
  82. trajectree/quimb/tests/test_gen/test_operators.py +361 -0
  83. trajectree/quimb/tests/test_gen/test_rand.py +296 -0
  84. trajectree/quimb/tests/test_gen/test_states.py +261 -0
  85. trajectree/quimb/tests/test_linalg/__init__.py +0 -0
  86. trajectree/quimb/tests/test_linalg/test_approx_spectral.py +368 -0
  87. trajectree/quimb/tests/test_linalg/test_base_linalg.py +351 -0
  88. trajectree/quimb/tests/test_linalg/test_mpi_linalg.py +127 -0
  89. trajectree/quimb/tests/test_linalg/test_numpy_linalg.py +84 -0
  90. trajectree/quimb/tests/test_linalg/test_rand_linalg.py +134 -0
  91. trajectree/quimb/tests/test_linalg/test_slepc_linalg.py +283 -0
  92. trajectree/quimb/tests/test_tensor/__init__.py +0 -0
  93. trajectree/quimb/tests/test_tensor/test_belief_propagation/__init__.py +0 -0
  94. trajectree/quimb/tests/test_tensor/test_belief_propagation/test_d1bp.py +39 -0
  95. trajectree/quimb/tests/test_tensor/test_belief_propagation/test_d2bp.py +67 -0
  96. trajectree/quimb/tests/test_tensor/test_belief_propagation/test_hd1bp.py +64 -0
  97. trajectree/quimb/tests/test_tensor/test_belief_propagation/test_hv1bp.py +51 -0
  98. trajectree/quimb/tests/test_tensor/test_belief_propagation/test_l1bp.py +142 -0
  99. trajectree/quimb/tests/test_tensor/test_belief_propagation/test_l2bp.py +101 -0
  100. trajectree/quimb/tests/test_tensor/test_circuit.py +816 -0
  101. trajectree/quimb/tests/test_tensor/test_contract.py +67 -0
  102. trajectree/quimb/tests/test_tensor/test_decomp.py +40 -0
  103. trajectree/quimb/tests/test_tensor/test_mera.py +52 -0
  104. trajectree/quimb/tests/test_tensor/test_optimizers.py +488 -0
  105. trajectree/quimb/tests/test_tensor/test_tensor_1d.py +1171 -0
  106. trajectree/quimb/tests/test_tensor/test_tensor_2d.py +606 -0
  107. trajectree/quimb/tests/test_tensor/test_tensor_2d_tebd.py +144 -0
  108. trajectree/quimb/tests/test_tensor/test_tensor_3d.py +123 -0
  109. trajectree/quimb/tests/test_tensor/test_tensor_arbgeom.py +226 -0
  110. trajectree/quimb/tests/test_tensor/test_tensor_builder.py +441 -0
  111. trajectree/quimb/tests/test_tensor/test_tensor_core.py +2066 -0
  112. trajectree/quimb/tests/test_tensor/test_tensor_dmrg.py +388 -0
  113. trajectree/quimb/tests/test_tensor/test_tensor_spectral_approx.py +63 -0
  114. trajectree/quimb/tests/test_tensor/test_tensor_tebd.py +270 -0
  115. trajectree/quimb/tests/test_utils.py +85 -0
  116. trajectree/trajectory.py +2 -2
  117. {trajectree-0.0.0.dist-info → trajectree-0.0.1.dist-info}/METADATA +2 -2
  118. trajectree-0.0.1.dist-info/RECORD +126 -0
  119. trajectree-0.0.0.dist-info/RECORD +0 -16
  120. {trajectree-0.0.0.dist-info → trajectree-0.0.1.dist-info}/WHEEL +0 -0
  121. {trajectree-0.0.0.dist-info → trajectree-0.0.1.dist-info}/licenses/LICENSE +0 -0
  122. {trajectree-0.0.0.dist-info → trajectree-0.0.1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,479 @@
1
+ """Functions for generating quantum states.
2
+ """
3
+
4
+ import itertools
5
+ import functools
6
+ import math
7
+ import numpy as np
8
+
9
+ from ..core import (dag, ldmul, dot, make_immutable,
10
+ qu, kron, eye, ikron, kronpow)
11
+ from ..linalg.base_linalg import eigh
12
+ from .operators import pauli, controlled
13
+
14
+
15
+ def basis_vec(i, dim, ownership=None, **kwargs):
16
+ r"""Constructs a unit vector ket:
17
+
18
+ .. math::
19
+
20
+ |i\rangle = \begin{pmatrix}
21
+ 0 \\ \vdots \\ 1 \\ \vdots \\ 0
22
+ \end{pmatrix}
23
+
24
+ Parameters
25
+ ----------
26
+ i : int
27
+ Which index should the single non-zero, unit entry.
28
+ dim : int
29
+ Total size of hilbert space.
30
+ sparse : bool, optional
31
+ Return vector as sparse matrix.
32
+ kwargs
33
+ Supplied to ``qu``.
34
+
35
+ Returns
36
+ -------
37
+ vector
38
+ The basis vector.
39
+ """
40
+ if ownership is None:
41
+ shape = (dim, 1)
42
+ x = np.zeros(shape, dtype=complex)
43
+ x[i] = 1.0
44
+ else:
45
+ ri, rf = ownership
46
+ shape = (rf - ri, 1)
47
+ x = np.zeros(shape, dtype=complex)
48
+ if ri <= i < rf:
49
+ x[i - ri] = 1.0
50
+
51
+ return qu(x, **kwargs)
52
+
53
+
54
+ @functools.lru_cache(8)
55
+ def up(**kwargs):
56
+ r"""Returns up-state, aka. ``|0>``, +Z eigenstate:
57
+
58
+ .. math::
59
+
60
+ |0\rangle = \begin{pmatrix}
61
+ 1 \\ 0
62
+ \end{pmatrix}
63
+
64
+ """
65
+ u = qu([[1], [0]], **kwargs)
66
+ make_immutable(u)
67
+ return u
68
+
69
+
70
+ zplus = up
71
+
72
+
73
+ @functools.lru_cache(8)
74
+ def down(**kwargs):
75
+ r"""Returns down-state, aka. ``|1>``, -Z eigenstate:
76
+
77
+ .. math::
78
+
79
+ |1\rangle = \begin{pmatrix}
80
+ 0 \\ 1
81
+ \end{pmatrix}
82
+
83
+ """
84
+ d = qu([[0], [1]], **kwargs)
85
+ make_immutable(d)
86
+ return d
87
+
88
+
89
+ zminus = down
90
+
91
+
92
+ @functools.lru_cache(8)
93
+ def plus(**kwargs):
94
+ r"""Returns plus-state, aka. ``|+>``, +X eigenstate:
95
+
96
+ .. math::
97
+
98
+ |+\rangle = \frac{1}{\sqrt{2}} \begin{pmatrix}
99
+ 1 \\ 1
100
+ \end{pmatrix}
101
+
102
+ """
103
+ return qu([[2**-0.5], [2**-0.5]], **kwargs)
104
+
105
+
106
+ xplus = plus
107
+
108
+
109
+ @functools.lru_cache(8)
110
+ def minus(**kwargs):
111
+ r"""Returns minus-state, aka. ``|->``, -X eigenstate:
112
+
113
+ .. math::
114
+
115
+ |-\rangle = \frac{1}{\sqrt{2}} \begin{pmatrix}
116
+ 1 \\ -1
117
+ \end{pmatrix}
118
+
119
+ """
120
+ return qu([[2**-0.5], [-2**-0.5]], **kwargs)
121
+
122
+
123
+ xminus = minus
124
+
125
+
126
+ @functools.lru_cache(8)
127
+ def yplus(**kwargs):
128
+ r"""Returns yplus-state, aka. ``|y+>``, +Y eigenstate:
129
+
130
+ .. math::
131
+
132
+ |y+\rangle = \frac{1}{\sqrt{2}} \begin{pmatrix}
133
+ 1 \\ i
134
+ \end{pmatrix}
135
+
136
+ """
137
+ return qu([[2**-0.5], [1.0j / (2**0.5)]], **kwargs)
138
+
139
+
140
+ @functools.lru_cache(8)
141
+ def yminus(**kwargs):
142
+ r"""Returns yplus-state, aka. ``|y->``, -Y eigenstate:
143
+
144
+ .. math::
145
+
146
+ |y-\rangle = \frac{1}{\sqrt{2}} \begin{pmatrix}
147
+ 1 \\ -i
148
+ \end{pmatrix}
149
+
150
+ """
151
+ return qu([[2**-0.5], [-1.0j / (2**0.5)]], **kwargs)
152
+
153
+
154
+ def bloch_state(ax, ay, az, purified=False, **kwargs):
155
+ r"""Construct qubit density operator from bloch vector:
156
+
157
+ .. math::
158
+
159
+ \rho = \frac{1}{2} \left( I + a_x X + a_y Y + a_z Z \right)
160
+
161
+ Parameters
162
+ ----------
163
+ ax : float
164
+ X component of bloch vector.
165
+ ay : float
166
+ Y component of bloch vector.
167
+ az : float
168
+ Z component of bloch vector.
169
+ purified :
170
+ Whether to map vector to surface of bloch sphere.
171
+
172
+ Returns
173
+ -------
174
+ Matrix
175
+ Density operator of qubit 'pointing' in (ax, ay, az) direction.
176
+ """
177
+ n = (ax**2 + ay**2 + az**2)**.5
178
+ if purified:
179
+ ax, ay, az = (a / n for a in (ax, ay, az))
180
+ return sum(0.5 * a * pauli(s, **kwargs)
181
+ for a, s in zip((1, ax, ay, az), "ixyz"))
182
+
183
+
184
+ @functools.lru_cache(maxsize=8)
185
+ def bell_state(s, **kwargs):
186
+ r"""One of the four bell-states.
187
+
188
+ If n = 2**-0.5, they are:
189
+
190
+ 0. ``'psi-'`` : ``n * ( |01> - |10> )``
191
+ 1. ``'psi+'`` : ``n * ( |01> + |10> )``
192
+ 2. ``'phi-'`` : ``n * ( |00> - |11> )``
193
+ 3. ``'phi+'`` : ``n * ( |00> + |11> )``
194
+
195
+ They can be enumerated in this order.
196
+
197
+ Parameters
198
+ ----------
199
+ s : str or int
200
+ String of number of state corresponding to above.
201
+ kwargs :
202
+ Supplied to ``qu`` called on state.
203
+
204
+ Returns
205
+ -------
206
+ p : immutable vector
207
+ The bell-state ``s``.
208
+ """
209
+ keymap = {"psi-": "psi-", 0: "psi-", "psim": "psi-",
210
+ "psi+": "psi+", 1: "psi+", "psip": "psi+",
211
+ "phi-": "phi-", 2: "phi-", "phim": "phi-",
212
+ "phi+": "phi+", 3: "phi+", "phip": "phi+"}
213
+ c = 2.**-.5
214
+ statemap = {"psi-": lambda: qu([0, c, -c, 0], **kwargs),
215
+ "phi+": lambda: qu([c, 0, 0, c], **kwargs),
216
+ "phi-": lambda: qu([c, 0, 0, -c], **kwargs),
217
+ "psi+": lambda: qu([0, c, c, 0], **kwargs)}
218
+ state = statemap[keymap[s]]()
219
+ make_immutable(state)
220
+ return state
221
+
222
+
223
+ def singlet(**kwargs):
224
+ """Alias for the 'psi-' bell-state.
225
+ """
226
+ return bell_state("psi-", **kwargs)
227
+
228
+
229
+ def thermal_state(ham, beta, precomp_func=False):
230
+ """Generate a thermal state of a Hamiltonian.
231
+
232
+ Parameters
233
+ ----------
234
+ ham : operator or (1d-array, 2d-array)
235
+ Hamiltonian, either full or tuple of (evals, evecs).
236
+ beta : float
237
+ Inverse temperature of state.
238
+ precomp_func : bool, optional
239
+ If True, return a function that takes ``beta``
240
+ only and is closed over the solved hamiltonian.
241
+
242
+ Returns
243
+ -------
244
+ operator or callable
245
+ Density operator of thermal state, or function to generate such given
246
+ a temperature.
247
+ """
248
+ if isinstance(ham, (list, tuple)): # solved already
249
+ evals, evecs = ham
250
+ else:
251
+ evals, evecs = eigh(ham)
252
+ evals -= evals.min() # offset by min to avoid numeric problems
253
+
254
+ def gen_state(b):
255
+ el = np.exp(-b * evals)
256
+ el /= np.sum(el)
257
+ return dot(evecs, ldmul(el, dag(evecs)))
258
+
259
+ return gen_state if precomp_func else gen_state(beta)
260
+
261
+
262
+ def computational_state(binary, **kwargs):
263
+ """Generate the qubit computational state with ``binary``.
264
+
265
+ Parameters
266
+ ----------
267
+ binary : sequence of 0s and 1s
268
+ The binary of the computation state.
269
+
270
+ Examples
271
+ --------
272
+ >>> computational_state('101'):
273
+ qarray([[0.+0.j],
274
+ [0.+0.j],
275
+ [0.+0.j],
276
+ [0.+0.j],
277
+ [0.+0.j],
278
+ [1.+0.j],
279
+ [0.+0.j],
280
+ [0.+0.j]])
281
+
282
+ >>> qu.computational_state([0, 1], qtype='dop')
283
+ qarray([[0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],
284
+ [0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j],
285
+ [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],
286
+ [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j]])
287
+
288
+ See Also
289
+ --------
290
+ MPS_computational_state, basic_vec
291
+ """
292
+ if not isinstance(binary, str):
293
+ binary = "".join(map(str, binary))
294
+
295
+ return basis_vec(int(binary, 2), 2 ** len(binary), **kwargs)
296
+
297
+
298
+ def neel_state(n, down_first=False, **kwargs):
299
+ """Construct Neel state for n spins, i.e. alternating up/down.
300
+
301
+ Parameters
302
+ ----------
303
+ n : int
304
+ Number of spins.
305
+ down_first : bool, optional
306
+ Whether to start with '1' or '0' first.
307
+ kwargs
308
+ Supplied to ``qu`` called on state.
309
+
310
+ See Also
311
+ --------
312
+ computational_state, MPS_neel_state
313
+ """
314
+ binary = "01" * (n // 2) + (n % 2 == 1) * "0"
315
+ if down_first:
316
+ binary = "1" + binary[:-1]
317
+
318
+ return computational_state(binary, **kwargs)
319
+
320
+
321
+ def singlet_pairs(n, **kwargs):
322
+ """Construct fully dimerised spin chain.
323
+
324
+ I.e. ``bell_state('psi-') & bell_state('psi-') & ...``
325
+
326
+ Parameters
327
+ ----------
328
+ n : int
329
+ Number of spins.
330
+ kwargs
331
+ Supplied to ``qu`` called on state.
332
+
333
+ Returns
334
+ -------
335
+ vector
336
+ """
337
+ return kronpow(bell_state('psi-', **kwargs), (n // 2))
338
+
339
+
340
+ def werner_state(p, **kwargs):
341
+ """Construct Werner State, i.e. fractional mix of identity with singlet.
342
+
343
+ Parameters
344
+ ----------
345
+ p : float
346
+ Singlet Fraction.
347
+ kwargs
348
+ Supplied to :func:`~quimb.qu` called on state.
349
+
350
+ Returns
351
+ -------
352
+ qarray
353
+ """
354
+ return (p * bell_state('psi-', qtype="dop", **kwargs) +
355
+ (1 - p) * eye(4, **kwargs) / 4)
356
+
357
+
358
+ def ghz_state(n, **kwargs):
359
+ """Construct GHZ state of `n` spins, i.e. equal superposition of all up
360
+ and down.
361
+
362
+ Parameters
363
+ ----------
364
+ n : int
365
+ Number of spins.
366
+ kwargs
367
+ Supplied to ``qu`` called on state.
368
+
369
+ Returns
370
+ -------
371
+ vector
372
+ """
373
+ psi = (basis_vec(0, 2**n) +
374
+ basis_vec(2**n - 1, 2**n)) / 2.**.5
375
+ return qu(psi, **kwargs)
376
+
377
+
378
+ def w_state(n, **kwargs):
379
+ """Construct W-state: equal superposition of all single spin up states.
380
+
381
+ Parameters
382
+ ----------
383
+ n : int
384
+ Number of spins.
385
+ kwargs
386
+ Supplied to ``qu`` called on state.
387
+
388
+ Returns
389
+ -------
390
+ vector
391
+ """
392
+ return sum(basis_vec(2**i, 2**n, **kwargs) for i in range(n)) / n**0.5
393
+
394
+
395
+ def levi_civita(perm):
396
+ """Compute the generalised levi-civita coefficient for a permutation.
397
+
398
+ Parameters
399
+ ----------
400
+ perm : sequence of int
401
+ The permutation, a re-arrangement of ``range(n)``.
402
+
403
+ Returns
404
+ -------
405
+ int
406
+ Either -1, 0 or 1.
407
+ """
408
+ n = len(perm)
409
+ if n != len(set(perm)): # infer there are repeated elements
410
+ return 0
411
+ mat = np.zeros((n, n), dtype=np.int32)
412
+ for i, j in zip(range(n), perm):
413
+ mat[i, j] = 1
414
+ return int(np.linalg.det(mat))
415
+
416
+
417
+ def perm_state(ps):
418
+ """Construct the anti-symmetric state which is the +- sum of all
419
+ tensored permutations of states ``ps``.
420
+
421
+ Parameters
422
+ ----------
423
+ ps : sequence of states
424
+ The states to combine.
425
+
426
+ Returns
427
+ -------
428
+ vector or operator
429
+ The permutation state, dimension same as ``kron(*ps)``.
430
+
431
+ Examples
432
+ --------
433
+ A singlet is the ``perm_state`` of up and down.
434
+
435
+ >>> states = [up(), down()]
436
+ >>> pstate = perm_state(states)
437
+ >>> expec(pstate, singlet())
438
+ 1.0
439
+ """
440
+ n = len(ps)
441
+ vec_perm = itertools.permutations(ps)
442
+ ind_perm = itertools.permutations(range(n))
443
+
444
+ def terms():
445
+ for vec, ind in zip(vec_perm, ind_perm):
446
+ yield levi_civita(ind) * kron(*vec)
447
+
448
+ return sum(terms()) / math.factorial(n)**0.5
449
+
450
+
451
+ def graph_state_1d(n, cyclic=False, sparse=False):
452
+ """Graph State on a line.
453
+
454
+ Parameters
455
+ ----------
456
+ n : int
457
+ The number of spins.
458
+ cyclic : bool, optional
459
+ Whether to use cyclic boundary conditions for the graph.
460
+ sparse : bool, optional
461
+ Whether to return a sparse state.
462
+
463
+ Returns
464
+ -------
465
+ vector
466
+ The 1d-graph state.
467
+ """
468
+ p = kronpow(plus(sparse=sparse), n)
469
+
470
+ for i in range(n - 1):
471
+ p = ikron(controlled("z", sparse=True), [2] * n, (i, i + 1)) @ p
472
+
473
+ if cyclic:
474
+ p = ((eye(2, sparse=True) & eye(2**(n - 2), sparse=True) &
475
+ qu([1, 0], qtype="dop", sparse=True)) +
476
+ (pauli("z", sparse=True) & eye(2**(n - 2), sparse=True) &
477
+ qu([0, 1], qtype="dop", sparse=True))) @ p
478
+
479
+ return p
@@ -0,0 +1,6 @@
1
+ """Linear algebra routines to solve quantum systems for example.
2
+ """
3
+
4
+ from ..utils import find_library
5
+
6
+ SLEPC4PY_FOUND = find_library("slepc4py")