Skip to content

Adhoc now supports n>3, and new arguments #902

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

Merged
merged 7 commits into from
Mar 19, 2025

Conversation

RishiNandha
Copy link
Contributor

@RishiNandha RishiNandha commented Mar 16, 2025

Summary

My previous pull request became messy due to bad version control from my side. So I've created a new one

This is related to #330

I have rewritten the ad_hoc dataset to work for n>3. I have also made some of the operations more efficient.

I'm also working on bringing more dataset generators to the repository, so I hope ad_hoc.py can still be kept around as the simpler one in the family now that it's been rewritten

Details and comments

  1. The tensor products such as H^{(x)n} were written in n step loops, I've made them logn step loops. And similar other small optimizations such as precomputing Zi*Zj. This step also supports 3 types of entangelement now: linear/circular/full

  2. The old implementation did an n-dimensional grid for generating random phase vectors. While this brought uniformity with small number of qubits, it was too much computational overhead for larger numbers. I've have added 2 more options of stratified sampling. The old method has been retained as the "grid" method as suggested so that old user codes don't behave differently now. The two other methods included are "hypercube" and "sobol". Docstring has been updated and can be referred to for more information on the methods

  3. The old implementation had labelling done with parity() and majority() in n=2 and n=3 respectively. I've used an n-qubit Z matrix directly, which aligns better with the reference paper attached in the documentation and also relieves the constraint an n being 2 or 3.

  4. Vectorized the labelling loop. This has given some performance gain. I have also given two options: the same "expectation" based labelling has been retained but also a "measurement" based labelling has been added

  5. I've verified lint. @rogue-infinity has developed unittests for this revamped ad hoc dataset. They have been verified to pass

@RishiNandha
Copy link
Contributor Author

@edoaltamura I hope we can continue the discussion/review here. We had some version conflicts in the way we were collaborating and got a lot of messy commits on the previous Pull Request. So I've closed it and started a fresh one here. I've updated the summary above according to the latest changes too

@RishiNandha
Copy link
Contributor Author

The failed test is unrelated to the files I've edited and it's failing only on the MacOS 3.12, so I'm not sure how to proceed

@woodsp-ibm
Copy link
Member

woodsp-ibm commented Mar 17, 2025

If I look at the nightly Actions here, where CI is run daily, I see what seem to be random failures and that includes an example of the unit test that failed here. I imagine if this was re-run it could pass - for instance last nights CI run passed ok. I re-started that failed job. lets see. (Update: I see it now passed ok)

@edoaltamura I guess it would be good to look at these random failures to see if it can be figured why and hopefully update them. I created an issue around this as a reminder.

@coveralls
Copy link

coveralls commented Mar 17, 2025

Pull Request Test Coverage Report for Build 13952014968

Details

  • 198 of 206 (96.12%) changed or added relevant lines in 1 file are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.2%) to 90.857%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit_machine_learning/datasets/ad_hoc.py 198 206 96.12%
Files with Coverage Reduction New Missed Lines %
qiskit_machine_learning/datasets/ad_hoc.py 1 94.01%
Totals Coverage Status
Change from base Build 13952007547: 0.2%
Covered Lines: 4482
Relevant Lines: 4933

💛 - Coveralls

@woodsp-ibm woodsp-ibm mentioned this pull request Mar 17, 2025
Copy link
Collaborator

@edoaltamura edoaltamura 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 @RishiNandha! I've made a few (very small) suggestions. To avoid the syncing trouble you experienced when in-PR commits are merged, make sure you git-pull your local repo before working on it so that incoming changes are merged with your local copy of the code.
The main change needed is in the syntax of the docstring in the ad hoc main function - it should use Args: like in the rest of the code so that the documentation builder can understand it and translate it to static HTML pages.

@RishiNandha RishiNandha requested a review from edoaltamura March 18, 2025 08:37
@edoaltamura
Copy link
Collaborator

Re-running the MacOS job, which seems affected by #903.

@edoaltamura edoaltamura added type: enhancement ✨ Features or aspects to improve Community PR 🌐 PRs from contributors that are not 'members' of the Qiskit organization labels Mar 18, 2025
@edoaltamura edoaltamura merged commit 59bd397 into qiskit-community:main Mar 19, 2025
26 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community PR 🌐 PRs from contributors that are not 'members' of the Qiskit organization type: enhancement ✨ Features or aspects to improve
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants