Skip to content

Extend Circuit parsing of qubit labels #495

@sserita

Description

@sserita

Describe the bug
Circuit parsing currently fails if the qubit labels are not integers or begin with 'Q'. This is both very restrictive, and the error message is uninformative.

To Reproduce

from pygsti.circuit import Circuit

c = Circuit([("Gxpi2", "A0")]) # This is fine
c.str # This is also fine

Circuit(c.str) # Errors with ValueError: invalid literal for int() with base 10: ''

Expected behavior
At the very least, a clearer error message. The current error message is because it assumes it is not a valid str since it doesn't start with Q, therefore it must be an int, and then the int cast fails. We should catch this and output a more useful message.

But we should also consider allowing arbitrary qubit labels (these can be used if not deserializing from string without issue, and can be serialized with no problem. It's just deserialization that is a problem). I'll note that there is some importance assigned to state space label prefixes; specifically, I believe Q is used to automatically set the state space dimensions to those of a qubit. Others exist (i.e. L for leakage, etc), so the user would maybe have to specify the state space more explicitly in these cases.

Environment (please complete the following information):

  • pyGSTi 0.9.12.3
  • python 3.11
  • OSX 14

Metadata

Metadata

Assignees

Labels

bugA bug or regression

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions