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

Add qml.commutator function #5051

Merged
merged 45 commits into from
Jan 25, 2024
Merged

Add qml.commutator function #5051

merged 45 commits into from
Jan 25, 2024

Conversation

Qottmann
Copy link
Contributor

@Qottmann Qottmann commented Jan 12, 2024

A function to compute commutators between operators, PauliWord and PauliSentence instances.
Work in progress, happy to hear early feedback!

  • Basic functionality for paulis
  • Basic functionality for operators
  • Basic functionality between paulis and operators
  • General Tests
  • Documentation
  • changelog

Copy link

codecov bot commented Jan 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (5cfdedd) 99.36% compared to head (8a9ed89) 99.68%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5051      +/-   ##
==========================================
+ Coverage   99.36%   99.68%   +0.31%     
==========================================
  Files         392      393       +1     
  Lines       35850    35602     -248     
==========================================
- Hits        35623    35489     -134     
+ Misses        227      113     -114     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Qottmann Qottmann changed the title [WIP] qml.commutator function Add qml.commutator function Jan 15, 2024
@Qottmann
Copy link
Contributor Author

[sc-53926]

Copy link
Contributor

@mudit2812 mudit2812 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 Korbinian! Happy to approve once the tests are updated with the bugfix for qml.equal with Sum

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.

Left some documentation formatting concerns, but once those are resolved, I'll be happy to approve 👍

Qottmann and others added 2 commits January 23, 2024 14:35
Thanks christina!

Co-authored-by: Christina Lee <christina@xanadu.ai>
Qottmann and others added 3 commits January 25, 2024 10:51
Co-authored-by: Christina Lee <christina@xanadu.ai>
Co-authored-by: Christina Lee <christina@xanadu.ai>
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.

We may need to retrigger the CI to get codecov to work, but looks good nonetheless.

@Qottmann Qottmann enabled auto-merge (squash) January 25, 2024 14:52
@Qottmann Qottmann merged commit 479591a into master Jan 25, 2024
35 checks passed
@Qottmann Qottmann deleted the commutator branch January 25, 2024 15:07
Qottmann added a commit that referenced this pull request Feb 1, 2024
Adding native commutators for paulis.
Works between `PauliSentence` and any of `Operator, PauliWord,
PauliSentence`

Builds on top of #5051

Todo

- [x] Basic functionality
- [x] Basic functionality tests
- [x] update qml.commutator
- [x] changelog

---------

Co-authored-by: Mudit Pandey <mudit.pandey@xanadu.ai>
Co-authored-by: Christina Lee <christina@xanadu.ai>
Qottmann added a commit that referenced this pull request Feb 22, 2024
…r possible (#5098)

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:
```python
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)
```

- [x] Basic functionality
- [x] Handle Zero case (empty PauliSentence) with 0 * Identity()
- [x] Add test ensuring pauli route is taken
- [x] All tests pass
- [x] Test mixed cases (ops and Paulis)
- [x] changelog

[sc-56865]

---------

Co-authored-by: Mudit Pandey <mudit.pandey@xanadu.ai>
Co-authored-by: Christina Lee <christina@xanadu.ai>
Mandrenkov added a commit that referenced this pull request Feb 26, 2024
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.

5 participants