Skip to content

Observable Measurement - 4 - Sampling Loop #3647

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

Closed
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions cirq/ops/pauli_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ def __init__(
self._qubit_pauli_map = m._qubit_pauli_map
self._coefficient = m._coefficient

def copy(self):
return PauliString(
qubit_pauli_map=self._qubit_pauli_map.copy(), coefficient=self.coefficient
)

@property
def coefficient(self) -> complex:
return self._coefficient
Expand Down Expand Up @@ -397,6 +402,8 @@ def __repr__(self) -> str:
factors = []
if self._coefficient == -1:
prefix = '-'
elif self._coefficient == 1 and len(ordered_qubits) == 1:
factors.append('1')
elif self._coefficient != 1:
factors.append(repr(self._coefficient))

Expand Down
3 changes: 3 additions & 0 deletions cirq/ops/pauli_string_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,9 @@ def test_repr():
cirq.testing.assert_equivalent_repr(2 * pauli_string)
cirq.testing.assert_equivalent_repr(cirq.PauliString())

ps = cirq.PauliString({q2: cirq.X})
cirq.testing.assert_equivalent_repr(ps)


def test_str():
q0, q1, q2 = _make_qubits(3)
Expand Down
Loading