Skip to content
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

Refactor BaseProblem.second_q_ops() #772

Merged
merged 4 commits into from
Aug 12, 2022

Conversation

mrossinek
Copy link
Member

Summary

This PR is another self-container step part of #701.
It refactors the BaseProblem.second_q_ops() method to produce a tuple, with the first element being the main operator, and the second element a dictionary of auxiliary operators. This matches the input expected by Terra algorithms and avoids the common need of extracting the main operator from one larger dictionary of operators.

Details and comments

This PR also enables settings.dict_aux_operators by default and deprecates ListOrDict since Qiskit Nature will always be producing dictionaries of auxiliary operators in the new stack/workflow.

@mrossinek mrossinek force-pushed the refactor-second_q_ops branch from 7db0954 to f995e28 Compare August 6, 2022 14:19
This removes the usage of ListOrDict wherever possible.
The QubitConverter class is the last place this is needed, because the
UCC and UVCC ansatze pass their excitation operators for conversion as
a list.

That is fine for now, but may be improved when tackling qiskit-community#771
The algorithms in Terra always take a tuple of the main operator and
some auxiliary operators. This commit changes the `BaseProblem`
interface to already return the generated operators in the same format.
This simplifies the handling of the main operator, a scenario that
occurs very often and required manual intervention thus far.
@mrossinek mrossinek force-pushed the refactor-second_q_ops branch from f995e28 to 1e14e1d Compare August 6, 2022 14:38
@coveralls
Copy link

coveralls commented Aug 6, 2022

Pull Request Test Coverage Report for Build 2847101259

  • 68 of 80 (85.0%) changed or added relevant lines in 23 files are covered.
  • 15 unchanged lines in 6 files lost coverage.
  • Overall coverage increased (+0.06%) to 85.478%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit_nature/list_or_dict.py 1 2 50.0%
qiskit_nature/second_q/mappers/qubit_converter.py 23 26 88.46%
qiskit_nature/second_q/algorithms/excited_states_solvers/excited_states_eigensolver.py 3 7 42.86%
qiskit_nature/second_q/algorithms/ground_state_solvers/ground_state_eigensolver.py 3 7 42.86%
Files with Coverage Reduction New Missed Lines %
qiskit_nature/second_q/algorithms/excited_states_solvers/excited_states_eigensolver.py 1 78.72%
qiskit_nature/second_q/algorithms/excited_states_solvers/qeom.py 1 81.57%
qiskit_nature/second_q/algorithms/ground_state_solvers/ground_state_eigensolver.py 1 81.61%
qiskit_nature/second_q/problems/base_problem.py 1 87.18%
qiskit_nature/drivers/second_quantization/psi4d/psi4driver.py 2 84.43%
qiskit_nature/list_or_dict.py 9 45.0%
Totals Coverage Status
Change from base Build 2847048248: 0.06%
Covered Lines: 17464
Relevant Lines: 20431

💛 - Coveralls

@mrossinek mrossinek requested a review from woodsp-ibm August 12, 2022 06:58
woodsp-ibm
woodsp-ibm previously approved these changes Aug 12, 2022
@mrossinek mrossinek merged commit 96d0e3b into qiskit-community:main Aug 12, 2022
@mrossinek mrossinek deleted the refactor-second_q_ops branch August 12, 2022 14:21
Anthony-Gandon pushed a commit to Anthony-Gandon/qiskit-nature that referenced this pull request May 25, 2023
* refactor: enable dict_aux_operators by default

* refactor: deprecate qiskit_nature.ListOrDict

This removes the usage of ListOrDict wherever possible.
The QubitConverter class is the last place this is needed, because the
UCC and UVCC ansatze pass their excitation operators for conversion as
a list.

That is fine for now, but may be improved when tackling qiskit-community#771

* refactor: match return type of `BaseProblem.second_q_ops()` to Terra

The algorithms in Terra always take a tuple of the main operator and
some auxiliary operators. This commit changes the `BaseProblem`
interface to already return the generated operators in the same format.
This simplifies the handling of the main operator, a scenario that
occurs very often and required manual intervention thus far.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants