feat: add PauliStringSum class for sums of weighted PauliStrings#1291
Open
tanishqbagriaresearch-hue wants to merge 21 commits into
Open
feat: add PauliStringSum class for sums of weighted PauliStrings#1291tanishqbagriaresearch-hue wants to merge 21 commits into
tanishqbagriaresearch-hue wants to merge 21 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1256
This PR introduces a new
PauliStringSumclass that represents a linear combination (weighted sum) ofPauliStringobjects, enabling richer algebraic operations on Pauli operators.Changes
New File:
src/braket/quantum_information/pauli_string_sum.pyPauliStringSumclass to represent sums of weightedPauliStringobjectsPauliStringobjects with optional scalar weights__mul__and__rmul__PauliString(element-wise Pauli product) via__mul__and__rmul____getitem__) andinchecks (__contains__)to_list()method for conversion to list of(float, str)tuplesfrom_list()class method for constructing from list of(float, str)tuplescommutes_with()for checking commutativity with anotherPauliStringis_self_commuting()to check if all terms in the sum mutually commuteBug Fix:
PauliString.__mul__PauliString.__mul__to returnNotImplementedfor non-PauliStringtypes, allowing Python to correctly fall back toPauliStringSum.__rmul__when multiplying aPauliStringby aPauliStringSumTesting
inchecksto_list()/from_list()round-tripscommutes_with()andis_self_commuting()checksMerge Checklist
Tests
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.