VibrationalOp#

class VibrationalOp(data, num_modals=None, *, copy=True, validate=True)[fuente]#

Bases: SparseLabelOp

N-mode vibrational operator.

A VibrationalOp represents a weighted sum of vibrational creation/annihilation operator terms. These terms are encoded as sparse labels, strings consisting of a space-separated list of expressions. Each expression must look like [+-]_<mode_index>_<modal_index>, where the <mode_index> and <modal_index> are non-negative integers representing the index of the vibrational mode and modal, respectively, where the + (creation) or - (annihilation) operation is to be performed.

Initialization

A VibrationalOp is initialized with a dictionary, mapping terms to their respective coefficients:

from qiskit_nature.second_q.operators import VibrationalOp

op = VibrationalOp(
    {
        "+_0_0 -_0_0": 1.0,
        "+_0_1 -_0_1": 1.0,
        "+_1_0 -_1_0": -1.0,
        "+_1_1 -_1_1": -1.0,
    },
    num_modals=[2, 2]
)

By default, this way of initializing will create a full copy of the dictionary of coefficients. If you have very restricted memory resources available, or would like to avoid the additional copy, the dictionary will be stored by reference if you disable copy like so:

some_big_data = {
    "+_0_0 -_0_0": 1.0,
    "+_0_1 -_0_1": 1.0,
    # ...
}

op = VibrationalOp(
    some_big_data,
    num_modals=[2, 2],
    copy=False,
)

Nota

It is the users” responsibility, that in the above scenario, some_big_data is not changed after initialization of the VibrationalOp, since the operator contents are not guaranteed to remain unaffected by such changes.

If num_modals is not provided then the maximum modal_index per mode will determine the num_modals for that mode.

from qiskit_nature.second_q.operators import VibrationalOp

op = VibrationalOp(
    {
        "+_0_0 -_0_0": 1.0,
        "+_0_1 -_0_1": 1.0,
        "+_1_0 -_1_0": -1.0,
        "+_1_1 -_1_1": -1.0,
    },
)

Algebra

This class supports the following basic arithmetic operations: addition, subtraction, scalar multiplication, operator multiplication, and adjoint. For example,

Addition

VibrationalOp({"+_1_0": 1}, num_modals=[2, 2]) + VibrationalOp({"+_0_0": 1}, num_modals=[2, 2])

Sum

sum(VibrationalOp({label: 1}, num_modals=[1, 1, 1]) for label in ["+_0_0", "-_1_0", "+_2_0 -_2_0"])

Scalar multiplication

0.5 * VibrationalOp({"+_1_0": 1}, num_modals=[1, 1])

Operator multiplication

op1 = VibrationalOp({"+_0_0 -_1_0": 1}, num_modals=[1, 1])
op2 = VibrationalOp({"-_0_0 +_0_0 +_1_0": 1}, num_modals=[1, 1])
print(op1 @ op2)

Tensor multiplication

op = VibrationalOp({"+_0_0 -_1_0": 1}, num_modals=[1, 1])
print(op ^ op)

Adjoint

VibrationalOp({"+_0_0 -_1_0": 1j}, num_modals=[1, 1]).adjoint()

Iteration

Instances of VibrationalOp are iterable. Iterating a VibrationalOp yields (term, coefficient) pairs describing the terms contained in the operator.

Nota

A VibrationalOp can contain qiskit.circuit.ParameterExpression objects as coefficients.

Parámetros:
  • data (Mapping[str, _TCoeff]) – the operator data, mapping string-based keys to numerical values.

  • num_modals (Sequence[int] | None) – number of modals - described by a sequence of integers where each integer describes the number of modals in the corresponding mode; the total number of modals defines the register_length.

  • copy (bool) – when set to False the data will not be copied and the dictionary will be stored by reference rather than by value (which is the default; copy=True). Note, that this requires you to not change the contents of the dictionary after constructing the operator. This also implies validate=False. Use with care!

  • validate (bool) – when set to False the data keys will not be validated. Note, that the SparseLabelOp base class, makes no assumption about the data keys, so will not perform any validation by itself. Only concrete subclasses are encouraged to implement a key validation method. Disable this setting with care!

