Skip to content

A new algorithm_globals to replace use of qiskit.utils instance #33

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 11 commits into from
Aug 15, 2023
Merged

A new algorithm_globals to replace use of qiskit.utils instance #33

merged 11 commits into from
Aug 15, 2023

Conversation

woodsp-ibm
Copy link
Member

@woodsp-ibm woodsp-ibm commented Aug 1, 2023

Summary

Fixes #21

Adds a new algorithm_globals here in qiskit_algorithms as part of the migration out of Qiskit. At present the instance here works with the instance in Qiskit, delegates to it, so that user code which may set the seed there still works as expected on the algorithms here. The code here has the same logic as the one in qiskit and that will be used when the Qiskit instance is removed by which time users should be using/seeding this instance directly.

The algorithm_globals introduced here only supports random and random_seed.

The massive property of the qiskit.utils version was only used in opflow so is not needed in this algorithm_globals.

The qiskit.utils algorithm_globals also has a num_processes but this seems only being used by Qiskit Nature - it allows how many processes to be used by Qiskit's parallel map, something I think is more directly configurable now which back in Aqua times, when the globals came about I think it always used all local CPU cores. Anyway since this is all related to the Qiskit parallel_map usage, having some setting here, that is not even used by the algorithms seems out of place.

Details and comments

  • Add local algorithm globals
  • Update algorithm code to use this instance
  • Update test cases to seed this instance (not the qiskit.utils one)
  • Add release note

This first commit just completes the first two items above. While locally I have the test cases updated too I am leaving them for now seeding the qiskit.utils instance to show that the algorithms still use this (indirectly) as many tests will fail without the RNG being seeded for a reproducible outcome. This works locally I am just assuring it does when run through CI here.

Ok CI passes e.g https://github.com/qiskit-community/qiskit-algorithms/actions/runs/5732026311/job/15534167826?pr=33 but it emits deprecation warnings about seeding the qiskit.utils instance e.g.

 /home/runner/work/qiskit-algorithms/qiskit-algorithms/qiskit_algorithms/utils/validate_initial_point.py:61: DeprecationWarning: Using random that is seeded via qiskit.utils algorithm_globals is deprecated since version 0.2.0. Instead set random_seed directly to qiskit_algorithms.utils algorithm_globals.

So updating to add altered tests that seed the instance here. CI now passes just the same but no longer are deprecation warnings like above being emitted.

Release note add. I updated the make files too as make clean html was not working and I expected it to - only manually deleting build and stubs would give me a clean run ahead of this change.

@woodsp-ibm woodsp-ibm added the on hold Can not fix yet label Aug 1, 2023
@coveralls
Copy link

coveralls commented Aug 1, 2023

Pull Request Test Coverage Report for Build 5868479771

  • 34 of 44 (77.27%) changed or added relevant lines in 9 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.09%) to 89.947%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit_algorithms/utils/algorithm_globals.py 26 36 72.22%
Totals Coverage Status
Change from base Build 5868419912: -0.09%
Covered Lines: 6451
Relevant Lines: 7172

💛 - Coveralls

@woodsp-ibm
Copy link
Member Author

woodsp-ibm commented Aug 2, 2023

At present it seems there is an issue building what I expect the release note to look like. Locally, before pushing the code, they seem to build out fine and be what I expect.

Here in CI the documentation zip just seems to have the release note from this PR and nothing of the prior release. The tutorials ones the release note page is entirely blank. Investigating....

I think the tutorials build is different since it has the script to ignore untagged release notes - in the apps this is only done for stable tutorials build so I removed it. That ought to make the documentation and tutorial zips the same in terms of release notes. That did make the difference go way as expected. Now the question of why its not including the prior notes from the 0.1.0 release.
Looking further, when building the html, I see locally in the console got versions ['0.1.0-8', '0.1.0'] but here in CI the log shows got versions ['0.1.0-4']. I updated the documentation build in the checks jobs to add in the earliest_version append to the reno config we had taken out - I now see it reports got versions ['0.1.0-4', '0.1.0'] and the release notes look fine. Will do the same for the html build in tutorials jobs - done, it all looks good now.

@woodsp-ibm woodsp-ibm removed the on hold Can not fix yet label Aug 3, 2023
@woodsp-ibm woodsp-ibm changed the title [WIP] A new algorithm_globals to replace use of qiskit.utils instance A new algorithm_globals to replace use of qiskit.utils instance Aug 3, 2023
Copy link
Collaborator

@ElePT ElePT left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks so much for taking care of the docs build issues too. I had to fix a minor merge conflict from #35 so I'll wait for the CI to build to assign the automerge label.

@mergify mergify bot merged commit 9fe18e6 into qiskit-community:main Aug 15, 2023
@woodsp-ibm woodsp-ibm deleted the globals branch August 15, 2023 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Figure what to do about algorithm_globals
3 participants