{"action":"created","issue":{"url":"https://api.github.com/repos/joblib/joblib/issues/498","repository_url":"https://api.github.com/repos/joblib/joblib","labels_url":"https://api.github.com/repos/joblib/joblib/issues/498/labels{/name}","comments_url":"https://api.github.com/repos/joblib/joblib/issues/498/comments","events_url":"https://api.github.com/repos/joblib/joblib/issues/498/events","html_url":"https://github.com/joblib/joblib/issues/498","id":207831612,"number":498,"title":"joblib.Parallel gives different result w.r.t calling the function directly","user":{"login":"xiaohan2012","id":789353,"avatar_url":"https://avatars.githubusercontent.com/u/789353?v=3","gravatar_id":"","url":"https://api.github.com/users/xiaohan2012","html_url":"https://github.com/xiaohan2012","followers_url":"https://api.github.com/users/xiaohan2012/followers","following_url":"https://api.github.com/users/xiaohan2012/following{/other_user}","gists_url":"https://api.github.com/users/xiaohan2012/gists{/gist_id}","starred_url":"https://api.github.com/users/xiaohan2012/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xiaohan2012/subscriptions","organizations_url":"https://api.github.com/users/xiaohan2012/orgs","repos_url":"https://api.github.com/users/xiaohan2012/repos","events_url":"https://api.github.com/users/xiaohan2012/events{/privacy}","received_events_url":"https://api.github.com/users/xiaohan2012/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-02-15T15:13:33Z","updated_at":"2017-02-15T15:17:27Z","closed_at":null,"body":"I have a function (`experiment_multiple_rounds` in the code) that I would like to repeat with different input parameters (`epsilon`  in the code). \r\n\r\nHowever, the result by calling the function directly and by calling it via Parallel gives inconsistent result. \r\n\r\nBasically, `experiment_multiple_rounds` repeats certain rounds of experiments  in which input is randomly generated  for an algorithm to solve. \r\n\r\nThe  cost of  each experiment is returned. Thus, the return result is a list of costs.\r\n\r\nThen, I compute the mean and median of the list. \r\n\r\nThe code:\r\n\r\n```\r\nrounds = 500\r\ninfp = 0.7\r\nfraction = 0.02\r\nepsilon = 0.8\r\nsampling_method = 'late_nodes'\r\n\r\n# calling it outside \r\nresult = experiment_multiple_rounds(rounds, g, infp, fraction,\r\n                                    epsilon=epsilon,\r\n                                    sampling_method=sampling_method)\r\ncnts, _ = zip(*result)\r\nprint(np.mean(cnts))  # 10.252\r\nprint(np.median(cnts)) # 8.0\r\n\r\n# calling it using parallel\r\nepsilons = [epsilon]\r\nresults = Parallel(n_jobs=-1)(\r\n    delayed(experiment_multiple_rounds)(rounds, g, infp, fraction,\r\n                                        epsilon=eps,\r\n                                        sampling_method=sampling_method)\r\n    for eps in epsilons)\r\n\r\ncnts, _ = zip(*results[0])\r\nprint(np.mean(cnts))  # 14.208\r\nprint(np.median(cnts))  # 11.0\r\n```\r\n\r\nAs you can see the result by `print`. The two ways of calling the function gives very different results. \r\n\r\nI repeatedly run the above code however their results are consistently far.\r\n\r\nThe definition of `experiment_multiple_rounds` is:\r\n\r\n```\r\ndef experiment_multiple_rounds(rounds, g, infp, fraction, epsilon, sampling_method):\r\n    results = []\r\n    for i in range(rounds):\r\n        source, obs_nodes, infection_times, tree = make_input(g, infp, fraction, sampling_method=sampling_method)\r\n        r = mwu(g, source, obs_nodes, infection_times, epsilon)\r\n        results.append(r)\r\n    return results\r\n```\r\n\r\nFor the relevant function `make_input` and `mwu`, please refer to [here](https://github.com/xiaohan2012/active-infection-source-finding/blob/master/simulations.py#L86) and [here](https://github.com/xiaohan2012/active-infection-source-finding/blob/master/multiplicative_weight_update.ipynb)\r\n\r\nI am using:\r\n\r\n- `joblib==0.10.3`\r\n- `Python 3.5.2`"},"comment":{"url":"https://api.github.com/repos/joblib/joblib/issues/comments/280038483","html_url":"https://github.com/joblib/joblib/issues/498#issuecomment-280038483","issue_url":"https://api.github.com/repos/joblib/joblib/issues/498","id":280038483,"user":{"login":"GaelVaroquaux","id":208217,"avatar_url":"https://avatars.githubusercontent.com/u/208217?v=3","gravatar_id":"","url":"https://api.github.com/users/GaelVaroquaux","html_url":"https://github.com/GaelVaroquaux","followers_url":"https://api.github.com/users/GaelVaroquaux/followers","following_url":"https://api.github.com/users/GaelVaroquaux/following{/other_user}","gists_url":"https://api.github.com/users/GaelVaroquaux/gists{/gist_id}","starred_url":"https://api.github.com/users/GaelVaroquaux/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GaelVaroquaux/subscriptions","organizations_url":"https://api.github.com/users/GaelVaroquaux/orgs","repos_url":"https://api.github.com/users/GaelVaroquaux/repos","events_url":"https://api.github.com/users/GaelVaroquaux/events{/privacy}","received_events_url":"https://api.github.com/users/GaelVaroquaux/received_events","type":"User","site_admin":false},"created_at":"2017-02-15T15:17:27Z","updated_at":"2017-02-15T15:17:27Z","body":"Could it be:\nhttps://github.com/joblib/joblib/issues/36\n\nhttp://stackoverflow.com/questions/31740561/random-number-generator-using-joblib\n"}}
{"actor":{"display_login":"GaelVaroquaux"}}