Skip to content

Qiskit Algorithms 0.2.0

Compare
Choose a tag to compare
@ElePT ElePT released this 24 Aug 13:12
· 63 commits to main since this release
8c9da41

Changelog

Upgrades

  • The qiskit-algorithms code uses a common random number generator, which can be seeded for reproducibility. The algorithms code here, having originated in Qiskit and having been moved here, used random function from qiskit.utils which was seeded as follows:

    from qiskit.utils import algorithm_globals
    algorithm_globals.random_seed = 101

    Now this will continue to work in qiskit-algorithms, until such time as the algorithm_globals are removed from Qiskit, however you are highly recommended to already change to import/seed the algorithm_globals that is now supplied by qiskit-algorithms thus:

    from qiskit_algorithms.utils import algorithm_globals
    algorithm_globals.random_seed = 101

    As can be seen it’s simply a change to the import statement, so as to import the qiskit-algorithms instance rather than the one from qiskit.

    This has been done to afford a transition and not break end-users code by supporting seeding the random generator as it was done before. How does it work - well, while the qiskit.utils version exists, the qiskit-algorithms version simply delegates its function to that instance. However the main codebase of qiskit-algorithms has already been altered to use the new instance and the delegation function, that accesses the random generator, will warn with a message to switch to seeding the qiskit-algorithms version if it detects a difference in the seed. A difference could exist if the random_seed was set direct to the qiskit.utils instance.

    At such a time when the qiskit.utils algorithm_globals version no longer exists, rather than delegating the functionality to that, it will use identical logic which it already has, so no further user change will be required if you already transitioned to seeding the qiskit_algorithms.utils algorithms_globals.

  • A couple of algorithms here, PVQD, AdaptVQE and optimizer SNOBFIT, directly raised a QiskitError. These have been changed to raise an AlgorithmError instead. Algorithms have now been moved out of Qiskit and this better distinguishes the exception to the algorithms when raised. Now AlgorithmError was already raised elsewhere by the algorithms here so this makes things more consistent too. Note, that as AlgorithmError internally extends QiskitError, any code that might have caught that specifically will continue to work. However we do recommend you update your code accordingly for AlgorithmError.

    The deprecated threshold input argument of AdaptVQE has been removed, and replaced by gradient_threshold. This change was made to avoid confusion with the later introduced eigenvalue_thresholdargument. The updatedAdaptVQE` use would look like this:

    from qiskit_algorithms import VQE, AdaptVQE
    
    adapt_vqe = AdaptVQE(
                  VQE(Estimator(), ansatz, optimizer),
                  gradient_threshold=1e-3,
                  eigenvalue_threshold=1e-3
                )

Other Notes

  • Removed the custom __str__ method from SamplingMinimumEigensolverResult so that string conversion is based on the method of its parent AlgorithmResult which prints all the result fields in a dictionary like format. The overridden method had only printed a select couple of fields, unlike when normally printing a result all fields are shown, and the lack of fields expected to be shown caused confusion when printing results derived from that, such as returned by SamplingVQE and QAOA.