Skip to content

tencirlab.peps

Source · Used by: Figure 2(a,b) · 6×6 PEPS versus exact densities

Single-layer PEPS amplitudes on open square lattices for variational Monte Carlo, bosonic or fermionic, contracted exactly along a cached path.

PEPS

PEPS on an open rows x columns square lattice, site i = y * columns + x.

Site tensors have legs (physical, left, right, down, up); legs on the boundary have dimension one. The parameters are one flat complex vector holding the free tensor entries site by site. A bosonic PEPS has all entries free. A fermionic PEPS keeps only parity-even entries, where physical index p and virtual index k carry parity p % 2 and k % 2, and absorbs the swap of each occupied physical leg with the up legs it crosses on its way to the left boundary of its row, the convention of arXiv:2506.20106.

The sampled single-layer network is contracted exactly along a path searched once at construction. Its cost grows exponentially with the shorter side, so this suits lattices up to about 8 x 8 at D=4; larger ones need boundary-MPS contraction, which is not implemented here.

Source code in tencirlab/peps.py
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
class PEPS:
    """
    PEPS on an open ``rows x columns`` square lattice, site ``i = y * columns + x``.

    Site tensors have legs ``(physical, left, right, down, up)``; legs on the
    boundary have dimension one. The parameters are one flat complex vector holding
    the free tensor entries site by site. A bosonic PEPS has all entries free. A
    fermionic PEPS keeps only parity-even entries, where physical index ``p`` and
    virtual index ``k`` carry parity ``p % 2`` and ``k % 2``, and absorbs the swap of
    each occupied physical leg with the up legs it crosses on its way to the left
    boundary of its row, the convention of arXiv:2506.20106.

    The sampled single-layer network is contracted exactly along a path searched
    once at construction. Its cost grows exponentially with the shorter side, so
    this suits lattices up to about 8 x 8 at D=4; larger ones need boundary-MPS
    contraction, which is not implemented here.
    """

    def __init__(
        self,
        rows: int,
        columns: int,
        bond_dim: int,
        phys_dim: int = 2,
        fermionic: bool = True,
    ):
        self.rows, self.columns = rows, columns
        self.nsites = rows * columns
        self.bond_dim, self.fermionic = bond_dim, fermionic
        self.shapes, self.coordinates, self.flat, self.offsets = [], [], [], [0]
        for y in range(rows):
            for x in range(columns):
                shape = (
                    phys_dim,
                    bond_dim if x > 0 else 1,
                    bond_dim if x < columns - 1 else 1,
                    bond_dim if y > 0 else 1,
                    bond_dim if y < rows - 1 else 1,
                )
                coordinates = [
                    c
                    for c in itertools.product(*map(range, shape))
                    if not fermionic or sum(c) % 2 == 0
                ]
                self.shapes.append(shape)
                self.coordinates.append(coordinates)
                self.flat.append(np.ravel_multi_index(np.array(coordinates).T, shape))
                self.offsets.append(self.offsets[-1] + len(coordinates))
        self.nparams = self.offsets[-1]
        labels = [[None] * 4 for _ in range(self.nsites)]
        bond = 0
        for i in range(self.nsites):
            y, x = divmod(i, self.columns)
            if x < self.columns - 1:
                labels[i][1] = labels[i + 1][0] = bond
                bond += 1
            if y < self.rows - 1:
                labels[i][3] = labels[i + self.columns][2] = bond
                bond += 1
        self._labels = [[b for b in site if b is not None] for site in labels]
        self._squeezed = [[self.bond_dim] * len(site) for site in self._labels]
        equation = (
            ",".join("".join(map(oe.get_symbol, site)) for site in self._labels) + "->"
        )
        self._path, _ = oe.contract_path(
            equation,
            *self._squeezed,
            shapes=True,
            optimize=oe.RandomGreedy(max_repeats=128),
        )

    def random_parameters(self, key: jax.Array) -> jax.Array:
        k1, k2 = jax.random.split(key)
        theta = jax.random.normal(k1, (self.nparams,)) + 1j * jax.random.normal(
            k2, (self.nparams,)
        )
        return self.normalize(theta)

    def normalize(self, theta: jax.Array) -> jax.Array:
        """Scale each site tensor to unit norm, which leaves the state unchanged."""
        return jnp.concatenate(
            [
                theta[a:b] / jnp.linalg.norm(theta[a:b])
                for a, b in zip(self.offsets[:-1], self.offsets[1:])
            ]
        )

    def tensors(self, theta: jax.Array) -> list[jax.Array]:
        return [
            jnp.zeros(math.prod(shape), theta.dtype)
            .at[flat]
            .set(theta[a:b])
            .reshape(shape)
            for shape, flat, a, b in zip(
                self.shapes, self.flat, self.offsets[:-1], self.offsets[1:]
            )
        ]

    def sliced(self, theta: jax.Array, occupation: jax.Array) -> list[jax.Array]:
        """Site tensors ``(left, right, down, up)`` at the given physical indices."""
        tensors = [t[occupation[i]] for i, t in enumerate(self.tensors(theta))]
        if not self.fermionic:
            return tensors
        grid = occupation.reshape(self.rows, self.columns) % 2
        # occupied sites to the right of each site in its row
        right = grid.sum(axis=1, keepdims=True) - jnp.cumsum(grid, axis=1)
        signed = []
        for i, t in enumerate(tensors):
            y, x = divmod(i, self.columns)
            parity = np.arange(t.shape[3]) % 2
            signed.append(t * (1 - 2 * ((right[y, x] * parity) % 2)))
        return signed

    def amplitude(self, theta: jax.Array, occupation: jax.Array) -> jax.Array:
        """Amplitude of one configuration, ``occupation`` an integer vector."""
        operands = []
        for t, shape, labels in zip(
            self.sliced(theta, occupation), self._squeezed, self._labels
        ):
            operands += [t.reshape(shape), labels]
        return jnp.einsum(*operands, [], optimize=self._path)

    def embed(self, theta: jax.Array, smaller: "PEPS") -> jax.Array:
        """Parameters of this PEPS representing the state of a smaller-D one."""
        positions = []
        for offset, small, large in zip(
            self.offsets, smaller.coordinates, self.coordinates
        ):
            index = {c: k for k, c in enumerate(large)}
            positions += [offset + index[c] for c in small]
        return jnp.zeros(self.nparams, theta.dtype).at[np.array(positions)].set(theta)

