Strings

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

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

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

An array-like container of mode-based normal-ordered fermionic strings that may be an owning instance referencing a contiguous Rust-bound data object, or a view on a slice of the elements in another collection.

__eq__(other: object) bool

Return whether self and other are equal.

__getitem__(indexer: int | slice) String | Self[source]
Overloads:
  • self, indexer (int) → String

  • self, indexer (slice) → Self

Get the element or elements selected by indexer.

Parameters:

indexer – Index or slice selecting the element(s) to return.

Returns:

Element or slice selected by indexer.

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

Initialize the string array.

Parameters:
  • modes – The mode space or number of modes.

  • n – Number of default elements with which to create the instance.

__iter__() Iterator[T]

Iterate over the elements of self.

__len__() int

Get the number of elements in self.

__repr__() str

Return a string representation of self.

__setitem__(indexer: int | slice, source: SpecT | Cmpnt[ImplT, SpecT] | Cmpnts[ImplT, SpecT]) None

Set the component at indexer in self to source.

Parameters:
  • indexer – Index of the string or slice of strings within self to assign.

  • source – Value specifying the component or a view of many components to assign at indexer.

append(source: SpecT | Cmpnt[ImplT, SpecT]) Self

Append source to the end of self.

Parameters:

source – Value to append.

Note

This method operates in-place.

append_iterable(source: Iterable[SpecT | Cmpnt[ImplT, SpecT]] = ()) Self

Append many values from an iterable source.

Parameters:

source – Iterable over any component specifiers.

Note

This method operates in-place.

append_n(n: int, source: SpecT | Cmpnt[ImplT, SpecT]) Self

Append source to the end of self n times.

Parameters:
  • n – Number of times to repeatedly append source.

  • source – Specification for the value to append.

Note

This method operates in-place.

as_view() Self

Return a view of self.

Returns:

If self is owning, a new view on the same underlying data, otherwise self.

clone() Self

Return a deep copy of self.

cmpnt_type

alias of String

count(value) integer -- return number of occurrences of value
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.

filter_populated() Self

Eagerly filter components of self, retaining only those that are not clear.

filter_unique() Cmpnts[ImplT, SpecT][source]

Get a new instance containing the unique strings of self.

classmethod from_cmpnt(cmpnt: Cmpnt[ImplT, SpecT]) Self

Create a new one-element instance from a single component.

Parameters:

cmpnt – Component to copy into the new instance.

Returns:

New owning instance containing only cmpnt.

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_size(n: int) Self

Create a new instance of cls with the given size.

Parameters:

n – The size of the new instance.

Returns:

An instance of cls with the given size.

classmethod from_str(source: str, modes: int | Modes | None = None) Self[source]

Create an instance of cls by parsing an input string.

Parameters:
  • source – String to parse.

  • modes – The mode space or mode count. If None, the mode space is inferred from the string specifier.

Returns:

An instance of cls parsed from source.

classmethod from_view(source: Self) Self

Create a new instance of cls from a view.

Parameters:

source – View to clone into the new instance.

Returns:

An owning clone of source.

into(t: type[OutT]) OutT

Clone self into a new related container of type t.

Parameters:

t – Type of the new container to create.

Returns:

A new instance of t containing the same data as self.

is_owning() bool

Check if self is owning (i.e. not a view).

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.

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

Lazily filter components of self, retaining only those that are not clear.

map_index(i: int) int

Map an index in self to an index in the underlying data.

Parameters:

i – Index in self.

Returns:

Corresponding index in the underlying data.

property modes: Modes

Get the modes corresponding to self.

new_clear_cmpnt() Cmpnt[ImplT, SpecT]

Get a new Cmpnt instance using the same implementation as self.

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.

reordered(inds: Sequence[int]) Self

Get a new instance with the elements of self in a new order.

Parameters:

inds – Sequence of indices defining the new order. Should be a permutation of range(len(self)).

Returns:

A new instance with the reordered elements.

resize(n: int) Self

Resize the underlying container.

Parameters:

n – The new size of the container.

Note

This method operates in-place.

Raises:

ValueError – If the container is a view.

to_str() str

Return the canonical string representation of self.