1
1
"""Represents Pauli strings, which is linear combinations of
2
- :class:`PauliMonomial` with is a combination of :class:`PauliAtom`.
2
+ :class:`PauliMonomial` which is a combination of :class:`PauliAtom`.
3
3
:class:`PauliString` objects can be added, subtracted, and multiplied by
4
4
scalars. They also support matrix multiplication with other :class:`PauliString`
5
5
objects.
@@ -48,7 +48,7 @@ def __init__(self, monomials: Optional[list["PauliStringMonomial"]] = None):
48
48
49
49
@property
50
50
def monomials (self ) -> list [PauliStringMonomial ]:
51
- """Get the monomials of the PauliString.
51
+ """Gets the monomials of the PauliString.
52
52
53
53
Returns:
54
54
The list of monomials in the PauliString.
@@ -57,7 +57,7 @@ def monomials(self) -> list[PauliStringMonomial]:
57
57
58
58
@property
59
59
def nb_qubits (self ) -> int :
60
- """Get the number of qubits associated with the PauliString.
60
+ """Gets the number of qubits associated with the PauliString.
61
61
62
62
Returns:
63
63
The number of qubits associated with the PauliString.
@@ -139,11 +139,11 @@ def __eq__(self, other: object) -> bool:
139
139
return self .to_dict () == other .to_dict ()
140
140
141
141
def simplify (self , inplace : bool = False ) -> PauliString :
142
- """Simplify the PauliString by combining like terms and removing terms
142
+ """Simplifies the PauliString by combining like terms and removing terms
143
143
with zero coefficients.
144
144
145
145
Args:
146
- inplace: If the simplify should change self.
146
+ inplace: Indicates if `` simplify`` should update self.
147
147
148
148
Example:
149
149
>>> ps = I @ I - 2 * I @ I + Z @ I - Z @ I
@@ -175,7 +175,7 @@ def simplify(self, inplace: bool = False) -> PauliString:
175
175
return res
176
176
177
177
def to_matrix (self ) -> Matrix :
178
- """Convert the PauliString to a matrix representation.
178
+ """Converts the PauliString to a matrix representation.
179
179
180
180
Example:
181
181
>>> ps = I + Z
@@ -195,18 +195,18 @@ def to_matrix(self) -> Matrix:
195
195
196
196
@classmethod
197
197
def from_matrix (cls , matrix : Matrix ) -> PauliString :
198
- """Construct a PauliString from a matrix.
198
+ """Constructs a PauliString from a matrix.
199
199
200
200
Args:
201
- Matrix from which the PauliString is generated
201
+ matrix: Matrix from which the PauliString is generated
202
202
203
203
Example:
204
204
>>> ps = PauliString.from_matrix(np.array([[0, 1], [1, 2]]))
205
205
>>> print(ps)
206
206
(1+0j)*I + (1+0j)*X + (-1+0j)*Z
207
207
208
208
Returns:
209
- PauliString: form class PauliString .
209
+ PauliString: Pauli string decomposition of the matrix in parameter .
210
210
211
211
Raises:
212
212
ValueError: If the input matrix is not square or its dimensions are not a power of 2.
@@ -238,15 +238,15 @@ def from_matrix(cls, matrix: Matrix) -> PauliString:
238
238
return pauli_list
239
239
240
240
def to_dict (self ) -> dict [str , float ]:
241
- """Convert the PauliString object to a dictionary representation.
242
-
243
- Returns:
244
- Dictionary representation of the PauliString object.
241
+ """Converts the PauliString object to a dictionary representation.
245
242
246
243
Example:
247
244
>>> ps = 1 * I @ Z + 2 * I @ I
248
245
>>> print(ps.to_dict())
249
246
{'II': 2, 'IZ': 1}
247
+
248
+ Returns:
249
+ Dictionary representation of the PauliString object.
250
250
"""
251
251
self = self .simplify ()
252
252
dict = {}
@@ -383,8 +383,8 @@ class PauliStringAtom(PauliStringMonomial):
383
383
"""Represents a single Pauli operator acting on a qubit in a Pauli string.
384
384
385
385
Args:
386
- Label : The label representing the Pauli operator (e.g., 'I', 'X', 'Y', 'Z').
387
- Matrix : The matrix representation of the Pauli operator.
386
+ label : The label representing the Pauli operator (e.g., 'I', 'X', 'Y', 'Z').
387
+ matrix : The matrix representation of the Pauli operator.
388
388
389
389
Raises:
390
390
AttributeError: new atoms cannot be created
0 commit comments