<commit_before>"""
(description)
"""
import cloudpickle
import os
import tensorflow as tf

import ray
import ray.rllib.ppo as ppo
from ray.tune.registry import get_registry, register_env as register_rllib_env

from examples.rllib.cooperative_merge import make_create_env

HORIZON = 1000

fn_choose_subpolicy = """
def choose_policy(inputs):
    return tf.cast(inputs[:, 7] > 210, tf.int32)
"""


if __name__ == "__main__":
    config = ppo.DEFAULT_CONFIG.copy()
    horizon = HORIZON
    num_cpus = 1
    n_rollouts = 30

    ray.init(num_cpus=num_cpus, redirect_output=True)

    config["num_workers"] = num_cpus
    config["timesteps_per_batch"] = horizon * n_rollouts
    config["gamma"] = 0.999  # discount rate

    config["lambda"] = 0.97
    config["sgd_batchsize"] = min(16 * 1024, config["timesteps_per_batch"])
    config["kl_target"] = 0.02
    config["num_sgd_iter"] = 10
    config["horizon"] = horizon

    # Two-level policy parameters
    config["model"].update(
        {"fcnet_hiddens": [[32, 32]] * 2})
    config["model"]["user_data"] = {}
    # fn = list(cloudpickle.dumps(lambda x: 0))
    # fn = list(cloudpickle.dumps(choose_subpolicy))
    config["model"]["user_data"].update({"num_subpolicies": 2,
                                         "fn_choose_subpolicy": fn_choose_subpolicy})

    flow_env_name = "TwoLoopsMergePOEnv"
    exp_tag = "merge_two_level_policy_example"
    this_file = os.path.basename(__file__)[:-3]  # filename without '.py'
    config['user_data'].update({'flowenv': flow_env_name,
                                'exp_tag': exp_tag,
                                'module': this_file})
    create_env, env_name = make_create_env(flow_env_name, version=0,
                                           exp_tag=exp_tag)

    # Register as rllib env<commit_msg>safer defaults; more aggressive subpolicy split<commit_after>"""
(description)
"""
import cloudpickle
import os
import tensorflow as tf

import ray
import ray.rllib.ppo as ppo
from ray.tune.registry import get_registry, register_env as register_rllib_env

from examples.rllib.cooperative_merge import make_create_env

HORIZON = 1000

# Inner ring distances closest to the merge are range 300 to 365-ish
fn_choose_subpolicy = """
def choose_policy(inputs):
    return tf.cast(inputs[:, 7] > 300, tf.int32)
"""


if __name__ == "__main__":
    config = ppo.DEFAULT_CONFIG.copy()
    horizon = HORIZON
    num_cpus = 1
    n_rollouts = 30

    ray.init(num_cpus=num_cpus, redirect_output=True)

    config["num_workers"] = num_cpus
    config["timesteps_per_batch"] = horizon * n_rollouts
    config["gamma"] = 0.999  # discount rate

    config["lambda"] = 0.97
    config["sgd_batchsize"] = min(16 * 1024, config["timesteps_per_batch"])
    config["kl_target"] = 0.00002
    config["num_sgd_iter"] = 30
    config["horizon"] = horizon

    # Two-level policy parameters
    config["model"].update(
        {"fcnet_hiddens": [[32, 32]] * 2})
    config["model"]["user_data"] = {}
    # fn = list(cloudpickle.dumps(lambda x: 0))
    # fn = list(cloudpickle.dumps(choose_subpolicy))
    config["model"]["user_data"].update({"num_subpolicies": 2,
                                         "fn_choose_subpolicy": fn_choose_subpolicy})

    flow_env_name = "TwoLoopsMergePOEnv"
    exp_tag = "merge_two_level_policy_example"
    this_file = os.path.basename(__file__)[:-3]  # filename without '.py'
    config['user_data'].update({'flowenv': flow_env_name,
                                'exp_tag': exp_tag,
                                'module': this_file})
    create_env, env_name = make_create_env(flow_env_name, version=0,
                                           exp_tag=exp_tag)

    # Register as rllib env
{'fraction_non_alphanumeric': 0.12183969876277569, 'fraction_numerical': 0.023937600860677782, 'mean_word_length': 3.0689277899343543, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6633220', 'n_tokens_mistral': 1303, 'n_tokens_neox': 1219, 'n_words': 244}