View source on GitHub |
Represents operator defined by linear combination of gate operations.
Inherits From: LinearDict
cirq.LinearCombinationOfOperations(
terms: Mapping[raw_types.Operation, value.Scalar]
) -> None
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.
Args | |
---|---|
terms
|
Mapping of gate operations to coefficients in the linear combination being initialized. |
Attributes | |
---|---|
qubits
|
Returns qubits acted on self. |
Methods
clean
clean(
*, atol: float = 1e-09
) -> Self
Remove terms with coefficients of absolute value atol or less.
clear
clear()
D.clear() -> None. Remove all items from D.
copy
copy() -> Self
fromkeys
@classmethod
fromkeys( vectors, coefficient=0 )
get
get(
vector, default=0
)
D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.
items
items() -> ItemsView[TVector, Scalar]
D.items() -> a set-like object providing a view on D's items
keys
keys() -> KeysView[TVector]
D.keys() -> a set-like object providing a view on D's keys
matrix
matrix() -> np.ndarray
Reconstructs matrix of self using unitaries of underlying operations.
Raises | |
---|---|
TypeError
|
if any of the gates in self does not provide a unitary. |
pop
pop(
key, default=__marker
)
D.pop(k[,d]) -> v, remove specified key and return the corresponding value. If key is not found, d is returned if given, otherwise KeyError is raised.
popitem
popitem()
D.popitem() -> (k, v), remove and return some (key, value) pair as a 2-tuple; but raise KeyError if D is empty.
setdefault
setdefault(
key, default=None
)
D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D
update
update(
*args, **kwargs
)
D.update([E, ]**F) -> None. Update D from mapping/iterable E and F. If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
values
values() -> ValuesView[Scalar]
D.values() -> an object providing a view on D's values
__add__
__add__(
other: Self
) -> Self
__bool__
__bool__() -> bool
__contains__
__contains__(
vector: Any
) -> bool
__eq__
__eq__(
other: Any
) -> bool
Checks whether two linear combinations are exactly equal.
Presence or absence of terms with coefficients exactly equal to zero does not affect outcome.
Not appropriate for most practical purposes due to sensitivity to numerical error in floating point coefficients. Use cirq.approx_eq() instead.
__getitem__
__getitem__(
vector: TVector
) -> Scalar
__iter__
__iter__() -> Iterator[TVector]
__len__
__len__() -> int
__mul__
__mul__(
a: Scalar
) -> Self
__ne__
__ne__(
other: Any
) -> bool
Checks whether two linear combinations are not exactly equal.
See eq().
__neg__
__neg__() -> Self
__pow__
__pow__(
exponent: int
) -> 'LinearCombinationOfOperations'
__rmul__
__rmul__(
a: Scalar
) -> Self
__sub__
__sub__(
other: Self
) -> Self
__truediv__
__truediv__(
a: Scalar
) -> Self