def _row_to_dense_pauli(self, i: int) -> 'cirq.DensePauliString': """Return a dense Pauli string for the given row in the tableau. Args: i: index of the row in the tableau. Returns: A DensePauliString representing the row. The length of the string is equal to the total number of qubits and each character represents the effective single Pauli operator on that qubit. The overall phase is captured in the coefficient. """ from cirq.ops.dense_pauli_string import DensePauliString coefficient = -1 if self.rs[i] else 1 pauli_mask = "" for k in range(self.n): if self.xs[i, k] & (not self.zs[i, k]): pauli_mask += "X" elif (not self.xs[i, k]) & self.zs[i, k]: pauli_mask += "Z" elif self.xs[i, k] & self.zs[i, k]: pauli_mask += "Y" else: pauli_mask += "I" return DensePauliString(pauli_mask, coefficient=coefficient)
def gate(self) -> 'cirq.DensePauliString': order: List[Optional[pauli_gates.Pauli]] = [ None, pauli_gates.X, pauli_gates.Y, pauli_gates.Z ] from cirq.ops.dense_pauli_string import DensePauliString return DensePauliString( coefficient=self.coefficient, pauli_mask=[order.index(self[q]) for q in self.qubits])
def dense(self, qubits: Sequence['cirq.Qid']) -> 'cirq.DensePauliString': """Returns a `cirq.DensePauliString` version of this Pauli string. This method satisfies the invariant `P.dense(qubits).on(*qubits) == P`. Args: qubits: The implicit sequence of qubits used by the dense pauli string. Specifically, if the returned dense Pauli string was applied to these qubits (via its `on` method) then the result would be a Pauli string equivalent to the receiving Pauli string. Returns: A `cirq.DensePauliString` instance `D` such that `D.on(*qubits)` equals the receiving `cirq.PauliString` instance `P`. """ from cirq.ops.dense_pauli_string import DensePauliString if not self.keys() <= set(qubits): raise ValueError('not self.keys() <= set(qubits)') # pylint: disable=too-many-function-args pauli_mask = [self.get(q, identity.I) for q in qubits] # pylint: enable=too-many-function-args return DensePauliString(pauli_mask, coefficient=self.coefficient)