Exemple #1
0
 def __init__(self):
     """Constructs a generator given experiment specifications.
     """
     self._parser = make_parser()
     self._trial_generator = []
     self._counter = 0
     self._finished = False
Exemple #2
0
 def __init__(
     self,
     uuid_prefix: str,
     num_samples: int,
     unresolved_spec: dict,
     constant_grid_search: bool = False,
     output_path: str = "",
     points_to_evaluate: Optional[List] = None,
     lazy_eval: bool = False,
     start: int = 0,
     random_state: Optional[Union[int, "np_random_generator",
                                  np.random.RandomState]] = None,
 ):
     self.parser = make_parser()
     self.num_samples = num_samples
     self.uuid_prefix = uuid_prefix
     self.num_samples_left = num_samples
     self.unresolved_spec = unresolved_spec
     self.constant_grid_search = constant_grid_search
     self.output_path = output_path
     self.points_to_evaluate = points_to_evaluate or []
     self.num_points_to_evaluate = len(self.points_to_evaluate)
     self.counter = start
     self.lazy_eval = lazy_eval
     self.variants = None
     self.random_state = random_state
Exemple #3
0
    def __init__(self, search_space, reward_attr):
        """Initialize AutoMLSearcher.

        Arguments:
            search_space: The space to search.
            reward_attr: The attribute name of the reward in the result.
        """
        # Pass experiment later to allow construction without this parameter
        super(AutoMLSearcher, self).__init__()

        self.search_space = search_space
        self.reward_attr = reward_attr

        self.experiment_list = []
        self.best_trial = None
        self._is_finished = False
        self._parser = make_parser()
        self._unfinished_count = 0
        self._running_trials = {}
        self._completed_trials = {}
        self._next_trials = []
        self._next_trial_iter = None

        self._iteration = 0
        self._total_trial_num = 0
        self._start_ts = 0
Exemple #4
0
 def __init__(self):
     """Constructs a generator given experiment specifications.
     """
     self._parser = make_parser()
     self._trial_generator = []
     self._counter = 0
     self._finished = False
Exemple #5
0
def create_parser(parser_creator=None):
    parser = make_parser(
        parser_creator=parser_creator,
        formatter_class=argparse.RawDescriptionHelpFormatter,
        description="Train a Starcraft II reinforcement learning agent.",
        epilog="")

    # See also the base parser definition in ray/tune/config_parser.py
    parser.add_argument(
        "--redis-address",
        default=None,
        type=str,
        help="Connect to an existing Ray cluster at this address instead "
        "of starting a new one.",
        required=True)
    parser.add_argument("--ray-num-cpus",
                        default=None,
                        type=int,
                        help="--num-cpus to use if starting a new cluster.")
    parser.add_argument(
        "--temp-dir",
        default=None,
        type=str,
        help="Manually specify the root temporary dir of the Ray process")

    return parser
Exemple #6
0
def create_parser(parser_creator=None):
    parser = make_parser(parser_creator=parser_creator,
                         formatter_class=argparse.RawDescriptionHelpFormatter,
                         description="Train a reinforcement learning agent.",
                         epilog=EXAMPLE_USAGE)

    # See also the base parser definition in ray/tune/config_parser.py
    parser.add_argument(
        "--redis-address",
        default=None,
        type=str,
        help="Connect to an existing Ray cluster at this address instead "
        "of starting a new one.")
    parser.add_argument("--ray-num-cpus",
                        default=None,
                        type=int,
                        help="--num-cpus to use if starting a new cluster.")
    parser.add_argument("--ray-num-gpus",
                        default=None,
                        type=int,
                        help="--num-gpus to use if starting a new cluster.")
    parser.add_argument("--ray-num-local-schedulers",
                        default=None,
                        type=int,
                        help="Emulate multiple cluster nodes for debugging.")
    parser.add_argument(
        "--ray-redis-max-memory",
        default=None,
        type=int,
        help="--redis-max-memory to use if starting a new cluster.")
    parser.add_argument(
        "--ray-object-store-memory",
        default=None,
        type=int,
        help="--object-store-memory to use if starting a new cluster.")
    parser.add_argument(
        "--experiment-name",
        default="default",
        type=str,
        help="Name of the subdirectory under `local_dir` to put results in.")
    parser.add_argument("--env",
                        default=None,
                        type=str,
                        help="The gym environment to use.")
    parser.add_argument(
        "--queue-trials",
        action='store_true',
        help=(
            "Whether to queue trials when the cluster does not currently have "
            "enough resources to launch one. This should be set to True when "
            "running on an autoscaling cluster to enable automatic scale-up."))
    parser.add_argument(
        "-f",
        "--config-file",
        default=None,
        type=str,
        help="If specified, use config options from this file. Note that this "
        "overrides any trial-specific options set via flags above.")
    return parser
 def __init__(self, use_early_stopped_trials=True):
     """Constructs a generator given experiment specifications.
     """
     self._parser = make_parser()
     self._trial_generator = []
     self._counter = 0
     self._finished = False
     self._use_early_stopped = use_early_stopped_trials
Exemple #8
0
    def __init__(self):
        """Constructs a generator given experiment specifications.

        Arguments:
            experiments (Experiment | list | dict): Experiments to run.
        """
        self._parser = make_parser()
        self._trial_generator = []
        self._finished = False
Exemple #9
0
    def __init__(self, shuffle=False):
        """Initializes the Variant Generator.

        """
        self._parser = make_parser()
        self._trial_generator = []
        self._counter = 0
        self._finished = False
        self._shuffle = shuffle
Exemple #10
0
 def __init__(self, searcher: Searcher):
     assert issubclass(type(searcher),
                       Searcher), "Searcher should be subclassing Searcher."
     self.searcher = searcher
     self._parser = make_parser()
     self._experiment = None
     self._counter = 0  # Keeps track of number of trials created.
     self._total_samples = 0  # int: total samples to evaluate.
     self._finished = False
Exemple #11
0
    def __init__(self, max_concurrent=10, shuffle=False):
        """Initializes the Variant Generator."""
        self._parser = make_parser()
        self._trial_generator = []
        self._counter = 0
        self._max_concurrent = max_concurrent
        self._finished = False
        self._shuffle = shuffle

        self._live_trials = set()
Exemple #12
0
 def __init__(self, metric=None, mode="max", use_early_stopped_trials=True):
     """Constructs a generator given experiment specifications."""
     self._parser = make_parser()
     self._trial_generator = []
     self._counter = 0
     self._finished = False
     self._metric = metric
     assert mode in ["min", "max"]
     self._mode = mode
     self._use_early_stopped = use_early_stopped_trials
Exemple #13
0
    def __init__(self, shuffle=False):
        """Initializes the Variant Generator.

        Arguments:
            shuffle (bool): Shuffles the generated list of configurations.
        """
        self._parser = make_parser()
        self._trial_generator = []
        self._counter = 0
        self._finished = False
        self._shuffle = shuffle
Exemple #14
0
def generate_trials(unresolved_spec, output_path=''):
    """Wraps `generate_variants()` to return a Trial object for each variant.

    See also: generate_variants()

    Arguments:
        unresolved_spec (dict): Experiment spec conforming to the argument
            schema defined in `ray.tune.config_parser`.
        output_path (str): Path where to store experiment outputs.
    """

    if "run" not in unresolved_spec:
        raise TuneError("Must specify `run` in {}".format(unresolved_spec))

    def to_argv(config):
        argv = []
        for k, v in config.items():
            argv.append("--{}".format(k.replace("_", "-")))
            if isinstance(v, str):
                argv.append(v)
            else:
                argv.append(json.dumps(v))
        return argv

    parser = make_parser()
    i = 0
    for _ in range(unresolved_spec.get("repeat", 1)):
        for resolved_vars, spec in generate_variants(unresolved_spec):
            try:
                # Special case the `env` param for RLlib by automatically
                # moving it into the `config` section.
                if "env" in spec:
                    spec["config"] = spec.get("config", {})
                    spec["config"]["env"] = spec["env"]
                    del spec["env"]
                args = parser.parse_args(to_argv(spec))
            except SystemExit:
                raise TuneError("Error parsing args, see above message", spec)
            if resolved_vars:
                experiment_tag = "{}_{}".format(i, resolved_vars)
            else:
                experiment_tag = str(i)
            i += 1
            yield Trial(
                trainable_name=spec["run"],
                config=spec.get("config", {}),
                local_dir=os.path.join(args.local_dir, output_path),
                experiment_tag=experiment_tag,
                resources=json_to_resources(spec.get("resources", {})),
                stopping_criterion=spec.get("stop", {}),
                checkpoint_freq=args.checkpoint_freq,
                restore_path=spec.get("restore"),
                upload_dir=args.upload_dir,
                max_failures=args.max_failures)
Exemple #15
0
    def __init__(self, shuffle=False):
        """Initializes the Variant Generator.

        Arguments:
            shuffle (bool): Shuffles the generated list of configurations.
        """
        self._parser = make_parser()
        self._trial_generator = []
        self._counter = 0
        self._finished = False
        self._shuffle = shuffle
