ComplexTerm

class zixy.qubit.state.ComplexTerm(qubits: int | Qubits = 0, source: Cmpnt[ImplT, SpecT] | SpecT | tuple[SpecT | Cmpnt[ImplT, SpecT], CoeffT | None] = '')[source]

Bases: Term[complex]

A term consisting of a state string and a complex coefficient.

A single qubit-based term consisting of a state string and a complex coefficient that may be an owning instance referencing a single element in a TermData instance, or a view on an element in another collection.

__eq__(other: object) bool

Return whether self and other are equal.

__imul__(rhs: int | float | complex | Sign | ComplexSign | Expr | String | Term[CoeffT]) Self

In-place multiplication of self by rhs.

__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) → ComplexTerm

  • self, other (ComplexSign) → ComplexTerm

  • self, other (float) → ComplexTerm

  • self, other (complex) → ComplexTerm

  • self, other (Expr) → SymbolicTerm

Multiplication of self by rhs.

__neg__() Self

Return the negation of self.

__pos__() Self

Return self.

__repr__() str

Return a string representation of self.

__rmul__(lhs: OtherCoeffT) Term[Any][source]
Overloads:
  • self, other (Sign) → ComplexTerm

  • self, other (ComplexSign) → ComplexTerm

  • self, other (float) → ComplexTerm

  • self, other (complex) → ComplexTerm

  • self, other (Expr) → SymbolicTerm

Multiplication of lhs by self.

aliases(other: Term[Any, Any, Any]) bool

Determine whether self is a view of the same component as other.

clear() None

Set the value of the component to zero and the coefficient to unity.

Note

This method operates in-place.

clone() Self

Return a deep copy of self.

property cmpnt: Cmpnt[ImplT, SpecT]

Get a view on the component of self.

property cmpnt_type: type[Cmpnt[ImplT, SpecT]]

Get the component type of self.

cmpnts_type

alias of Strings

property coeff: CoeffT

Get a copy of the coefficient of self.

coeff_type

alias of complex

property coeffs_type: type[Coeffs[CoeffT]]

Get the coefficient container type of self.

classmethod from_cmpnt_coeff(cmpnt: Cmpnt[ImplT, SpecT], coeff: CoeffT) Self

Factory to make an instance of cls from a component and a coefficient.

Parameters:
  • cmpnt – Component to copy from.

  • coeff – Coefficient scaling the cmpnt in the new instance.

Returns:

An instance of cls with the given component and coefficient.

classmethod from_str(source: str, *args: Any, **kwargs: Any) Self

Create an instance of cls from 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 cls parsed from source.

into(t: type[OutT]) OutT

Clone self into a new related container of type t.

Parameters:

t – Type of the new container to create.

Returns:

A new instance of t containing the same data as self.

is_owning() bool

Check if self is owning (i.e. not a view).

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 cls parsed from source.

property qubits: Qubits

Get the qubits corresponding to self.

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.

property string: String

Get the string component of the term.

to_sparse_matrix(big_endian: bool = False) Any

Return self as a sparse matrix.

Parameters:

big_endian – Whether to use big-endian basis ordering.

Returns:

The sparse matrix representation of self.

to_str() str

Return the canonical string representation of self.