ray/scripts/shell.py

40 lines
1.7 KiB
Python
Raw Normal View History

2016-06-27 16:33:12 -07:00
import os
2016-06-14 15:42:28 -07:00
import argparse
import numpy as np
import ray
import ray.services as services
import ray.worker as worker
2016-06-27 11:35:31 -07:00
import ray.array.remote as ra
import ray.array.distributed as da
import example_functions
2016-06-14 15:42:28 -07:00
2016-06-27 16:33:12 -07:00
DEFAULT_NUM_WORKERS = 10
DEFAULT_WORKER_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "default_worker.py")
parser = argparse.ArgumentParser(description="Parse shell options")
2016-06-14 15:42:28 -07:00
parser.add_argument("--scheduler-address", default="127.0.0.1:10001", type=str, help="the scheduler's address")
parser.add_argument("--objstore-address", default="127.0.0.1:20001", type=str, help="the objstore's address")
parser.add_argument("--worker-address", default="127.0.0.1:30001", type=str, help="the worker's address")
2016-06-27 16:33:12 -07:00
parser.add_argument("--attach", action="store_true", help="If true, attach the shell to an already running cluster. If false, start a new cluster.")
2016-06-30 13:26:06 -07:00
parser.add_argument("--worker-path", type=str, help="Path to the worker script")
parser.add_argument("--num-workers", type=int, help="Number of workers to start")
2016-06-14 15:42:28 -07:00
2016-06-24 19:43:24 -07:00
if __name__ == "__main__":
2016-06-14 15:42:28 -07:00
args = parser.parse_args()
2016-06-27 16:33:12 -07:00
if args.attach:
assert args.worker_path is None, "when attaching, no new worker can be started"
assert args.num_workers is None, "when attaching, no new worker can be started"
2016-06-30 22:57:29 -07:00
worker.connect(args.scheduler_address, args.objstore_address, args.worker_address, is_driver=True, mode=ray.SHELL_MODE)
2016-06-27 16:33:12 -07:00
else:
services.start_ray_local(num_workers=args.num_workers if not args.num_workers is None else DEFAULT_NUM_WORKERS,
2016-06-30 22:57:29 -07:00
worker_path=args.worker_path if not args.worker_path is None else DEFAULT_WORKER_PATH,
driver_mode=ray.SHELL_MODE)
2016-06-14 15:42:28 -07:00
import IPython
IPython.embed()
2016-06-27 16:33:12 -07:00
if not args.attach:
services.cleanup()