RealTerms¶
- class zixy.qubit.state.RealTerms(qubits: int | Qubits = 0, n: int = 0)[source]¶
Bases:
NumericTerms[QubitStateArray,None|Sequence[bool] |set[int] |str,float],Terms[float]A collection of terms consisting of state strings and real coefficients.
An array-like container of qubit-based terms consisting of state strings and
floatcoefficients that may be an owning instance referencing aTermDatainstance, or a view on a slice of the elements in another collection.- __getitem__(indexer: int | slice) Term[ImplT, SpecT, CoeffT] | Terms[ImplT, SpecT, CoeffT]¶
- Overloads:
self, indexer (int) → Term[ImplT, SpecT, CoeffT]
self, indexer (builtins.slice) → Terms[ImplT, SpecT, CoeffT]
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)¶
Initialize the term array.
- Parameters:
qubits – The qubit register or qubit count.
n – The number of items to initialize the array with.
- __setitem__(indexer: int | slice, source: Cmpnt[ImplT, SpecT] | SpecT | tuple[SpecT | Cmpnt[ImplT, SpecT] | None, CoeffT | None] | None | Term[ImplT, SpecT, CoeffT] | Terms[ImplT, SpecT, CoeffT]) None¶
- Overloads:
self, indexer (int), source (TermSpecT[ImplT, SpecT, CoeffT] | Term[ImplT, SpecT, CoeffT]) → None
self, indexer (builtins.slice), source (Terms[ImplT, SpecT, CoeffT]) → None
Set the term at
indexerinselftosource.- Parameters:
indexer – Index of the string or slice of strings within
selfto assign.source – Value specifying the term or a view of many components to assign at
indexer.
- allclose(other: Self, rtol: float = 1e-05, atol: float = 1e-08) bool¶
Check whether
selfandotherare within a certain tolerance.- Parameters:
other – Other instance to compare to.
rtol – Relative tolerance.
atol – Absolute tolerance.
- Returns:
Whether
selfandotherare within the given tolerances of each other.
Note
This method operates by comparing the NumPy arrays returned by
np_array.
- append(source: Cmpnt[ImplT, SpecT] | SpecT | tuple[SpecT | Cmpnt[ImplT, SpecT] | None, CoeffT | None] | None | Term[ImplT, SpecT, CoeffT] = None) Self¶
Append
sourceto the end ofself.- Parameters:
source – Value to append.
Note
This method operates in-place.
- append_iterable(source: Iterable[Cmpnt[ImplT, SpecT] | SpecT | tuple[SpecT | Cmpnt[ImplT, SpecT] | None, CoeffT | None] | None | Term[ImplT, SpecT, CoeffT]] = ()) Self¶
Append the elements of
sourceto the end ofself.- Parameters:
source – Other iterable whose terms to append to
self.
Note
This method operates in-place.
- append_n(n: int, source: Cmpnt[ImplT, SpecT] | SpecT | tuple[SpecT | Cmpnt[ImplT, SpecT] | None, CoeffT | None] | None | Term[ImplT, SpecT, CoeffT] = None) Self¶
Append
sourceto the end ofselfntimes.- Parameters:
n – Number of times to repeatedly append
source.source – 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[[Term[ImplT, SpecT, CoeffT]], bool]) Self¶
Eagerly evaluate a filter-map operation over the terms of
self.- Parameters:
f – Function which may mutate copies of the terms of
self, returningTrueif those mutated copies are to be included in the generator. The function signature should take a singleTerminstance as an argument, and return a boolean.- Returns:
New instance containing the occurrences of selected (and possibly mutated) components of
selfaccording tof.
- classmethod from_iterable(source: Iterable[Cmpnt[ImplT, SpecT] | SpecT | tuple[SpecT | Cmpnt[ImplT, SpecT] | None, CoeffT | None] | None | Term[ImplT, SpecT, CoeffT]], *args: Any, **kwargs: Any) Self¶
Create a new instance of
clsfrom an iterable.- Parameters:
source – Iterable returning specifiers of all the terms 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 terms specified bysource.
- 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.
- 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[[Term[ImplT, SpecT, CoeffT]], bool]) Iterator[Term[ImplT, SpecT, CoeffT]]¶
Lazily evaluate a filter-map operation over the components of
self.- Parameters:
f – Function which may mutate copies of the terms of
self, returningTrueif those mutated copies are to be included in the generator. The function signature should take a singleTerminstance as an argument, and return a boolean.- Returns:
Iterator over the selected (and possibly mutated) terms of
selfaccording tof.
- 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.
- new_clear_term() Term[ImplT, SpecT, CoeffT]¶
Factory to make a new term with a zero component and a unit coefficient.
- Returns:
A new owing term with the component and coefficient type of
self.
- 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
tuple(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.
- scale(scalar: CoeffT) None¶
Scale all elements by a given factor.
- Parameters:
scalar – Scalar factor by which to scale all elements.
Note
This method operates in-place.
- to_dataframe() DataFrame¶
Convert
selfto aDataFrame.