Muestra:

QiskitNatureError – when an invalid key is encountered during validation.

Attributes

atol = 1e-08#
num_modals#

The number of modals for each mode on which this operator acts.

This is an optional sequence of integers which are considered lower bounds. That means that mathematical operations acting on two or more operators will result in a new operator with the maximum number of modals for each mode involved in any of the operators.

register_length#
rtol = 1e-05#

Methods

adjoint()#

Return the adjoint of the Operator.

Tipo del valor devuelto:

Self

argsort(*, weight=False)#

Returns the keys which sort this operator.

Parámetros:

weight (bool) – when True, the returned keys will sort this operator according to the coefficient weights of the stored terms; when False, the keys will sort the operator by its keys (i.e. lexicographically).

Devuelve:

The sequence of keys which sort this operator.

Tipo del valor devuelto:

Sequence[str]

assign_parameters(parameters)#

Assign parameters to new parameters or values.

Parámetros:

parameters (Mapping[ParameterExpression, complex | ParameterExpression]) – The mapping from parameters to new parameters or values.

Devuelve:

A new operator with the parameters assigned.

Tipo del valor devuelto:

SparseLabelOp

static build_dual_index(num_modals, index)[fuente]#

Convert a single expanded index into a dual mode and modal index string.

Parámetros:
  • num_modals (Sequence[int]) – The number of modals - described by a list of integers where each integer describes the number of modals in the corresponding mode; the total number of modals defines the register_length.

  • index (int) – The expanded (register) index.

Devuelve:

The dual index label.

Muestra:

ValueError – If the index is greater than the sum of num_modals.

Tipo del valor devuelto:

str

chop(atol=None)#

Chops the real and imaginary parts of the operator coefficients.

This function separately chops the real and imaginary parts of all coefficients to the provided tolerance. Parameters are chopped only if they are exactly zero.

Parámetros:

atol (float | None) – the tolerance to which to chop. If None, atol will be used.

Devuelve:

The chopped operator.

Tipo del valor devuelto:

SparseLabelOp

compose(other, qargs=None, front=False)[fuente]#

Returns the operator composition with another operator.

Parámetros:
  • other (VibrationalOp) – the other operator.

  • qargs – UNUSED.

  • front (bool) – If True composition uses right operator multiplication, otherwise left multiplication is used (the default).

Devuelve:

The operator resulting from the composition.

Tipo del valor devuelto:

VibrationalOp

Nota

Composition (&) by default is defined as left matrix multiplication for matrix operators, while @ (equivalent to dot()) is defined as right matrix multiplication. This means that A & B == A.compose(B) is equivalent to B @ A == B.dot(A) when A and B are of the same type.

Setting the front=True keyword argument changes this to right matrix multiplication which is equivalent to the dot() method A.dot(B) == A.compose(B, front=True).

conjugate()#

Returns the conjugate of the SparseLabelOp.

Devuelve:

The complex conjugate of the starting SparseLabelOp.

Tipo del valor devuelto:

SparseLabelOp

dot(other, qargs=None)#

Return the right multiplied operator self * other.

Parámetros:
  • other (Operator) – an operator object.

  • qargs (list or None) – Optional, a list of subsystem positions to apply other on. If None apply on all subsystems (default: None).

Devuelve:

The right matrix multiplied Operator.

Tipo del valor devuelto:

Operator

Nota

The dot product can be obtained using the @ binary operator. Hence a.dot(b) is equivalent to a @ b.

equiv(other, *, atol=None, rtol=None)#

Check equivalence of two SparseLabelOp instances up to an accepted tolerance.

Parámetros:
  • other (SparseLabelOp) – the second SparseLabelOp to compare with this instance.

  • atol (float | None) – Absolute numerical tolerance. The default behavior is to use self.atol.

  • rtol (float | None) – Relative numerical tolerance. The default behavior is to use self.rtol.

Devuelve:

True if operators are equivalent, False if not.

Muestra:

ValueError – Raised if either operator contains parameters

