Skip to content
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

Upgrade qml.commutator to use pauli arithmetic under the hood whenever possible #5098

Merged
merged 113 commits into from
Feb 22, 2024

Conversation

Qottmann
Copy link
Contributor

@Qottmann Qottmann commented Jan 24, 2024

Upgrade qml.commutator to use pauli artihmetic whenever that is possible (i.e. whenever both operators have a pauli_rep. This was initiated in #5051 (comment) Similar things could be done in qml.dot and other points of the codebase. The grander idea is to use fater pauli arithmetic under the hood whenever that is possible.

The main feature of this update is performance:

op1 = qml.dot(range(30), [X(i) @ X(i+1) for i in range(30)])
op2 = qml.dot(range(30), [Y(i) @ Y(i+1) for i in range(30)])

%timeit qml.commutator(op1, op2) # on main branch
11.9 ms ± 32.2 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
%timeit qml.commutator(op1, op2) # this branch
1.28 ms ± 3.42 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)
  • Basic functionality
  • Handle Zero case (empty PauliSentence) with 0 * Identity()
  • Add test ensuring pauli route is taken
  • All tests pass
  • Test mixed cases (ops and Paulis)
  • changelog

[sc-56865]

@Qottmann Qottmann changed the title [WIP] Upgrade qml.commutator to use pauli arithmetic under the hood whenever possible Upgrade qml.commutator to use pauli arithmetic under the hood whenever possible Feb 16, 2024
Copy link
Contributor

@albi3ro albi3ro left a comment

Choose a reason for hiding this comment

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

Just a request for PauliWord.pauli_rep to be a PauliSentence, since Operator.pauli_rep is always a PauliSentence. Might be worth a discussion about allowing Operator.pauli_rep to also be a PauliWord, but I think we can put off that discussion.

@Qottmann Qottmann requested a review from a team February 21, 2024 12:48
@Qottmann Qottmann added this to the v0.35 milestone Feb 21, 2024
@Qottmann Qottmann enabled auto-merge (squash) February 22, 2024 09:19
@Qottmann Qottmann merged commit b4f89ca into master Feb 22, 2024
39 checks passed
@Qottmann Qottmann deleted the commutator2 branch February 22, 2024 09:40
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.

3 participants