Workflow for MiniZinc Python in Jupyter Notebook

245 views
Skip to first unread message

Thomas Bulka

unread,
Nov 5, 2021, 5:10:45 AM11/5/21
to MiniZinc
Hello everyone,

I try to use MiniZinc for a small project, but while I really like the language, I'm not yet satisfied with my workflow.

I do have a huge amount of input data, which requires pre-processing and analysis. I'm used to do such things in a Jupyter notebook using Python.

My idea was to save my MiniZinc model as mzn-file, to do the data pre-processing in my Jupyter notebook, to create and solve the model instance via the minizinc package for Python and then to further process the results in the notebook.

However, this doesn't work, since the attempt to solve the model yields an error:  RuntimeError: asyncio.run() cannot be called from a running event loop.

Working with the minizinc package outside a Jupyter notebook works nicely, but this really would not be the best workflow for me. Is there a way to use the minizinc package from inside a Jupyter notebook?

Thanks in advance and kind regards,

Thomas

Jip J. Dekker

unread,
Nov 6, 2021, 1:56:15 AM11/6/21
to mini...@googlegroups.com
Hi Thomas,

This is a general problem of the Python's asynchronous design. Only one “event loop” can exists at a time. Other have also encountered the same problem. I’ve offered some solutions here: https://github.com/MiniZinc/minizinc-python/issues/38

Generally it comes down to either avoid having a second event look by using “solve_async” instead of “solve” or use one of the well known patches to allow these “multi-level event loops"

Cheers,
– Jip

--
You received this message because you are subscribed to the Google Groups "MiniZinc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to minizinc+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/minizinc/57994b47-78c4-4147-a792-a0b8eab2e0aan%40googlegroups.com.

signature.asc
Reply all
Reply to author
Forward
0 new messages