diff --git a/cirq-core/cirq/ops/pauli_string.py b/cirq-core/cirq/ops/pauli_string.py index 9d146639143..028a0d5d22d 100644 --- a/cirq-core/cirq/ops/pauli_string.py +++ b/cirq-core/cirq/ops/pauli_string.py @@ -1546,6 +1546,6 @@ def _pauli_like_to_pauli_int(key: Any, pauli_gate_like: PAULI_GATE_LIKE): f'Expected {key!r}: {pauli_gate_like!r} to have a ' f'cirq.PAULI_GATE_LIKE value. ' f"But the value isn't in " - f"{list(PAULI_GATE_LIKE_TO_INDEX_MAP.values())!r}" + f"{set(PAULI_GATE_LIKE_TO_INDEX_MAP.keys())!r}" ) return cast(int, pauli_int) diff --git a/cirq-core/cirq/ops/pauli_string_test.py b/cirq-core/cirq/ops/pauli_string_test.py index 59f25e67f12..c164d573b38 100644 --- a/cirq-core/cirq/ops/pauli_string_test.py +++ b/cirq-core/cirq/ops/pauli_string_test.py @@ -1873,6 +1873,22 @@ def test_mutable_pauli_string_dict_functionality(): assert b not in p +@pytest.mark.parametrize( + 'pauli', (cirq.X, cirq.Y, cirq.Z, cirq.I, "I", "X", "Y", "Z", "i", "x", "y", "z", 0, 1, 2, 3) +) +def test_mutable_pauli_string_dict_pauli_like(pauli): + p = cirq.MutablePauliString() + # Check that is successfully converts. + p[0] = pauli + + +def test_mutable_pauli_string_dict_pauli_like_not_pauli_like(): + p = cirq.MutablePauliString() + # Check error string includes terms like "X" in error message. + with pytest.raises(TypeError, match="PAULI_GATE_LIKE.*X"): + p[0] = 1.2 + + def test_mutable_pauli_string_text(): p = cirq.MutablePauliString(cirq.X(cirq.LineQubit(0)) * cirq.Y(cirq.LineQubit(1))) assert str(cirq.MutablePauliString()) == "mutable I"