-
Notifications
You must be signed in to change notification settings - Fork 210
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
Migrate MP2Info #590
Migrate MP2Info #590
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM! Thanks a lot @declanmillar for your hard work on this!
@pbark @woodsp-ibm please also take a look before we merge 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This now also LGTM :) Thanks a lot @declanmillar !
* migrate compute_mp2 (WIP) * Create Initializer interface and MP2Interface * Add some initial tests of mp2 initializer * expose mp2 deltas * Hard code UCC excitation list for MP2 tests * Pass num_spin_orbitals in constructor * save data for mp2 tests in json file * Add synonym property for initial point * test with no initializer * test mp2initializer in UCC with h2 * fix ucc mp2 h2 tests * minor name change * add initializer option to vqe_ucc_factory * fix style * refactor initializer as an arg in solve() * call vqe_ucc_factory from gs_eigensolver with initializer * Update docstring * remove unused import * move test resources for initializers * fix copyright * type->isinstance * linting * linting * raise NotImplementedError for initializers with uvcc factory * move mp2 init test from ucc to uccsd * fix custom factory in tests * fix style * remove commented out code originating from the aqua implementation * improve abstract base Initializer class * Improve docstring and comments * Improve docstring and comments * revert changes to most ground_state_solvers * expose excitation_list in UCC * remove initializer from UCCSD * refactor ucc and mp2initializer to avoid pref_init_points * undo changes to test_ucc * undo changes to test_ucc * fix copyright and spelling * edit docstring * refactor vqe_ucc_factory with mp2 * refactor mp2_initializer tests * update docstring * fix style * fix spelling * remove mp2 tests from uccsd * linting * docstring typo * add vqe ucc with mp2 tests * revert copyright for now unchanged files * fix copyright * fix copyright * fix style * fix style * update typing * fix typo * make properties public again * fix _kwargs * Update docstring * update docstrings * fix typing * remove unused getter/setter * add release note for fix of qiskit-community#89 * rename and refactor mp2_initializer to mp2_point_generator * fix copyright * fix copyright * fix spelling and copyright * Add interface for point generators * Add interface for point generators * if initial_point is None do not change it * spelling * unit test point_generator * raise error for bad strings * Raise error if electronic energy has missing properties * lint * add unit test for point_generator * spelling * update release note * update docstring * some minor name changes and new tests * add test data * clean up comment and docstrings * ._build() -> .data * update setters: raise error if excitation_list is None * remove typo from tests * type annotation * remove unused logger * reorder properties * typing * document need for orbital_energies * use 3.9+ type annotation * allow zero threshold * refactor mp2_point_generator as mp2_initial_point MP2InitialPoint is now passed as an empty instance to the VQE UCC factory rather than instanciated via string flag. Rename point_generator to initial_point in all cases. Adjust tests accordingly. Edit docstrings accordingly. * decorate abstract method * update release note * fix style * remove unused imports * set _corrections to None in init * update docstring * update docstring * update docstring * Update docstring Co-authored-by: Max Rossmannek <[email protected]> * Update docstring Co-authored-by: Max Rossmannek <[email protected]> * Update docstring Co-authored-by: Max Rossmannek <[email protected]> * Update docstring Co-authored-by: Max Rossmannek <[email protected]> * Update release note Co-authored-by: Max Rossmannek <[email protected]> * Update releasenotes/notes/migrate-mp2-info-b1a3ee7320c46053.yaml Co-authored-by: Max Rossmannek <[email protected]> * Update releasenote Co-authored-by: Max Rossmannek <[email protected]> * update test class name * remove duplicate import * update release note to reflect initial_point refactor * update release note format * update release note format * update release note * remove todos raised as new PRs * Update qiskit_nature/algorithms/initial_points/mp2_initial_point.py Co-authored-by: dlasecki <[email protected]> * Update qiskit_nature/circuit/library/ansatzes/uccsd.py Co-authored-by: dlasecki <[email protected]> * Update qiskit_nature/algorithms/initial_points/mp2_initial_point.py Co-authored-by: dlasecki <[email protected]> * Update qiskit_nature/algorithms/initial_points/mp2_initial_point.py Co-authored-by: dlasecki <[email protected]> * Update qiskit_nature/algorithms/initial_points/mp2_initial_point.py Co-authored-by: dlasecki <[email protected]> * Update qiskit_nature/algorithms/initial_points/mp2_initial_point.py Co-authored-by: dlasecki <[email protected]> * Update qiskit_nature/algorithms/initial_points/mp2_initial_point.py Co-authored-by: dlasecki <[email protected]> * Update qiskit_nature/algorithms/initial_points/mp2_initial_point.py Co-authored-by: dlasecki <[email protected]> * Note raised error in docstring * make mp2 variable names more explicit * remove setter and directly expose initial_point in vqe_ucc_factory * Apply @mrossinek's suggestions from code review Co-authored-by: Max Rossmannek <[email protected]> * compute num MO from ElectronicEnergy and improve documentation * refactor grouped_property setter * refactor error raising in grouped property setter * refactor to remove get_initial_point * fix input validation for mp2 (needs unit tests); update release note * update docstring * separate compute and convert. e.g. initial_point -> to_numpy_array * fix input checking and add unit tests for all input * fix typo in unit tests * restore initial_point get/set to vqe factory (will be remove later) * update docstrings and var names * spelling * test if can compute on excitations not ansatz * fix typo * Apply @mrossinek's suggestions from code review Co-authored-by: Max Rossmannek <[email protected]> * update docstring * document not implemented error * update docstring * adapt unittests for not implemented addition * rename mp2 test resources * raise error inside compute, not inside converters * update error message * update error message * update docstring * update raised error message * linting * docstring grammar * improve docs and re-order methods and properties * fix typo * minor docstring changes * minor docstring changes * reorder special chars in pylintdict * else if -> elif * remove redundant float conversion Co-authored-by: Panagiotis Barkoutsos <[email protected]> Co-authored-by: Max Rossmannek <[email protected]> Co-authored-by: dlasecki <[email protected]>
* migrate compute_mp2 (WIP) * Create Initializer interface and MP2Interface * Add some initial tests of mp2 initializer * expose mp2 deltas * Hard code UCC excitation list for MP2 tests * Pass num_spin_orbitals in constructor * save data for mp2 tests in json file * Add synonym property for initial point * test with no initializer * test mp2initializer in UCC with h2 * fix ucc mp2 h2 tests * minor name change * add initializer option to vqe_ucc_factory * fix style * refactor initializer as an arg in solve() * call vqe_ucc_factory from gs_eigensolver with initializer * Update docstring * remove unused import * move test resources for initializers * fix copyright * type->isinstance * linting * linting * raise NotImplementedError for initializers with uvcc factory * move mp2 init test from ucc to uccsd * fix custom factory in tests * fix style * remove commented out code originating from the aqua implementation * improve abstract base Initializer class * Improve docstring and comments * Improve docstring and comments * revert changes to most ground_state_solvers * expose excitation_list in UCC * remove initializer from UCCSD * refactor ucc and mp2initializer to avoid pref_init_points * undo changes to test_ucc * undo changes to test_ucc * fix copyright and spelling * edit docstring * refactor vqe_ucc_factory with mp2 * refactor mp2_initializer tests * update docstring * fix style * fix spelling * remove mp2 tests from uccsd * linting * docstring typo * add vqe ucc with mp2 tests * revert copyright for now unchanged files * fix copyright * fix copyright * fix style * fix style * update typing * fix typo * make properties public again * fix _kwargs * Update docstring * update docstrings * fix typing * remove unused getter/setter * add release note for fix of qiskit-community#89 * rename and refactor mp2_initializer to mp2_point_generator * fix copyright * fix copyright * fix spelling and copyright * Add interface for point generators * Add interface for point generators * if initial_point is None do not change it * spelling * unit test point_generator * raise error for bad strings * Raise error if electronic energy has missing properties * lint * add unit test for point_generator * spelling * update release note * update docstring * some minor name changes and new tests * add test data * clean up comment and docstrings * ._build() -> .data * update setters: raise error if excitation_list is None * remove typo from tests * type annotation * remove unused logger * reorder properties * typing * document need for orbital_energies * use 3.9+ type annotation * allow zero threshold * refactor mp2_point_generator as mp2_initial_point MP2InitialPoint is now passed as an empty instance to the VQE UCC factory rather than instanciated via string flag. Rename point_generator to initial_point in all cases. Adjust tests accordingly. Edit docstrings accordingly. * decorate abstract method * update release note * fix style * remove unused imports * set _corrections to None in init * update docstring * update docstring * update docstring * Update docstring Co-authored-by: Max Rossmannek <[email protected]> * Update docstring Co-authored-by: Max Rossmannek <[email protected]> * Update docstring Co-authored-by: Max Rossmannek <[email protected]> * Update docstring Co-authored-by: Max Rossmannek <[email protected]> * Update release note Co-authored-by: Max Rossmannek <[email protected]> * Update releasenotes/notes/migrate-mp2-info-b1a3ee7320c46053.yaml Co-authored-by: Max Rossmannek <[email protected]> * Update releasenote Co-authored-by: Max Rossmannek <[email protected]> * update test class name * remove duplicate import * update release note to reflect initial_point refactor * update release note format * update release note format * update release note * remove todos raised as new PRs * Update qiskit_nature/algorithms/initial_points/mp2_initial_point.py Co-authored-by: dlasecki <[email protected]> * Update qiskit_nature/circuit/library/ansatzes/uccsd.py Co-authored-by: dlasecki <[email protected]> * Update qiskit_nature/algorithms/initial_points/mp2_initial_point.py Co-authored-by: dlasecki <[email protected]> * Update qiskit_nature/algorithms/initial_points/mp2_initial_point.py Co-authored-by: dlasecki <[email protected]> * Update qiskit_nature/algorithms/initial_points/mp2_initial_point.py Co-authored-by: dlasecki <[email protected]> * Update qiskit_nature/algorithms/initial_points/mp2_initial_point.py Co-authored-by: dlasecki <[email protected]> * Update qiskit_nature/algorithms/initial_points/mp2_initial_point.py Co-authored-by: dlasecki <[email protected]> * Update qiskit_nature/algorithms/initial_points/mp2_initial_point.py Co-authored-by: dlasecki <[email protected]> * Note raised error in docstring * make mp2 variable names more explicit * remove setter and directly expose initial_point in vqe_ucc_factory * Apply @mrossinek's suggestions from code review Co-authored-by: Max Rossmannek <[email protected]> * compute num MO from ElectronicEnergy and improve documentation * refactor grouped_property setter * refactor error raising in grouped property setter * refactor to remove get_initial_point * fix input validation for mp2 (needs unit tests); update release note * update docstring * separate compute and convert. e.g. initial_point -> to_numpy_array * fix input checking and add unit tests for all input * fix typo in unit tests * restore initial_point get/set to vqe factory (will be remove later) * update docstrings and var names * spelling * test if can compute on excitations not ansatz * fix typo * Apply @mrossinek's suggestions from code review Co-authored-by: Max Rossmannek <[email protected]> * update docstring * document not implemented error * update docstring * adapt unittests for not implemented addition * rename mp2 test resources * raise error inside compute, not inside converters * update error message * update error message * update docstring * update raised error message * linting * docstring grammar * improve docs and re-order methods and properties * fix typo * minor docstring changes * minor docstring changes * reorder special chars in pylintdict * else if -> elif * remove redundant float conversion Co-authored-by: Panagiotis Barkoutsos <[email protected]> Co-authored-by: Max Rossmannek <[email protected]> Co-authored-by: dlasecki <[email protected]>
* migrate compute_mp2 (WIP) * Create Initializer interface and MP2Interface * Add some initial tests of mp2 initializer * expose mp2 deltas * Hard code UCC excitation list for MP2 tests * Pass num_spin_orbitals in constructor * save data for mp2 tests in json file * Add synonym property for initial point * test with no initializer * test mp2initializer in UCC with h2 * fix ucc mp2 h2 tests * minor name change * add initializer option to vqe_ucc_factory * fix style * refactor initializer as an arg in solve() * call vqe_ucc_factory from gs_eigensolver with initializer * Update docstring * remove unused import * move test resources for initializers * fix copyright * type->isinstance * linting * linting * raise NotImplementedError for initializers with uvcc factory * move mp2 init test from ucc to uccsd * fix custom factory in tests * fix style * remove commented out code originating from the aqua implementation * improve abstract base Initializer class * Improve docstring and comments * Improve docstring and comments * revert changes to most ground_state_solvers * expose excitation_list in UCC * remove initializer from UCCSD * refactor ucc and mp2initializer to avoid pref_init_points * undo changes to test_ucc * undo changes to test_ucc * fix copyright and spelling * edit docstring * refactor vqe_ucc_factory with mp2 * refactor mp2_initializer tests * update docstring * fix style * fix spelling * remove mp2 tests from uccsd * linting * docstring typo * add vqe ucc with mp2 tests * revert copyright for now unchanged files * fix copyright * fix copyright * fix style * fix style * update typing * fix typo * make properties public again * fix _kwargs * Update docstring * update docstrings * fix typing * remove unused getter/setter * add release note for fix of qiskit-community#89 * rename and refactor mp2_initializer to mp2_point_generator * fix copyright * fix copyright * fix spelling and copyright * Add interface for point generators * Add interface for point generators * if initial_point is None do not change it * spelling * unit test point_generator * raise error for bad strings * Raise error if electronic energy has missing properties * lint * add unit test for point_generator * spelling * update release note * update docstring * some minor name changes and new tests * add test data * clean up comment and docstrings * ._build() -> .data * update setters: raise error if excitation_list is None * remove typo from tests * type annotation * remove unused logger * reorder properties * typing * document need for orbital_energies * use 3.9+ type annotation * allow zero threshold * refactor mp2_point_generator as mp2_initial_point MP2InitialPoint is now passed as an empty instance to the VQE UCC factory rather than instanciated via string flag. Rename point_generator to initial_point in all cases. Adjust tests accordingly. Edit docstrings accordingly. * decorate abstract method * update release note * fix style * remove unused imports * set _corrections to None in init * update docstring * update docstring * update docstring * Update docstring Co-authored-by: Max Rossmannek <[email protected]> * Update docstring Co-authored-by: Max Rossmannek <[email protected]> * Update docstring Co-authored-by: Max Rossmannek <[email protected]> * Update docstring Co-authored-by: Max Rossmannek <[email protected]> * Update release note Co-authored-by: Max Rossmannek <[email protected]> * Update releasenotes/notes/migrate-mp2-info-b1a3ee7320c46053.yaml Co-authored-by: Max Rossmannek <[email protected]> * Update releasenote Co-authored-by: Max Rossmannek <[email protected]> * update test class name * remove duplicate import * update release note to reflect initial_point refactor * update release note format * update release note format * update release note * remove todos raised as new PRs * Update qiskit_nature/algorithms/initial_points/mp2_initial_point.py Co-authored-by: dlasecki <[email protected]> * Update qiskit_nature/circuit/library/ansatzes/uccsd.py Co-authored-by: dlasecki <[email protected]> * Update qiskit_nature/algorithms/initial_points/mp2_initial_point.py Co-authored-by: dlasecki <[email protected]> * Update qiskit_nature/algorithms/initial_points/mp2_initial_point.py Co-authored-by: dlasecki <[email protected]> * Update qiskit_nature/algorithms/initial_points/mp2_initial_point.py Co-authored-by: dlasecki <[email protected]> * Update qiskit_nature/algorithms/initial_points/mp2_initial_point.py Co-authored-by: dlasecki <[email protected]> * Update qiskit_nature/algorithms/initial_points/mp2_initial_point.py Co-authored-by: dlasecki <[email protected]> * Update qiskit_nature/algorithms/initial_points/mp2_initial_point.py Co-authored-by: dlasecki <[email protected]> * Note raised error in docstring * make mp2 variable names more explicit * remove setter and directly expose initial_point in vqe_ucc_factory * Apply @mrossinek's suggestions from code review Co-authored-by: Max Rossmannek <[email protected]> * compute num MO from ElectronicEnergy and improve documentation * refactor grouped_property setter * refactor error raising in grouped property setter * refactor to remove get_initial_point * fix input validation for mp2 (needs unit tests); update release note * update docstring * separate compute and convert. e.g. initial_point -> to_numpy_array * fix input checking and add unit tests for all input * fix typo in unit tests * restore initial_point get/set to vqe factory (will be remove later) * update docstrings and var names * spelling * test if can compute on excitations not ansatz * fix typo * Apply @mrossinek's suggestions from code review Co-authored-by: Max Rossmannek <[email protected]> * update docstring * document not implemented error * update docstring * adapt unittests for not implemented addition * rename mp2 test resources * raise error inside compute, not inside converters * update error message * update error message * update docstring * update raised error message * linting * docstring grammar * improve docs and re-order methods and properties * fix typo * minor docstring changes * minor docstring changes * reorder special chars in pylintdict * else if -> elif * remove redundant float conversion Co-authored-by: Panagiotis Barkoutsos <[email protected]> Co-authored-by: Max Rossmannek <[email protected]> Co-authored-by: dlasecki <[email protected]>
Summary
Closes #89. Migrates the class that computes Møller-Plesset 2nd order corrections from the Aqua module to Nature. The double-excitation coefficients are intended to be used as initial point values for the corresponding operators in VQE when using a UCC ansatz. This should introduce an initial point that is closer to the ground state point, leading to fewer evaluations. However, I have not done any experiments to show that this is true in practice. These will be documented in #633.
The original Aqua implementation is here, with tests here.
Details and comments
MP2InitialPoint
inherits from the abstract base class (interface)InitialPoint
, which takes a driver result and a UCC Ansatz. TheMP2InitialPoint
requires the number of spin orbitals, the electronic energy, and the excitation lists from the second quantized properties of the driver result.If using a
VQEUCCFactory
, one can pass anMP2InitialPoint
instance via theinitial_point
keyword argument, in which case the driver result and ansatz will be used to compute the initial point automatically. This will then be passed to the VQE. Outside of the factory, one can do this manually (see examples below).The eventual intention is to retire
preferred_init_points
fromVQE
in Terra, so the implementation avoids this property. A defaultHFInitialPoint
will be introduced in #632.Example scripts
A simple complete script to use an MP2 initial point via the factory is:
Or to use it outside a factory: