MiniZinc/minizinc-python

timeout parameter receives timedelta but still not working

AlvielD opened this issue · 5 comments

Hello :)
I am working on something with the library and I have followed the documentation to solve an instance using a time limit.

model = Model(f"CP/src/{model_name}.mzn")   # Load model from the file
solver = Solver.lookup(solver_name)              # Look for the configuration of gecode solver

instance = Instance(solver, model)          # Create instance of the problem
instance.add_file(data_file)                # Add the data to the instance

# Solve instance (set a timeout of 300000 miliseconds)
timeout = datetime.timedelta(milliseconds=300000)
result = instance.solve(timeout=timeout)

But still it raises the following error:
minizinc.error.MiniZincError: WARNING: the --time-out flag has recently been changed.The time-out is now provided in milliseconds instead of seconds

I am been checking carefully the source code but I cannot either check the problem of the source or of mine. I only know that the exception is raised on the Instance.solutions() method.

# Raise error if required
stderr = await read_stderr
if code != 0 or status == Status.ERROR:
    raise parse_error(stderr)

    if debug_output is not None:
        debug_output.write_bytes(stderr)

I assume might be a problem about versions? I am using python 3.9.7 and minizinc python 0.9

I'm not fully sure, but I wonder whether the issue is that you have a very old version of MiniZinc. What version of MiniZinc do you currently have? Could you try again with the newest MiniZinc bundle?

I am currently using Minizinc 2.7.0. I just tried updating to Minizinc 2.7.6 (latest) to see if there is any changes but it still gives same error. Maybe I should try downgrading the version.

I just checked again more carefully the source code and I found the following method

def flat(
    self,
    timeout: Optional[timedelta] = None,
    optimisation_level: Optional[int] = None,
    **kwargs,
):
    """Produce a FlatZinc file for the instance.

    Args:
        timeout (Optional[timedelta]): Set the time limit for the process
            of flattening the instance. TODO: An exception is raised if the
            timeout is reached.

Is it related? Could it be that the raised exception is raised in purpose? If yes, how can I get the last result reached by the solver if it raises an exception?

The fragment you shared does not use flat method. This method is something that can be explicitly called by a user to generate the FlatZinc for a particular solver and model instance, but normally the flattening and solving will happen within the same call to MiniZinc.

I'm still a bit surprised that this isn't a problem with an older version of MiniZinc. With the newer version of MiniZinc (that have the --json-stream flag), these odd types of mixups with warnings and errors shouldn't happen. Could you make sure that you are using the MiniZinc executable that you think you are. You should be able to check using minizinc.default_driver.version() and minizinc.default_driver.executable()

With no additional information I will close this issue