Changed ray.select() to ray.wait() and its functionality (#426)

* Re-implemented select, changed name to wait

* Changed tests for select to tests for wait

* Updated the hyperopt example to match wait

* Small fixes and improve example readme.

* Make tests pass.
This commit is contained in:
Wapaul1
2016-09-14 17:14:11 -07:00
committed by Philipp Moritz
parent 8c6d3a88a9
commit d5815673a5
12 changed files with 132 additions and 69 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ if hasattr(ctypes, "windll"):
import config
import serialization
from worker import scheduler_info, register_class, visualize_computation_graph, task_info, init, connect, disconnect, get, put, select, remote, kill_workers, restart_workers_local
from worker import scheduler_info, register_class, visualize_computation_graph, task_info, init, connect, disconnect, get, put, wait, remote, kill_workers, restart_workers_local
from worker import Reusable, reusables
from libraylib import SCRIPT_MODE, WORKER_MODE, PYTHON_MODE, SILENT_MODE
from libraylib import ObjectID
+28 -20
View File
@@ -838,35 +838,43 @@ def put(value, worker=global_worker):
worker.put_object(objectid, value)
return objectid
def select(objectids, num_objects=0, worker=global_worker):
"""Return a list of the indices of the objects that are ready.
def wait(objectids, num_returns=1, timeout=None, worker=global_worker):
"""Return a list of IDs that are ready and a list of IDs that are not ready.
If num_objects is 0, the function immediately returns the indices of all
objects that are ready. If it is set, the function waits until that number of
objects is ready and returns that exact number of objectids.
If timeout is set, the function returns either when the requested number of
IDs are ready or when the timeout is reached, whichever occurs first. If it is
not set, the function simply waits until that number of objects is ready and
returns that exact number of objectids.
This method returns two lists. The first list consists of object IDs that
correspond to objects that are stored in the object store. The second list
corresponds to the rest of the object IDs (which may or may not be ready).
Args:
objectids (List[ray.ObjectID]): List of objectids for objects that may or
may not be ready.
num_objects (int): The number of indices that should be returned.
objectids (List[raylib.ObjectID]): List of object IDs for objects that may
or may not be ready.
num_returns (int): The number of object IDs that should be returned.
timeout (float): The maximum amount of time in seconds that should be spent
polling the scheduler.
Returns:
List of indices in the original list of objects that are ready.
A list of object IDs that are ready and a list of the remaining object IDs.
"""
check_connected(worker)
if num_objects > len(objectids):
raise Exception("num_objects cannot be greater than len(objectids), num_objects is {}, and len(objectids) is {}.".format(num_objects, len(objectids)))
ready_ids = raylib.ray_select(worker.handle, objectids)
if num_returns < 0:
raise Exception("num_returns cannot be less than 0.")
if num_returns > len(objectids):
raise Exception("num_returns cannot be greater than the length of the input list: num_objects is {}, and the length is {}.".format(num_returns, len(objectids)))
start_time = time.time()
ready_indices = raylib.wait(worker.handle, objectids)
# Polls scheduler until enough objects are ready.
while len(ready_ids) < num_objects:
ready_ids = raylib.ray_select(worker.handle, objectids)
while len(ready_indices) < num_returns and (time.time() - start_time < timeout or timeout is None):
ready_indices = raylib.wait(worker.handle, objectids)
time.sleep(0.1)
if num_objects != 0:
# Return indices for exactly the requested number of objects.
return ready_ids[:num_objects]
else:
# Return indices for all objects that are ready.
return ready_ids
# Return indices for exactly the requested number of objects.
ready_ids = [objectids[i] for i in ready_indices[:num_returns]]
not_ready_ids = [objectids[i] for i in range(len(objectids)) if i not in ready_indices[:num_returns]]
return ready_ids, not_ready_ids
def kill_workers(worker=global_worker):
"""Kill all of the workers in the cluster. This does not kill drivers.