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

New matrix variable functionality #957

Merged
merged 42 commits into from
Feb 25, 2025
Merged

New matrix variable functionality #957

merged 42 commits into from
Feb 25, 2025

Conversation

Joao-Dionisio
Copy link
Collaborator

What is this?

This PR will track the implementation of the matrix variable functionality. With the current changes, users can do the following:

from pyscipopt import Model, sin, log
import numpy as np

m = Model()
matrix_variable1 = m.addMatrixVar( shape=(3,3), vtype="B", name="test", obj=np.ones((3,3)) )

obj = np.asarray([ [2,1,3], [1,1,0], [1,2,3] ])
matrix_variable2 = m.addMatrixVar( shape=(3,3), vtype="C", name="", obj=obj )
# # note that depending on the argument type, what you pass to the function may be broadcasted by numpy (intentional decision on our part)
# # e.g., passing vtype="C" makes every variable have type "C", but obj is taking an iterable, and so every variable will be assigned its own value

m.addMatrixCons( log(log(matrix_variable1)) - sin(matrix_variable2) >= 32 ) # same here. This means every entry should be >= 32

m.optimize() # should be running without errors

Motivation

In some optimization sub-fields and other adjacent fields, it is sometimes standard to have a matrix view of the problem. For example, in machine learning one often gets a matrix, does some things to it, and passes it on.
It is also something that general modeling frameworks tend to support, so adding this functionality should make integrating PySCIPOpt into them easier, thus possibly increasing the visibility of PySCIPOpt.

Status

It is now possible to add matrix variables, create expression involving matrix varaibles, and create linear and general nonlinear expressions involving matrix variables. So, in a sense, most of the basic functionality is already here. What is yet missing is proper documentation, more thorough testing (especially on the nonlinear side), and a focus on performance optimization when it comes to building big models. We also want to allow addCons to accept matrix variables, as some users might find it more intuitive.


Please let us know your thoughts and suggestions regarding this functionality.

This is joint work by @Opt-Mucca, @mmghannam, and @Joao-Dionisio.

Copy link

codecov bot commented Feb 21, 2025

Codecov Report

Attention: Patch coverage is 42.40964% with 239 lines in your changes missing coverage. Please review.

Project coverage is 52.01%. Comparing base (1db095e) to head (f9c1caa).
Report is 62 commits behind head on master.

Files with missing lines Patch % Lines
src/pyscipopt/scip.pxi 36.07% 179 Missing ⚠️
src/pyscipopt/matrix.pxi 39.56% 55 Missing ⚠️
src/pyscipopt/expr.pxi 90.69% 4 Missing ⚠️
src/pyscipopt/_version.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #957      +/-   ##
==========================================
- Coverage   52.54%   52.01%   -0.54%     
==========================================
  Files          20       22       +2     
  Lines        4345     4893     +548     
==========================================
+ Hits         2283     2545     +262     
- Misses       2062     2348     +286     

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

Opt-Mucca and others added 3 commits February 25, 2025 11:04
Co-authored-by: Mohammed Ghannam <ghannam@zib.de>
Co-authored-by: Mohammed Ghannam <ghannam@zib.de>
@Joao-Dionisio Joao-Dionisio merged commit a0165ec into master Feb 25, 2025
1 check passed
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