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

DefaultTensor: misc scalability improvements #5795

Merged
merged 72 commits into from
Jun 14, 2024
Merged

Conversation

vincentmr
Copy link
Contributor

@vincentmr vincentmr commented Jun 4, 2024

Before submitting

Please complete the following checklist when submitting a PR:

  • All new features must include a unit test.
    If you've fixed a bug or added code that should be tested, add a test to the
    test directory!

  • All new functions and code must be clearly commented and documented.
    If you do make documentation changes, make sure that the docs build and
    render correctly by running make docs.

  • Ensure that the test suite passes, by running make test.

  • Add a new entry to the doc/releases/changelog-dev.md file, summarizing the
    change, and including a link back to the PR.

  • The PennyLane source code conforms to
    PEP8 standards.
    We check all of our code against Pylint.
    To lint modified files, simply pip install pylint, and then
    run pylint pennylane/path/to/file.py.

When all the above are checked, delete everything above the dashed
line and fill in the pull request template.


Context:
Certain operations and observables cannot be expressed as matrix because of their size, but they have a straightforward MPO form amenable to the MPS simulator.

Description of the Change:
Introduce dispatching for operations and observables.
Introduce method for StateMP.
Handle state preparation in simulate.
Add correctness tests validating gates against DQ.
Add scalability tests.

Benefits:

Possible Drawbacks:

Related GitHub Issues:
[sc-64793]
[sc-64794]

@vincentmr vincentmr changed the title Feature/split expval DefaultTensor: misc scalability improvements Jun 4, 2024
@vincentmr vincentmr force-pushed the feature/split_expval branch from ed6aadf to 37790fa Compare June 5, 2024 17:29
@vincentmr vincentmr changed the base branch from tn_method_default_tensor to master June 5, 2024 17:30
Base automatically changed from tn_method_default_tensor to master June 13, 2024 02:38
@Qottmann
Copy link
Contributor

Please tag me again when you want a full review :)

Copy link
Contributor

@Qottmann Qottmann left a comment

Choose a reason for hiding this comment

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

Great work @vincentmr !

Awesome that we now also have the MPO method 😍 And really cool to see that those gates also work with with the full contraction method.

For the tests in test_scalability.py: is it intentional that they are not asserting / testing anything and just run with 16 qubits? I am not sure that is a good way to test the scalability. Perhaps that is something that we just made sure while implementing this without having it be part of the CI. Instead, we can test that the implemented methods are indeed correct by comparing with exact simulation (at slightly smaller qubit count)?

Co-authored-by: Korbinian Kottmann <43949391+Qottmann@users.noreply.github.com>
@vincentmr
Copy link
Contributor Author

For the tests in test_scalability.py: is it intentional that they are not asserting / testing anything and just run with 16 qubits? I am not sure that is a good way to test the scalability.

Correctness is tested in other modules. The goal here is just make sure things run at all or quickly enough. If the wrong function is hit, it will likely just fail with NumPy complaining it does not have enough memory.

@vincentmr vincentmr requested a review from Qottmann June 14, 2024 14:56
Copy link
Contributor

@Qottmann Qottmann left a comment

Choose a reason for hiding this comment

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

awesome addition @vincentmr !!!

Copy link
Contributor

@PietropaoloFrisoni PietropaoloFrisoni left a comment

Choose a reason for hiding this comment

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

Thanks a lot for this @vincentmr! Just a very few comments/questions 👍

@PietropaoloFrisoni
Copy link
Contributor

Also, I just noticed an indentation error in the second example of the documentation for the draw method (the indentation of qml.Hadamard(wires=i) is incorrect). Can you please change it here? Thanks!

Copy link
Contributor

@PietropaoloFrisoni PietropaoloFrisoni left a comment

Choose a reason for hiding this comment

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

Thanks again @vincentmr.

I just tried to run a small benchmark on my notebook and the mps method seems a little slower than before (at least with my example, which is the one used in the 'Usage with MPS' section of the doc). In the worst-case scenario, it is a small price to pay to resolve major scalability issues, so this PR has priority.

Finally, I didn't test all the new functionalities and workflows explicitly, but can we currently return the state even with the tn method? In case we can't that's fine with me, but perhaps we should specify this in the documentation. Amazing work!

@vincentmr
Copy link
Contributor Author

I just tried to run a small benchmark on my notebook and the mps method seems a little slower than before (at least with my example, which is the one used in the 'Usage with MPS' section of the doc).

Laptops don't have very stable timings because they heat so easily. Running the example on an Epyc machine (using 8 threads) I get 0.94 sec. on master and 0.81 sec here. Let's dig more into profiles later on.

Finally, I didn't test all the new functionalities and workflows explicitly, but can we currently return the state even with the tn method?

Yes, it works for both methods.

@vincentmr vincentmr merged commit 2f63ca4 into master Jun 14, 2024
40 checks passed
@vincentmr vincentmr deleted the feature/split_expval branch June 14, 2024 21:10
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