Skip to content

Commit

Permalink
add PEPS.zeros
Browse files Browse the repository at this point in the history
  • Loading branch information
jcmgray committed Oct 22, 2024
1 parent b08a113 commit 63e1bd7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
34 changes: 34 additions & 0 deletions quimb/tensor/tensor_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -5008,6 +5008,40 @@ def ones(cls, Lx, Ly, bond_dim, phys_dim=2, like="numpy", **peps_opts):
**peps_opts,
)

@classmethod
def zeros(cls, Lx, Ly, bond_dim, phys_dim=2, like="numpy", **peps_opts):
"""Create a 2D PEPS whose tensors are filled with zeros.
Parameters
----------
Lx : int
The number of rows.
Ly : int
The number of columns.
bond_dim : int
The bond dimension.
physical : int, optional
The physical index dimension.
peps_opts
Supplied to :class:`~quimb.tensor.tensor_2d.PEPS`.
Returns
-------
psi : PEPS
See Also
--------
PEPS.from_fill_fn
"""
return cls.from_fill_fn(
lambda shape: ar.do("zeros", shape, like=like),
Lx,
Ly,
bond_dim,
phys_dim,
**peps_opts,
)

@classmethod
def rand(
cls,
Expand Down
6 changes: 6 additions & 0 deletions tests/test_tensor/test_tensor_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ def test_cyclic_edge_cases(self):
assert peps.is_cyclic_y()
assert peps.num_indices == peps.num_tensors * 3

def test_zeros(self):
peps = qtn.PEPS.zeros(3, 3, cyclic=True, bond_dim=1)
assert peps.num_tensors == 9
assert peps.num_indices == 27
assert_allclose(peps.to_dense(), np.zeros([512, 1]))

def test_flatten(self):
psi = qtn.PEPS.rand(3, 5, 3, seed=42)
norm = psi.H & psi
Expand Down

0 comments on commit 63e1bd7

Please sign in to comment.