Tipo del valor devuelto:

bool

expand(other)[fuente]#

Returns the reverse-order tensor product with another operator.

Parámetros:

other (VibrationalOp) – the other operator.

Devuelve:

The operator resulting from the tensor product, \(othr \otimes self\).

Tipo del valor devuelto:

VibrationalOp

classmethod from_polynomial_tensor(tensor)[fuente]#

Constructs the operator from a PolynomialTensor.

Parámetros:

tensor (PolynomialTensor) – the PolynomialTensor to be expanded.

Devuelve:

The constructed operator.

Tipo del valor devuelto:

VibrationalOp

classmethod from_terms(terms)[fuente]#

Constructs a new SparseLabelOp from a sequence returned by terms().

Parámetros:

terms (Sequence[tuple[list[tuple[str, int]], Union[complex, qiskit.circuit.parameterexpression.ParameterExpression]]]) – a sequence as returned by terms().

Devuelve:

The constructed operator.

Tipo del valor devuelto:

VibrationalOp

get(k[, d]) D[k] if k in D, else d.  d defaults to None.#
index_order()[fuente]#

Convert to the equivalent operator with the terms of each label ordered by index.

Returns a new operator (the original operator is not modified).

Nota

You can use this method to achieve the most aggressive simplification of an operator without changing the operation order per index. simplify() does not reorder the terms and, thus, cannot deduce -_0_0 +_1_0 and +_1_0 -_0_0 +_0_0 -_0_0 to be identical labels. Calling this method will reorder the latter label to -_0_0 +_0_0 -_0_0 +_1_0, after which simplify() will be able to correctly collapse these two labels into one.

Devuelve:

The index ordered operator.

Tipo del valor devuelto:

VibrationalOp

induced_norm(order=1)#

Returns the p-norm induced by the operator coefficients.

If the operator is represented as a sum of terms

\[\sum_i w_i H_i\]

then the induced \(p\)-norm is

\[\left(\sum_i |w_i|^p \right)^{1/p}\]

