cirq.LinearCombinationOfGates

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.

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

Methods

clean(*, atol) Remove terms with coefficients of absolute value atol or less.
clear()
copy()
fromkeys(vectors[, coefficient])
get(k[,d])
items()
keys()
matrix() Reconstructs matrix of self using unitaries of underlying gates.
num_qubits() Returns number of qubits in the domain if known, None if unknown.
pop(k[,d]) If key is not found, d is returned if given, otherwise KeyError is raised.
popitem() 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]
values()

Attributes

TSelf