Skip to content

be smarter when assembling the constraints expression#281

Merged
cdiener merged 2 commits into
opencobra:masterfrom
cdiener:fix/hybrid_expression
May 29, 2026
Merged

be smarter when assembling the constraints expression#281
cdiener merged 2 commits into
opencobra:masterfrom
cdiener:fix/hybrid_expression

Conversation

@cdiener

@cdiener cdiener commented May 28, 2026

Copy link
Copy Markdown
Member

When assembling Constraint.expression the matrix interface would iterate over all variables for each constraint. Now it prefilters the coefficients and only uses the relevant variables making the expression sparse as it should be.

Also fixed a typo.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR optimizes how Constraint.expression is assembled in the matrix-based interfaces (used by the hybrid solver), avoiding per-constraint iteration over every model variable by instead constructing expressions only from non-zero stored coefficients. It also fixes a local typo in the objective parsing code path.

Changes:

  • Build Constraint.expression from the sparse (constraint, variable) -> coefficient mapping instead of scanning all variables.
  • Fix typo quadratic_coeffientsquadratic_coefficients in the objective setter.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/optlang/matrix_interface.py

@oxinabox oxinabox left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This makes sense to me.

I can't test it.
Because versioneer on this branch thinks it is v2.dev
and so pip refuses to install the branch.
(If this isn't merged/tagged by time i start work tomorrow, I will hack around it, and test it.)

@cdiener cdiener merged commit 903a1a6 into opencobra:master May 29, 2026
6 checks 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