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

Add MPS and GZ support in translators #583

Open
wants to merge 24 commits into
base: main
Choose a base branch
from

Conversation

dthuerck
Copy link
Contributor

✅ I have added the tests to cover my changes.
✅ I have updated the documentation accordingly.
✅ I have read the CONTRIBUTING document.

Summary

See issue #582: This PR succeeds #581, having moved lp/mps/gz IO functions into translators.

Details and comments

lp functions in QuadraticProgram have been marked as deprecated. Tests and Tutorials have been updated to use the file_io.

@coveralls
Copy link

coveralls commented Dec 27, 2023

Pull Request Test Coverage Report for Build 8389542132

Details

  • 93 of 95 (97.89%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.06%) to 93.089%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit_optimization/translators/file_io.py 77 79 97.47%
Totals Coverage Status
Change from base Build 8048858331: 0.06%
Covered Lines: 4580
Relevant Lines: 4920

💛 - Coveralls

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.

A couple of quick comments. And it will need a release note for the new function and to note the deprecation see https://github.com/qiskit-community/qiskit-optimization/blob/main/CONTRIBUTING.md#release-notes for info on this, if you need it, which is done with a tool called reno.

" _e f\n",
"End\n",
"\n"
"ename": "NameError",
Copy link
Member

Choose a reason for hiding this comment

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

It looks like perhaps just this cell was run - probably best to re-run the whole notebook locally for whats checked in. It will get re-run too when docs are built but it should be checked in a state that would match what CI produces.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks - re-ran and checked it.

@@ -917,45 +916,47 @@ def export_as_lp_string(self) -> str:
Returns:
A string representing the quadratic program.
"""
warn(
Copy link
Member

Choose a reason for hiding this comment

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

There are some deprecation decorators in Qiskit that we try and use now. They also emit the deprecation into the docstring so the notices come out in the published docs. You can most likely find usage examples in Qiskit - this is the file with the decorators https://github.com/Qiskit/qiskit/blob/main/qiskit/utils/deprecation.py

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks again for the reference - used the appropriate decorators in the last commit.

@dthuerck
Copy link
Contributor Author

dthuerck commented Feb 5, 2024

@woodsp-ibm Thanks for the hints! Should be all done by now, release note is there.

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.

One other thing. Its now 2024 and many of these files still have 2023 dates. This passes on CI presently but, from past experience, the files, when merged in to main will end up have last updated dates of 2024. This PR will not fail, but any subsequent ones, since the checks are run against all files, will fail on these despite it might not even touch them. To avoid this, if I could ask you to update the dates for 2024 in all the files with a copyright that will avoid us having to deal with it down the line. Its a bit of a pain I know but having a PR cross a year boundary has been more of an exception.

@@ -0,0 +1,12 @@
---
features:
Copy link
Member

Choose a reason for hiding this comment

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

This file should be in releasenotes/notes - if you ran the reno command that is where it should have created it. We only move the notes into a folder under there for the version at the point its released.

Bear in mind too this should be describing things user perspective, and since we expect people to import these from translators the extra "unit"/module is arguably an implementation detail. And as far as I can see there are functions to read and write .mps and .lp files and additionally for the read it supports gzipped files i.e. .mps.gz and .lp.gz (I did not see any write capatibility for gz unless I missed it). It might be list the functions here so someone can click and go to the API ref from the release note here. Often we would have a small sample code for new function but I think this is simple enough that its not needed, right.

@@ -44,7 +45,7 @@ def test_cplex_optimizer(self, config):
# load optimization problem
problem = QuadraticProgram()
lp_file = self.get_resource_path(filename, "algorithms/resources")
problem.read_from_lp_file(lp_file)
problem = read_from_lp_file(lp_file)
Copy link
Member

Choose a reason for hiding this comment

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

Ideally we continue to test the deprecated function to ensure that it still works while its supported before we remove it. In this case maybe this is ok knowing that the deprecated code just simply forwards the call to the new function - hopefully its hard for that to fail before its removed.

def test_read_from_lp_gz_file(self):
"""test read compressed lp file"""
try:
with self.assertRaises(IOError):
Copy link
Member

Choose a reason for hiding this comment

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

This test is bundling together a number of tests. If it fails the first here the rest of the tests won't be run and that might provide insight into the failure - does depend on what the tests/code are and it may not in this case. Usually we try to do with sub-test, or parameterize a testt with ddt, eg since all the failure tests are the same but the data that part of could be done that way. I see the helper above is a ton of asserts - and that may be overkill for that though again its going to stop the test on the first failure of course. Something to think about anyway.

@@ -34,6 +34,14 @@
"""

from .docplex_mp import from_docplex_mp, to_docplex_mp
from .file_io import (
Copy link
Member

@woodsp-ibm woodsp-ibm Feb 14, 2024

Choose a reason for hiding this comment

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

We should include these in the documentation as they are public methods we now expect a user to use. You can see the pre-existing list above in the docstring - maybe it makes sense to have another section that lists these - or perhaps the export ones go under Translators there and the others under "File loading and saving" ?

You can see what the current page looks like from here https://qiskit-community.github.io/qiskit-optimization/apidocs/qiskit_optimization.translators.html. To build docs locally runmake html in the project root, or make clean html which will wipe away whats there which sometimes is needed if the incremental build does not come out as expected - I find this more if I change the structure. One or more docstrings changed is pretty much ok. html will be in the _build folder that is created under docs

If you want to see how the docs come out in the build, if you go to build Details and Summary you can scroll down and see artifacts that the build creates. documentation is the docs built without running the tutorials as a quicker check. tutorials_3.x are jobs under that version of Python that also build the docs but run the notebooks too.

@dthuerck
Copy link
Contributor Author

Thanks for the extensive comments, @woodsp-ibm ! I added test cases for the deprecated functions and updated the docs accordingly.

@CLAassistant
Copy link

CLAassistant commented Nov 6, 2024

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
2 out of 3 committers have signed the CLA.

✅ woodsp-ibm
✅ dthuerck
❌ Daniel Thuerck


Daniel Thuerck seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

4 participants