Exemple #16
0
    def __init__(self, experiments=None):
        """Constructs a generator given experiment specifications.

        Arguments:
            experiments (Experiment | list | dict): Experiments to run.
        """
        experiment_list = convert_to_experiment_list(experiments)
        self._parser = make_parser()
        self._trial_generator = chain.from_iterable([
            self._generate_trials(experiment.spec, experiment.name)
            for experiment in experiment_list
        ])
        self._finished = False
def create_parser(parser_creator=None):
    """ Creates argument parser."""
    parser = make_parser(parser_creator=parser_creator,
                         formatter_class=argparse.RawDescriptionHelpFormatter,
                         description="Train a reinforcement learning agent.",
                         epilog=EXAMPLE_USAGE)

    # See also the base parser definition in ray/tune/config_parser.py
    parser.add_argument(
        "-f",
        "--config-file",
        default=None,
        type=str,
        help="If specified, use config options from this file. Note that this "
        "overrides any trial-specific options set via flags above.")
    return parser
Exemple #18
0
    def __init__(self, shuffle=False):
        """Initializes the Variant Generator.

        """
        self._parser = make_parser()
        self._trial_generator = []
        self._counter = 0
        self._finished = False
        self._shuffle = shuffle

        # Unique prefix for all trials generated, e.g., trial ids start as
        # 2f1e_00001, 2f1ef_00002, 2f1ef_0003, etc. Overridable for testing.
        force_test_uuid = os.environ.get("_TEST_TUNE_TRIAL_UUID")
        if force_test_uuid:
            self._uuid_prefix = force_test_uuid + "_"
        else:
            self._uuid_prefix = str(uuid.uuid1().hex)[:5] + "_"
Exemple #19
0
 def __init__(self,
              uuid_prefix: str,
              num_samples: int,
              unresolved_spec: dict,
              output_path: str = "",
              points_to_evaluate: Optional[List] = None,
              lazy_eval: bool = False,
              start: int = 0):
     self.parser = make_parser()
     self.num_samples = num_samples
     self.uuid_prefix = uuid_prefix
     self.num_samples_left = num_samples
     self.unresolved_spec = unresolved_spec
     self.output_path = output_path
     self.points_to_evaluate = points_to_evaluate or []
     self.num_points_to_evaluate = len(self.points_to_evaluate)
     self.counter = start
     self.lazy_eval = lazy_eval
     self.variants = None
def create_parser(parser_creator=None):
    parser = make_parser(
        parser_creator=parser_creator,
        formatter_class=argparse.RawDescriptionHelpFormatter,
        description="Train a reinforcement learning agent.",
        epilog=EXAMPLE_USAGE)

    # See also the base parser definition in ray/tune/config_parser.py
    parser.add_argument(
        "--redis-address",
        default=None,
        type=str,
        help="The Redis address of the cluster.")
    parser.add_argument(
        "--ray-num-cpus",
        default=None,
        type=int,
        help="--num-cpus to pass to Ray."
        " This only has an affect in local mode.")
    parser.add_argument(
        "--ray-num-gpus",
        default=None,
        type=int,
        help="--num-gpus to pass to Ray."
        " This only has an affect in local mode.")
    parser.add_argument(
        "--queue-trials",
        default=False,
        type=bool,
        help=(
            "Whether to queue trials when the cluster does not currently have "
            "enough resources to launch one. This should be set to True when "
            "running on an autoscaling cluster to enable automatic scale-up."))
    parser.add_argument(
        "-f",
        "--config-file",
        default=None,
        type=str,
        help="If specified, use config options from this file. Note that this "
        "overrides any trial-specific options set via flags above.")
    return parser
Exemple #21
0
    def add_experiment(self, experiment, trial_runner):
        """Tracks one experiment.

        Will error if one tries to track multiple experiments.
        """
        assert self._experiment is None, "HyperOpt only tracks one experiment!"
        self._experiment = experiment

        self._output_path = experiment.name
        spec = copy.deepcopy(experiment.spec)

        # Set Scheduler field, as Tune Parser will default to FIFO
        assert spec.get("scheduler") in [None, "HyperOpt"], "Incorrectly " \
            "specified scheduler!"
        spec["scheduler"] = "HyperOpt"

        if "env" in spec:
            spec["config"] = spec.get("config", {})
            spec["config"]["env"] = spec["env"]
            del spec["env"]

        space = spec["config"]["space"]
        del spec["config"]["space"]

        self.parser = make_parser()
        self.args = self.parser.parse_args(to_argv(spec))
        self.args.scheduler = "HyperOpt"
        self.default_config = copy.deepcopy(spec["config"])

        self.algo = hpo.tpe.suggest
        self.domain = hpo.Domain(lambda spc: spc, space)
        self._hpopt_trials = hpo.Trials()
        self._tune_to_hp = {}
        self._num_trials_left = self.args.repeat

        if type(self._max_concurrent) is int:
            self._max_concurrent = min(self._max_concurrent, self.args.repeat)

        self.rstate = np.random.RandomState()
        self.trial_generator = self._trial_generator()
        self._add_new_trials_if_needed(trial_runner)
