Skip to content

Useful functions

Currently, there are two useful methods for querying and manipulating expressions, namely collect_operators and replace. In following are examples for each.

from qadence2_expressions import *

collected_ops = collect_operators(Z(1) + 2 * Z(1) * Z (2) - X(3))
{QuantumOperator(Symbol('Z'), [1], is_hermitian=True, is_unitary=True): Value(1.0), KroneckerProduct(QuantumOperator(Symbol('Z'), [1], is_hermitian=True, is_unitary=True), QuantumOperator(Symbol('Z'), [2], is_hermitian=True, is_unitary=True)): Value(2.0), QuantumOperator(Symbol('X'), [3], is_hermitian=True, is_unitary=True): Value(-1.0)}
replacement_rules = {Z(1): X(1)}

replaced_ops = replace(Z(1) + 2 * Z(1) * Z (2) - X(3), replacement_rules)
 X[1] + 2.0 * X[1] * Z[2] - X[3]