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

[feature] Shots backend #130

Merged
merged 90 commits into from
Jul 4, 2024
Merged

[feature] Shots backend #130

merged 90 commits into from
Jul 4, 2024

Conversation

PabloAndresCQ
Copy link
Collaborator

@PabloAndresCQ PabloAndresCQ commented Jun 25, 2024

Description

  • Refactors CuTensorNetBackend into CuTensorNetStateBackend which now uses the new GeneralState.
  • Introduces a new CuTensorNetShotsBackend for shot-based simulation.

Related issues

Completes #121.

Checklist

  • I have run the tests on a device with GPUs.
  • I have performed a self-review of my code.
  • I have commented hard-to-understand parts of my code.
  • I have made corresponding changes to the public API documentation.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have updated the changelog with any user-facing changes.

… Added `GeneralState.update_gates()` method.
@PabloAndresCQ PabloAndresCQ changed the title Feature/shots backend [feature] Shots backend Jun 25, 2024
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've moved get_operator_expectation_value and get_circuit_overlap here because they did not match with the intended use of pytket Backend class: there's an intended way to support expectation values in there, but through a BackendResult, not this.

Additionally, these functions are based on the tensor_network_convert approach that I intend to eventually deprecate once GeneralState is full-featured, so it makes sense they are in the same file that will eventually be moved to a deprecated submodule.


# TODO: this should be optionally parallelised with MPI
# (both wrt Pauli strings and contraction itself).
def get_operator_expectation_value(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Unfortunately, this git diff completely butchers what actually happened with get_operator_expectation_value: it was moved (verbatim, except for removals of self argument) to the tensor_network_convert.py file. See https://github.com/CQCL/pytket-cutensornet/pull/130/files#r1653061092 for details on why.


def get_circuit_overlap(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Unfortunately, this git diff completely butchers what actually happened with get_circuit_overlap: it was moved (verbatim, except for removals of self argument) to the tensor_network_convert.py file. See https://github.com/CQCL/pytket-cutensornet/pull/130/files#r1653061092 for details on why.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The diff in this file is unfortunately quite confusing. The changes where quite simple, but they are somehow intertwinned in the diff, so I suggest to compare the files to each other separately. Here's a brief of the changes:

  • Changed the name of CuTensorNetBackend to CuTensorNetStateBackend, since it is meant to support state vector output only.
  • Added a new CuTensorNetShotsBackend that satisfies the requirements of Support multi-shot exact simulation backends using Sampler from cuTensorNet #121.
  • Created a _CuTensorNetBaseBackend that the other two backends are based on, where all of the common code lives.
  • Some chore tasks: provided details of BackendInfo, removed the gateset requirements and replaced them with a custom predicate that checks for commands with .get_unitary() implemented, removed the use of auto_rebase_pass since it is no longer needed.
  • Moved some functions to another file, see https://github.com/CQCL/pytket-cutensornet/pull/130/files#r1653061092.

The approach of using a base class _CuTensorNetBaseBackend is inspired on AerBackend from pytket-qiskit, same with the creation of specialised backends for statevector output and shots output.

I've been using a tutorial for backend creation. It's a bit out of date in places, but mostly fine.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The tests added for CuTensorNetShotsBackend are very basic because these just need to check that the backend wrapper works. More involved tests for the shot extraction logic were already added in #129 in test_general_state.py.

@PabloAndresCQ PabloAndresCQ marked this pull request as ready for review June 25, 2024 16:18
Base automatically changed from feature/general_sampler to main June 27, 2024 09:02
@PabloAndresCQ PabloAndresCQ merged commit b224587 into main Jul 4, 2024
8 checks passed
@PabloAndresCQ PabloAndresCQ deleted the feature/shots_backend branch July 4, 2024 10:37
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