Exemple #22
0
    def __init__(self, points_to_evaluate: Optional[List[Dict]] = None):
        """Initializes the Variant Generator.

        """
        self._parser = make_parser()
        self._trial_generator = []
        self._trial_iter = None
        self._counter = 0
        self._finished = False

        self._points_to_evaluate = points_to_evaluate or []

        # Unique prefix for all trials generated, e.g., trial ids start as
        # 2f1e_00001, 2f1ef_00002, 2f1ef_0003, etc. Overridable for testing.
        force_test_uuid = os.environ.get("_TEST_TUNE_TRIAL_UUID")
        if force_test_uuid:
            self._uuid_prefix = force_test_uuid + "_"
        else:
            self._uuid_prefix = str(uuid.uuid1().hex)[:5] + "_"

        self._total_samples = 0
Exemple #23
0
def create_parser(parser_creator=None):
    parser = make_parser(parser_creator=parser_creator,
                         formatter_class=argparse.RawDescriptionHelpFormatter,
                         description="Train a reinforcement learning agent.",
                         epilog=EXAMPLE_USAGE)

    # See also the base parser definition in ray/tune/config_parser.py
    parser.add_argument(
        "--ray-address",
        default=None,
        type=str,
        help="Connect to an existing Ray cluster at this address instead "
        "of starting a new one.")
    parser.add_argument("--ray-num-cpus",
                        default=None,
                        type=int,
                        help="--num-cpus to use if starting a new cluster.")
    parser.add_argument("--ray-num-gpus",
                        default=None,
                        type=int,
                        help="--num-gpus to use if starting a new cluster.")
    parser.add_argument("--ray-num-nodes",
                        default=None,
                        type=int,
                        help="Emulate multiple cluster nodes for debugging.")
    parser.add_argument(
        "--ray-redis-max-memory",
        default=None,
        type=int,
        help="--redis-max-memory to use if starting a new cluster.")
    parser.add_argument("--ray-memory",
                        default=None,
                        type=int,
                        help="--memory to use if starting a new cluster.")
    parser.add_argument(
        "--ray-object-store-memory",
        default=None,
        type=int,
        help="--object-store-memory to use if starting a new cluster.")
    parser.add_argument(
        "--experiment-name",
        default="default",
        type=str,
        help="Name of the subdirectory under `local_dir` to put results in.")
    parser.add_argument(
        "--local-dir",
        default=DEFAULT_RESULTS_DIR,
        type=str,
        help="Local dir to save training results to. Defaults to '{}'.".format(
            DEFAULT_RESULTS_DIR))
    parser.add_argument(
        "--upload-dir",
        default="",
        type=str,
        help="Optional URI to sync training results to (e.g. s3://bucket).")
    parser.add_argument("-v",
                        action="store_true",
                        help="Whether to use INFO level logging.")
    parser.add_argument("-vv",
                        action="store_true",
                        help="Whether to use DEBUG level logging.")
    parser.add_argument(
        "--resume",
        action="store_true",
        help="Whether to attempt to resume previous Tune experiments.")
    parser.add_argument(
        "--torch",
        action="store_true",
        help="Whether to use PyTorch (instead of tf) as the DL framework.")
    parser.add_argument(
        "--eager",
        action="store_true",
        help="Whether to attempt to enable TF eager execution.")
    parser.add_argument(
        "--trace",
        action="store_true",
        help="Whether to attempt to enable tracing for eager mode.")
    parser.add_argument("--env",
                        default=None,
                        type=str,
                        help="The gym environment to use.")
    parser.add_argument(
        "--queue-trials",
        action="store_true",
        help=(
            "Whether to queue trials when the cluster does not currently have "
            "enough resources to launch one. This should be set to True when "
            "running on an autoscaling cluster to enable automatic scale-up."))
    parser.add_argument(
        "-f",
        "--config-file",
        default=None,
        type=str,
        help="If specified, use config options from this file. Note that this "
        "overrides any trial-specific options set via flags above.")

    # NOTE: customs
    parser.add_argument("--no-tensorboard", default=False, action='store_true')

    return parser
Exemple #24
0
"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import sys
import yaml

import ray
from ray.tune.config_parser import make_parser, parse_to_trials
from ray.tune.trial_scheduler import MedianStoppingRule
from ray.tune.trial_runner import TrialRunner
from ray.tune.trial import Trial

parser = make_parser("Train a reinforcement learning agent.")

