-
Notifications
You must be signed in to change notification settings - Fork 47
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
Refactor PauliStrings as templates for easier interop #1081
Conversation
The error at stub generation is occurring because |
pytket/binders/pauli.cpp
Outdated
"string", &QubitPauliTensor::string, | ||
.def( | ||
"__mul__", | ||
[](const Complex &c, const SpCxPauliTensor &qpt) { |
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.
[](const Complex &c, const SpCxPauliTensor &qpt) { | |
[](const SpCxPauliTensor &qpt, const Complex &c) { |
With .def
you define a normal method called on class objects and the first parameter is always "self
".
pytket/binders/pauli.cpp
Outdated
.def_readwrite( | ||
"string", &QubitPauliTensor::string, | ||
.def( | ||
"__mul__", |
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.
The old code .def(Complex() * py::self)
caused this to be defined as __rmul__
. I'm not sure if it matters but maybe best to use __rmul__
here as well
Thanks for the pointer. I think I've now fixed the stubs. I'll get to work on filling out the test coverage next week. |
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.
Good work! Only some minor comments
Not sure how well If this still fails coverage, I might just have to add some tests for other parts of the codebase to pad out the stats and get the PR in. |
@cqc-alec might be able to override the checks |
The coverage checker is unreliable with anything implemented in header files (including templates). Happy to merge this. |
Across tket, we use QubitPauliString, PauliStabiliser, QubitPauliTensor, std::vector, std::pair<QubitPauliString, Expr> all to refer to some combination of a Pauli string (sparse or dense) and (optional coefficient). Reviewer feedback in #941 raised the point we should have one which restricts to Clifford phases {+1, +i, -1, -i} in place of QubitPauliTensor for Clifford and stabiliser code. This is all a bit much to manage separately and could do with a refactor for better code reuse, flexibility of structures, and standard conversions between them.
Class inheritance wasn't a great option because we have variations in both the string (sparse vs dense) and coefficient (none, Clifford, complex, symbolic), so I couldn't see an obviously clear hierarchy. Templates allow this multi-dimensional parameterisation easier.
I have refactored the code base to switch out the old with the new as best as I could determine. Json serialisation and a lot of the binder code is a bit ugly in order to leave no breaking changes to pytket users.
Style-wise, let me know if you have a better suggestion for naming conventions for the different typedef specialisations of PauliTensor. Also, I haven't changed variable names throughout (many still called e.g. qps or qpt in reference to old class names) so let me know if you want these updated.