MiniZinc / libminizinc

The MiniZinc compiler
http://www.minizinc.org
Other
512 stars 80 forks source link

--solver ...msc does not override installed solver with same id #715

Closed PerMildner closed 11 months ago

PerMildner commented 1 year ago

If I pass a solver config file using minizinc --solver ....msc I would expect this to be given preference when looking up tools and libraries.

Currently the ID seems to be taken from the passed configuration file but if there is also a globally installed configuration for the same ID, the tools and library of the latter are used instead of those specified in the configuration file.

This makes it hard to use alternative versions of a solver if a solver with the same ID is already globally installed.

In my case it is a problem when developing a solver, but presumably the same problem happens if you want to try out a new version of some of the default (or manually, globally), installed solvers.

In the following transcript there is a global configuration sicstus.msc for the id org.sicstus.sicstus (mentioned in ~/.minizinc/Preferences.json), and it works as expected, e.g. if using minizinc --solver org.sicstus.sicstus ....

However, if I instead pass a path to an alternative sicstus.msc using --solver, what seems to happen is that the solver ID is taken from this alternative sicstus.msc but then the default search is used to find the associated tools, instead of using the tool paths specified in the alternative `sicstus.msc'.

The following uses a relative path to the configuration file, but the result is the same if an absolute path is used.

# Pass the path to a custom .msc configuration file
$ '/Applications/MiniZincIDE.app/Contents/Resources/minizinc' --verbose  --solver library/zinc/sicstus.msc  Suite/sprm_21295.mzn
MiniZinc to FlatZinc converter, version 2.7.6, build 905165378
Copyright (C) 2014-2023 Monash University, NICTA, Data61
Parsing file(s) Suite/sprm_21295.mzn' ...
...
# NOTE: This uses the "mznlib" from the global configuration, not from my local library/zinc/sicstus.msc
processing file '/usr/local/sicstus4.8.0/lib/sicstus-4.8.0/library/zinc/globals/fzn_lex_lesseq_int.mzn'
...
 done parsing (0.49 s)
Flattening ...
        # NOTE: This uses the "mznlib" from the global configuration, not from my local library/zinc/sicstus.msc
    CompilePass: Flatten with '/usr/local/sicstus4.8.0/lib/sicstus-4.8.0/library/zinc/globals' library ...
...
# NOTE: This uses the "executable" from the global configuration, not from my local library/zinc/sicstus.msc
Using FZN solver /usr/local/sicstus4.8.0/bin/spfz for solving, parameters: 

$ cat library/zinc/sicstus.msc
{
  "id": "org.sicstus.sicstus",
  "name": "SICStus",
  "description": "SICStus FlatZinc executable",
  "version": "4.8.0",
  "mznlib": "./globals",
  "executable": "../../Utils/x86_64-darwin-22.5.0/bin/spfz",
  "tags": [
    "cp",
    "int"
  ],
  "stdFlags": [
    "-a",
    "-f",
    "-n",
    "-p",
    "-r",
    "-s",
    "-t"
  ],
  "supportsMzn": false,
  "supportsFzn": true,
  "needsSolns2Out": true,
  "needsMznExecutable": false,
  "needsStdlibDir": false,
  "isGUIApplication": false,
  "extraFlags": [
    [
      "-search",
      "Optimization engine variant (bab, restart)",
      "string",
      "bab"
    ]
  ]
}
# The "mznlib" key in the sicstus.msc points here, and the directory exists:
$ ls library/zinc/./globals
README                      fzn_diffn_nonstrict.mzn             fzn_lex_less_int.mzn
fzn_all_different_int.mzn           fzn_diffn_nonstrict_k.mzn           fzn_lex_lesseq_bool.mzn
fzn_all_equal_int.mzn               fzn_disjunctive.mzn             fzn_lex_lesseq_int.mzn
fzn_all_equal_int_reif.mzn          fzn_disjunctive_strict.mzn          fzn_mdd.mzn
fzn_alldifferent_except_0.mzn           fzn_distribute.mzn              fzn_member_bool.mzn
fzn_among.mzn                   fzn_geost.mzn                   fzn_member_int.mzn
fzn_arg_max_bool.mzn                fzn_geost_bb.mzn                fzn_nvalue.mzn
fzn_arg_max_int.mzn             fzn_geost_nonoverlap_k.mzn          fzn_regular.mzn
fzn_arg_min_bool.mzn                fzn_geost_smallest_bb.mzn           fzn_regular_nfa.mzn
fzn_arg_min_int.mzn             fzn_global_cardinality.mzn          fzn_seq_precede_chain_int.mzn
fzn_arg_sort_int.mzn                fzn_global_cardinality_closed.mzn       fzn_sort.mzn
fzn_bin_packing.mzn             fzn_global_cardinality_low_up.mzn       fzn_strict_lex2.mzn
fzn_bin_packing_capa.mzn            fzn_global_cardinality_low_up_closed.mzn    fzn_subcircuit.mzn
fzn_bin_packing_load.mzn            fzn_if_then_else_bool.mzn           fzn_sum_pred.mzn
fzn_circuit.mzn                 fzn_if_then_else_int.mzn            fzn_symmetric_all_different.mzn
fzn_cost_mdd.mzn                fzn_if_then_else_var_bool.mzn           fzn_table_bool.mzn
fzn_cost_regular.mzn                fzn_if_then_else_var_int.mzn            fzn_table_int.mzn
fzn_cumulative.mzn              fzn_increasing_bool.mzn             fzn_value_precede_chain_int.mzn
fzn_decreasing_bool.mzn             fzn_increasing_int.mzn              fzn_value_precede_int.mzn
fzn_decreasing_int.mzn              fzn_inverse.mzn                 redefinitions.mzn
fzn_diffn.mzn                   fzn_lex2.mzn                    sicstus.mzn
fzn_diffn_k.mzn                 fzn_lex_less_bool.mzn

# The "executable" key in the sicstus.msc points here, it the file exists:
$ ls library/zinc/../../Utils/x86_64-darwin-22.5.0/bin/spfz
library/zinc/../../Utils/x86_64-darwin-22.5.0/bin/spfz

$ '/Applications/MiniZincIDE.app/Contents/Resources/minizinc' --solvers
MiniZinc driver.
Available solver configurations:
  Chuffed 0.12.1 (org.chuffed.chuffed, cp, lcg, int)
  COIN-BC 2.10.10/1.17.8 (org.minizinc.mip.coin-bc, mip, float, api, osicbc, coinbc, cbc)
  CPLEX <unknown version> (org.minizinc.mip.cplex, mip, float, api)
  findMUS 0.7.0 (org.minizinc.findmus)
  Gecode 6.3.0 (org.gecode.gecode, default solver, cp, int, float, set, restart)
  Gecode Gist 6.3.0 (org.gecode.gist, cp, int, float, set, restart)
  Globalizer 0.1.7.2 (org.minizinc.globalizer, experimental, tool)
  Gurobi <unknown version> (org.minizinc.mip.gurobi, mip, float, api)
  HiGHS 1.5.1 (org.minizinc.mip.highs, mip, float, api, highs)
  OR Tools 9.4.1874 (com.google.or-tools, ortools, cp, lcg, float, int)
  SCIP <unknown version> (org.minizinc.mip.scip, mip, float, api)
  SICStus 4.8.0 (org.sicstus.sicstus, cp, int)
  Xpress <unknown version> (org.minizinc.mip.xpress, mip, float, api)
Search path for solver configurations:
  /Users/perm/bin/or-tools_cpp_MacOsX-12.5_v9.4.1874/share/minizinc/solvers
  /usr/local/sicstus4.8.0/lib/sicstus-4.8.0/library/zinc
  /Applications/MiniZincIDE.app/Contents/Resources/share/minizinc/solvers
  /usr/local/share/minizinc/solvers
  /usr/share/minizinc/solvers

$ '/Applications/MiniZincIDE.app/Contents/Resources/minizinc' --version
MiniZinc to FlatZinc converter, version 2.7.6, build 905165378
Copyright (C) 2014-2023 Monash University, NICTA, Data61
$ uname -a
Darwin Mackaper 22.5.0 Darwin Kernel Version 22.5.0: Thu Jun  8 22:22:22 PDT 2023; root:xnu-8796.121.3~7/RELEASE_X86_64 x86_64
$ 
cyderize commented 1 year ago

This seems to happen when the given .msc file has the same id and version as another - changing either fixes the problem

PerMildner commented 1 year ago

@cyderize Yes, as mentioned in the issue, the problem is precisely that the wrong information is used when there are multiple definitions of the same solver ID.