Exemplo n.º 1
0
    def __init__(
        self,
        pauli_string: ps.PauliString,
        *,
        exponent_neg: Union[int, float, sympy.Expr] = 1,
        exponent_pos: Union[int, float, sympy.Expr] = 0,
    ) -> None:
        """Initializes the operation.

        Args:
            pauli_string: The PauliString defining the positive and negative
                eigenspaces that will be independently phased.
            exponent_neg: How much to phase vectors in the negative eigenspace,
                in the form of the t in (-1)**t = exp(i pi t).
            exponent_pos: How much to phase vectors in the positive eigenspace,
                in the form of the t in (-1)**t = exp(i pi t).

        Raises:
            ValueError: If coefficient is not 1 or -1.
        """
        gate = PauliStringPhasorGate(
            pauli_string.dense(pauli_string.qubits),
            exponent_neg=exponent_neg,
            exponent_pos=exponent_pos,
        )
        super().__init__(gate, pauli_string.qubits)
        self._pauli_string = gate.dense_pauli_string.on(*self.qubits)
Exemplo n.º 2
0
    def __init__(
        self,
        pauli_string: ps.PauliString,
        qubits: Optional[Sequence['cirq.Qid']] = None,
        *,
        exponent_neg: Union[int, float, sympy.Expr] = 1,
        exponent_pos: Union[int, float, sympy.Expr] = 0,
    ) -> None:
        """Initializes the operation.

        Args:
            pauli_string: The PauliString defining the positive and negative
                eigenspaces that will be independently phased.
            qubits: The qubits upon which the PauliStringPhasor acts. This
                must be a superset of the qubits of `pauli_string`.
                If None, it will use the qubits from `pauli_string`
                The `pauli_string` contains only the non-identity component
                of the phasor, while the qubits supplied here and not in
                `pauli_string` are acted upon by identity. The order of
                these qubits must match the order in `pauli_string`.
            exponent_neg: How much to phase vectors in the negative eigenspace,
                in the form of the t in (-1)**t = exp(i pi t).
            exponent_pos: How much to phase vectors in the positive eigenspace,
                in the form of the t in (-1)**t = exp(i pi t).

        Raises:
            ValueError: If coefficient is not 1 or -1 or the qubits of
                `pauli_string` are not a subset of `qubits`.
        """
        if qubits is not None:
            it = iter(qubits)
            if any(not any(q0 == q1 for q1 in it)
                   for q0 in pauli_string.qubits):
                raise ValueError(
                    f"PauliStringPhasor's pauli string qubits ({pauli_string.qubits}) "
                    f"are not an ordered subset of the explicit qubits ({qubits})."
                )
        else:
            qubits = pauli_string.qubits
        # Use qubits below instead of `qubits or pauli_string.qubits`
        gate = PauliStringPhasorGate(pauli_string.dense(qubits),
                                     exponent_neg=exponent_neg,
                                     exponent_pos=exponent_pos)
        super().__init__(gate, qubits)
        self._pauli_string = gate.dense_pauli_string.on(*self.qubits)