View source on GitHub
|
Represents control values as N OR (sum) clauses, each of which applies to one qubit.
cirq.ProductOfSums(
data: Sequence[int | Collection[int]]
)
Attributes | |
|---|---|
is_trivial
|
|
Methods
expand
expand() -> SumOfProducts
Returns an expanded cirq.SumOfProduct representation of this control values.
validate
validate(
qid_shapes: Sequence[int]
) -> None
Validates that all control values for ith qubit are in range [0, qid_shaped[i])
__and__
__and__(
other: AbstractControlValues
) -> AbstractControlValues
Returns a cartesian product of all control values predicates in self x other.
The and of two control values cv1 and cv2 represents a control value object
acting on the union of qubits represented by cv1 and cv2. For example:
cv1 = cirq.ProductOfSums([(0, 1), 2])cv2 = cirq.SumOfProducts([[0, 0], [1, 1]])assert cirq.num_qubits(cv1 & cv2) == cirq.num_qubits(cv1) + cirq.num_qubits(cv2)
| Args | |
|---|---|
other
|
An instance of AbstractControlValues.
|
| Returns | |
|---|---|
An instance of AbstractControlValues that represents the cartesian product of
control values represented by self and other.
|
__eq__
__eq__(
other: _SupportsValueEquality
) -> bool
__getitem__
__getitem__(
key: (int | slice)
) -> (ProductOfSums | tuple[int, ...])
__iter__
__iter__() -> Iterator[tuple[int, ...]]
Iterator on internal representation of control values used by the derived classes.
>>> print(*cirq.ProductOfSums([(0, 1), (0,)]))
(0, 1) (0,)
>>> print(*cirq.SumOfProducts([(0, 0), (1, 0)]))
(0, 0) (1, 0)
__ne__
__ne__(
other: _SupportsValueEquality
) -> bool
__or__
__or__(
other: AbstractControlValues
) -> AbstractControlValues
Returns a union of all control values predicates in self + other.
Both self and other must represent control values for the same set of qubits and
hence their or would also be a control value object acting on the same set of qubits.
For example:
cv1 = cirq.ProductOfSums([(0, 1), 2])cv2 = cirq.SumOfProducts([[0, 0], [1, 1]])assert cirq.num_qubits(cv1 | cv2) == cirq.num_qubits(cv1) == cirq.num_qubits(cv2)
| Args | |
|---|---|
other
|
An instance of AbstractControlValues.
|
| Returns | |
|---|---|
An instance of AbstractControlValues that represents the union of control values
represented by self and other.
|
| Raises | |
|---|---|
ValueError
|
If cirq.num_qubits(self) != cirq.num_qubits(other).
|
View source on GitHub