StringSet¶
- class zixy.qubit.state.StringSet(qubits: int | Qubits = 0)[source]¶
Bases:
StringSet[QubitStateArray,None|Sequence[bool] |set[int] |str,bool]A collection of unique state strings.
A set-like container of qubit-based Pauli strings that may be used to store unique components and perform set-like operations on them.
- __init__(qubits: int | Qubits = 0)[source]¶
Initialize the string set.
- Parameters:
qubits – The qubit register or qubit count.
- contains(value: SpecT | Cmpnt[ImplT, SpecT]) bool¶
Check whether
valueis stored inself.- Parameters:
value – The component specifier.
- Returns:
Whether the lookup of
valuewas 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, 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. The type of the components is determined bycmpnts_type.
- classmethod from_cmpnts(cmpnts: Cmpnts[ImplT, SpecT]) Self¶
Create a new instance of
clsfrom the components incmpnts.- Parameters:
cmpnts – Owned or viewed components with which to populate the new instance.
- Returns:
A new instance of
clscontaining the components incmpnts.
- 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_strings(strings: Strings[ImplT, SpecT, ElemT]) StringSet[ImplT, SpecT, ElemT][source]¶
Create a new instance of
clsfrom the strings instrings.- Parameters:
strings – Owned or viewed strings with which to populate the new instance.
- Returns:
A new instance of
clscontaining the strings instrings.
- 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, 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. The type of the components is determined bycmpnts_type.
- lookup(value: SpecT | Cmpnt[ImplT, SpecT]) int | None¶
Try to find the index of
valueinself.- Parameters:
value – The component specifier.
- Returns:
The index at which the value was inserted, or
Noneif the value was not found.
- map_type¶
alias of
Map
- remove(value: SpecT | Cmpnt[ImplT, SpecT]) int¶
Try to remove
valuefromself.- 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
Cmpntsinstance containing copies of the components inself. The type is determined bycmpnts_type.