MiniZinc/minizinc-python

message: syntax error, unexpected ';'

MaxOstrowski opened this issue · 6 comments

Hi,

I'm using the minizinc/libminizinc tests to run with my own solver to have an additional test suite for the solver.
After some initial hickups this worked very well so far, adding ~450 more unit tests for the solver.

After changing from minizinc 2.5.5 to 2.6.0 I now recognized new behaviour that was triggered due to an update of minizinc-python.
In the libminizinc/tests/requirements.txt there is a dependency to the develop branch of minizinc-python.

When I now execute the tests with my solver, I do get the following errors on some of the tests:
pytest -k globals_all_different_int_opt --driver=../../MiniZincIDE-2.6.0-bundle-linux-x86_64/bin

E   AssertionError: expected one of
E
...
E     but got
E     
E     !Error
E     message: syntax error, unexpected ';'
E     type: SyntaxError

Executing minizinc directly with my solver
minizinc --solver flatzingo spec/unit/globals/alldifferent/globals_all_different_int_opt.mzn
or with chuffed
minizinc --solver chuffed spec/unit/globals/alldifferent/globals_all_different_int_opt.mzn
doesn't show anything special and the output is the same.

Any idea what and where this ';' could come from ?
A reproduction of the error can be found in this github action here:
https://github.com/potassco/flatzingo/runs/5360589007?check_suite_focus=true

Thanks a lot in advance.

Since this test is working on the MiniZinc CI, I would think that this is a problem with your environment. However, maybe @cyderize has more insight into the problem than I do.

I agree that this is probably a problem with my environment and I would highly appreciate any pointers to hint me to a cause, as the output of the binary call minizinc with my solver seems to be indistinguishable from chuffed and gecode.

I'm not sure what could cause this. It may be useful to try to run something more similar to what minizinc-python is doing. It should be something like:

minizinc --solver flatzingo --allow-multiple-assignments --json-stream --output-mode json --output-time --output-objective --output-output-item --statistics --intermediate-solutions spec/unit/globals/alldifferent/globals_all_different_int_opt.mzn

And see if there's anything suspicious about its output (it should be line-break-delimited JSON objects as described here).

Thanks, this actually helps me a lot to understand this.
The call:

minizinc --solver flatzingo --json-stream --statistics spec/unit/globals/alldifferent/globals_all_different_int_opt.mzn

results in the following output:

{"type": "solution", "output": {"default": "alldiff_avi1 = array1d(5..9, [1, 2, 3, <>, 5, <>]);\n", "raw": "alldiff_avi1 = array1d(5..9, [1, 2, 3, <>, 5, <>]);\n"}, "sections": ["default", "raw"]}
{"type": "error", "what": "syntax error", "location": {"filename": "statistics received from solver", "firstLine": 1, "firstColumn": 10, "lastLine": 1, "lastColumn": 10}, "message": "syntax error, unexpected ';'"}
{"type": "error", "what": "syntax error", "location": {"filename": "statistics received from solver", "firstLine": 1, "firstColumn": 66, "lastLine": 1, "lastColumn": 66}, "message": "syntax error, unexpected '(', expecting end of file"}

I had some troubles understanding the error messages, but with some try an error I could identify the cause:

minizinc --solver flatzingo --statistics spec/unit/globals/alldifferent/globals_all_different_int_opt.mzn

without the --json_stream produces:

alldiff_avi1 = array1d(5..9, [1, 2, 3, <>, 5, <>]);
----------
%%%mzn-stat: models=1+
%%%mzn-stat: time=0.028
%%%mzn-stat: choices=3       
%%%mzn-stat: conflicts=0
%%%mzn-stat: rules=721      (Original: 715)
%%%mzn-stat: boolVariables=50
%%%mzn-stat: nogoods=52
%%%mzn-stat: init_total=9.4099e-05
%%%mzn-stat: init_simplify=1.8194e-05
%%%mzn-stat: init_translate=2.69e-07
%%%mzn-stat: csp_constraints=0
%%%mzn-stat: intVariables=2
%%%mzn-stat: csp_clauses=90
%%%mzn-stat: csp_literals=38
%%%mzn-stat: csp_clauses=0
%%%mzn-stat: csp_literals=0
%%%mzn-stat: csp_time_propagation=5.583e-06
%%%mzn-stat: csp_time_check=2.8e-07
%%%mzn-stat: csp_time_undo=0
%%%mzn-stat: csp_refined_reason=0
%%%mzn-stat: csp_introduced_reason=0
%%%mzn-stat: csp_literals_introduced=0
%%%mzn-stat: nSolutions=1
%%%mzn-stat-end

The following lines:

%%%mzn-stat: models=1+

and

%%%mzn-stat: rules=721      (Original: 715)

do trigger this bug.

According to the Minizinc Handbook, statistics have the form:

%%%mzn-stat: <name>=<value>

which does not impose any restrictions
Is there a restriction of what <name> and <value> can be or is this simply a bug in the json converter...

@cyderize Thanks a lot for the very useful hint that enabled me to pinpoint this.

I believe in https://www.minizinc.org/doc-2.6.0/en/fzn-spec.html#statistics-output it does mention that

The <name> describes the kind of statistics gathered, and the <value> can be any value of a MiniZinc type.

So the values are supposed to be of a valid MiniZinc type. Previously this was not really enforced, so maybe we should make that clearer in the documentation.

Thanks a lot, I actually just had to scroll down to find this restriction.
Now almost all tests are excepted by my solver. Thanks!