String¶
- class zixy.qubit.state.String(qubits: int | Qubits | None = None, source: SpecT = '')[source]¶
Bases:
String[QubitStateArray,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 = '')[source]¶
Initialize the string.
- Parameters:
qubits – The qubit register or qubit count. If
None, the qubit register is inferred from the string specifier.source – The string specifier to use for default qubits and initial value.
- 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.
- classmethod from_str(source: str, qubits: int | Qubits | None = None) String[source]¶
Create an instance of
clsfrom a string.- Parameters:
source – String to parse.
qubits – The qubit register or qubit count. If
None, the qubit register is inferred from the string specifier.
- Returns:
An instance of
clsparsed fromsource.
- 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]\)).
- 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
clsparsed fromsource.
- set(source: Sequence[bool] | set[int] | str | String[QubitStateArray, 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.