This is the standard \(p\)-norm of the operator coefficients considered as a vector (see https://en.wikipedia.org/wiki/Norm_(mathematics)#p-norm). Note that this method does not normal-order or simplify the operator before computing the norm; performing either of those operations can affect the result.

Parámetros:

order (int) – Order \(p\) of the norm. The default value is 1.

Devuelve:

The induced norm.

Tipo del valor devuelto:

float

Muestra:

ValueError – Operator contains parameters.

Tipo del valor devuelto:

float

is_parameterized()#

Returns whether the operator contains any parameters.

Tipo del valor devuelto:

bool

is_zero(tol=None)#

Returns true if operator length is zero or all coefficients have value zero.

Parámetros:

tol (int | None) – tolerance for checking coefficient values. If this is None, atol will be used instead.

Devuelve:

If operator length is zero or all coefficients are zero.

Tipo del valor devuelto:

bool

items() a set-like object providing a view on D's items#
keys() a set-like object providing a view on D's keys#
normal_order()[fuente]#

Convert to the equivalent operator in normal order.

The normal order for this operator is defined as follows: - creation (+) operations are applied before annihilation (-) ones - operators are ordered by index within each of the operator type groups

Returns a new operator (the original operator is not modified).

Nota

The operations encoded by a VibrationalOp are fully commutative, which means that re-ordering of individual terms does not result in a phase shift.

Devuelve:

The normal ordered operator.

Tipo del valor devuelto:

VibrationalOp

classmethod one()#

Constructs a unity-operator.

Devuelve:

The unity-operator of the given length.

Tipo del valor devuelto:

SparseLabelOp

parameters()#

Returns a list of the parameters in the operator.

Devuelve:

A list of the parameters in the operator.

Tipo del valor devuelto:

list[qiskit.circuit.parameterexpression.ParameterExpression]

permute_indices(permutation)#

Permutes the indices of the operator.

This method applies the provided index permutation to all labels of this operator. The provided permutation must be a sequence of integers whose length is equal to the register_length of the operator. The integer at any given index of the sequence indicates the new index which that location will be permuted to. For example:

op = SparseLabelOp({"+_0 -_1 +_2 -_3": 1.0})
permuted_op = op.permute_indices([3, 1, 0, 2])
assert permuted_op == SparseLabelOp({"+_3 -_1 +_0 -_2": 1.0})

Advertencia

This permutation utility is very powerful. Be mindful of the implications such a permutation might have on other components of the stack. To name an example, the builtin two-qubit reduction of the ParityMapper might not yield the expected results when used on permuted operator.

Parámetros:

permutation (Sequence[int]) – a sequence of integers indicating the permutation to be applied. See above for an example.

Devuelve:

A new operator instance with the permuted indices.

Muestra:

ValueError – if the length of the permutation argument does not equal register_length.

Tipo del valor devuelto:

SparseLabelOp

power(n)#

Return the compose of a operator with itself n times.

Parámetros:

n (int) – the number of times to compose with self (n>0).

Devuelve:

the n-times composed operator.

Tipo del valor devuelto:

Clifford

Muestra:

QiskitError – if the input and output dimensions of the operator are not equal, or the power is not a positive integer.

round(decimals=0)#

Rounds the operator coefficients to a specified number of decimal places.

Parámetros:

decimals (int) – the number of decimal places to round coefficients to. By default this will round to the nearest integer value.

Devuelve:

The rounded operator.

Tipo del valor devuelto:

SparseLabelOp

simplify(atol=None)[fuente]#

Simplify the operator.

The simplifications implemented by this method should be: - to eliminate terms whose coefficients are close (w.r.t. atol) to 0. - to combine the coefficients which correspond to equivalent terms (see also the note below)

Nota

simplify() should be used to simplify terms whose coefficients are close to zero, up to the specified numerical tolerance. It still differs slightly from chop() because that will chop real and imaginary part components individually.

Nota

The meaning of «equivalence» between multiple terms depends on the specific operator subclass. As a restriction this method is required to preserve the order of appearance of the different components within a term. This avoids some possibly unexpected edge cases. However, this also means that some equivalencies cannot be detected. Check for other methods of a specific subclass which may affect the order of terms and can allow for further simplifications to be implemented. For example, check out index_order().

This method returns a new operator (the original operator is not modified).

Parámetros:

atol (float | None) – Absolute numerical tolerance. The default behavior is to use self.atol.

Devuelve:

The simplified operator.

Tipo del valor devuelto:

VibrationalOp

sort(*, weight=False)#

Returns a new sorted operator.

Parámetros:

weight (bool) – when True, the returned keys will sort this operator according to the coefficient weights of the stored terms; when False, the keys will sort the operator by its keys (i.e. lexicographically).

Devuelve:

A new operator instance with its contents sorted.

Tipo del valor devuelto:

SparseLabelOp

tensor(other)[fuente]#

Returns the tensor product with another SparseLabelOp.

Parámetros:

other (VibrationalOp) – the other SparseLabelOp.

Devuelve:

The operator resulting from the tensor product, \(self \otimes other\).

Tipo del valor devuelto:

VibrationalOp

Nota

The tensor product can be obtained using the ^ binary operator. Hence a.tensor(b) is equivalent to a ^ b.

terms()[fuente]#

Provides an iterator analogous to items() but with the labels already split into pairs of operation characters and indices.

Campos:

A tuple with two items; the first one being a list of pairs of the form (char, int) where char is either + or - and the integer corresponds to the vibrational mode and modal index on which the operator gets applied; the second item of the returned tuple is the coefficient of this term.

Tipo del valor devuelto:

Iterator[tuple[list[tuple[str, int]], Union[complex, qiskit.circuit.parameterexpression.ParameterExpression]]]

transpose()[fuente]#

Returns the transpose of the operator.

Devuelve:

The transpose of the operator.

Tipo del valor devuelto:

VibrationalOp

values() an object providing a view on D's values#
classmethod zero()#

Constructs a zero-operator.

Devuelve:

The zero-operator of the given length.

Tipo del valor devuelto:

SparseLabelOp