You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Following on from #1007, @jlbosse also improved in #984 some of the error messages for PauliSum and PauliTerm objects, but they certainly could continue to improve. A valid approach would be to separate errors into those concerned with operators and those concerned with coefficients, and to create custom exceptions that point users in the right direction for creating a valid object from a Pauli string.
In [5]: PauliTerm.from_compact_str("(1.0+9i)*X0")
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
~/code/rigetti/github/pyquil/pyquil/paulis.py in from_compact_str(cls, str_pauli_term)
371 try:
--> 372 coef = float(str_coef)
373 except ValueError:
ValueError: could not convert string to float: '(1.0+9i)'
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
~/code/rigetti/github/pyquil/pyquil/paulis.py in from_compact_str(cls, str_pauli_term)
374 try:
--> 375 coef = complex(str_coef)
376 except ValueError:
ValueError: complex() arg is a malformed string
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
<ipython-input-5-e7b8a524abb7> in <module>
----> 1 PauliTerm.from_compact_str("(1.0+9i)*X0")
~/code/rigetti/github/pyquil/pyquil/paulis.py in from_compact_str(cls, str_pauli_term)
375 coef = complex(str_coef)
376 except ValueError:
--> 377 raise ValueError("Could not parse the coefficient "
378 f"{str_coef}")
379
ValueError: Could not parse the coefficient (1.0+9i)
In [6]: PauliTerm.from_compact_str("(1.0+0j)*A0")
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-6-c2a2c5e2d3b7> in <module>
----> 1 PauliTerm.from_compact_str("(1.0+0j)*A0")
~/code/rigetti/github/pyquil/pyquil/paulis.py in from_compact_str(cls, str_pauli_term)
385 str_op = re.sub(r'\*', '', str_op)
386 if not re.match(r'^(([XYZ])(\d+))+$', str_op):
--> 387 raise ValueError(f"Could not parse operator string {str_op}. "
388 r"It should match ^(([XYZ])(\d+))+$")
389
ValueError: Could not parse operator string A0. It should match ^(([XYZ])(\d+))+$
The text was updated successfully, but these errors were encountered:
Following on from #1007, @jlbosse also improved in #984 some of the error messages for
PauliSum
andPauliTerm
objects, but they certainly could continue to improve. A valid approach would be to separate errors into those concerned with operators and those concerned with coefficients, and to create custom exceptions that point users in the right direction for creating a valid object from a Pauli string.The text was updated successfully, but these errors were encountered: