njnmco / hopticulate

Reticulate wrapper for hyperopt
11 stars 2 forks source link

Join trials? #1

Open mosscoder opened 3 years ago

mosscoder commented 3 years ago

I'm interested in using this package to perform a parallel search and then join trials. This is demonstrated here in native python/hyperopt.

Would you have any time to demonstrate trials joining in the hopticulate wrapper? Joining an arbitrary number of trials would also be helpful.

nfultz commented 3 years ago

Because of differences between how Python and R implement iterables, this is somewhat fiddly. Here is a corresponding MWE:

> trials1 = Trials(); trials2 = Trials();
> best = fmin(objective, space, algo=tpe.suggest, max_evals=100, trials=trials1)
100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████| 100/100.0 [00:00<00:00, 245.05trial/s, best loss: 0.0025786775660636965]
> best = fmin(objective, space, algo=tpe.suggest, max_evals=100, trials=trials2)
100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████| 100/100.0 [00:00<00:00, 284.47trial/s, best loss: 0.0006141434774347515]
> itertools <- reticulate::import("itertools")
> trials_from_docs <- hopticulate:::hyperopt$trials_from_docs
> joined <- trials_from_docs(itertools$chain( trials1$`__iter__`(), trials2$`__iter__`()   ))
> length(joined$trials)
[1] 200

Notes:

If you get parallelization working, please let me know what strategy you take. I would be curious if there are any interactions between the parallel package and reticulate.

EDIT:

I think the above is ugly, so I've posted this question on SO as well - https://stackoverflow.com/questions/65312460/concatenate-two-python-objects-using-reticulate