GroupedSite
full name: tenpy.networks.site.GroupedSite
parent module:
tenpy.networks.site
type: class
Inheritance Diagram
Methods
|
|
|
Add one on-site operators. |
|
Change the charges of the site (in place). |
|
Convert charge values to Jordan-Wigner parity. |
|
Load instance from a HDF5 file. |
Return the hermitian conjugate of a given operator. |
|
|
Return operator of given name. |
Return the Kronecker product \(op0 \otimes op1\) of local operators. |
|
Multiply operator names together. |
|
|
Multiply local operators (possibly given by their names) together. |
|
Whether an (composite) onsite operator is fermionic and needs a Jordan-Wigner string. |
|
Remove an added operator. |
|
Rename an added operator. |
|
Export self into a HDF5 file. |
|
Sort the |
|
Return index of a basis state from its label. |
|
Same as |
Sanity check, raises ValueErrors, if something is wrong. |
|
|
Check whether 'name' labels a valid onsite-operator. |
Class Attributes and Properties
Dimension of the local Hilbert space. |
|
Dictionary of on-site operators for iteration. |
- class tenpy.networks.site.GroupedSite(sites, labels=None, charges='same')[source]
Bases:
Site
Group two or more
Site
into a larger one.A typical use-case is that you want a NearestNeighborModel for TEBD although you have next-nearest neighbor interactions: you just double your local Hilbertspace to consist of two original sites. Note that this is a ‘hack’ at the cost of other things (e.g., measurements of ‘local’ operators) getting more complicated/computationally expensive.
If the individual sites indicate fermionic operators (with entries in need_JW_string), we construct the new on-site operators of site1 to include the JW string of site0, i.e., we use the Kronecker product of
[JW, op]
instead of[Id, op]
if necessary (but always[op, Id]
). In that way the onsite operators of this DoubleSite automatically fulfill the expected commutation relations. See also Fermions and the Jordan-Wigner transformation.- Parameters:
sites (list of
Site
) – The individual sites being grouped together. Copied before use ifcharges!='same'
.labels – Include the Kronecker product of each onsite operator op on
sites[i]
and identities on other sites with the nameopname+labels[i]
. Similarly, set state labels for' '.join(state[i]+'_'+labels[i])
. Defaults to[str(i) for i in range(n_sites)]
, which for example grouping two SpinSites gives operators name like"Sz0"
and state labels like'up_0 down_1'
.charges (
'same' | 'drop' | 'independent'
) – How to handle charges, defaults to ‘same’.'same'
means that all sites have the same ChargeInfo, and the total charge is the sum of the charges on the individual sites.'independent'
means that the sites have possibly different ChargeInfo, and the charges are conserved separately, i.e., we have n_sites conserved charges. For'drop'
, we drop any charges, such that the remaining legcharges are trivial. For more complex situations, you can callset_common_charges()
beforehand.
- labels
The labels using which the single-site operators are added during construction.
- add_op(name, op, need_JW=False, hc=None, permute_dense=None)[source]
Add one on-site operators.
- Parameters:
name (str) – A valid python variable name, used to label the operator. The name under which op is added as attribute to self.
op (np.ndarray |
Array
) – A matrix acting on the local hilbert space representing the local operator. Dense numpy arrays are automatically converted toArray
. LegCharges have to be[leg, leg.conj()]
. We set labels'p', 'p*'
.need_JW (bool) – Whether the operator needs a Jordan-Wigner string. If
True
, add name toneed_JW_string
.hc (None | False | str) – The name for the hermitian conjugate operator, to be used for
hc_ops
. By default (None
), try to auto-determine it. IfFalse
, disable adding entries tohc_ops
.permute_dense (bool | None) – Flag to enable/disable permutations when converting op from numpy to np_conserved arrays. If True, the operator is permuted with
perm
to account for permutations induced by sorting charges; False disables the permutations. By default (None
), the value ofused_sort_charge
is used.
- change_charge(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. IfNone
, use trivial charges.permute (ndarray | None) – The permutation applied to the physical leg, which also gets used to adjust
state_labels
andperm
. If you sorted the previous leg withperm_qind, new_leg_charge = leg.sort()
, useold_leg.perm_flat_from_perm_qind(perm_qind)
. Ignored ifNone
.
- charge_to_JW_signs(charges)[source]
Convert charge values to Jordan-Wigner parity.
Often, charge conservation contains the (parity of) the total fermion number. This information is enough to lift a Jordan-Wigner string applied on the left of a given bond to the virtual leg of an MPS: given the total parity number of fermions
parity[alpha] = N_fermions[alpha] % 2
in each Schmidt state|alpha>
, simply send|alpha> --> (-1)**parity[alpha] |alpha>
. Given the charges values of the Schmidt states|alpha>
, this function returns the corresponding(-1)**parity
Jordan-Wigner signs.- Parameters:
charges (2D or 1D array) – Charge values, last dimension is len
chinfo.qnumber
. We choose the convention that these charge values correspond to an “incoming” leg withqconj=+1
.- Returns:
Should only have values +1 or -1.
- Return type:
JW_signs
- property dim
Dimension of the local Hilbert space.
- classmethod from_hdf5(hdf5_loader, h5gr, subpath)[source]
Load instance from a HDF5 file.
This method reconstructs a class instance from the data saved with
save_hdf5()
.- Parameters:
hdf5_loader (
Hdf5Loader
) – Instance of the loading engine.h5gr (
Group
) – HDF5 group which is represent the object to be constructed.subpath (str) – The name of h5gr with a
'/'
in the end.
- Returns:
obj – Newly generated class instance containing the required data.
- Return type:
cls
- get_op(name)[source]
Return operator of given name.
- Parameters:
name (str) – 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 – The operator given by name, with labels
'p', 'p*'
. If name already was an npc Array, it’s directly returned.- Return type:
- multiply_op_names(names)[source]
Multiply operator names together.
Join the operator names in names such that get_op returns the product of the corresponding operators.
- multiply_operators(operators)[source]
Multiply local operators (possibly given by their names) together.
- Parameters:
operators (list of {str |
Array
}) – List of valid operator names (to be translated withget_op()
) or directly on-site operators in the form of npc arrays with'p', 'p*'
label. The operators are multiplied left-to-right.- Returns:
combined_operator – The product of the given operators in a left-to-right multiplication following the usual mathematical convention. For example, if
operators=['Sz', 'Sp', 'Sx']
, the final operator is equivalent tosite.get_op('Sz Sp Sx')
, with the'Sx'
operator acting first on any physical state.- Return type:
- property onsite_ops
Dictionary of on-site operators for iteration.
Single operators are accessible as attributes.
- op_needs_JW(name)[source]
Whether an (composite) onsite operator is fermionic and needs a Jordan-Wigner string.
- remove_op(name)[source]
Remove an added operator.
- Parameters:
name (str) – The name of the operator to be removed.
- save_hdf5(hdf5_saver, h5gr, subpath)[source]
Export self into a HDF5 file.
This method saves all the data it needs to reconstruct self with
from_hdf5()
.This implementation saves the content of
__dict__
withsave_dict_content()
, storing the format under the attribute'format'
.
- sort_charge(bunch=True)[source]
Sort the
leg
charges (in place).- Parameters:
bunch (bool) – Whether to also group equal charges into larger blocks (usually a good idea).
- Returns:
perm – The permutation
- Return type:
1D ndarray
- state_indices(labels)[source]
Same as
state_index()
, but for multiple labels.