# ChargeInfo¶

Inheritance Diagram

Methods

 ChargeInfo.__init__([mod, names]) ChargeInfo.add(chinfos) Create a ChargeInfo combining multiple charges. ChargeInfo.change(chinfo, charge, new_qmod) Change the qmod of a given charge. ChargeInfo.check_valid(charges) Check, if charges has all entries as expected from self.mod. ChargeInfo.drop(chinfo[, charge]) Remove a charge from a ChargeInfo. ChargeInfo.from_hdf5(hdf5_loader, h5gr, subpath) Load instance from a HDF5 file. ChargeInfo.make_valid([charges]) Take charges modulo self.mod. ChargeInfo.save_hdf5(hdf5_saver, h5gr, subpath) Export self into a HDF5 file. Sanity check, raises ValueErrors, if something is wrong.

Class Attributes and Properties

 ChargeInfo.mod Modulo how much each of the charges is taken. ChargeInfo.qnumber The number of charges.
class tenpy.linalg.charges.ChargeInfo(mod=[], names=None)[source]

Bases: object

Meta-data about the charge of a tensor.

Saves info about the nature of the charge of a tensor. Provides make_valid() for taking modulo m.

(This class is implemented in tenpy.linalg.charges but also imported in tenpy.linalg.np_conserved for convenience.)

Parameters
• mod (iterable of QTYPE) – The len gives the number of charges, qnumber. Each entry is a positive integer, where 1 implies a $$U(1)$$ charge and N>1 implies a $$Z_N$$ symmetry. Defaults to “trivial”, i.e., no charge.

• names (list of str) – Descriptive names for the charges. Defaults to ['']*qnumber.

names

A descriptive name for each of the charges. May have ‘’ entries.

Type

list of strings

mask (mod == 1), to speed up make_valid in pure python.

Type

1D array bool

Equivalent to self.mod[self._maks_mod1]

Type

1D array QTYPE

_qnumber, _mod

Storage of qnumber and mod.

Notes

Instances of this class can (should) be shared between different LegCharge and Array’s.

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().

It stores the names under the path "names", and mod as dataset "U1_ZN".

Parameters
• hdf5_saver (Hdf5Saver) – Instance of the saving engine.

• h5gr (:classGroup) – HDF5 group which is supposed to represent self.

• subpath (str) – The name of h5gr with a '/' in the end.

Load instance from a HDF5 file.

This method reconstructs a class instance from the data saved with save_hdf5().

The "U1_ZN" dataset is mandatory, 'names' are optional.

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

Create a ChargeInfo combining multiple charges.

Parameters

chinfos (iterable of ChargeInfo) – ChargeInfo instances to be combined into a single one (in the given order).

Returns

chinfo – ChargeInfo combining all the given charges.

Return type

ChargeInfo

classmethod drop(chinfo, charge=None)[source]

Remove a charge from a ChargeInfo.

Parameters
• chinfo (ChargeInfo) – The ChargeInfo from where to drop/remove a charge.

• charge (int | str) – Number or name of the charge (within chinfo) which is to be dropped. None means dropping all charges.

Returns

chinfo – ChargeInfo where the specified charge is dropped.

Return type

ChargeInfo

classmethod change(chinfo, charge, new_qmod, new_name='')[source]

Change the qmod of a given charge.

Parameters
• chinfo (ChargeInfo) – The ChargeInfo for which qmod of charge should be changed.

• new_qmod (int) – The new qmod to be set.

• new_name (str) – The new name of the charge.

Returns

chinfo – ChargeInfo where qmod of the specified charge was changed.

Return type

ChargeInfo

test_sanity()[source]

Sanity check, raises ValueErrors, if something is wrong.

property qnumber

The number of charges.

property mod

Modulo how much each of the charges is taken.

Entries are 1 for a $$U(1)$$ charge, and N for a $$Z_N$$ symmetry.

make_valid(charges=None)[source]

Take charges modulo self.mod.

Parameters

charges (array_like or None) – 1D or 2D array of charges, last dimension self.qnumber None defaults to trivial charges np.zeros(qnumber, dtype=QTYPE).

Returns

A copy of charges taken modulo mod, but with x % 1 := x

Return type

charges

check_valid(charges)[source]

Check, if charges has all entries as expected from self.mod.

Parameters

charges (2D ndarray QTYPE_t) – Charge values to be checked.

Returns

res – True, if all 0 <= charges <= self.mod (wherever self.mod != 1)

Return type

bool