SCIP Solver UnicodeDecodeError

Hello together,

When using the SCIP solver in gampsy with output to sys.stdout (or any other output), there exists an error with the output parsing of SCIP that makes it unusable:

--- Executing SCIP (Solvelink=2): elapsed 0:00:00.003

SCIP             47.6.0 c2de9d6d Sep 12, 2024          DAC arm 64bit/macOS    
SCIP version 9.1 (8cab0278ba)
Copyright (c) 2002-2024 Zuse Institute Berlin (ZIB)

Traceback (most recent call last):
  File ".../main.py", line 47, in <module>
    ce = minlp.verify(torch_model, params)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../minlp.py", line 152, in verify
    solve(model, "local", Options(minlp="scip"), silent=False)
  File ".../minlp.py", line 40, in solve
    model.solve(output=sys.stdout, options=options)  
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/miniconda/base/envs/repair-env/lib/python3.12/site-packages/gamspy/_model.py", line 1143, in solve
    summary = runner.run()
              ^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/miniconda/base/envs/repair-env/lib/python3.12/site-packages/gamspy/_backend/local.py", line 91, in run
    self.execute_gams(gams_string)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/repair-env/lib/python3.12/site-packages/gamspy/_backend/local.py", line 111, in execute_gams
    self.container._send_job(self.job_name, self.pf_file, self.output)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/repair-env/lib/python3.12/site-packages/gamspy/_container.py", line 361, in _send_job
    data = self._process.stdout.readline()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen codecs>", line 322, in decode
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 37: invalid continuation byte

Deactivating the output, SCIP runs without problems.

GAMSPy version

GAMSPy version: 1.0.1
GAMS version: 47.6.0
gamspy_base version: 47.6.0

Hi Jannick. Can you also share an example script to reproduce the issue?

Yeah sure, here is the minimal example that leads to the error for me:

import sys
import gamspy as gp

m = gp.Container()

x = gp.Variable(m, name="x", type="free")
y = gp.Variable(m, name="y", type="binary")

eq1 = gp.Equation(m, name="eq1", type="regular")
eq1[...] = -3 * x + 2 * y >= 1
eq2 = x + y

model = gp.Model(
    m,
    name="simple_milp",
    equations=m.getEquations(),  
    objective=eq2,       
    sense="MIN",                  
    problem="MIP" 
)

model.solve(output=sys.stdout, solver="scip")

I have to add that I am using macOS 15.0.

I really appreciate your help, thank you!

I cannot reproduce it. We suspect that it is related to your machine’s language setting which causes a non utf-8 output from the solver. Can you run your script with the log_file option and attach the log.log here? Here is the updated script:

import gamspy as gp

m = gp.Container(working_directory=".", options=gp.Options(log_file="log.log"))

x = gp.Variable(m, name="x", type="free")
y = gp.Variable(m, name="y", type="binary")

eq1 = gp.Equation(m, name="eq1", type="regular")
eq1[...] = -3 * x + 2 * y >= 1
eq2 = x + y

model = gp.Model(
    m,
    name="simple_milp",
    equations=m.getEquations(),  
    objective=eq2,       
    sense="MIN",                  
    problem="MIP" 
)

model.solve(solver="scip")

This is the logfile produced:

--- _04548a53-70b5-4638-b4a1-51ad7a7772fc.gms(7) 2 Mb
--- Job _04548a53-70b5-4638-b4a1-51ad7a7772fc.gms Start 10/01/24 10:32:49 47.6.0 c2de9d6d DAX-DAC arm 64bit/macOS
--- Applying:
    /opt/homebrew/Caskroom/miniconda/base/envs/repair-env/lib/python3.12/site-packages/gamspy_base/gmsprmun.txt
--- GAMS Parameters defined
    MIP scip
    Input /Users/jannickstrobel/Library/CloudStorage/OneDrive-Personal/Studies/PhD/phd/1_projects/paper_ma/paper_ma/_04548a53-70b5-4638-b4a1-51ad7a7772fc.gms
    Output /Users/jannickstrobel/Library/CloudStorage/OneDrive-Personal/Studies/PhD/phd/1_projects/paper_ma/paper_ma/_04548a53-70b5-4638-b4a1-51ad7a7772fc.lst
    ScrDir /Users/jannickstrobel/Library/CloudStorage/OneDrive-Personal/Studies/PhD/phd/1_projects/paper_ma/paper_ma/tmp_khiz5q3/
    SysDir /opt/homebrew/Caskroom/miniconda/base/envs/repair-env/lib/python3.12/site-packages/gamspy_base/
    LogOption 2
    LogFile /Users/jannickstrobel/Library/CloudStorage/OneDrive-Personal/Studies/PhD/phd/1_projects/paper_ma/paper_ma/log.log
    Trace /Users/jannickstrobel/Library/CloudStorage/OneDrive-Personal/Studies/PhD/phd/1_projects/paper_ma/paper_ma/_04548a53-70b5-4638-b4a1-51ad7a7772fc.txt
    License "/Users/jannickstrobel/Library/Application Support/GAMSPy/gamspy_license.txt"
    OptDir /Users/jannickstrobel/Library/CloudStorage/OneDrive-Personal/Studies/PhD/phd/1_projects/paper_ma/paper_ma/
    LimRow 0
    LimCol 0
    TraceOpt 3
    GDX /Users/jannickstrobel/Library/CloudStorage/OneDrive-Personal/Studies/PhD/phd/1_projects/paper_ma/paper_ma/_04548a53-70b5-4638-b4a1-51ad7a7772fcout.gdx
    SolPrint 0
    PreviousWork 1
    gdxSymbols newOrChanged
Licensee: Jannick Strobel                                G240923+0003Ac-GEN
          jannick.strobel@uni-konstanz.de                         GPA100673
          /Users/jannickstrobel/Library/CloudStorage/OneDrive-Personal/Studies/PhD/phd/1_projects/paper_ma/paper_ma/tmp_khiz5q3/gamslice.dat
          node:46213601 mem:36 cores:12 ipport:51258                       
          Time-limited free academic license
          The evaluation period of the license will expire on Sep 18, 2025
Processor information: 1 socket(s), 12 core(s), and 12 thread(s) available
--- Starting compilation
--- _04548a53-70b5-4638-b4a1-51ad7a7772fc.gms(67) 2 Mb
--- Starting execution: elapsed 0:00:00.001
--- Generating MIP model simple_milp
--- _04548a53-70b5-4638-b4a1-51ad7a7772fc.gms(35) 3 Mb
---   2 rows  3 columns  5 non-zeroes
---   1 discrete-columns
--- Range statistics (absolute non-zero finite values)
--- RHS       [min, max] : [ 1.000E+00, 1.000E+00] - Zero values observed as well
--- Bound     [min, max] : [ 1.000E+00, 1.000E+00] - Zero values observed as well
--- Matrix    [min, max] : [ 1.000E+00, 3.000E+00]
--- Executing SCIP (Solvelink=2): elapsed 0:00:00.007

SCIP             47.6.0 c2de9d6d Sep 12, 2024          DAC arm 64bit/macOS    
SCIP version 9.1 (8cab0278ba)
Copyright (c) 2002-2024 Zuse Institute Berlin (ZIB)

External libraries: 
  CPLEX 22.1.1.0�     Linear Programming Solver developed by IBM (www.cplex.com)
  CppAD 20180000.0     Algorithmic Differentiation of C++ algorithms developed by B. Bell (github.com/coin-or/CppAD)
  PaPILO 2.3.0         parallel presolve for integer and linear optimization (github.com/scipopt/papilo) (built with TBB) [GitHash: 4b8ce6ed]
  Nauty 2.8.8          Computing Graph Automorphism Groups by Brendan D. McKay (users.cecs.anu.edu.au/~bdm/nauty)
  sassy 1.1            Symmetry preprocessor by Markus Anders (github.com/markusa4/sassy)
  Ipopt 3.14.16        Interior Point Optimizer developed by A. Waechter et.al. (github.com/coin-or/Ipopt)
non-default parameter settings:
limits/time = 10000000000
limits/gap = 0.0001
misc/printreason = FALSE
presolving/milp/threads = 0
nlpi/ipopt/linear_solver = "ma27"
nlpi/ipopt/linear_system_scaling = "mc19"

original problem has 2 variables (1 bin, 0 int, 1 cont) and 1 constraints

all 1 solutions given by solution candidate storage are infeasible

feasible solution found by trivial heuristic after 0.0 seconds, objective value -1.000000e+05
presolving:
problem infeasible or unbounded: variable <t_x> with objective 1 can be made infinitely small
presolving (1 rounds: 1 fast, 0 medium, 0 exhaustive):
 0 deleted vars, 0 deleted constraints, 0 added constraints, 0 tightened bounds, 0 added holes, 0 changed sides, 0 changed coefficients
 0 implications, 0 cliques
transformed 2/2 original solutions to the transformed problem space
presolving detected unboundedness
Presolving Time: 0.00

SCIP Status        : problem is solved [unbounded]
Solving Time (sec) : 0.02
Solving Nodes      : 0
Primal Bound       : -1.00000000000000e+20 (2 solutions)
Dual Bound         : -1.00000000000000e+20
Gap                : 0.00 %


--- Reading solution for model simple_milp
***
*** Solver did not provide marginals for model simple_milp
***
--- Executing after solve: elapsed 0:00:00.258
--- _04548a53-70b5-4638-b4a1-51ad7a7772fc.gms(97) 3 Mb
--- GDX File /Users/jannickstrobel/Library/CloudStorage/OneDrive-Personal/Studies/PhD/phd/1_projects/paper_ma/paper_ma/_04548a53-70b5-4638-b4a1-51ad7a7772fcout.gdx
*** Status: Normal completion
--- Job _04548a53-70b5-4638-b4a1-51ad7a7772fc.gms Stop 10/01/24 10:32:49 elapsed 0:00:00.259

Can you share it as a file? Copy-paste to the forum might change the encoding.

log.log (5.2 KB)

Thank you Jannick. I was able to reproduce the issue. This issue will be fixed with the new release.

This problem is fixed with GAMSPy 1.0.2. You can upgrade GAMSPy and try again. Please let us know if the problem persists.