Skip to main content
IBM Quantum Platform

OperatorTrait

class OperatorTrait(*args, **kwargs)

Bases: Protocol

A protocol indicating all methods implemented by operator classes.


Attributes

groups

Returns the groups indices.


Methods

adjoint

adjoint()

Returns the adjoint of this operator.

Return type

Self

equiv

equiv(other, atol)

Checks this operator with another for equivalence up to the specified absolute tolerance.

Parameters

Return type

bool

from_terms

classmethod from_terms(terms)

Constructs a new operator from an iterator (see also iter_terms()).

Parameters

terms (Iterable)

Return type

Self

from_terms_with_groups

classmethod from_terms_with_groups(terms)

Constructs a new operator from an iterator (see also iter_terms_with_groups()).

Parameters

terms (Iterable)

Return type

Self

get_coeffs

get_coeffs()

Returns the term coefficients.

Return type

list[complex]

get_support

get_support()

Returns the set of mode indices which this operator acts upon.

Return type

frozenset[int]

has_groups

has_groups()

Returns whether this operator tracks group indices.

This is equivalent to (but cheaper than) checking op.groups is not None, because it does not copy the group indices out of the operator in order to inspect them.

Return type

bool

ichop

ichop(atol)

Trims coefficients below the absolute tolerance from this operator.

Parameters

atol (float)

is_hermitian

is_hermitian(atol=1e-08)

Returns whether this operator is Hermitian.

The check reduces the difference of this operator and its adjoint() to a normal form (see normal_ordered()) and compares the result against zero(). It is therefore only as strong as the normal form that the specific operator type reduces through.

Note

A True result is always reliable. A False result is reliable only for operator types whose normal form is a genuine canonical form; for the others this check is conservative and can return False for an operator that is in fact Hermitian. Consult the specific implementation to find out which of the two applies.

Parameters

atol (float) – The numerical accuracy upto which coefficients are considered equal. This value defaults to 1e-8.

Returns

Whether this operator is Hermitian.

Return type

bool

iter_terms

iter_terms()

Iterates over the terms of this operator.

Return type

Iterator

iter_terms_with_groups

iter_terms_with_groups()

Iterates over the terms of this operator with their group indices.

Return type

Iterator

normal_ordered

normal_ordered(*args, **kwargs)

Returns the normal-ordered form of this operator.

Note

A specific implementation of this method may take additional arguments.

Return type

Self

num_groups

num_groups()

Returns the number of groups.

Return type

int | None

one

classmethod one()

Constructs the multiplicative identity operator.

Return type

Self

relabel_modes

relabel_modes(permutation)

Relabels the modes of the operator.

Parameters

permutation (list[int])

Return type

Self

simplify

simplify(atol)

Simplifies the terms of this operator, discarding those below the absolute tolerance.

Parameters

atol (float)

Return type

Self

split_out_groups

split_out_groups(group_indices=None)

Splits this operator into an optional list of new operators based on its groups.

Note

If group_indices is omitted, every group is built, in index order. Otherwise, only the requested indices are built, in the given order.

Parameters

group_indices (Sequence[int] | None)

Return type

list[Self]

zero

classmethod zero()

Constructs the additive identity operator.

Return type

Self

Was this page helpful?
Report a bug, typo, or request content on GitHub.