Strings¶
- class zixy.qubit.state.Strings(qubits: int | Qubits = 0, n: int = 0)[source]¶
Bases:
Strings[QubitStateArray,None|Sequence[bool] |set[int] |str,bool]A collection of state strings.
An array-like container of qubit-based state 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.
- __getitem__(indexer: int | slice) String | Strings[source]¶
- Overloads:
self, indexer (int) → String
self, indexer (slice) → Strings
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__(qubits: int | Qubits = 0, n: int = 0)[source]¶
Initialize the string array.
- Parameters:
qubits – Qubits object or number of qubits to use.
n – Number of default elements with which to create the instance.
- __setitem__(indexer: int | slice, source: SpecT | Cmpnt[ImplT, SpecT] | Cmpnts[ImplT, SpecT] | None) None¶
Set the component at
indexerinselftosource.- Parameters:
indexer – Index of the string or slice of strings within
selfto assign.source – Value specifying the component or a view of many components to assign at
indexer.
- append(source: SpecT | Cmpnt[ImplT, SpecT] | None = None) Self¶
Append
sourceto the end ofself.- Parameters:
source – Value to append.
Note
This method operates in-place.
- append_iterable(source: Iterable[SpecT | Cmpnt[ImplT, SpecT] | None] = ()) 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] | None = None) Self¶
Append
sourceto the end ofselfntimes.- 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
selfis owning, a new view on the same underlying data, otherwiseself.
- 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, returningTrueif those mutated copies are to be included in the generator. The function signature should take a singleCmpntinstance as an argument, and return a boolean.- Returns:
New instance containing the occurrences of selected (and possibly mutated) components of
selfaccording tof.
- filter_populated() Self¶
Eagerly filter components of
self, retaining only those that are not clear.
- filter_unique() Cmpnts[ImplT, SpecT]¶
Get a new
Cmpntsinstance containing the unique components ofself.
- 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
clsfrom 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
clscontaining the components specified byiterable.
- classmethod from_size(n: int) Self¶
Create a new instance of
clswith the given size.- Parameters:
n – The size of the new instance.
- Returns:
An instance of
clswith the given size.
- classmethod from_view(source: Self) Self¶
Create a new instance of
clsfrom a view.- Parameters:
source – View to clone into the new instance.
- Returns:
An owning clone of
source.
- get_sets() tuple[set[int], ...][source]¶
Get the strings as a list of sets of the indices of bits with value 1.
- get_tuples() tuple[tuple[ElemT, ...], ...][source]¶
Get all the strings as a list of tuples of their elements.
- into(t: type[OutT]) OutT¶
Clone
selfinto a new related container of typet.- Parameters:
t – Type of the new container to create.
- Returns:
A new instance of
tcontaining the same data asself.
- 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, returningTrueif those mutated copies are to be included in the generator. The function signature should take a singleCmpntinstance as an argument, and return a boolean.- Returns:
Iterator over the selected (and possibly mutated) components of
selfaccording tof.
- 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
selfto an index in the underlying data.- Parameters:
i – Index in
self.- Returns:
Corresponding index in the underlying data.
- classmethod new(qubits: int | Qubits = 0, n: int = 0) Strings[source]¶
Create a new instance with a given qubit count and number of 00…0 strings.
- Parameters:
qubits – Space of qubits or a number of qubits.
n – Number of default elements with which to create the instance.
- new_clear_cmpnt() Cmpnt[ImplT, SpecT]¶
Get a new
Cmpntinstance using the same implementation asself.
- relabel(qubits: Qubits) Self[source]¶
Relabel the contents of the strings according to a new qubit register.
- Parameters:
qubits – The qubit register or qubit count.
- Returns:
selffor chaining.
Note
This method operates in-place.
- relabelled(qubits: Qubits) Self[source]¶
Relabel the contents of a clone of the strings according to a new set of qubit register.
- Parameters:
qubits – The qubit register or qubit count.
- Returns:
The resulting value.
- reordered(inds: Sequence[int]) Self¶
Get a new instance with the elements of
selfin 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.
- standardize(n_qubit: int) Self[source]¶
Standardize the string labels according to a given number of qubits.
Reorders the contents of the strings such that the associated qubit register can be reassigned to
Qubits.from_count(n_qubit)without semantic relabelling. The givenn_qubitmay differ from the size of the original register. If larger, clear qubits are appended after the reordered contents; if smaller, only contents at qubit indices less thann_qubitwill be retained.- Parameters:
n_qubit – The number of qubits.
- Returns:
selffor chaining.
Note
This method operates in-place.
- standardized(n_qubit: int) Self[source]¶
Standardize the labels of a clone of the string according to a given number of qubits.
Reorders the contents of the strings such that the associated qubit register can be reassigned to
Qubits.from_count(n_qubit)without semantic relabelling. The givenn_qubitmay differ from the size of the original register. If larger, clear qubits are appended after the reordered contents; if smaller, only contents at qubit indices less thann_qubitwill be retained.- Parameters:
n_qubit – The number of qubits.
- Returns:
The resulting value.