normalize

normalize(theta: Array) -> jax.Array

Scale each site tensor to unit norm, which leaves the state unchanged.

Source code in tencirlab/peps.py
 93
 94
 95
 96
 97
 98
 99
100
def normalize(self, theta: jax.Array) -> jax.Array:
    """Scale each site tensor to unit norm, which leaves the state unchanged."""
    return jnp.concatenate(
        [
            theta[a:b] / jnp.linalg.norm(theta[a:b])
            for a, b in zip(self.offsets[:-1], self.offsets[1:])
        ]
    )

sliced

sliced(theta: Array, occupation: Array) -> list[jax.Array]

Site tensors (left, right, down, up) at the given physical indices.

Source code in tencirlab/peps.py
113
114
115
116
117
118
119
120
121
122
123
124
125
126
def sliced(self, theta: jax.Array, occupation: jax.Array) -> list[jax.Array]:
    """Site tensors ``(left, right, down, up)`` at the given physical indices."""
    tensors = [t[occupation[i]] for i, t in enumerate(self.tensors(theta))]
    if not self.fermionic:
        return tensors
    grid = occupation.reshape(self.rows, self.columns) % 2
    # occupied sites to the right of each site in its row
    right = grid.sum(axis=1, keepdims=True) - jnp.cumsum(grid, axis=1)
    signed = []
    for i, t in enumerate(tensors):
        y, x = divmod(i, self.columns)
        parity = np.arange(t.shape[3]) % 2
        signed.append(t * (1 - 2 * ((right[y, x] * parity) % 2)))
    return signed

amplitude

amplitude(theta: Array, occupation: Array) -> jax.Array

Amplitude of one configuration, occupation an integer vector.

Source code in tencirlab/peps.py
128
129
130
131
132
133
134
135
def amplitude(self, theta: jax.Array, occupation: jax.Array) -> jax.Array:
    """Amplitude of one configuration, ``occupation`` an integer vector."""
    operands = []
    for t, shape, labels in zip(
        self.sliced(theta, occupation), self._squeezed, self._labels
    ):
        operands += [t.reshape(shape), labels]
    return jnp.einsum(*operands, [], optimize=self._path)

embed

embed(theta: Array, smaller: PEPS) -> jax.Array

Parameters of this PEPS representing the state of a smaller-D one.

Source code in tencirlab/peps.py
137
138
139
140
141
142
143
144
145
def embed(self, theta: jax.Array, smaller: "PEPS") -> jax.Array:
    """Parameters of this PEPS representing the state of a smaller-D one."""
    positions = []
    for offset, small, large in zip(
        self.offsets, smaller.coordinates, self.coordinates
    ):
        index = {c: k for k, c in enumerate(large)}
        positions += [offset + index[c] for c in small]
    return jnp.zeros(self.nparams, theta.dtype).at[np.array(positions)].set(theta)

History

Date Pull request Kind Change
2026-12-01 #10 migration Fermionic PEPS–tVMC corner quench