Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error and add test for mutable pauli string #5213

Merged
merged 3 commits into from
Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cirq-core/cirq/ops/pauli_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
16 changes: 16 additions & 0 deletions cirq-core/cirq/ops/pauli_string_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down