Exemplo n.º 1
0
def _max_weight_state(states: Iterable[value.ProductState]) \
        -> Union[None, value.ProductState]:
    """Create a new state that is compatible with all input states
    and has the maximum weight.

    The returned TensorProductState is constructed by taking the
    single-qubit state at each qubit position.

    This function will return `None` if the input states are not compatible

    For example, the max_weight_state of [+X(0), -Z(1)] is
    "+X(0) * -Z(1)". Asking for the max weight state of something like
    [+X(0), +Z(0)] will return None.
    """
    qubit_state_map = dict()  # type: Dict[ops.Qid, _NamedOneQubitState]
    for state in states:
        for qubit, named_state in state:
            if qubit in qubit_state_map:
                if qubit_state_map[qubit] != named_state:
                    return None
            else:
                qubit_state_map[qubit] = named_state
    return value.ProductState(qubit_state_map)
Exemplo n.º 2
0
def zeros_state(qubits: Iterable['cirq.Qid']):
    """Return the ProductState that is |00..00> on all qubits."""
    return value.ProductState({q: value.KET_ZERO for q in qubits})