Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_int_dataframe():
ray.init()
pandas_df = pd.DataFrame({'col1': [0, 1, 2, 3],
'col2': [4, 5, 6, 7],
'col3': [8, 9, 10, 11],
'col4': [12, 13, 14, 15]})
ray_df = rdf.from_pandas(pandas_df, 2)
testfuncs = [lambda x: x + 1,
lambda x: str(x),
lambda x: x * x,
lambda x: x,
lambda x: False]
test_roundtrip(ray_df, pandas_df)
test_index(ray_df, pandas_df)
def test_on_ring(self):
trainable_class = ExperimentRunner
variant_spec = get_variant_spec(sac_params)
experiment_kwargs = generate_experiment_kwargs(variant_spec)
try:
ray.init(num_cpus=N_CPUS, num_gpus=N_GPUS)
except Exception:
pass # already initialized
tune.run(
trainable_class,
**experiment_kwargs,
reuse_actors=True)
num_cpus = args.num_cpus
# upload dir
upload_dir = args.upload_dir
# Import the benchmark and fetch its flow_params
benchmark = __import__(
"flow.benchmarks.%s" % benchmark_name, fromlist=["flow_params"])
flow_params = benchmark.flow_params
# get the env name and a creator for the environment
create_env, env_name = make_create_env(params=flow_params, version=0)
alg_run = "ARS"
# initialize a ray instance
ray.init(redirect_output=True)
agent_cls = get_agent_class(alg_run)
config = agent_cls._default_config.copy()
config["num_workers"] = min(num_cpus, num_rollouts)
config["num_rollouts"] = num_rollouts
config["rollouts_used"] = num_rollouts
# config["sgd_stepsize"] = grid_search([.01, .02])
# config["noise_stdev"] = grid_search([.01, .02])
# optimal hyperparameters:
config["sgd_stepsize"] = 0.2
config["noise_stdev"] = 0.2
config['eval_prob'] = 0.05
config['clip_actions'] = False # FIXME(ev) temporary ray bug
config['observation_filter'] = "NoFilter"
# save the flow params for replay
return gym.make(args.env)
if not args.config:
# Load configuration from file
config_dir = os.path.dirname(args.checkpoint)
# params.json is saved in the model directory during ray training by default
config_path = os.path.join(config_dir, "params.json")
with open(config_path) as f:
args.config = json.load(f)
if not args.env:
if not args.config.get("env"):
parser.error("the following arguments are required: --env")
args.env = args.config.get("env")
ray.init()
register_env(args.env, create_environment)
if ray.__version__ >= "0.6.5":
from ray.rllib.agents.registry import get_agent_class
else:
from ray.rllib.agents.agent import get_agent_class
cls = get_agent_class(args.algorithm)
config = args.config
config["monitor"] = False
config["num_workers"] = 1
config["num_gpus"] = 0
agent = cls(env=args.env, config=config)
agent.restore(args.checkpoint)
num_episodes = int(args.evaluate_episodes)
from ship_gym.config import GameConfig, EnvConfig
from ship_gym.ship_env import ShipEnv
import multiprocessing
if __name__ == "__main__":
game_config = GameConfig
game_config.FPS = 100000
game_config.SPEED = 40
game_config.DEBUG = True
game_config.BOUNDS = (1000, 1000)
# Change this to 0 if you don't have any CUDA enabled GPUs
ray.init(num_gpus=1)
def env_creator(_):
env_config = EnvConfig
return ShipEnv(game_config, env_config)
experiments = {
"shipgym_best": {
"run": "PPO",
"stop": {
"time_total_s": 12 * 60 * 60 # 12 hours
},
"env": "ship-gym-v1",
"config": {
"num_gpus": 1,
"num_workers" : multiprocessing.cpu_count() - 1,
from models import register_carla_model
from scenarios import TOWN2_STRAIGHT
env_config = ENV_CONFIG.copy()
env_config.update({
"verbose": False,
"x_res": 80,
"y_res": 80,
"use_depth_camera": False,
"discrete_actions": False,
"server_map": "/Game/Maps/Town02",
"scenarios": TOWN2_STRAIGHT,
})
register_carla_model()
ray.init()
run_experiments({
"carla": {
"run": "PPO",
"env": CarlaEnv,
"config": {
"env_config": env_config,
"model": {
"custom_model": "carla",
"custom_options": {
"image_shape": [
env_config["x_res"], env_config["y_res"], 6
],
},
"conv_filters": [
[16, [8, 8], 4],
[32, [4, 4], 2],
# parameters specifying the positioning of vehicles upon initialization/
# reset (see flow.core.params.InitialConfig)
initial=InitialConfig(
spacing="uniform",
min_gap=5,
lanes_distribution=float("inf"),
edges_distribution=["2", "3", "4", "5"],
),
# traffic lights to be introduced to specific nodes (see
# flow.core.traffic_lights.TrafficLights)
tls=traffic_lights,
)
if __name__ == '__main__':
ray.init(num_cpus=N_CPUS+1, redirect_output=True)
config = ppo.DEFAULT_CONFIG.copy()
config["num_workers"] = N_CPUS # number of parallel rollouts
config["train_batch_size"] = HORIZON * N_ROLLOUTS
config["gamma"] = 0.999 # discount rate
config["model"].update({"fcnet_hiddens": [300, 300, 300]})
config["lambda"] = 0.99
config["sgd_minibatch_size"] = 64
config["kl_target"] = 0.02
config["num_sgd_iter"] = 10
config["horizon"] = HORIZON
# save the flow params for replay
flow_json = json.dumps(
flow_params, cls=FlowParamsEncoder, sort_keys=True, indent=4)
config['env_config']['flow_params'] = flow_json
def run_driver():
ray.init(redis_address=args.ip)
# start workers training asynchronously
workers = [Worker.remote(i, args.num_workers) for i in
range(args.num_workers)]
workers[0].train.remote(100)
print(ray.get(workers[0].get_params.remote()))
def start_worker(w):
w.train.remote(args.iters)
print("First part done")
threads = []
for worker in workers:
threads.append(threading.Thread(target=start_worker, args=(worker,)))
threads[-1].start()
def main():
print("Tip: set TESTS_TO_RUN='pattern' to run a subset of benchmarks")
ray.init()
value = ray.put(0)
arr = np.zeros(100 * 1024 * 1024, dtype=np.int64)
def get_small():
ray.get(value)
timeit("single client get calls", get_small)
def put_small():
ray.put(0)
timeit("single client put calls", put_small)
def put_large():
ray.put(arr)
def run_driver():
ray.init(redis_address=args.ip)
worker = Worker.remote()
ps = ParameterServer.remote()
log = util.FileLogger('out')
log(f"Worker ip {ray.get(worker.ip.remote())}")
log(f"Driver ip {socket.gethostbyname(socket.gethostname())}")
time_list = []
for i in range(args.iters):
start_time = time.perf_counter()
grads = worker.compute_gradients.remote()
result = ps.assign_add.remote(grads)
result = ray.get(result)[0]
elapsed_time_ms = (time.perf_counter() - start_time)*1000
time_list.append(elapsed_time_ms)
rate = args.size_mb / (elapsed_time_ms/1000)