-
Notifications
You must be signed in to change notification settings - Fork 207
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
Update API to allow QubitMapper where QubitConverter is used. #999
Update API to allow QubitMapper where QubitConverter is used. #999
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.
Just some initial observations 👍
qiskit_nature/second_q/algorithms/excited_states_solvers/excited_states_eigensolver.py
Outdated
Show resolved
Hide resolved
@@ -34,7 +34,7 @@ class ExcitedStatesEigensolver(ExcitedStatesSolver): | |||
|
|||
def __init__( | |||
self, | |||
qubit_converter: QubitConverter, | |||
qubit_converter: Union[QubitConverter, QubitMapper], |
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.
In the future I would like to rename this argument to qubit_mapper
. This will not be an easy process so it will be done in a separate PR once all the API is updated to support QubitMapper
and works. I'm mentioning it now just as an FYI.
This will not be an easy undertaking but I will start discussing some plans on how to do this properly offline.
qiskit_nature/second_q/algorithms/excited_states_solvers/excited_states_eigensolver.py
Outdated
Show resolved
Hide resolved
@@ -58,7 +58,7 @@ def get_qubit_operators( | |||
) -> Tuple[PauliSumOp, Optional[dict[str, PauliSumOp]]]: | |||
"""Construct qubit operators by getting the second quantized operators from the problem | |||
(potentially running a driver in doing so [can be computationally expensive]) | |||
and using a QubitConverter to map and reduce the operators to qubit operators. | |||
and using a QubitConverter or QubitMapper to map and reduce the operators to qubit operators. |
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.
We will need to do a thorough pass of the docs. Just mentioning this so its on our radar (I know that this is still a draft PR)
qiskit_nature/second_q/algorithms/excited_states_solvers/qeom_vibrational_ops_builder.py
Outdated
Show resolved
Hide resolved
releasenotes/notes/update-api-for-qubitmapper-qubitconverter-d237a7b596d50207.yaml
Outdated
Show resolved
Hide resolved
Pull Request Test Coverage Report for Build 3856020053
💛 - Coveralls |
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 think this is now looking a lot better in terms of API 👍
Could you please add more unittests to cover the usage of the new API?
releasenotes/notes/update-api-for-qubitmapper-qubitconverter-d237a7b596d50207.yaml
Outdated
Show resolved
Hide resolved
New unit tests were added following the API changes, however I still need to review properly the docstrings. |
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 is already looking quite good. A few more details need to be ironed out.
Ideally, we would add even more tests but I think for now until the remaining issues of the
QubitMapper refactoring are done, we can keep things as they are in this PR.
qiskit_nature/second_q/algorithms/ground_state_solvers/ground_state_eigensolver.py
Show resolved
Hide resolved
@@ -63,20 +63,21 @@ def __init__( | |||
) | |||
|
|||
@property | |||
def qubit_converter(self) -> QubitConverter: | |||
def qubit_converter(self) -> QubitConverter | QubitMapper | None: |
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 currently still holds QubitConverter(DirectMapper())
as the internally-generated default
value. Can we already change this or do we need to keep this as is?
If the latter, shall we log a warning that this default is going to change?
Also pinging @woodsp-ibm
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.
Having the default value set to DirectMapper()
won't change any of the logic. However, because it is a public attribute, it might be possible that one defines a VSCF object with the default value and then affects symmetries to the qubit converter. In that case, the QubitMapper will fail.
test/second_q/algorithms/excited_state_solvers/test_excited_states_solvers.py
Outdated
Show resolved
Hide resolved
test/second_q/algorithms/excited_state_solvers/test_qeom_electronic_ops.py
Show resolved
Hide resolved
test/second_q/algorithms/excited_state_solvers/test_qeom_vibrational_ops.py
Show resolved
Hide resolved
…added new tests to cover more cases
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.
Thanks, Anthony! 👍
…-community#999) * Failing tests but stable QubitConverter and QubitMapper can now be interverted * Modifications of the mappers map() * Update API for QubitMapper * Adds release note * Small corrections after first feedback. * Fix indentation: * Change for map_all to map and map to map_single. * Updated release note * Updated release note 2 * Small updates before pushing * small fix spell * First review of docstrings * Other docstrings * Make black * Fix mypy * Fix comments * fix * Rolled back the type expansion of the map and convert_match methods, added new tests to cover more cases * Implement the unwrapper in the _ListOrDict class * Fix spelling * Fix spell 2
Summary
Closes #972
This PR updates the API to allow
QubitMapper
object whereQubitConverter
were previously required. THis is possible because theQubitConverter
is a wrapper around theQubitMapper
with additional methods for qubit reduction (two qubit reduction and tapering). The utility methodmap()
was modified in the QubitMapper to act on lists, as theconvert_match()
does for the QubitConverter.The following gist goes through a the main classes where this functionality is accessible: gist
This PR is going to be affected by #971, but I wanted to initiate the reflexion and feedback process.