StringSet

class zixy.fermion.StringSet(modes: int | Modes = 0)[source]

Bases: StringSet[NormalFermionOperatorArray, str | tuple[Sequence[int] | Sequence[bool], Sequence[int] | Sequence[bool]], tuple[list[int], list[int]]]

A collection of unique normal-ordered fermionic ladder-operator strings.

A set-like container of mode-based normal-ordered fermionic strings that may be used to store unique strings and perform set-like operations on them.

__eq__(other: object) bool

Return whether self and other are equal.

__init__(modes: int | Modes = 0)[source]

Initialize the string set.

Parameters:

modes – The mode space or number of modes.

__iter__() Iterator[Cmpnt[ImplT, SpecT]]

Iterate over the elements of self.

__len__() int

Get the number of elements in self.

__repr__() str

Return a string representation of self.

clone() Self

Return a deep copy of self.

cmpnts_type

alias of Strings

contains(value: SpecT | Cmpnt[ImplT, SpecT]) bool

Check whether value is stored in self.

Parameters:

value – The component specifier.

Returns:

Whether the lookup of value was successful.

filter_map(f: Callable[[Cmpnt[ImplT, SpecT]], bool]) Self

Eagerly evaluate a filter-map operation over the components of self.

Parameters:

f – Function which may mutate copies of the components of self, returning True if those mutated copies are to be included in the generator. The function signature should take a single Cmpnt instance as an argument, and return a boolean.

Returns:

New instance containing the occurrences of selected (and possibly mutated) components of self according to f. The type of the components is determined by cmpnts_type.

classmethod from_cmpnts(cmpnts: Cmpnts[ImplT, SpecT]) Self

Create a new instance of cls from the components in cmpnts.

Parameters:

cmpnts – Owned or viewed components with which to populate the new instance.

Returns:

A new instance of cls containing the components in cmpnts.

classmethod from_iterable(iterable: Iterable[SpecT | Cmpnt[ImplT, SpecT]], *args: Any, **kwargs: Any) Self

Create a new instance of cls from an iterable.

Parameters:
  • iterable – Iterable returning specifiers of all the components to be appended.

  • args – Positional arguments to forward to the constructor of cls.

  • kwargs – Keyword arguments to forward to the constructor of cls.

Returns:

New instance of cls containing the components specified by iterable.

classmethod from_str(source: str, *args: Any, **kwargs: Any) Self

Create an instance of cls from a string.

Parameters:
  • source – String to parse.

  • *args – Positional arguments to forward to the component constructor.

  • **kwargs – Keyword arguments to forward to the component constructor.

Returns:

An instance of cls parsed from source.

insert(value: SpecT | Cmpnt[ImplT, SpecT]) int

Try to insert the given component.

Parameters:

value – The component specifier.

Returns:

The index at which the term was inserted, or the index at which it already was stored if insertion is unsuccessful.

Note

This method operates in-place.

insert_iterable(source: Iterable[SpecT | Cmpnt[ImplT, SpecT]] = ()) None

Insert many components from an iterable source.

Parameters:

source – Iterable over any component specifiers.

Note

This method operates in-place.

iter_filter_map(f: Callable[[Cmpnt[ImplT, SpecT]], bool]) Iterator[Cmpnt[ImplT, SpecT]]

Lazily evaluate a filter-map operation over the components of self.

Parameters:

f – Function which may mutate copies of the components of self, returning True if those mutated copies are to be included in the generator. The function signature should take a single Cmpnt instance as an argument, and return a boolean.

Returns:

Iterator over the selected (and possibly mutated) components of self according to f. The type of the components is determined by cmpnts_type.

lookup(value: SpecT | Cmpnt[ImplT, SpecT]) int | None

Try to find the index of value in self.

Parameters:

value – The component specifier.

Returns:

The index at which the value was inserted, or None if the value was not found.

map_type

alias of Map

classmethod parse(source: str) Self

Parse a string into an instance of cls.

Deprecated:

use from_str() instead.

Parameters:

source – String to parse.

Returns:

An instance of cls parsed from source.

remove(value: SpecT | Cmpnt[ImplT, SpecT]) int

Try to remove value from self.

Parameters:

value – The component specifier.

Returns:

The index at which the value was removed.

Raises:

KeyError – The value was not found.

to_cmpnts() Cmpnts[ImplT, SpecT]

Create a new array of components owning copies of all those contained in self.

Returns:

New Cmpnts instance containing copies of the components in self. The type is determined by cmpnts_type.

to_str() str

Return the canonical string representation of self.