class cirq.LinearCombinationOfGates(terms: Mapping[cirq.ops.raw_types.Gate, Union[complex, float]])[source]

Represents linear operator defined by a linear combination of gates.

Suppose G1, G2, …, Gn are gates and b1, b2, …, bn are complex
numbers. Then
LinearCombinationOfGates({G1: b1, G2: b2, ..., Gn: bn})

represents the linear operator

A = b1 G1 + b2 G2 + ... + bn Gn

Note that A may not be unitary or even normal.

Rather than creating LinearCombinationOfGates instance explicitly, one may
use overloaded arithmetic operators. For example,
cirq.LinearCombinationOfGates({cirq.X: 2, cirq.Z: -2})

is equivalent to

2 * cirq.X - 2 * cirq.Z
__init__(terms: Mapping[cirq.ops.raw_types.Gate, Union[complex, float]]) → None[source]

Initializes linear combination from a collection of terms.


terms – Mapping of gates to coefficients in the linear combination being initialized.