grid_outer

tenpy.linalg.np_conserved.grid_outer(grid, grid_legs, qtotal=None, grid_labels=None)[source]

Given an np.array of npc.Arrays, return the corresponding higher-dimensional Array.

Parameters:
  • grid (array_like of {Array | None}) – The grid gives the first part of the axes of the resulting array. Entries have to have all the same shape and charge-data, giving the remaining axes. None entries in the grid are interpreted as zeros.

  • grid_legs (list of LegCharge) – One LegCharge for each dimension of the grid along the grid.

  • qtotal (charge) – The total charge of the Array. By default (None), derive it out from a non-trivial entry of the grid.

  • grid_labels (list of {str | None}) – One label associated to each of the grid axes. None for non-named labels.

Returns:

res – An Array with shape grid.shape + nontrivial_grid_entry.shape. Constructed such that res[idx] == grid[idx] for any index idx of the grid the grid entry is not trivial (None).

Return type:

Array

See also

detect_grid_outer_legcharge

can calculate one missing LegCharge of the grid.

Examples

A typical use-case for this function is the generation of an MPO. Say you have npc.Arrays Splus, Sminus, Sz, Id, each with legs [phys.conj(), phys]. Further, you have to define appropriate LegCharges l_left and l_right. Then one ‘matrix’ of the MPO for a nearest neighbor Heisenberg Hamiltonian could look like:

>>> s = tenpy.networks.site.SpinHalfSite(conserve='Sz')
>>> Id, Splus, Sminus, Sz = s.Id, s.Sp, s.Sm, s.Sz
>>> J = 1.
>>> leg_wR = npc.LegCharge.from_qflat(s.leg.chinfo,
...                                   [op.qtotal for op in [Id, Splus, Sminus, Sz, Id]],
...                                   qconj=-1)
>>> W_mpo = npc.grid_outer([[Id, Splus, Sminus, Sz, None],
...                         [None, None, None, None, J*0.5*Sminus],
...                         [None, None, None, None, J*0.5*Splus],
...                         [None, None, None, None, J*Sz],
...                         [None, None, None, None, Id]],
...                        grid_legs=[leg_wR.conj(), leg_wR],
...                        grid_labels=['wL', 'wR'])
>>> W_mpo.shape
(5, 5, 2, 2)
>>> W_mpo.get_leg_labels()
['wL', 'wR', 'p', 'p*']