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

Interface to "high-level" API (State, NetworkOperator and Expectation) #84

Merged
merged 68 commits into from
Jun 26, 2024

Conversation

yapolyak
Copy link
Contributor

@yapolyak yapolyak commented Mar 11, 2024

Description

Implemented interface to cutensornet "high-level API", specifically to State, NetworkOperator and Expectation. Mostly based on examples such as this one, but with some bugs fixed and some uncovered features discussed here and here with cuTN authors.

Note that automatic parallelisation (while not available in their examples yet) should be straightforward to achieve.

This shoud be wrapped in a pytket Backend class in a future PR.
I also suppose that Marginal, Accessor and Sampler objects deserve to be interfaced to in the future.

Related issues

NA

Checklist

  • I have run the tests on a device with a GPU.
  • 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 base branch from develop to main June 6, 2024 12:09
PabloAndresCQ and others added 5 commits June 6, 2024 13:33
…ecause they are only used locally in get_statevector and expectation_value and they only need to survive for the duration of said function calls.
@PabloAndresCQ PabloAndresCQ removed the request for review from NathanCQC June 7, 2024 14:51
@PabloAndresCQ PabloAndresCQ marked this pull request as ready for review June 7, 2024 16:04
@PabloAndresCQ PabloAndresCQ self-requested a review June 7, 2024 16:04
@PabloAndresCQ
Copy link
Collaborator

PabloAndresCQ commented Jun 21, 2024

An upcoming PR will need to reintroduce the ability to use mutable tensors. To do so in ExpectationValue, the user will need to have access to an ExpectationValue object that they keep alive and update by calling the appropriate update_tensors method. The API will need to change accordingly and either provide a shallow wrapper of NVIDIA's ExpectationValue object, or inform the user to make use of NVIDIA's API explicitly.

I propose we merge this PR now and defer these changes to a later PR once NVIDIA releases their new API (excepted sometime in July), since it's likely they'll be making the user experience smoother on their side, and hence the option of not wrapping ExpectationValue being more reasonable.

Copy link
Collaborator

@jake-arkinstall jake-arkinstall left a comment

Choose a reason for hiding this comment

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

The changes to the interface are clear, well documented, and I have no criticisms. Tests pass fine, including when merged with the nix-support branch.

On a pedantic level, some of the changes in this commit introduced inconsistent line endings. Most of the files use unix \n line endings, whereas some files now contain \r\n. This isn't a major concern but, for consistency, I recommend that we fix the symptoms and causes before a release is made.

Additionally, I think that some tests need looking at as a pre-release measure. For instance, on the nix-support branch some (existing) tests fail due to the fidelity being better than anticipated, likely due to an updated dependency somewhere along the lines. Adding lower bounds rather than approximations may be better,. Even better would be to move fidelity checks into a benchmarking approach rather than an assertion approach, so we can track improvements and have alerts when there are changes.

Copy link
Collaborator

@PabloAndresCQ PabloAndresCQ left a comment

Choose a reason for hiding this comment

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

Thanks Jake!

Let's add the changes you suggest as a commit before release, once these PRs are merged.

  • Regarding line endings we should enforce them in CI or pre-commits somehow (so that they are replaced automatically). I don't have a preference of which of the two to enforce.
  • Regarding tests, I agree the test should only be concerned with whether the algorithm works qualitatively as expected, so that it only fails when a change broke the algorithm. Setting a lower bound could work, but then it'd be missing the sublety that these are not exact simulations. For instance, a change could get rid of the way self.fidelity is updated, so that 1.0 is always reported, when it's not the true fidelity. Detecting such a bug would be challenging, but perhaps a fair compromise is to have two asserts: one with a lower bound and another one imposing that fidelity < 1.0. The framework for benchmarking is not a priority atm.

Feel free to create an issue for these in the repo.

@PabloAndresCQ PabloAndresCQ merged commit 35e0fd8 into main Jun 26, 2024
8 checks passed
@PabloAndresCQ PabloAndresCQ deleted the feature/exact_state branch June 26, 2024 14:33
@yapolyak
Copy link
Contributor Author

Thank you guys! Sorry I didn't review it in time, but you seem to be handling it well!

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