Skip to content

mosek_direct.py : Fixed iparam parsing and added support for Task.putparam #3488

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

Merged
merged 17 commits into from
Apr 16, 2025

Conversation

Utkarsh-Detha
Copy link
Contributor

Fixes:

In _apply_solver

  • Call to putintparam was missing in the isinstance(option, str) conditional when parsing iparam. Fixed.
  • Was calling option.pop('mosek') instead of option.pop(0) within the same conditional. Fixed.

Summary/Motivation:

A user wanted to be able to pass the value of ALL parameters as strings. MOSEK's optimizer API supports this through the Task.putparam function, which accepts a parameter name (string) and a value (also string).

Changes proposed in this PR:

Legal Acknowledgement

By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution:

  1. I agree my contributions are submitted under the BSD license.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.

Utkarsh-Detha and others added 2 commits February 24, 2025 14:52
…ameter and the parameter value as strings, as long as the "generic" parameter names are used.

Fixed: call to putintparam was missing in the isinstance(option, str) conditional when parsing 'iparam'.
@mrmundt
Copy link
Contributor

mrmundt commented Mar 3, 2025

@Utkarsh-Detha - please run black -S -C on your branch (with the newest version of black)

@Utkarsh-Detha
Copy link
Contributor Author

Thank you for the review, @mrmundt . I ran the formatter as you recommended, with the newest version thereof.

@blnicho
Copy link
Member

blnicho commented Mar 5, 2025

@Utkarsh-Detha could you add a couple tests for these changes?

@mrmundt
Copy link
Contributor

mrmundt commented Apr 8, 2025

@Utkarsh-Detha - Pinging again about this! Could you please add in some tests?

Copy link
Member

@jsiirola jsiirola left a comment

Choose a reason for hiding this comment

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

Overall this looks reasonable, but could be improved by some defensive checks. In addition, it would be good to test this functionality thought the unit tests.

1. Included warning for the case when an invalid input value is passed for iparams.
2. Added unit-test to check parameter-setting functionality in mosek_direct.
@Utkarsh-Detha
Copy link
Contributor Author

@blnicho @mrmundt sorry for the delay in getting this done. I have now added a few unit tests to check the parameter adding functionality. Feel free to suggest any corrections/changes. Thank you for your help.

@Utkarsh-Detha
Copy link
Contributor Author

@jsiirola I am starting to wonder if I should simply remove the option of allowing strings as iparam values. The idea initially was to allow users to pass MOSEK enums as strings, for example mosek.onoffkey.off. But I now think that it is more straightforward to just pass the option value directly to MOSEK, which would raise a TypeError if wrong input type is provided. As this would mean removing functionality, I wanted your opinion. (Lmk if I should rather open an Issue to discuss this)

2. Added a test to check if an AttributeError is raised when wrong parameter names are passed in options.
@mrmundt mrmundt requested review from mrmundt and jsiirola April 15, 2025 19:01
Copy link
Member

@jsiirola jsiirola left a 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 really close. It would be good to add one extra check and clarify the error message. If you have a chance to address this in the next couple hours, great - otherwise I may try and push to this branch and try to squeeze it into tomorrow's release.

@jsiirola
Copy link
Member

@Utkarsh-Detha Good question. I don't have a strong opinion on supporting strings for iparam. However, this is a "core" solver: if you want to remove it, I think we we would need to put in a deprecation path for several releases before deleting the functionality completely.

Copy link

codecov bot commented Apr 16, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.75%. Comparing base (6f2a50e) to head (86ec82c).
Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3488      +/-   ##
==========================================
+ Coverage   88.73%   88.75%   +0.02%     
==========================================
  Files         890      890              
  Lines      102207   102209       +2     
==========================================
+ Hits        90692    90715      +23     
+ Misses      11515    11494      -21     
Flag Coverage Δ
builders 26.62% <0.00%> (+<0.01%) ⬆️
default 84.86% <100.00%> (?)
expensive 34.00% <0.00%> (?)
linux 86.24% <0.00%> (-2.24%) ⬇️
linux_other 86.24% <0.00%> (-0.01%) ⬇️
osx 82.84% <0.00%> (-0.01%) ⬇️
win 84.74% <0.00%> (-0.01%) ⬇️
win_other 84.74% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

… instead of warnings for wrong input type

2. Removed call to "split" before searching for string pattern in key names
@Utkarsh-Detha
Copy link
Contributor Author

@jsiirola I also added/changed some tests to check if the correct exceptions are raised in case wrong types are passed for values of params. If a "str" type is passed to iparam but the name is recognized as a valid MOSEK enum, then an AttributeError is raised, which is also tested for in the tests. Let me know if you don't think this is a reasonable approach. Thanks for your help on this.

@github-project-automation github-project-automation bot moved this from Review In Progress to Reviewer Approved in Pyomo Release April 2025 Apr 16, 2025
@mrmundt mrmundt merged commit 653220a into Pyomo:main Apr 16, 2025
35 checks passed
@github-project-automation github-project-automation bot moved this from Reviewer Approved to Done in Pyomo Release April 2025 Apr 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

5 participants