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

Update to_ising and from_ising to support SparsePauliOp #467

Merged
merged 8 commits into from
Apr 20, 2023

Conversation

t-imamichi
Copy link
Collaborator

@t-imamichi t-imamichi commented Jan 23, 2023

Summary

  • Adds opflow option to to_ising to control the output is SparsePauliOp or Opflow's operator.
  • Allows from_ising to receive quantum_info's operators.

This is part of #433.
The legacy minimum eigensolver of Terra supports only opflow (not SparsePauliOp).
We will deprecate the legacy minimum eigensover and opflow when they are deprecated in Terra.

Details and comments

@coveralls
Copy link

coveralls commented Jan 23, 2023

Pull Request Test Coverage Report for Build 4732501811

  • 40 of 40 (100.0%) changed or added relevant lines in 4 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.003%) to 92.083%

Files with Coverage Reduction New Missed Lines %
qiskit_optimization/algorithms/minimum_eigen_optimizer.py 1 87.69%
Totals Coverage Status
Change from base Build 4663084632: -0.003%
Covered Lines: 4350
Relevant Lines: 4724

💛 - Coveralls

@t-imamichi
Copy link
Collaborator Author

I updated the option name from quantum_info to opflow because I thought it is easier to understand why it will be deprecated when opflow is deprecated in terra.
I also changed the code to display a warning message if opflow option is not set explicitly.

Copy link
Contributor

@a-matsuo a-matsuo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed the code changes thoroughly and everything looks good to me!

@a-matsuo a-matsuo self-requested a review March 24, 2023 04:23
a-matsuo
a-matsuo previously approved these changes Mar 24, 2023
Copy link
Contributor

@a-matsuo a-matsuo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed the code changes thoroughly and everything looks good to me!

"""Return the Ising Hamiltonian of this problem.

Variables are mapped to qubits in the same order, i.e.,
i-th variable is mapped to i-th qubit.
See https://github.com/Qiskit/qiskit-terra/issues/1148 for details.

Args:
opflow: The output object is an OpFlow's operator if True.
Otherwise, it is ``SparsePauliOp``. (default: True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think directly stating the default here is easier for an end user - but we will have to remember to update this here too when the default changes. The alternative would be to say the default is determined by the to_ising function and link to that, this is the place that determines it and we have to change next time so if this were done not change would be needed here.

Copy link
Collaborator Author

@t-imamichi t-imamichi Apr 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your idea. I updated it to refer to to_ising function. cc41551

.. note::

The default value of ``opflow`` argument is currently set ``True``, but it will
first be changed to ``False`` and then deprecated in future releases.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just as a note given opflow is planned for deprecation in the upcoming Terra 0.24 release it would be removed in 0.26 two releases later. At that time this parameter can still exist but will be need to be ignored since there will no longer be any opflow logic in Terra. I guess we can consider updating this note when its changed over to False next time based on how things will progress.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we need to update it depending on the opflow deprecation status of Terra in the future.

Comment on lines 155 to 157
The ``qubit_op`` argument can currently accept Opflow operators, but it has been
superseded by ``SparsePauliOp``.
Opflow will be deprecated in a future release and subsequently removed after that.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The ``qubit_op`` argument can currently accept Opflow operators, but it has been
superseded by ``SparsePauliOp``.
Opflow will be deprecated in a future release and subsequently removed after that.
The ``qubit_op`` argument can currently accept Opflow operators (OperatorBase type), but have been
superseded by Qiskit Terra quantum info BaseOperators such as ``SparsePauliOp``.
Opflow operator support will be deprecated in a future release and subsequently removed after that.

Here is accepts all quantum info BaseOperator types right. Most often it will be SparsePauliOp bit its not restricted to this. I will also note that we can make these class references since we have the intersphinx with Terra.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I include it. cc41551

Comment on lines 184 to 186
"The `qubit_op` argument can currently accept Opflow operators, but it has been "
"superseded by `SparsePauliOp`. "
"Opflow will be deprecated in a future release and subsequently removed after that.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not alter the text here as per he above suggestion. But if the suggestion seems better then perhaps this should be the same.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I include it. cc41551

Comment on lines 4 to 8
Updated :func:`~.to_ising` to support ``qiskit.quantum_info.SparsePauliOp``.
Added ``opflow`` argument to :func:`~.to_ising` to control the output is
opflow operator (if ``True``) or ``SparsePauliOp`` (if ``False``).
The default value of ``opflow`` argument is currently ``True``, but it will
first be changed to ``False`` and then deprecated in future releases.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Updated :func:`~.to_ising` to support ``qiskit.quantum_info.SparsePauliOp``.
Added ``opflow`` argument to :func:`~.to_ising` to control the output is
opflow operator (if ``True``) or ``SparsePauliOp`` (if ``False``).
The default value of ``opflow`` argument is currently ``True``, but it will
first be changed to ``False`` and then deprecated in future releases.
Updated :func:`~.to_ising` to support optionally returning ``qiskit.quantum_info.SparsePauliOp``.
This is achieved by a new ``opflow`` argument to :func:`~.to_ising` to control if the output is
the opflow operator, as has been done in the past, (if ``True``) or ``SparsePauliOp`` (if ``False``).
The default value of ``opflow`` argument is currently ``True``, but it will
first be changed to ``False``. The parameter will be deprecated and removed in a future release.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I include it. cc41551

Comment on lines 10 to 13
Updated :func:`~.from_ising` to support ``qiskit.quantum_info.SparsePauliOp``.
``qubit_op`` argument can currently accept opflow operators,
but it has been superseded by ``SparsePauliOp``.
Opflow will be deprecated in a future release and subsequently removed after that.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This text is similar again to the suggestion made for the from_ising note. So again is thats ok probably we want the same/similar here too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I include it. cc41551

Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com>
Copy link
Member

@woodsp-ibm woodsp-ibm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I see the release note has a minor spelling mistake in its name support-sprase-pauli-op where its sprase instead of sparse - but since the name never shows up anywhere outside of looking at the files themselves it's of little consequence.

@t-imamichi
Copy link
Collaborator Author

Good catch. But, it is a bit complicated to rename reno. So, I will merge it without renaming it.

@t-imamichi t-imamichi added Changelog: Deprecation Include in Deprecated section of changelog Changelog: New feature Include in the Added section of the changelog automerge and removed Changelog: Deprecation Include in Deprecated section of changelog labels Apr 20, 2023
@mergify mergify bot merged commit e360343 into qiskit-community:main Apr 20, 2023
@t-imamichi t-imamichi deleted the spo branch April 20, 2023 02:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Changelog: New feature Include in the Added section of the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants