def _ps_on_qubits(ps: cirq.PauliString, qubits: tuple[cirq.Qid, ...]):
        """Extracts a sub-PauliString from a given PauliString, restricted to
        a specified subset of qubits.
        """
        pauli_map = {}
        for q, pauli in ps.items():
            if q in qubits:
                pauli_map[q] = pauli
        return cirq.PauliString(qubit_pauli_map=pauli_map, coefficient=ps.coefficient)
Extracts a sub-PauliString from a given PauliString, restricted to
        a specified subset of qubits.
        
cirq-core/cirq/ops/pauli_string_test.py