# Extends the base parser defined in ray/tune/config_parser, to add some
# RLlib specific arguments. For more arguments, see the configuration
# defined there.
parser.add_argument("--redis-address",
                    default=None,
                    type=str,
                    help="The Redis address of the cluster.")
parser.add_argument("--num-cpus",
                    default=None,
                    type=int,
                    help="Number of CPUs to allocate to Ray.")
parser.add_argument("--num-gpus",
                    default=None,
                    type=int,
Exemple #25
0
def create_parser(parser_creator=None):
    parser = make_parser(
        parser_creator=parser_creator,
        formatter_class=argparse.RawDescriptionHelpFormatter,
        description="Train a reinforcement learning agent.",
        epilog=EXAMPLE_USAGE)

    # See also the base parser definition in ray/tune/config_parser.py
    parser.add_argument(
        "--ray-address",
        default=None,
        type=str,
        help="Connect to an existing Ray cluster at this address instead "
             "of starting a new one.")
    parser.add_argument(
        "--ray-num-cpus",
        default=None,
        type=int,
        help="--num-cpus to use if starting a new cluster.")
    parser.add_argument(
        "--ray-num-gpus",
        default=None,
        type=int,
        help="--num-gpus to use if starting a new cluster.")
    parser.add_argument(
        "--ray-num-nodes",
        default=None,
        type=int,
        help="Emulate multiple cluster nodes for debugging.")
    parser.add_argument(
        "--ray-redis-max-memory",
        default=None,
        type=int,
        help="--redis-max-memory to use if starting a new cluster.")
    parser.add_argument(
        "--ray-memory",
        default=None,
        type=int,
        help="--memory to use if starting a new cluster.")
    parser.add_argument(
        "--ray-object-store-memory",
        default=None,
        type=int,
        help="--object-store-memory to use if starting a new cluster.")
    parser.add_argument(
        "--experiment-name",
        default="default",
        type=str,
        help="Name of the subdirectory under `local_dir` to put results in.")
    parser.add_argument(
        "--local-dir",
        default=DEFAULT_RESULTS_DIR,
        type=str,
        help="Local dir to save training results to. Defaults to '{}'.".format(
            DEFAULT_RESULTS_DIR))
    parser.add_argument(
        "--upload-dir",
        default="",
        type=str,
        help="Optional URI to sync training results to (e.g. s3://bucket).")
    parser.add_argument(
        "-v", action="store_true", help="Whether to use INFO level logging.")
    parser.add_argument(
        "-vv", action="store_true", help="Whether to use DEBUG level logging.")
    parser.add_argument(
        "--resume",
        action="store_true",
        help="Whether to attempt to resume previous Tune experiments.")
    parser.add_argument(
        "--torch",
        action="store_true",
        help="Whether to use PyTorch (instead of tf) as the DL framework.")
    parser.add_argument(
        "--eager",
        action="store_true",
        help="Whether to attempt to enable TF eager execution.")
    parser.add_argument(
        "--trace",
        action="store_true",
        help="Whether to attempt to enable tracing for eager mode.")
    parser.add_argument(
        "--log-flatland-stats",
        action="store_true",
        default=True,
        help="Whether to log additional flatland specfic metrics such as percentage complete or normalized score.")
    parser.add_argument(
        "-e",
        "--eval",
        action="store_true",
        help="Whether to run evaluation. Default evaluation config is default.yaml "
        "to use custom evaluation config set (eval_generator:test_eval) under configs")
    parser.add_argument(
        "-i",
        "--custom-fn",
        action="store_true",
        help="Whether the experiment uses a custom function for training"
        "Default custom function is imitation_ppo_train_fn")
    parser.add_argument(
        "-r",
        "--record",
        action="store_true",
        help="Whether the experiment requires video recording during evaluation"
        "Default evaluation config is default_render.yaml "
        "Can also be done via custom evaluation config set (eval_generator:test_render) under configs")
    parser.add_argument(
        "-s",
        "--save-checkpoint",
        action="store_true",
        help="Whether the experiment will save the checkpoints to weights and biases")
    parser.add_argument(
        "--bind-all",
        action="store_true",
        default=False,
        help="Whether to expose on network (binding on all network interfaces).")
    parser.add_argument(
        "--env", default=None, type=str, help="The gym environment to use.")
    parser.add_argument(
        "--queue-trials",
        action="store_true",
        help=(
            "Whether to queue trials when the cluster does not currently have "
            "enough resources to launch one. This should be set to True when "
            "running on an autoscaling cluster to enable automatic scale-up."))
    parser.add_argument(
        "-f",
        "--config-file",
        default=None,
        type=str,
        help="If specified, use config options from this file. Note that this "
             "overrides any trial-specific options set via flags above.")
    return parser
Exemple #26
0
from ray.tune.tune import _make_scheduler, run_experiments


EXAMPLE_USAGE = """
Training example:
    ./train.py --run DQN --env CartPole-v0

Grid search example:
    ./train.py -f tuned_examples/cartpole-grid-search-example.yaml

Note that -f overrides all other trial-specific command-line options.
"""


parser = make_parser(
    formatter_class=argparse.RawDescriptionHelpFormatter,
    description="Train a reinforcement learning agent.",
    epilog=EXAMPLE_USAGE)

# See also the base parser definition in ray/tune/config_parser.py
parser.add_argument(
    "--redis-address", default=None, type=str,
    help="The Redis address of the cluster.")
parser.add_argument(
    "--num-cpus", default=None, type=int,
    help="Number of CPUs to allocate to Ray.")
parser.add_argument(
    "--num-gpus", default=None, type=int,
    help="Number of GPUs to allocate to Ray.")
parser.add_argument(
    "--experiment-name", default="default", type=str,
    help="Name of the subdirectory under `local_dir` to put results in.")
Exemple #27
0
def create_parser(parser_creator=None):
    parser = make_parser(
        parser_creator=parser_creator,
        formatter_class=argparse.RawDescriptionHelpFormatter,
        description="Train a reinforcement learning agent.",
        epilog=EXAMPLE_USAGE,
    )

    # See also the base parser definition in ray/tune/config_parser.py
    parser.add_argument(
        "--ray-address",
        default=None,
        type=str,
        help="Connect to an existing Ray cluster at this address instead "
        "of starting a new one.",
    )
    parser.add_argument("--ray-ui",
                        action="store_true",
                        help="Whether to enable the Ray web UI.")
    # Deprecated: Use --ray-ui, instead.
    parser.add_argument(
        "--no-ray-ui",
        action="store_true",
        help="Deprecated! Ray UI is disabled by default now. "
        "Use `--ray-ui` to enable.",
    )
    parser.add_argument(
        "--local-mode",
        action="store_true",
        help="Run ray in local mode for easier debugging.",
    )
    parser.add_argument(
        "--ray-num-cpus",
        default=None,
        type=int,
        help="--num-cpus to use if starting a new cluster.",
    )
    parser.add_argument(
        "--ray-num-gpus",
        default=None,
        type=int,
        help="--num-gpus to use if starting a new cluster.",
    )
    parser.add_argument(
        "--ray-num-nodes",
        default=None,
        type=int,
        help="Emulate multiple cluster nodes for debugging.",
    )
    parser.add_argument(
        "--ray-object-store-memory",
        default=None,
        type=int,
        help="--object-store-memory to use if starting a new cluster.",
    )
    parser.add_argument(
        "--experiment-name",
        default="default",
        type=str,
        help="Name of the subdirectory under `local_dir` to put results in.",
    )
    parser.add_argument(
        "--local-dir",
        default=DEFAULT_RESULTS_DIR,
        type=str,
        help="Local dir to save training results to. Defaults to '{}'.".format(
            DEFAULT_RESULTS_DIR),
    )
    parser.add_argument(
        "--upload-dir",
        default="",
        type=str,
        help="Optional URI to sync training results to (e.g. s3://bucket).",
    )
    # This will override any framework setting found in a yaml file.
    parser.add_argument(
        "--framework",
        choices=["tf", "tf2", "tfe", "torch"],
        default=None,
        help="The DL framework specifier.",
    )
    parser.add_argument("-v",
                        action="store_true",
                        help="Whether to use INFO level logging.")
    parser.add_argument("-vv",
                        action="store_true",
                        help="Whether to use DEBUG level logging.")
    parser.add_argument(
        "--resume",
        action="store_true",
        help="Whether to attempt to resume previous Tune experiments.",
    )
    parser.add_argument(
        "--trace",
        action="store_true",
        help="Whether to attempt to enable tracing for eager mode.",
    )
    parser.add_argument("--env",
                        default=None,
                        type=str,
                        help="The gym environment to use.")
    parser.add_argument(
        "-f",
        "--config-file",
        default=None,
        type=str,
        help="If specified, use config options from this file. Note that this "
        "overrides any trial-specific options set via flags above.",
    )

    # Obsolete: Use --framework=torch|tf2|tfe instead!
    parser.add_argument(
        "--torch",
        action="store_true",
        help="Whether to use PyTorch (instead of tf) as the DL framework.",
    )
    parser.add_argument(
        "--eager",
        action="store_true",
        help="Whether to attempt to enable TF eager execution.",
    )

    return parser
Exemple #28
0
    def create_parser(self, parser_creator=None):
        parser = make_parser(
            parser_creator=parser_creator,
            formatter_class=argparse.RawDescriptionHelpFormatter,
            description="Evaluate a trained RL agent.",
            epilog=self.EXAMPLE_USAGE)

        parser.add_argument(
            "--random-agent",
            default=False,
            type=bool,
            help="Evaluate and test an agent with random policy")

        parser.add_argument(
            "--evaluation-file",
            default=None,
            type=str,
            help="Path to the object file of the trained model." 
            "The file should be in the following format: checkpoint_<NUM>/checkpoint-<NUM>")
        
        parser.add_argument(
            "--agent-path",
            default=None,
            type=str,
            help="Path to the agent folder")

        parser.add_argument(
            "--checkpoint-num",
            default=None,
            type=int,
            help="Number of the checkpoint")

        parser.add_argument(
            "--agent-config-file",
            default=None,
            type=str,
            help="Path to the json configuration file of the trained model." 
            "The file should be in the following format: __.json")

        parser.add_argument(
            "--observation-space-type",
            default=["end_points", "end_points_velocities"],
            type=list,
            help="Set the observation space type to be one of those: [end_points, rest_length, current_length, end_points_velocities] or any option from them together in a form of a list")

        parser.add_argument(
            "--controller-type",
            default="rest_length_mod",
            type=str,
            help="Set the controller type to be one of those: [rest_length, current_length, rest_length_mod, current_length_mod]")
        
        parser.add_argument(
            "--num-episodes",
            default="10",
            type=int,
            help="Set the number of the episodes for the evaluation and running the model on")

        parser.add_argument(
            "-f",
            "--config-file",
            default=None,
            type=str,
            help="If specified, use config options from this file. Note that this "
            "overrides any trial-specific options set via flags above.")

        return parser
Exemple #29
0
def create_parser(parser_creator=None):
    parser = make_parser(parser_creator=parser_creator,
                         formatter_class=argparse.RawDescriptionHelpFormatter,
                         description="Train a reinforcement learning agent.",
                         epilog=EXAMPLE_USAGE)

    # See also the base parser definition in ray/tune/config_parser.py
    parser.add_argument(
        "--ray-address",
        default=None,
        type=str,
        help="Connect to an existing Ray cluster at this address instead "
        "of starting a new one.")
    parser.add_argument("--no-ray-ui",
                        action="store_true",
                        help="Whether to disable the Ray web ui.")
    parser.add_argument("--local-mode",
                        action="store_true",
                        help="Whether to run ray with `local_mode=True`. "
                        "Only if --ray-num-nodes is not used.")
    parser.add_argument("--ray-num-cpus",
                        default=None,
                        type=int,
                        help="--num-cpus to use if starting a new cluster.")
    parser.add_argument("--ray-num-gpus",
                        default=None,
                        type=int,
                        help="--num-gpus to use if starting a new cluster.")
    parser.add_argument("--ray-num-nodes",
                        default=None,
                        type=int,
                        help="Emulate multiple cluster nodes for debugging.")
    parser.add_argument(
        "--ray-redis-max-memory",
        default=None,
        type=int,
        help="--redis-max-memory to use if starting a new cluster.")
    parser.add_argument("--ray-memory",
                        default=None,
                        type=int,
                        help="--memory to use if starting a new cluster.")
    parser.add_argument(
        "--ray-object-store-memory",
        default=None,
        type=int,
        help="--object-store-memory to use if starting a new cluster.")
    parser.add_argument(
        "--experiment-name",
        default="default",
        type=str,
        help="Name of the subdirectory under `local_dir` to put results in.")
    parser.add_argument(
        "--local-dir",
        default=DEFAULT_RESULTS_DIR,
        type=str,
        help="Local dir to save training results to. Defaults to '{}'.".format(
            DEFAULT_RESULTS_DIR))
    parser.add_argument(
        "--upload-dir",
        default="",
        type=str,
        help="Optional URI to sync training results to (e.g. s3://bucket).")
    parser.add_argument("-v",
                        action="store_true",
                        help="Whether to use INFO level logging.")
    parser.add_argument("-vv",
                        action="store_true",
                        help="Whether to use DEBUG level logging.")
    parser.add_argument(
        "--resume",
        action="store_true",
        help="Whether to attempt to resume previous Tune experiments.")
    parser.add_argument(
        "--torch",
        action="store_true",
        help="Whether to use PyTorch (instead of tf) as the DL framework.")
    parser.add_argument(
        "--eager",
        action="store_true",
        help="Whether to attempt to enable TF eager execution.")
    parser.add_argument(
        "--trace",
        action="store_true",
        help="Whether to attempt to enable tracing for eager mode.")
    parser.add_argument(
        "--queue-trials",
        action="store_true",
        help=(
            "Whether to queue trials when the cluster does not currently have "
            "enough resources to launch one. This should be set to True when "
            "running on an autoscaling cluster to enable automatic scale-up."))
    parser.add_argument(
        "-f",
        "--config-file",
        default=None,
        type=str,
        help="If specified, use config options from this file. Note that this "
        "overrides any trial-specific options set via flags above.")
    # Modified:
    parser.add_argument('--algo',
                        default=None,
                        help='use --experiment flag instead')
    parser.add_argument(
        '--experiment',
        default=None,
        type=str,
        help='name of the experiment yaml file in the config folder')
    parser.add_argument('--discrete',
                        action='store_true',
                        help='Use discrete action space with kmeans')
    parser.add_argument('--num-actions',
                        default=32,
                        help='Number of discrete actions used for kmeans')
    parser.add_argument("--env",
                        default='MineRLNavigateDenseVectorObf-v0',
                        type=str,
                        help="The gym environment to use.")
    parser.add_argument('--data-dir',
                        type=Path,
                        default=os.getenv('MINERL_DATA_ROOT', 'data'),
                        help='Path to MineRL data directory')
    parser.add_argument('--mode',
                        choices=['online', 'offline', 'mixed'],
                        default='online')
    parser.add_argument(
        '--mixing-ratio',
        default=0.5,
        help='How much to sample from data over the environment')
    parser.add_argument('--debug', action='store_true')
    return parser
Exemple #30
0
def create_parser(parser_creator=None):
    parser = make_parser(
        parser_creator=parser_creator,
        formatter_class=argparse.RawDescriptionHelpFormatter,
        description="Train a reinforcement learning agent.",
        epilog=EXAMPLE_USAGE)

    # See also the base parser definition in ray/tune/config_parser.py
    parser.add_argument(
        "--redis-address",
        default=None,
        type=str,
        help="Connect to an existing Ray cluster at this address instead "
        "of starting a new one.")
    parser.add_argument(
        "--ray-num-cpus",
        default=None,
        type=int,
        help="--num-cpus to use if starting a new cluster.")
    parser.add_argument(
        "--ray-num-gpus",
        default=None,
        type=int,
        help="--num-gpus to use if starting a new cluster.")
    parser.add_argument(
        "--ray-num-nodes",
        default=None,
        type=int,
        help="Emulate multiple cluster nodes for debugging.")
    parser.add_argument(
        "--ray-redis-max-memory",
        default=None,
        type=int,
        help="--redis-max-memory to use if starting a new cluster.")
    parser.add_argument(
        "--ray-object-store-memory",
        default=None,
        type=int,
        help="--object-store-memory to use if starting a new cluster.")
    parser.add_argument(
        "--experiment-name",
        default="default",
        type=str,
        help="Name of the subdirectory under `local_dir` to put results in.")
    parser.add_argument(
        "--resume",
        action="store_true",
        help="Whether to attempt to resume previous Tune experiments.")
    parser.add_argument(
        "--env", default=None, type=str, help="The gym environment to use.")
    parser.add_argument(
        "--queue-trials",
        action='store_true',
        help=(
            "Whether to queue trials when the cluster does not currently have "
            "enough resources to launch one. This should be set to True when "
            "running on an autoscaling cluster to enable automatic scale-up."))
    parser.add_argument(
        "-f",
        "--config-file",
        default=None,
        type=str,
        help="If specified, use config options from this file. Note that this "
        "overrides any trial-specific options set via flags above.")
    return parser
Exemple #31
0
 def __init__(self):
     self._parser = make_parser()
     self._trial_generator = []
     self._counter = 0
     self._finished = False
Exemple #32
0
from ray.tune.config_parser import make_parser, resources_to_json
from ray.tune.tune import _make_scheduler, run_experiments

EXAMPLE_USAGE = """
Training example:
    ./train.py --run DQN --env CartPole-v0

Grid search example:
    ./train.py -f tuned_examples/cartpole-grid-search-example.yaml

Note that -f overrides all other trial-specific command-line options.
"""

parser = make_parser(formatter_class=argparse.RawDescriptionHelpFormatter,
                     description="Train a reinforcement learning agent.",
                     epilog=EXAMPLE_USAGE)

# See also the base parser definition in ray/tune/config_parser.py
parser.add_argument("--redis-address",
                    default=None,
                    type=str,
                    help="The Redis address of the cluster.")
parser.add_argument("--num-cpus",
                    default=None,
                    type=int,
                    help="Number of CPUs to allocate to Ray.")
parser.add_argument("--num-gpus",
                    default=None,
                    type=int,
                    help="Number of GPUs to allocate to Ray.")