-
Notifications
You must be signed in to change notification settings - Fork 209
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
Property Finalization #303
Property Finalization #303
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.
Since I cannot comment on a changed binary file:
The file test/transformers/second_quantization/electronic/LiH_sto3g_reduced.hdf5
had to be updated because the stored QMolecule
in that file was missing its num_molecular_orbitals
attribute.
self._molecule_data = cast(QMolecule, self.driver.run()) | ||
driver_result = self.driver.run() | ||
if self._legacy_transform: | ||
qmol_transformed = self._transform(self._molecule_data) | ||
qmol_transformed = self._transform(driver_result) | ||
self._properties_transformed = ( | ||
ElectronicStructureDriverResult.from_legacy_driver_result(qmol_transformed) | ||
) | ||
elif isinstance(driver_result, QMolecule): | ||
self._properties_transformed = ( | ||
ElectronicStructureDriverResult.from_legacy_driver_result(driver_result) | ||
) | ||
else: | ||
prop = ElectronicStructureDriverResult.from_legacy_driver_result(self._molecule_data) | ||
self._properties_transformed = self._transform(prop) | ||
self._properties_transformed = self._transform(driver_result) |
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 still needs to be cleaned up. In order for that to happen I need to figure out how to properly deprecate the BaseProblem.molecule_data*
..
@woodsp-ibm @manoelmarques do you have some ideas on how to proceed with that?
Since they are part of the public API I am unsure if I can just change/delete them. They won't exist in their format any longer and they were really just auxiliary access points to the driver results (which are now Property
objects).
In #263 I added the BaseProblem.roperties_transformed
attribute as a temporary workaround. Ideally I think we should have something like this:
class BaseProblem:
@property
def driver_result(self) -> GroupedProperty:
return self._driver_result
@property
def transformed_driver_result(self) -> GroupedProperty:
return self._transformed_driver_result
Please let me know your opinions 🙂
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.
You can’t delete the properties if you intend to deprecate. Is it possible to get the molecule data by other means to keep the properties or is it lost ?
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.
molecule_data
used to be QMolecule
or WatsonHamiltonian
. Since these are now deprecated, they will no longer occur within the stack, if a user uses one of the new drivers in qiskit_nature.drivers.second_quantization
.
I could deprecate the properties and change their type to be Optional[...]
but I am not sure if that is allowed? [Technically they probably should have been that though, because the __init__
sets them to None
...]
And to be clear: the deprecated drivers are still supported by this stack but right now they will not store these properties (which I could change ofcourse) 👍
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.
It would be nice if using things with the existing drivers, for users that have code to what is currently released, works the same albeit deprecated. Switching to the newer drivers then other code for properties can come about. At that level things can be more separated - in the problem I guess it has the unenviable task of, in the interim, allowing the old way to work and supporting the new way too if thats indeed doable.
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.
I have updated the code and we now have the following:
BaseProblem.molecule_data*
are deprecated in favor ofBaseProblem.grouped_property*
We have some internal logic as follows:
Legacy Driver + Legacy Transformers
Works as expected. Deprecation warnings will be raised by those classes themselvers.
The following properties will be set:
molecule_data
molecule_data_transformed
grouped_property
grouped_property_transformed
Legacy Driver + New Transformers
Works. A UserWarning
will be raised, suggesting to look into the new drivers.
The following properties will be set:
molecule_data
(remainsmolecule_data_transformed
None
)grouped_property
grouped_property_transformed
New Driver + Legacy Transformers
Impossible! A QiskitNatureError
will be raised.
New Driver + New Transfomrers
Works as expected.
The following properties will be set:
(remainsmolecule_data
None
)(remainsmolecule_data_transformed
None
)grouped_property
grouped_property_transformed
Finally, if a user mixes legacy and new transformers, a QiskitNatureError
will be raised, too.
qiskit_nature/problems/second_quantization/vibrational/vibrational_structure_problem.py
Outdated
Show resolved
Hide resolved
qiskit_nature/properties/second_quantization/driver_metadata.py
Outdated
Show resolved
Hide resolved
qiskit_nature/properties/second_quantization/electronic/angular_momentum.py
Outdated
Show resolved
Hide resolved
qiskit_nature/properties/second_quantization/electronic/angular_momentum.py
Outdated
Show resolved
Hide resolved
qiskit_nature/properties/second_quantization/electronic/bases/electronic_basis_transform.py
Outdated
Show resolved
Hide resolved
qiskit_nature/properties/second_quantization/electronic/electronic_structure_driver_result.py
Outdated
Show resolved
Hide resolved
qiskit_nature/properties/second_quantization/electronic/integrals/electronic_integrals.py
Outdated
Show resolved
Hide resolved
test/drivers/second_quantization/fcidumpd/test_driver_methods_fcidump.py
Outdated
Show resolved
Hide resolved
@@ -21,6 +21,7 @@ | |||
from qiskit_nature.drivers.second_quantization import HDF5Driver | |||
|
|||
|
|||
@unittest.skip("Until the Property framework supports HDF5 storage") |
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.
FYI: #302
This tests an internal method of the driver which is yet to be refactored to use the Property framework.
The previous cyclic import issues do not occur since the removal of qiskit_nature.drivers.second_quantization.QMolecule
I am marking this as ready for review. Early next week, I am going to tackle the outstanding tasks:
|
In the notebook this warning message is emitted - as we use the default value for display_format. As this message is only emitted when we rely on the default can we explicitly pass in the value we want (maybe we need to change it internally to sparse later but I think thats better than having warnings come out by default from our internal use of our code)
(PS. I fixed for the formatting of the message in #330) |
In the notebook ParticleNumber prints out this
I had to look at the code to figure what the [1. 0.] was for - with the example it looks not so far from the tuple that is used to define the num particles (1, 1) given the lengths are the same. I see now its the orbital occupation. It might be helpful to say a little more e.g. something like this perhaps, though I agree its a bit verbose; maybe there is a better way to format it and say what things are.
|
In looking at the strings, particularly the integrals, should we be truncating the output by default, like numpy does with its arrays. You example in the notebook is small. By the time the integrals are more real-world it seems the formatted string is going to be huge. Having a summary like the size/shape and then some of content seems more practical. With access to data it can be printed anyway the user wants, but the str here should be a useful summary/overview of that data - given sizes of things dumping out all the data seems too much. |
Co-authored-by: Steve Wood <[email protected]>
I have added a truncation method similar to what we did for the |
qiskit_nature/properties/second_quantization/electronic/integrals/electronic_integrals.py
Outdated
Show resolved
Hide resolved
qiskit_nature/properties/second_quantization/vibrational/integrals/vibrational_integrals.py
Outdated
Show resolved
Hide resolved
Co-authored-by: Steve Wood <[email protected]>
* Minor fixes * Prevent cyclic imports in property framework * Use Property framework for ElectronicStructureDrivers * Clean up tests * Deprecate QMolecule class * Deprecate WatsonHamiltonian class * Partially clean up docs * Migrate PySCFDriver to property framework * Fix spell * Fix lint * Fix html * Fix unittests * Fix GaussianFromMat unittest This tests an internal method of the driver which is yet to be refactored to use the Property framework. * Move imports to toplevel The previous cyclic import issues do not occur since the removal of qiskit_nature.drivers.second_quantization.QMolecule * Improve typehint * Implement missing __str__ methods * Filter some deprecation warnings * WIP tutorial * Add Property.log() method * Disable false-positive pylint for Python 3.6 * Deprecate BaseProblem.molecule_data* properties * Ensure legacy driver+transformer stack still works * Filter more warnings during unittesting * Fix linters * Apply suggestions from code review Co-authored-by: dlasecki <[email protected]> * Fix style after suggestions commit * Property framework doc updates * Update Problem docs * Update Transformer docs * Update tutorial * Add reno * Fix linters * Fix reno formatting and spell * Add Molecule.__str__ method * Fix docstrings referring to legacy driver results * Deprecate bosonic_bases in favor of properties bases * Fix linters * Filter warnings in CI * Make ParticleNumber expected check tolerance configurable * Enable expected spin to be set on AngularMomentum property * Move mismatching expected value log to INFO level * Review comments Co-authored-by: Dariusz Lasecki <[email protected]> * Docstring formatting Co-authored-by: Steve Wood <[email protected]> * Fix docstring correctness * Suppress DeprecationWarnings on driver level * Rerun tutorial * Re-enable skipped unittest (might break CI) * Filter warnings in Psi4 process * Fix 4-th level heading HTML rendering * Add ElectronicEnergy.from_raw_integrals utility method * Fix GaussianForcesDriver unittest * Filter deprecation warning in CI * More doc rendering fixes * Apply suggestions from code review Co-authored-by: Steve Wood <[email protected]> * Fix FermionicOp Warning msg format (qiskit-community#330) * Avoid UserWarning in tutorial * Improve ParticleNumber.__str__ * Truncate integral printing output * Fix unittests * Fix more unittests * Fix mypy * Apply suggestions from code review Co-authored-by: Steve Wood <[email protected]> Co-authored-by: Manoel Marques <[email protected]> Co-authored-by: dlasecki <[email protected]> Co-authored-by: Steve Wood <[email protected]>
Summary
Closes #264
Closes #148
Details and comments
Task list partially carried over from #263
DriverResult
with drivers (i.e. do not returnQMolecule
as intermediate storage container)BaseProblem.molecule_data*
propertiesimplementation of HDF5 interface (storing and loading similar to(cf. HDF5 integration for theQMolecule
)Property
framework #302)Property.log()