Site¶
full name: tenpy.networks.site.Site
parent module:
tenpy.networks.sitetype: class
-
class
tenpy.networks.site.Site(leg, state_labels=None, **site_ops)[source]¶ Bases:
objectCollects necessary information about a single local site of a lattice.
This class defines what the local basis states are: it provides the
legdefining the charges of the physical leg for this site. Moreover, it stores (local) on-site operators, which are directly available as attribute, e.g.,self.Szis the Sz operator for theSpinSite. Alternatively, operators can be obained withget_op(). The operator namesIdandJWare reserved for the identy and Jordan-Wigner strings.Warning
The order of the local basis can change depending on the charge conservation! This is a necessary feature since we need to sort the basis by charges for efficiency. We use the
state_labelsandpermto keep track of these permutations.- Parameters
- leg
LegCharge Charges of the physical states, to be used for the physical leg of MPS.
- state_labelsNone | list of str
Optionally a label for each local basis states.
Noneentries are ignored / not set.- **site_ops :
Additional keyword arguments of the form
name=opgiven toadd_op(). The identity operator'Id'is automatically included. If no'JW'for the Jordan-Wigner string is given,'JW'is set as an alias to'Id'.
- leg
Examples
The following generates a site for spin-1/2 with Sz conservation. Note that
Sx = (Sp + Sm)/2violates Sz conservation and is thus not a valid on-site operator.>>> chinfo = npc.ChargeInfo([1], ['Sz']) >>> ch = npc.LegCharge.from_qflat(chinfo, [1, -1]) >>> Sp = [[0, 1.], [0, 0]] >>> Sm = [[0, 0], [1., 0]] >>> Sz = [[0.5, 0], [0, -0.5]] >>> site = Site(ch, ['up', 'down'], Splus=Sp, Sminus=Sm, Sz=Sz) >>> print(site.Splus.to_ndarray()) array([[ 0., 1.], [ 0., 0.]]) >>> print(site.get_op('Sminus').to_ndarray()) array([[ 0., 0.], [ 1., 0.]]) >>> print(site.get_op('Splus Sminus').to_ndarray()) array([[ 1., 0.], [ 0., 0.]])
- Attributes
dimDimension of the local Hilbert space.
onsite_opsDictionary of on-site operators for iteration.
- leg
LegCharge Charges of the local basis states.
- state_labels{str: int}
(Optional) labels for the local basis states.
- opnamesset
Labels of all onsite operators (i.e.
self.opexists if'op'inself.opnames). Note thatget_op()allows arbitrary concatenations of them.- need_JW_stringset
Labels of all onsite operators that need a Jordan-Wigner string. Used in
op_needs_JW()to determine whether an operator anticommutes or commutes with operators on other sites.- ops
Array Onsite operators are added directly as attributes to self. For example after
self.add_op('Sz', Sz)you can useself.Szfor the Sz operator. All onsite operators have labels'p', 'p*'.- perm1D array
Index permutation of the physical leg compared to conserve=None, i.e.
OP_conserved = OP_nonconserved[np.ix_(perm,perm)]andperm[state_labels_conserved["some_state"]] == state_labels_nonconserved["some_state"].- JW_exponent1D array
Exponents of the
'JW'operator, such thatself.JW.to_ndarray() = np.diag(np.exp(1.j*np.pi* JW_exponent))
Methods
add_op(self, name, op[, need_JW])Add one on-site operators.
change_charge(self[, new_leg_charge, permute])Change the charges of the site (in place).
get_op(self, name)Return operator of given name.
multiply_op_names(self, names)Multiply operator names together.
op_needs_JW(self, name)Whether an (composite) onsite operator is fermionic and needs a Jordan-Wigner string.
remove_op(self, name)Remove an added operator.
rename_op(self, old_name, new_name)Rename an added operator.
state_index(self, label)Return index of a basis state from its label.
state_indices(self, labels)Same as
state_index(), but for multiple labels.test_sanity(self)Sanity check, raises ValueErrors, if something is wrong.
valid_opname(self, name)Check whether ‘name’ labels a valid onsite-operator.
-
change_charge(self, new_leg_charge=None, permute=None)[source]¶ Change the charges of the site (in place).
- Parameters
- new_leg_charge
LegCharge| None The new charges to be used. If
None, use trivial charges.- permutendarray | None
The permuation applied to the physical leg, which gets used to adjust
state_labelsandperm. If you sorted the previous leg withperm_qind, new_leg_charge = leg.sort(), useleg.perm_flat_from_perm_qind(perm_qind). Ignored ifNone.
- new_leg_charge
-
property
dim¶ Dimension of the local Hilbert space.
-
property
onsite_ops¶ Dictionary of on-site operators for iteration.
Single operators are accessible as attributes.
-
add_op(self, name, op, need_JW=False)[source]¶ Add one on-site operators.
- Parameters
- namestr
A valid python variable name, used to label the operator. The name under which op is added as attribute to self.
- opnp.ndarray |
Array A matrix acting on the local hilbert space representing the local operator. Dense numpy arrays are automatically converted to
Array. LegCharges have to be[leg, leg.conj()]. We set labels'p', 'p*'.- need_JWbool
Whether the operator needs a Jordan-Wigner string. If
True, the function adds name toneed_JW_string.
-
rename_op(self, old_name, new_name)[source]¶ Rename an added operator.
- Parameters
- old_namestr
The old name of the operator.
- new_namestr
The new name of the operator.
-
remove_op(self, name)[source]¶ Remove an added operator.
- Parameters
- namestr
The name of the operator to be removed.
-
state_index(self, label)[source]¶ Return index of a basis state from its label.
- Parameters
- labelint | string
eather the index directly or a label (string) set before.
- Returns
- state_indexint
the index of the basis state associated with the label.
-
state_indices(self, labels)[source]¶ Same as
state_index(), but for multiple labels.
-
get_op(self, name)[source]¶ Return operator of given name.
- Parameters
- namestr
The name of the operator to be returned. In case of multiple operator names separated by whitespace, we multiply them together to a single on-site operator (with the one on the right acting first).
- Returns
- op
np_conserved The operator given by name, with labels
'p', 'p*'. If name already was an npc Array, it’s directly returned.
- op
-
op_needs_JW(self, name)[source]¶ Whether an (composite) onsite operator is fermionic and needs a Jordan-Wigner string.
- Parameters
- namestr
The name of the operator, as in
get_op().
- Returns
- needs_JWbool
Whether the operator needs a Jordan-Wigner string, judging from
need_JW_string.
-
valid_opname(self, name)[source]¶ Check whether ‘name’ labels a valid onsite-operator.
- Parameters
- namestr
Label for the operator. Can be multiple operator(labels) separated by whitespace, indicating that they should be multiplied together.
- Returns
- validbool
Trueif name is a valid argument toget_op().
-
multiply_op_names(self, names)[source]¶ Multiply operator names together.
Join the operator names in names such that get_op returns the product of the corresponding operators.
- Parameters
- nameslist of str
List of valid operator labels.
- Returns
- combined_opnamestr
A valid operator name Operatorname representing the product of operators in names.