-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add QubitPauliOperator.get_dict
#1755
Conversation
pytket/tests/utils_test.py
Outdated
qps1 = QubitPauliString(Qubit(0), Pauli.Y) | ||
qps2 = QubitPauliString(Qubit(0), Pauli.X) | ||
op = QubitPauliOperator({qps1: 1j, qps2: 0.5}) | ||
assert op.get_dict() == op._dict |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is maybe a bit cheeky. I could do the explcit comparision if prefferred.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I think we should do an explicit comparison, to be safe against future surprises.
pytket/tests/utils_test.py
Outdated
qps1 = QubitPauliString(Qubit(0), Pauli.Y) | ||
qps2 = QubitPauliString(Qubit(0), Pauli.X) | ||
op = QubitPauliOperator({qps1: 1j, qps2: 0.5}) | ||
assert op.get_dict() == op._dict |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I think we should do an explicit comparison, to be safe against future surprises.
Co-authored-by: Alec Edgington <[email protected]>
@@ -22,7 +22,7 @@ | |||
from hypothesis import HealthCheck, given, settings, strategies | |||
from hypothesis.strategies._internal import SearchStrategy | |||
from simulator import TketSimBackend, TketSimShotBackend # type: ignore | |||
from sympy import symbols | |||
from sympy import I, symbols |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that pylint doesn't seem to detect the unused imports here
Dict, List, Tuple
are not used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, this is because we disable https://docs.astral.sh/ruff/rules/unused-import/ (F401) in the ruff.toml
file. I disabled it because I wanted to allow unused imports in init files, but it would be good to disallow them in other files. Will make an issue to fix this.
@@ -22,7 +22,7 @@ | |||
from hypothesis import HealthCheck, given, settings, strategies | |||
from hypothesis.strategies._internal import SearchStrategy | |||
from simulator import TketSimBackend, TketSimShotBackend # type: ignore | |||
from sympy import symbols | |||
from sympy import I, symbols |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, this is because we disable https://docs.astral.sh/ruff/rules/unused-import/ (F401) in the ruff.toml
file. I disabled it because I wanted to allow unused imports in init files, but it would be good to disallow them in other files. Will make an issue to fix this.
Description
Please summarise the changes.
Minor change adding a
get_dict
export forQubitPauliOperator
. This avoids having to used the undocumented private_dict
attribute`Using
.get_dict
as opposed toto_dict
here as this new method is not intended for json serialisation.Related issues
Please mention any github issues addressed by this PR.
Checklist