@@ -305,3 +305,53 @@ function get_artifact_path(artifact_name::String)
305305 artifact_hash = Pkg. Artifacts. artifact_hash (artifact_name, artifact_toml)
306306 return Pkg. Artifacts. artifact_path (artifact_hash)
307307end
308+
309+ """
310+ $TYPEDSIGNATURES
311+
312+ Matrix product state (MPS) is a tensor network model that is widely used in
313+ quantum many-body physics. It is a special case of tensor network model where
314+ the tensors are rank-3 tensors and the physical indices are connected in a
315+ chain. The MPS is defined as:
316+
317+ ```math
318+ \\ begin{align*}
319+ \\ left| \\ psi \\ right\\ rangle &= \\ sum_{x_1, x_2, \\ ldots, x_n} \\ text{Tr}(A_1^{x_1} A_2^{x_2} \\ cdots A_n^{x_n}) \\ left| x_1, x_2, \\ ldots, x_n \\ right\\ rangle \\\\
320+ \\ left\\ langle \\ psi \\ right| &= \\ sum_{x_1, x_2, \\ ldots, x_n} \\ text{Tr}(A_n^{x_n} \\ cdots A_2^{x_2} A_1^{x_1}) \\ left\\ langle x_1, x_2, \\ ldots, x_n \\ right|
321+ \\ end{align*}
322+ ```
323+
324+ where \$ A_i^{x_i}\$ is a rank-3 tensor with physical index \$ x_i\$ and two virtual
325+ indices connecting to the next tensor. The MPS is a special case of the tensor
326+ network model where the tensors are rank-3 tensors and the physical indices are
327+ connected in a chain.
328+
329+ ### Arguments
330+ - `n` is the number of physical indices.
331+ - `chi` is the bond dimension of the virtual indices.
332+ - `d` is the dimension of the physical indices.
333+ """
334+ function matrix_product_state (n:: Int , chi:: Int , d:: Int = 2 )
335+ tensors = Any[randn (ComplexF64, d, chi)]
336+ physical_indices = collect (1 : n)
337+ virtual_indices_ket = collect (n+ 1 : 2 n- 1 )
338+ virtual_indices_bra = collect (2 n: 3 n- 2 )
339+ ixs_ket = [[physical_indices[1 ], virtual_indices_ket[1 ]]]
340+ ixs_bra = [[physical_indices[1 ], virtual_indices_bra[1 ]]]
341+ for i = 2 : n- 1
342+ push! (tensors, randn (ComplexF64, chi, d, chi))
343+ push! (ixs_ket, [virtual_indices_ket[i- 1 ], physical_indices[i], virtual_indices_ket[i]])
344+ push! (ixs_bra, [virtual_indices_bra[i- 1 ], physical_indices[i], virtual_indices_bra[i]])
345+ end
346+ push! (tensors, randn (ComplexF64, chi, d))
347+ push! (ixs_ket, [virtual_indices_ket[n- 1 ], physical_indices[n]])
348+ push! (ixs_bra, [virtual_indices_bra[n- 1 ], physical_indices[n]])
349+ tensors, ixs = [tensors... , conj .(tensors)... ], [ixs_ket... , ixs_bra... ]
350+ return TensorNetworkModel (
351+ collect (1 : 3 n- 2 ),
352+ optimize_code (DynamicEinCode (ixs, Int[]), OMEinsum. get_size_dict (ixs, tensors), GreedyMethod ()),
353+ tensors,
354+ Dict {Int, Int} (),
355+ Vector{Int}[[i] for i= 1 : n]
356+ )
357+ end
0 commit comments