def init_mps_random(nsites, physdim, bonddim=1, left_label='left',
right_label='right', phys_label='phys'):
"""
Create an MPS with `nsites` sites and random tensors with physical
dimensions given by `physdim` and bond dimensions given by
`bonddim`. Open boundary conditions are used. The MPS is not normalized.
Parameters
----------
nsites : int
physdim : int or list of ints
bonddim : int or list of ints, optional
The nth element of `bonddim` determines the right and left index of
the tensors at sites n and n+1, respectively. The length of `bonddim`
should be `nsites`-1. If `bonddim` is an int this is this is used for
all bonds.
left_label : str
right_label : str
phys_label : str
"""
if not np.iterable(physdim):
physdim = [physdim] * nsites
if not np.iterable(bonddim):
bonddim = [bonddim] * (nsites - 1)
bonddim = [1] + bonddim + [1]
tensors = []
for i in range(nsites):
rt = tnc.Tensor(np.random.rand(
physdim[i], bonddim[i], bonddim[i + 1]),
[phys_label, left_label, right_label])
# Normalize matrix to avoid norm blowing up
U, S, V = tnc.tensor_svd(rt, [phys_label, left_label])
S.data = S.data / S.data[0, 0]
rt = U["svd_in",] * S["svd_out",]
rt = rt["svd_in",] * V["svd_out",]
tensors.append(rt)
return onedim.MatrixProductState(tensors, left_label=left_label,
right_label=right_label, phys_label=phys_label)
评论列表
文章目录