Load solution from .sol file into Pyomo model instance

696 views
Skip to first unread message

Mathias Berger

unread,
May 16, 2019, 9:35:20 AM5/16/19
to Pyomo Forum
Hello,

I am currently modelling some optimal gas flow problems in Pyomo 5.6.1 (CPython 3.6.3 on Darwin 16.7.0) on macOS Sierra (10.12.6) and testing the performance of different models, including MILPs, MISOCPs and MINLPs. I would like to solve MINLP models with SCIP 6.0.1, but I am having trouble doing so. So far, I have tried two approaches

1) Directly calling SCIP from Pyomo using:

                opt = SolverFactory('scip')
                opt.solve(model, tee=True, keepfiles=False)

which returns an error (see scip_from_pyomo.png). From what I understand, Pyomo is trying to pass a .nl file to the SCIP executable, save the solution in a .sol file and recover it. For some reason, it seems like SCIP 6.0.1 cannot read the .nl file generated by Pyomo. I also tested it in the interactive shell with a different .nl file generated from Pyomo and ended up with the error shown in scip_reader.png.

2) Generating a .mps file from Pyomo, reading and solving it with SCIP from command line or in the interactive shell, writing a .sol file and loading the solution back into a Pyomo model instance, following the instructions given in a previous post and the Pyomo gallery. I slightly updated the code proposed there to incorporate it into my own, and ended up with this function to read the .sol file

def read_sol(self, sol_filename, symbol_map_filename, suffixes=[".*"]):
       
        if suffixes is None:
            suffixes = []

        # parse the SOL file
        with ReaderFactory(ResultsFormat.sol) as reader:
            results = reader(sol_filename, suffixes=suffixes)
           
        if results.solver.termination_condition != TerminationCondition.optimal:
            raise RuntimeError("Solver did not terminate with status = optimal")

        # regenerate the symbol_map for this model
        with open(symbol_map_filename, "rb") as f:
            symbol_cuid_pairs = pickle.load(f)
            symbol_map = SymbolMap()
            symbol_map.addSymbols((cuid.find_component(self.model), symbol)
                          for symbol, cuid in symbol_cuid_pairs)

        # tag the results object with the symbol_map
        results._smap = symbol_map
        self.model.solutions.load_from(results)

When using it, I get the error shown in scipsol_to_pyomo.png. I also checked what happened when I tried to load .sol files generated by Gurobi 8.0.0 and CPLEX 12.8.0.0 for MISOCPs. The exact same procedure (write mps with Pyomo, then read, solve and write .sol file with Gurobi and CPLEX interactive shells) is followed, and errors are returned in both cases (see gurobisol_to_pyomo.png and cplexsol_to_pyomo.png). All .sol files used are attached to this post.

I am slightly stuck here, and before attempting anything else, I was wondering whether anyone was aware of an easy fix or work-around? Any help or ideas would be much appreciated.

Thank you in advance for considering this post,

Best,

Mathias Berger

cplexsol_to_pyomo.png
gurobisol_to_pyomo.png
scip_from_pyomo.png
scip_reader.png
scipsol_to_pyomo.png
MISOCP_CPLEX.sol
MISOCP_Gurobi.sol
MINLP_SCIP.sol

Gabriel Hackebeil

unread,
May 16, 2019, 10:04:03 AM5/16/19
to Pyomo Forum
I believe Pyomo can interface with SCIP through the scipampl executable (https://www.zverovich.net/2012/08/07/using-scip-with-ampl.html). Once you have this executable built and added to your PATH, use ’scipampl’ as the solver name with Pyomo and everything should work.

Gabe

--
You received this message because you are subscribed to the Google Groups "Pyomo Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyomo-forum/c50ee80d-a00c-43a2-8526-3e37e5dd6b8a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
<cplexsol_to_pyomo.png><gurobisol_to_pyomo.png><scip_from_pyomo.png><scip_reader.png><scipsol_to_pyomo.png><MISOCP_CPLEX.sol><MISOCP_Gurobi.sol><MINLP_SCIP.sol>

omowu...@gmail.com

unread,
Nov 25, 2021, 7:32:25 AM11/25/21
to Pyomo Forum

Dear Gabe/Pyomo Team,

Please I am having this same problem with loading solution from .sol file into Pyomo model instance but using Gurobi solver. I use the academic license for Gurobi and the gurobiampl, doesn't work with academic license. I am also running my model from an HPC server. Please how can I resolve this problem?

Thank you.
Ola
Reply all
Reply to author
Forward
0 new messages