Skip to content

Commit f4e066f

Browse files
Add documentation for pauli string
1 parent 38365ca commit f4e066f

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

docs/measures.rst

+4
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,7 @@ Measuring using an observable
4343

4444
.. automodule:: mpqp.core.instruction.measurement.expectation_value
4545

46+
Pauli String
47+
^^^^^^^^^^^^
48+
49+
.. automodule:: mpqp.core.instruction.measurement.pauli_string

mpqp/core/instruction/measurement/pauli_string.py

+15-16
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class PauliString:
2525
monomials : List of Pauli monomials.
2626
2727
Example:
28-
>>> I@Z + 2*Y@I + X@Z
28+
>>> I @ Z + 2 * Y @ I + X @ Z
2929
1*I@Z + 2*Y@I + 1*X@Z
3030
"""
3131

@@ -118,7 +118,7 @@ def __itruediv__(self, other: FixedReal) -> "PauliString":
118118
return self
119119

120120
def __truediv__(self, other: FixedReal) -> "PauliString":
121-
return self * (1 / other) # pyright: ignore[reportOperatorIssue]
121+
return self * (1 / other) # pyright: ignore[reportOperatorIssue]
122122

123123
def __imatmul__(self, other: "PauliString") -> "PauliString":
124124
self._monomials = [
@@ -140,7 +140,7 @@ def simplify(self) -> PauliString:
140140
"""Simplify the PauliString by combining like terms and removing terms with zero coefficients.
141141
142142
Example:
143-
>>> ps = I@I - 2* I@I + Z@I - Z@I
143+
>>> ps = I @ I - 2 * I @ I + Z @ I - Z @ I
144144
>>> simplified_ps = ps.simplify()
145145
>>> print(simplified_ps)
146146
-1*I@I
@@ -426,7 +426,9 @@ def __repr__(self):
426426
return str(self)
427427

428428
def __truediv__(self, other: FixedReal) -> PauliStringMonomial:
429-
return PauliStringMonomial(1 / other , [self]) # pyright: ignore[reportArgumentType]
429+
return PauliStringMonomial(
430+
1 / other, [self]
431+
) # pyright: ignore[reportArgumentType]
430432

431433
def __imul__(self, other: FixedReal) -> PauliStringMonomial:
432434
return self * other
@@ -467,27 +469,24 @@ def __hash__(self):
467469
_allow_atom_creation = True
468470

469471
I = PauliStringAtom("I", np.eye(2, dtype=np.complex64))
470-
"""Pauli-I atom representing the identity operator in a Pauli monomial or string.
472+
r"""Pauli-I atom representing the identity operator in a Pauli monomial or string.
471473
Matrix representation:
472-
[1 0]
473-
[0 1]
474+
`\begin{pmatrix}1&0\\0&1\end{pmatrix}`
474475
"""
475476
X = PauliStringAtom("X", 1 - np.eye(2, dtype=np.complex64))
476-
"""Pauli-X atom representing the X operator in a Pauli monomial or string.
477+
r"""Pauli-X atom representing the X operator in a Pauli monomial or string.
477478
Matrix representation:
478-
[0 1]
479-
[1 0]
479+
`\begin{pmatrix}0&1\\1&0\end{pmatrix}`
480+
480481
"""
481482
Y = PauliStringAtom("Y", np.fliplr(np.diag([1j, -1j])))
482-
"""Pauli-Y atom representing the Y operator in a Pauli monomial or string.
483+
r"""Pauli-Y atom representing the Y operator in a Pauli monomial or string.
483484
Matrix representation:
484-
[0 -i]
485-
[i 0]
485+
`\begin{pmatrix}0&-i\\i&0\end{pmatrix}`
486486
"""
487487
Z = PauliStringAtom("Z", np.diag([1, -1]))
488-
"""Pauli-Z atom representing the Z operator in a Pauli monomial or string.
488+
r"""Pauli-Z atom representing the Z operator in a Pauli monomial or string.
489489
Matrix representation:
490-
[1 0]
491-
[0 -1]
490+
`\begin{pmatrix}1&0\\0&-1\end{pmatrix}`
492491
"""
493492
_allow_atom_creation = False

0 commit comments

Comments
 (0)