From 63e1bd7a4ca37252756faefc35c5f4118ddb3195 Mon Sep 17 00:00:00 2001 From: Johnnie Gray Date: Mon, 21 Oct 2024 18:59:11 -0700 Subject: [PATCH] add PEPS.zeros --- quimb/tensor/tensor_2d.py | 34 +++++++++++++++++++++++++++++ tests/test_tensor/test_tensor_2d.py | 6 +++++ 2 files changed, 40 insertions(+) diff --git a/quimb/tensor/tensor_2d.py b/quimb/tensor/tensor_2d.py index 2201bf29..1d501e17 100644 --- a/quimb/tensor/tensor_2d.py +++ b/quimb/tensor/tensor_2d.py @@ -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, diff --git a/tests/test_tensor/test_tensor_2d.py b/tests/test_tensor/test_tensor_2d.py index 4c6a6ac7..0bd896b8 100644 --- a/tests/test_tensor/test_tensor_2d.py +++ b/tests/test_tensor/test_tensor_2d.py @@ -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