optlang icon indicating copy to clipboard operation
optlang copied to clipboard

No-Op solver

Open oxinabox opened this issue 9 months ago • 3 comments

Checklist

Is your feature related to a problem? Please describe it.

When using cobrapy, sometimes times I want to load up a model (in my case constructing it manually) to inspect it, and use cobrapy's tools for querying what reactions are linked to what genes etc. Or for example to use it as the source for gapfilling.

I have a rather extreme example of a model that takes about 20 minutes to define.

The time taken to construct a model in cobrapy is heavily dominated by the time taken to add_constraintss to the optlang problem it is defining behind the scenes. However, if you never intend to solve it, then this time is wasted.

Describe the solution you would like.

I would like a solver which implements the full optlang interface, but almost all the operations are no-ops. Then I could just call model.solver=optlang.NoOpSolver() before i start loading anything. And all the calls to model.add_reaction and model.add_metabolites would be much faster.

Then if I were to call model.solve() then an error could be thrown explaining that this model has been created with the noop solver, and that i should set it to us an actual solver if I wanted to be able to solve it.

Describe alternatives you considered

Allowing the solver to be set to None in cobrapy, and then putting if solver around all the calls to it.

oxinabox avatar Mar 31 '25 07:03 oxinabox

Fully agree, this will be useful. My own idea was to have a class inbetween. One to directly interact with SBML only and then another class on top that has the solver integrations. Never got around to it.

Midnighter avatar Mar 31 '25 08:03 Midnighter

I will probably put one together in the next few days and open a PR then. This loading time is really hurting me.

oxinabox avatar Mar 31 '25 08:03 oxinabox

actually I have to put this on backburner for a bit. But I will probably be back for it at some point.

oxinabox avatar Apr 02 '25 07:04 oxinabox