rigetti / rigetti/pyquil

Allow for Pauli strings that have only operators

Open
#1,007 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug :bug: good first issue :baby:
Dominant language
Python
Stars
1.5k
Forks
358
Avg merge
1d 58m
Merged PRs (30d)
4

Description

In #984, @jlbosse has improved our functionality for creating PauliTerm and PauliSum objects from their string representations. However, there were some underlying issues with the pyquil.paulis module before he started. He captured a collection of strings that do not work as part of the unit tests he added. One of them is the following, a pauli string which is just the operator without a coefficient. I think the behavior should be changed so that this is a valid string, and the coefficient should be assumed to be 1.

In [2]: PauliTerm.from_compact_str("X0")
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
~/code/rigetti/github/pyquil/pyquil/paulis.py in from_compact_str(cls, str_pauli_term)
    362             str_coef, str_op = re.split(r'\*(?![^(]*\))', str_pauli_term,
--> 363                                         maxsplit=1)
    364         except ValueError:

ValueError: not enough values to unpack (expected 2, got 1)

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-2-05e743997d63> in <module>
----> 1 PauliTerm.from_compact_str("X0")

~/code/rigetti/github/pyquil/pyquil/paulis.py in from_compact_str(cls, str_pauli_term)
    363                                         maxsplit=1)
    364         except ValueError:
--> 365             raise ValueError("Could not separate the pauli string into "
    366                              f"coefficient and operator. {str_pauli_term} does"
    367                              " not match <coefficient>*<operator>")

ValueError: Could not separate the pauli string into coefficient and operator. X0 does not match <coefficient>*<operator>

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Inspect pyquil/paulis.py at PauliTerm.from_compact_str and review the unit tests added in #984 for unsupported string representations. Verify that an operator-only string such as "X0" is accepted with an assumed coefficient of 1, and run the relevant Pauli parsing tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.