# cirq.LinearCombinationOfOperations¶

class cirq.LinearCombinationOfOperations(*args, **kwds)[source]

Represents operator defined by linear combination of gate operations.

If G1, …, Gn are gate operations, {q1_1, …, q1_k1}, {q2_1, …, q2_k2},
…, {qn_1, …, qn_kn} are (not necessarily disjoint) sets of qubits and
b1, b2, …, bn are complex numbers, then
LinearCombinationOfOperations({
G1(q1_1, ..., q1_k1): b1,
G2(q2_1, ..., q2_k2): b2,
...,
Gn(qn_1, ..., qn_kn): bn})


represents the linear operator

A = b1 G1(q1_1, ..., q1_k1) +
+ b2 G2(q2_1, ..., q2_k2) +
+ ... +
+ bn Gn(qn_1, ..., qn_kn)

where in each term qubits not explicitly listed are assumed to be acted on
by the identity operator. Note that A may not be unitary or even normal.
__init__(terms: Mapping[cirq.ops.raw_types.Operation, Union[complex, float]]) → None[source]

Initializes linear combination from a collection of terms.

Parameters

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

Methods

 clean(*[, atol]) Remove terms with coefficients of absolute value atol or less. fromkeys(vectors[, coefficient]) get(k[,d]) Reconstructs matrix of self using unitaries of underlying operations. pop(k[,d]) If key is not found, d is returned if given, otherwise KeyError is raised. as a 2-tuple; but raise KeyError if D is empty. setdefault(k[,d]) update([E, ]**F) If E present and has a .keys() method, does: for k in E: D[k] = E[k]

Attributes

 TSelf qubits Returns qubits acted on self.