String¶
- class zixy.qubit.state.String(qubits: int | Qubits | None = None, source: SpecT | None = None)[source]¶
Bases:
String[QubitStateArray,None|Sequence[bool] |set[int] |str,bool]A state string.
A single qubit-based state string that may be an owning instance referencing a single element in a Rust-bound data object, or a view on an element in another collection.
- __init__(qubits: int | Qubits | None = None, source: SpecT | None = None)[source]¶
Initialize the string.
- Parameters:
qubits – The qubit register or qubit count.
source – The string specifier to use for default qubits and initial value.
- __mul__(rhs: CoeffT | Cmpnt[ImplT, SpecT]) Term[ImplT, SpecT, CoeffT] | Term[ImplT, SpecT, OtherCoeffT]¶
- Overloads:
self, rhs (Cmpnt[ImplT, SpecT]) → Term[ImplT, SpecT, OtherCoeffT]
self, rhs (CoeffT) → Term[ImplT, SpecT, CoeffT]
Return the product of
selfandrhs.
- aliases(other: Cmpnt[ImplT, SpecT]) bool¶
Determine whether
selfis a view of the same component asother.
- count(elem: ElemT) int[source]¶
Return the number of occurrences of
elemin the string.- Parameters:
elem – The element to count.
- Returns:
The number of occurrences of
elemin the string.
- hamming_weight() int[source]¶
Get the Hamming weight of this bit string.
The Hamming weight is defined as
\[\sum_i s_i\]where \(s_i\) is the value of the bit at index \(i\) in the string.
- impl_type¶
alias of
QubitStateArray
- imul_get_phase(op: String) ComplexSign[source]¶
In-place multiplication of
selfbyop, returning the phase.
- 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.
- is_vacuum() bool[source]¶
Check whether the string is the vacuum state (\(\left[0, 0, \ldots, 0\right]\)).
- set(source: None | Sequence[bool] | set[int] | str | String[QubitStateArray, None | Sequence[bool] | set[int] | str, bool]) None[source]¶
Set the value of the string.
- Parameters:
source – Specification for the new value.
Note
This method operates in-place.