SymbolicTerm¶
- class zixy.qubit.state.SymbolicTerm(qubits: int | Qubits = 0, source: Cmpnt[ImplT, SpecT] | SpecT | tuple[SpecT | Cmpnt[ImplT, SpecT], CoeffT | None] = '')[source]¶
Bases:
Term[Expr]A term consisting of a state string and a symbolic coefficient.
A single qubit-based term consisting of a state string and a
Exprcoefficient that may be an owning instance referencing a single element in aTermDatainstance, or a view on an element in another collection.- __imul__(rhs: int | float | complex | Sign | ComplexSign | Expr | String | Term[CoeffT]) Self¶
In-place multiplication of
selfbyrhs.
- __init__(qubits: int | Qubits = 0, source: Cmpnt[ImplT, SpecT] | SpecT | tuple[SpecT | Cmpnt[ImplT, SpecT], CoeffT | None] = '')¶
Initialize the term.
- Parameters:
qubits – The qubit register or qubit count.
source – The term specifier to use for default qubits and initial value.
- __mul__(rhs: OtherCoeffT) Term[Any][source]¶
- Overloads:
self, other (Sign) → SymbolicTerm
self, other (ComplexSign) → SymbolicTerm
self, other (float) → SymbolicTerm
self, other (complex) → SymbolicTerm
self, other (Expr) → SymbolicTerm
Multiplication of
selfbyrhs.
- __rmul__(lhs: OtherCoeffT) Term[Any][source]¶
- Overloads:
self, other (Sign) → SymbolicTerm
self, other (ComplexSign) → SymbolicTerm
self, other (float) → SymbolicTerm
self, other (complex) → SymbolicTerm
self, other (Expr) → SymbolicTerm
Multiplication of
lhsbyself.
- aliases(other: Term[Any, Any, Any]) bool¶
Determine whether
selfis a view of the same component asother.
- clear() None¶
Set the value of the component to zero and the coefficient to unity.
Note
This method operates in-place.
- property coeff: CoeffT¶
Get a copy of the coefficient of
self.
- classmethod from_cmpnt_coeff(cmpnt: Cmpnt[ImplT, SpecT], coeff: CoeffT) Self¶
Factory to make an instance of
clsfrom a component and a coefficient.- Parameters:
cmpnt – Component to copy from.
coeff – Coefficient scaling the
cmpntin the new instance.
- Returns:
An instance of
clswith the given component and coefficient.
- classmethod from_str(source: str, *args: Any, **kwargs: Any) Self¶
Create an instance of
clsfrom a string.- Parameters:
source – String to parse.
*args – Positional arguments to forward to the component constructor.
**kwargs – Keyword arguments to forward to the component constructor.
- Returns:
An instance of
clsparsed fromsource.
- 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.
- isubs(values: dict[Symbol | str, int | float | complex | Expr]) None[source]¶
Apply a partial substitution of the symbols in-place.
- Parameters:
values – Map from a symbol or symbol name to its new expression or numeric value.
Note
This method operates in-place.
See also
- 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: Self | Cmpnt[ImplT, SpecT] | SpecT | tuple[SpecT | Cmpnt[ImplT, SpecT], CoeffT | None]) None¶
Set the value of the term.
- Parameters:
source – Specification for the new value.
Note
This method operates in-place.
- subs(values: dict[Symbol | str, int | float | complex | Expr]) SymbolicTerm[source]¶
Apply a partial substitution of the symbols out of place.
- Parameters:
values – Map from a symbol or symbol name to its new expression or numeric value.
- Returns:
A new contiguously stored instance with the substitution applied.
- to_sparse_matrix(big_endian: bool = False) Any¶
Return
selfas a sparse matrix.- Parameters:
big_endian – Whether to use big-endian basis ordering.
- Returns:
The sparse matrix representation of
self.
- try_to_complex() ComplexTerm[source]¶
Try to evaluate
selfas a term containing a complex coefficient.- Returns:
An instance of
ComplexTermwith the evaluated coefficient.- Raises:
TypeError – If
selfcannot be evaluated with a complex coefficient.
See also