Skip to content

Commit 63e1bd7

Browse files
committed
add PEPS.zeros
1 parent b08a113 commit 63e1bd7

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

quimb/tensor/tensor_2d.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5008,6 +5008,40 @@ def ones(cls, Lx, Ly, bond_dim, phys_dim=2, like="numpy", **peps_opts):
50085008
**peps_opts,
50095009
)
50105010

5011+
@classmethod
5012+
def zeros(cls, Lx, Ly, bond_dim, phys_dim=2, like="numpy", **peps_opts):
5013+
"""Create a 2D PEPS whose tensors are filled with zeros.
5014+
5015+
Parameters
5016+
----------
5017+
Lx : int
5018+
The number of rows.
5019+
Ly : int
5020+
The number of columns.
5021+
bond_dim : int
5022+
The bond dimension.
5023+
physical : int, optional
5024+
The physical index dimension.
5025+
peps_opts
5026+
Supplied to :class:`~quimb.tensor.tensor_2d.PEPS`.
5027+
5028+
Returns
5029+
-------
5030+
psi : PEPS
5031+
5032+
See Also
5033+
--------
5034+
PEPS.from_fill_fn
5035+
"""
5036+
return cls.from_fill_fn(
5037+
lambda shape: ar.do("zeros", shape, like=like),
5038+
Lx,
5039+
Ly,
5040+
bond_dim,
5041+
phys_dim,
5042+
**peps_opts,
5043+
)
5044+
50115045
@classmethod
50125046
def rand(
50135047
cls,

tests/test_tensor/test_tensor_2d.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ def test_cyclic_edge_cases(self):
5353
assert peps.is_cyclic_y()
5454
assert peps.num_indices == peps.num_tensors * 3
5555

56+
def test_zeros(self):
57+
peps = qtn.PEPS.zeros(3, 3, cyclic=True, bond_dim=1)
58+
assert peps.num_tensors == 9
59+
assert peps.num_indices == 27
60+
assert_allclose(peps.to_dense(), np.zeros([512, 1]))
61+
5662
def test_flatten(self):
5763
psi = qtn.PEPS.rand(3, 5, 3, seed=42)
5864
norm = psi.H & psi

0 commit comments

Comments
 (0)