Skip to content

Conversation

@DeDuckProject
Copy link
Contributor

@DeDuckProject DeDuckProject commented Sep 21, 2025

Added support for constructing stim.PauliString using a Dict with keys as either int (for qubit indices) or str (for Pauli).

e.g.:

stim.PauliString({0: "X", 2: "Y", 3: "X"}) == stim.PauliString("X_YX")
stim.PauliString({"X": 1, "Z: [0, 3]}) == stim.PauliString("ZX_Z")

Resolves #852

@google-cla
Copy link

google-cla bot commented Sep 21, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@DeDuckProject DeDuckProject changed the title Feature/pauli string dict PauliString constructor - Add support for Dict Sep 21, 2025
Copy link
Collaborator

@Strilanc Strilanc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This is nearly mergeable.

Mainly, I think the dict[int, int] case needs to be guaranteed to be int->pauli (rather than pauli->int) to avoid ambiguity.

Secondarily, there's a few places the code is being inefficient by having a quadratic check or potential unnecessary copies.

Stylistically, the method is getting so long that this case should be extracted.

@Strilanc Strilanc changed the title PauliString constructor - Add support for Dict Add support for dict[int, Iterable[str | int]] and dict[str | int, int] to stim.PauliString.__init__` Sep 22, 2025
@DeDuckProject
Copy link
Contributor Author

DeDuckProject commented Sep 26, 2025

@Strilanc Fixed all your comments. PR is ready for merging as far as I'm concerned.
Only thing I'm debating is whether the documentation of this feature is clear enough.

Copy link
Collaborator

@Strilanc Strilanc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thanks!

@Strilanc Strilanc merged commit 365a1d8 into quantumlib:main Sep 26, 2025
63 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add dict[int, int | str] and dict[str, int | Iterable[int]] argument support to stim.PauliString.__init__

2 participants