ChargeInfo

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
moditerable of QTYPE

The len gives the number of charges, qnumber. For each charge one entry m: the charge is conserved modulo m. Defaults to trivial, i.e., no charge.

nameslist of str

Descriptive names for the charges. Defaults to ['']*qnumber.

Notes

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

Attributes
qnumberint

The number of charges.

modndarray[QTYPE,ndim=1]

Modulo how much each of the charges is taken.

nameslist of strings

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

_mask_mod11D array bool

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

_mod_masked1D array QTYPE

Equivalent to self.mod[self._maks_mod1]

_qnumber, _mod :

Storage of qnumber and mod.

Methods

add(chinfos)

Create a ChargeInfo combining multiple charges.

change(chinfo, charge, new_qmod[, new_name])

Change the qmod of a given charge.

check_valid(self, charges)

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

drop(chinfo[, charge])

Remove a charge from a ChargeInfo.

make_valid(self[, charges])

Take charges modulo self.mod.

test_sanity(self)

Sanity check, raises ValueErrors, if something is wrong.

classmethod add(chinfos)[source]

Create a ChargeInfo combining multiple charges.

Parameters
chinfositerable of ChargeInfo

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

Returns
chinfoChargeInfo

ChargeInfo combining all the given charges.

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

Remove a charge from a ChargeInfo.

Parameters
chinfoChargeInfo

The ChargeInfo from where to drop/remove a charge.

chargeint | str

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

Returns
chinfoChargeInfo

ChargeInfo where the specified charge is dropped.

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

Change the qmod of a given charge.

Parameters
chinfoChargeInfo

The ChargeInfo for which qmod of charge should be changed.

new_qmodint

The new qmod to be set.

new_namestr

The new name of the charge.

Returns
chinfoChargeInfo

ChargeInfo where qmod of the specified charge was changed.

test_sanity(self)[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.

1 for a U(1) charge, i.e., mod 1 -> mod infinity.

make_valid(self, charges=None)[source]

Take charges modulo self.mod.

Parameters
chargesarray_like or None

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

Returns
charges :

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

check_valid(self, charges)[source]

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

Parameters
charges2D ndarray QTYPE_t

Charge values to be checked.

Returns
resbool

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