-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scheduling notebook #66
Conversation
galleon
commented
Oct 5, 2021
•
edited
Loading
edited
- Removing prints from code
- Using async call to MZN so that it is usable in Notebooks
- Telling right story for user
The cleaning of debug strings notably in discrete-optimisation part is interesting to include. The notebook is not ready so I can't approve this PR for now. |
About the following bullet point : |
ParametersCP, | ||
CPSolverName, | ||
map_cp_solver_name, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No! Do not reformat while making changes. This commit is unreadable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You also put unrelated changes in commit 376afe8 (asyncio stuff in cp_solvers.py and the change in rcpsp_pile.py), you must move these changes in a seperate commit.
|
||
try: | ||
result = self.instance.solve(timeout=timedelta(seconds=timeout), | ||
intermediate_solutions=intermediate_solutions) | ||
# Execute the solver in a separate thread |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change of solve() code to use a separated thread is the right trick to be able to use the CP Solver in Jupiter notebook for example. However, are we sure this doesn't interfere with the current way we are using the library (simple python script). I would prefer to have the choice between the two implementation via an attribute of the solver for example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may have a switch to call self.instance.solve
or self.instance.solve_async
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm ... There is no solve_async
. In fact, the problem is caused by Jupyter is running its own event loop. Many projects have faced the same problem and the simplest solution proposed is to call the function (here solve
on the MZN instance
in a separate thread.
I am happy to add a switch that would execute this function in the current thread or in a different thread but I am not sure who (developper or user) will trigger the switch. It seems to me that this might add at the end dead code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes the trigger would be between choosing to run self.instance.solve
or _exec_async(...)
. So @galleon do you think your _exec_async
is well named ? it seems it may be clearer if it was exec_in_other_thread
if it's what it is doing really?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm ... There is no
solve_async
.
I was referring to https://minizinc-python.readthedocs.io/en/latest/api.html#minizinc.instance.Instance.solve_async but have no idea what to do with it.
In fact, the problem is caused by Jupyter is running its own event loop. Many projects have faced the same problem and the simplest solution proposed is to call the function (here
solve
on the MZNinstance
in a separate thread.
Ok but some tests now fail. not sure whether these failures are related to these changes.
OTOH with
import nest_asyncio
nest_asyncio.apply()
at the top of the notebook, it seems to work just fine, but some people report performance problems with this solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I have seen that ... (probably same SO thread) but I choose not to implement that because of:
- the performance issue that was mentioned,
- it is not robust for other users willing to test, start developing using Jupyter / JupyterLab
Need to have a look to the failing tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok so python 3.7 brings its own problem so I propose to use the patch nest_asyncio
knowing that it is not a perfect solution as explained in this thread.
I also propose to make it explicit in the documentation and notebook so that users that want to use scikit-decide behind their own GUI or simply in Jypyter/JupyterLab know that they have to use that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, sounds more realistic to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW it may be interesting to keep your thread idea in a different branch (rebased on this branch), in case we want to investigate it in the future.
Notebook comments : -"Let's analyse the graph" cell : we could remove for now this cell if we don't have a super nice way of plotting the precedence graph
|
from concurrent.futures import ThreadPoolExecutor as _ThreadPoolExecutor | ||
|
||
|
||
def _exec_async(func, *args, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this way of calling minizinc solver is the new way to go, it would be better placed at skdecide/discrete_optimisation/generic_tools/cp_tools as a public function with a simple name. It would help the implementation of other CP based solver (other problems than RCPSP) without having to replicate this small code everywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not review run_cp.py, will this script be committed or is it an helper tool to write the notebook?
if self.reuse_plans: | ||
self.planned[next_state][key_scenario] = True | ||
self.q_values[source][action] += (cost + cost_f) * self.weight_scenario[key_scenario] | ||
return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dbarbier Might be could to add a pre-commit hook
to clean notebooks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And do we have some documentation explaining how a dev can install all those hooks to get a warning when committing locally
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are putting the charrues before the boeufs, we first have to commit fixed files in master (without introducing conflicts in PRs). If developers run pre-commit before this task is done, this may cause conflicts.
notebooks/scheduling_demo.ipynb
Outdated
"source": [ | ||
"import nest_asyncio\n", | ||
"nest_asyncio.apply()" | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please redo this commit without output cells to keep changes as small as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ParametersCP.nr_solutions
is described as "max number of solution returned". According to your new commit message, this description is wrong and should be fixed.
@galleon, i edited the notebook to address notably the third bullet point "Telling right story for user" and pushed to your branch. All can have a look to it :). We can have a last pass on it but we are close to the end I think |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but please squash all commits which modify notebooks/* into a single one to make history cleaner.
Commit history has been rewritten. The binder is provided but a new version will have to be issued as bug fixes are provided in the branch. The last solver will work only with a local install. |
Code changes have been moved to #97 |