We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[tune] sync_on_checkpoint ignored when list of experiments passed to tune.run
### What is the problem?
When passing a list of predefined Experiments to tune via the `run` function, the `sync_on_checkpoint` flag is ignored.

**Reason for this behaviour:**
The `make_parser` function takes in `no_sync_on_checkpoint`; it's set to False by default.
https://github.com/ray-project/ray/blob/981f67bfb01725f1e153c881f81082fcba0ac223/python/ray/tune/config_parser.py#L75-L77

The create_trial_from_spec function gets a `sync_on_checkpoint` from the Experiment spec, but that key is never used by the parser. So the following line makes the `sync_on_checkpoint` of the returned `Trial` object `True` by default, thus ignoring the value of `sync_on_checkpoint` in the incoming Experiment spec.
https://github.com/ray-project/ray/blob/981f67bfb01725f1e153c881f81082fcba0ac223/python/ray/tune/config_parser.py#L185

*Ray Version: All versions starting from 0.7.7 when the feature was released.*

### Reproduction (REQUIRED)
```python3
import ray
from ray import tune
from ray.tune import Experiment

def func(config):
    pass

sync_true_obj = Experiment("test_sync", func, sync_on_checkpoint=True)
sync_false_obj = Experiment("test_sync", func, sync_on_checkpoint=False)

ls = [sync_true_obj, sync_false_obj]

ray.init(local_mode=True)
analysis = tune.run(ls)
```
To check the error, add the following lines just before the `return Trial(` line in `config_parser.py`
```python3
print(args)
print(args.no_sync_on_checkpoint)
```
https://github.com/ray-project/ray/blob/981f67bfb01725f1e153c881f81082fcba0ac223/python/ray/tune/config_parser.py#L173


- [x] I have verified my script runs in a clean environment and reproduces the issue.
- [x] I have verified the issue also occurs with the [latest wheels](https://docs.ray.io/en/latest/installation.html).


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `python/ray/tune/config_parser.py`
Content:
```
1 import argparse
2 import json
3 import os
4 
5 # For compatibility under py2 to consider unicode as str
6 from six import string_types
7 
8 from ray.tune import TuneError
9 from ray.tune.trial import Trial
10 from ray.tune.resources import json_to_resources
11 from ray.tune.logger import _SafeFallbackEncoder
12 
13 
14 def make_parser(parser_creator=None, **kwargs):
15     """Returns a base argument parser for the ray.tune tool.
16 
17     Args:
18         parser_creator: A constructor for the parser class.
19         kwargs: Non-positional args to be passed into the
20             parser class constructor.
21     """
22 
23     if parser_creator:
24         parser = parser_creator(**kwargs)
25     else:
26         parser = argparse.ArgumentParser(**kwargs)
27 
28     # Note: keep this in sync with rllib/train.py
29     parser.add_argument(
30         "--run",
31         default=None,
32         type=str,
33         help="The algorithm or model to train. This may refer to the name "
34         "of a built-on algorithm (e.g. RLLib's DQN or PPO), or a "
35         "user-defined trainable function or class registered in the "
36         "tune registry.")
37     parser.add_argument(
38         "--stop",
39         default="{}",
40         type=json.loads,
41         help="The stopping criteria, specified in JSON. The keys may be any "
42         "field returned by 'train()' e.g. "
43         "'{\"time_total_s\": 600, \"training_iteration\": 100000}' to stop "
44         "after 600 seconds or 100k iterations, whichever is reached first.")
45     parser.add_argument(
46         "--config",
47         default="{}",
48         type=json.loads,
49         help="Algorithm-specific configuration (e.g. env, hyperparams), "
50         "specified in JSON.")
51     parser.add_argument(
52         "--resources-per-trial",
53         default=None,
54         type=json_to_resources,
55         help="Override the machine resources to allocate per trial, e.g. "
56         "'{\"cpu\": 64, \"gpu\": 8}'. Note that GPUs will not be assigned "
57         "unless you specify them here. For RLlib, you probably want to "
58         "leave this alone and use RLlib configs to control parallelism.")
59     parser.add_argument(
60         "--num-samples",
61         default=1,
62         type=int,
63         help="Number of times to repeat each trial.")
64     parser.add_argument(
65         "--checkpoint-freq",
66         default=0,
67         type=int,
68         help="How many training iterations between checkpoints. "
69         "A value of 0 (default) disables checkpointing.")
70     parser.add_argument(
71         "--checkpoint-at-end",
72         action="store_true",
73         help="Whether to checkpoint at the end of the experiment. "
74         "Default is False.")
75     parser.add_argument(
76         "--no-sync-on-checkpoint",
77         action="store_true",
78         help="Disable sync-down of trial checkpoint, which is enabled by "
79         "default to guarantee recoverability. If set, checkpoint syncing from "
80         "worker to driver is asynchronous. Set this only if synchronous "
81         "checkpointing is too slow and trial restoration failures can be "
82         "tolerated")
83     parser.add_argument(
84         "--keep-checkpoints-num",
85         default=None,
86         type=int,
87         help="Number of best checkpoints to keep. Others get "
88         "deleted. Default (None) keeps all checkpoints.")
89     parser.add_argument(
90         "--checkpoint-score-attr",
91         default="training_iteration",
92         type=str,
93         help="Specifies by which attribute to rank the best checkpoint. "
94         "Default is increasing order. If attribute starts with min- it "
95         "will rank attribute in decreasing order. Example: "
96         "min-validation_loss")
97     parser.add_argument(
98         "--export-formats",
99         default=None,
100         help="List of formats that exported at the end of the experiment. "
101         "Default is None. For RLlib, 'checkpoint' and 'model' are "
102         "supported for TensorFlow policy graphs.")
103     parser.add_argument(
104         "--max-failures",
105         default=3,
106         type=int,
107         help="Try to recover a trial from its last checkpoint at least this "
108         "many times. Only applies if checkpointing is enabled.")
109     parser.add_argument(
110         "--scheduler",
111         default="FIFO",
112         type=str,
113         help="FIFO (default), MedianStopping, AsyncHyperBand, "
114         "HyperBand, or HyperOpt.")
115     parser.add_argument(
116         "--scheduler-config",
117         default="{}",
118         type=json.loads,
119         help="Config options to pass to the scheduler.")
120 
121     # Note: this currently only makes sense when running a single trial
122     parser.add_argument(
123         "--restore",
124         default=None,
125         type=str,
126         help="If specified, restore from this checkpoint.")
127 
128     return parser
129 
130 
131 def to_argv(config):
132     """Converts configuration to a command line argument format."""
133     argv = []
134     for k, v in config.items():
135         if "-" in k:
136             raise ValueError("Use '_' instead of '-' in `{}`".format(k))
137         if v is None:
138             continue
139         if not isinstance(v, bool) or v:  # for argparse flags
140             argv.append("--{}".format(k.replace("_", "-")))
141         if isinstance(v, string_types):
142             argv.append(v)
143         elif isinstance(v, bool):
144             pass
145         else:
146             argv.append(json.dumps(v, cls=_SafeFallbackEncoder))
147     return argv
148 
149 
150 def create_trial_from_spec(spec, output_path, parser, **trial_kwargs):
151     """Creates a Trial object from parsing the spec.
152 
153     Arguments:
154         spec (dict): A resolved experiment specification. Arguments should
155             The args here should correspond to the command line flags
156             in ray.tune.config_parser.
157         output_path (str); A specific output path within the local_dir.
158             Typically the name of the experiment.
159         parser (ArgumentParser): An argument parser object from
160             make_parser.
161         trial_kwargs: Extra keyword arguments used in instantiating the Trial.
162 
163     Returns:
164         A trial object with corresponding parameters to the specification.
165     """
166     try:
167         args, _ = parser.parse_known_args(to_argv(spec))
168     except SystemExit:
169         raise TuneError("Error parsing args, see above message", spec)
170     if "resources_per_trial" in spec:
171         trial_kwargs["resources"] = json_to_resources(
172             spec["resources_per_trial"])
173     return Trial(
174         # Submitting trial via server in py2.7 creates Unicode, which does not
175         # convert to string in a straightforward manner.
176         trainable_name=spec["run"],
177         # json.load leads to str -> unicode in py2.7
178         config=spec.get("config", {}),
179         local_dir=os.path.join(spec["local_dir"], output_path),
180         # json.load leads to str -> unicode in py2.7
181         stopping_criterion=spec.get("stop", {}),
182         remote_checkpoint_dir=spec.get("remote_checkpoint_dir"),
183         checkpoint_freq=args.checkpoint_freq,
184         checkpoint_at_end=args.checkpoint_at_end,
185         sync_on_checkpoint=not args.no_sync_on_checkpoint,
186         keep_checkpoints_num=args.keep_checkpoints_num,
187         checkpoint_score_attr=args.checkpoint_score_attr,
188         export_formats=spec.get("export_formats", []),
189         # str(None) doesn't create None
190         restore_path=spec.get("restore"),
191         trial_name_creator=spec.get("trial_name_creator"),
192         loggers=spec.get("loggers"),
193         # str(None) doesn't create None
194         sync_to_driver_fn=spec.get("sync_to_driver"),
195         max_failures=args.max_failures,
196         **trial_kwargs)
197
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/python/ray/tune/config_parser.py b/python/ray/tune/config_parser.py
--- a/python/ray/tune/config_parser.py
+++ b/python/ray/tune/config_parser.py
@@ -73,13 +73,13 @@
         help="Whether to checkpoint at the end of the experiment. "
         "Default is False.")
     parser.add_argument(
-        "--no-sync-on-checkpoint",
+        "--sync-on-checkpoint",
         action="store_true",
-        help="Disable sync-down of trial checkpoint, which is enabled by "
-        "default to guarantee recoverability. If set, checkpoint syncing from "
-        "worker to driver is asynchronous. Set this only if synchronous "
-        "checkpointing is too slow and trial restoration failures can be "
-        "tolerated")
+        help="Enable sync-down of trial checkpoint to guarantee "
+        "recoverability. If unset, checkpoint syncing from worker "
+        "to driver is asynchronous, so unset this only if synchronous "
+        "checkpointing is too slow and trial restoration failures "
+        "can be tolerated.")
     parser.add_argument(
         "--keep-checkpoints-num",
         default=None,
@@ -182,7 +182,7 @@
         remote_checkpoint_dir=spec.get("remote_checkpoint_dir"),
         checkpoint_freq=args.checkpoint_freq,
         checkpoint_at_end=args.checkpoint_at_end,
-        sync_on_checkpoint=not args.no_sync_on_checkpoint,
+        sync_on_checkpoint=args.sync_on_checkpoint,
         keep_checkpoints_num=args.keep_checkpoints_num,
         checkpoint_score_attr=args.checkpoint_score_attr,
         export_formats=spec.get("export_formats", []),

{"golden_diff": "diff --git a/python/ray/tune/config_parser.py b/python/ray/tune/config_parser.py\n--- a/python/ray/tune/config_parser.py\n+++ b/python/ray/tune/config_parser.py\n@@ -73,13 +73,13 @@\n         help=\"Whether to checkpoint at the end of the experiment. \"\n         \"Default is False.\")\n     parser.add_argument(\n-        \"--no-sync-on-checkpoint\",\n+        \"--sync-on-checkpoint\",\n         action=\"store_true\",\n-        help=\"Disable sync-down of trial checkpoint, which is enabled by \"\n-        \"default to guarantee recoverability. If set, checkpoint syncing from \"\n-        \"worker to driver is asynchronous. Set this only if synchronous \"\n-        \"checkpointing is too slow and trial restoration failures can be \"\n-        \"tolerated\")\n+        help=\"Enable sync-down of trial checkpoint to guarantee \"\n+        \"recoverability. If unset, checkpoint syncing from worker \"\n+        \"to driver is asynchronous, so unset this only if synchronous \"\n+        \"checkpointing is too slow and trial restoration failures \"\n+        \"can be tolerated.\")\n     parser.add_argument(\n         \"--keep-checkpoints-num\",\n         default=None,\n@@ -182,7 +182,7 @@\n         remote_checkpoint_dir=spec.get(\"remote_checkpoint_dir\"),\n         checkpoint_freq=args.checkpoint_freq,\n         checkpoint_at_end=args.checkpoint_at_end,\n-        sync_on_checkpoint=not args.no_sync_on_checkpoint,\n+        sync_on_checkpoint=args.sync_on_checkpoint,\n         keep_checkpoints_num=args.keep_checkpoints_num,\n         checkpoint_score_attr=args.checkpoint_score_attr,\n         export_formats=spec.get(\"export_formats\", []),\n", "issue": "[tune] sync_on_checkpoint ignored when list of experiments passed to tune.run\n### What is the problem?\r\nWhen passing a list of predefined Experiments to tune via the `run` function, the `sync_on_checkpoint` flag is ignored.\r\n\r\n**Reason for this behaviour:**\r\nThe `make_parser` function takes in `no_sync_on_checkpoint`; it's set to False by default.\r\nhttps://github.com/ray-project/ray/blob/981f67bfb01725f1e153c881f81082fcba0ac223/python/ray/tune/config_parser.py#L75-L77\r\n\r\nThe create_trial_from_spec function gets a `sync_on_checkpoint` from the Experiment spec, but that key is never used by the parser. So the following line makes the `sync_on_checkpoint` of the returned `Trial` object `True` by default, thus ignoring the value of `sync_on_checkpoint` in the incoming Experiment spec.\r\nhttps://github.com/ray-project/ray/blob/981f67bfb01725f1e153c881f81082fcba0ac223/python/ray/tune/config_parser.py#L185\r\n\r\n*Ray Version: All versions starting from 0.7.7 when the feature was released.*\r\n\r\n### Reproduction (REQUIRED)\r\n```python3\r\nimport ray\r\nfrom ray import tune\r\nfrom ray.tune import Experiment\r\n\r\ndef func(config):\r\n    pass\r\n\r\nsync_true_obj = Experiment(\"test_sync\", func, sync_on_checkpoint=True)\r\nsync_false_obj = Experiment(\"test_sync\", func, sync_on_checkpoint=False)\r\n\r\nls = [sync_true_obj, sync_false_obj]\r\n\r\nray.init(local_mode=True)\r\nanalysis = tune.run(ls)\r\n```\r\nTo check the error, add the following lines just before the `return Trial(` line in `config_parser.py`\r\n```python3\r\nprint(args)\r\nprint(args.no_sync_on_checkpoint)\r\n```\r\nhttps://github.com/ray-project/ray/blob/981f67bfb01725f1e153c881f81082fcba0ac223/python/ray/tune/config_parser.py#L173\r\n\r\n\r\n- [x] I have verified my script runs in a clean environment and reproduces the issue.\r\n- [x] I have verified the issue also occurs with the [latest wheels](https://docs.ray.io/en/latest/installation.html).\r\n\n", "before_files": [{"content": "import argparse\nimport json\nimport os\n\n# For compatibility under py2 to consider unicode as str\nfrom six import string_types\n\nfrom ray.tune import TuneError\nfrom ray.tune.trial import Trial\nfrom ray.tune.resources import json_to_resources\nfrom ray.tune.logger import _SafeFallbackEncoder\n\n\ndef make_parser(parser_creator=None, **kwargs):\n    \"\"\"Returns a base argument parser for the ray.tune tool.\n\n    Args:\n        parser_creator: A constructor for the parser class.\n        kwargs: Non-positional args to be passed into the\n            parser class constructor.\n    \"\"\"\n\n    if parser_creator:\n        parser = parser_creator(**kwargs)\n    else:\n        parser = argparse.ArgumentParser(**kwargs)\n\n    # Note: keep this in sync with rllib/train.py\n    parser.add_argument(\n        \"--run\",\n        default=None,\n        type=str,\n        help=\"The algorithm or model to train. This may refer to the name \"\n        \"of a built-on algorithm (e.g. RLLib's DQN or PPO), or a \"\n        \"user-defined trainable function or class registered in the \"\n        \"tune registry.\")\n    parser.add_argument(\n        \"--stop\",\n        default=\"{}\",\n        type=json.loads,\n        help=\"The stopping criteria, specified in JSON. The keys may be any \"\n        \"field returned by 'train()' e.g. \"\n        \"'{\\\"time_total_s\\\": 600, \\\"training_iteration\\\": 100000}' to stop \"\n        \"after 600 seconds or 100k iterations, whichever is reached first.\")\n    parser.add_argument(\n        \"--config\",\n        default=\"{}\",\n        type=json.loads,\n        help=\"Algorithm-specific configuration (e.g. env, hyperparams), \"\n        \"specified in JSON.\")\n    parser.add_argument(\n        \"--resources-per-trial\",\n        default=None,\n        type=json_to_resources,\n        help=\"Override the machine resources to allocate per trial, e.g. \"\n        \"'{\\\"cpu\\\": 64, \\\"gpu\\\": 8}'. Note that GPUs will not be assigned \"\n        \"unless you specify them here. For RLlib, you probably want to \"\n        \"leave this alone and use RLlib configs to control parallelism.\")\n    parser.add_argument(\n        \"--num-samples\",\n        default=1,\n        type=int,\n        help=\"Number of times to repeat each trial.\")\n    parser.add_argument(\n        \"--checkpoint-freq\",\n        default=0,\n        type=int,\n        help=\"How many training iterations between checkpoints. \"\n        \"A value of 0 (default) disables checkpointing.\")\n    parser.add_argument(\n        \"--checkpoint-at-end\",\n        action=\"store_true\",\n        help=\"Whether to checkpoint at the end of the experiment. \"\n        \"Default is False.\")\n    parser.add_argument(\n        \"--no-sync-on-checkpoint\",\n        action=\"store_true\",\n        help=\"Disable sync-down of trial checkpoint, which is enabled by \"\n        \"default to guarantee recoverability. If set, checkpoint syncing from \"\n        \"worker to driver is asynchronous. Set this only if synchronous \"\n        \"checkpointing is too slow and trial restoration failures can be \"\n        \"tolerated\")\n    parser.add_argument(\n        \"--keep-checkpoints-num\",\n        default=None,\n        type=int,\n        help=\"Number of best checkpoints to keep. Others get \"\n        \"deleted. Default (None) keeps all checkpoints.\")\n    parser.add_argument(\n        \"--checkpoint-score-attr\",\n        default=\"training_iteration\",\n        type=str,\n        help=\"Specifies by which attribute to rank the best checkpoint. \"\n        \"Default is increasing order. If attribute starts with min- it \"\n        \"will rank attribute in decreasing order. Example: \"\n        \"min-validation_loss\")\n    parser.add_argument(\n        \"--export-formats\",\n        default=None,\n        help=\"List of formats that exported at the end of the experiment. \"\n        \"Default is None. For RLlib, 'checkpoint' and 'model' are \"\n        \"supported for TensorFlow policy graphs.\")\n    parser.add_argument(\n        \"--max-failures\",\n        default=3,\n        type=int,\n        help=\"Try to recover a trial from its last checkpoint at least this \"\n        \"many times. Only applies if checkpointing is enabled.\")\n    parser.add_argument(\n        \"--scheduler\",\n        default=\"FIFO\",\n        type=str,\n        help=\"FIFO (default), MedianStopping, AsyncHyperBand, \"\n        \"HyperBand, or HyperOpt.\")\n    parser.add_argument(\n        \"--scheduler-config\",\n        default=\"{}\",\n        type=json.loads,\n        help=\"Config options to pass to the scheduler.\")\n\n    # Note: this currently only makes sense when running a single trial\n    parser.add_argument(\n        \"--restore\",\n        default=None,\n        type=str,\n        help=\"If specified, restore from this checkpoint.\")\n\n    return parser\n\n\ndef to_argv(config):\n    \"\"\"Converts configuration to a command line argument format.\"\"\"\n    argv = []\n    for k, v in config.items():\n        if \"-\" in k:\n            raise ValueError(\"Use '_' instead of '-' in `{}`\".format(k))\n        if v is None:\n            continue\n        if not isinstance(v, bool) or v:  # for argparse flags\n            argv.append(\"--{}\".format(k.replace(\"_\", \"-\")))\n        if isinstance(v, string_types):\n            argv.append(v)\n        elif isinstance(v, bool):\n            pass\n        else:\n            argv.append(json.dumps(v, cls=_SafeFallbackEncoder))\n    return argv\n\n\ndef create_trial_from_spec(spec, output_path, parser, **trial_kwargs):\n    \"\"\"Creates a Trial object from parsing the spec.\n\n    Arguments:\n        spec (dict): A resolved experiment specification. Arguments should\n            The args here should correspond to the command line flags\n            in ray.tune.config_parser.\n        output_path (str); A specific output path within the local_dir.\n            Typically the name of the experiment.\n        parser (ArgumentParser): An argument parser object from\n            make_parser.\n        trial_kwargs: Extra keyword arguments used in instantiating the Trial.\n\n    Returns:\n        A trial object with corresponding parameters to the specification.\n    \"\"\"\n    try:\n        args, _ = parser.parse_known_args(to_argv(spec))\n    except SystemExit:\n        raise TuneError(\"Error parsing args, see above message\", spec)\n    if \"resources_per_trial\" in spec:\n        trial_kwargs[\"resources\"] = json_to_resources(\n            spec[\"resources_per_trial\"])\n    return Trial(\n        # Submitting trial via server in py2.7 creates Unicode, which does not\n        # convert to string in a straightforward manner.\n        trainable_name=spec[\"run\"],\n        # json.load leads to str -> unicode in py2.7\n        config=spec.get(\"config\", {}),\n        local_dir=os.path.join(spec[\"local_dir\"], output_path),\n        # json.load leads to str -> unicode in py2.7\n        stopping_criterion=spec.get(\"stop\", {}),\n        remote_checkpoint_dir=spec.get(\"remote_checkpoint_dir\"),\n        checkpoint_freq=args.checkpoint_freq,\n        checkpoint_at_end=args.checkpoint_at_end,\n        sync_on_checkpoint=not args.no_sync_on_checkpoint,\n        keep_checkpoints_num=args.keep_checkpoints_num,\n        checkpoint_score_attr=args.checkpoint_score_attr,\n        export_formats=spec.get(\"export_formats\", []),\n        # str(None) doesn't create None\n        restore_path=spec.get(\"restore\"),\n        trial_name_creator=spec.get(\"trial_name_creator\"),\n        loggers=spec.get(\"loggers\"),\n        # str(None) doesn't create None\n        sync_to_driver_fn=spec.get(\"sync_to_driver\"),\n        max_failures=args.max_failures,\n        **trial_kwargs)\n", "path": "python/ray/tune/config_parser.py"}], "after_files": [{"content": "import argparse\nimport json\nimport os\n\n# For compatibility under py2 to consider unicode as str\nfrom six import string_types\n\nfrom ray.tune import TuneError\nfrom ray.tune.trial import Trial\nfrom ray.tune.resources import json_to_resources\nfrom ray.tune.logger import _SafeFallbackEncoder\n\n\ndef make_parser(parser_creator=None, **kwargs):\n    \"\"\"Returns a base argument parser for the ray.tune tool.\n\n    Args:\n        parser_creator: A constructor for the parser class.\n        kwargs: Non-positional args to be passed into the\n            parser class constructor.\n    \"\"\"\n\n    if parser_creator:\n        parser = parser_creator(**kwargs)\n    else:\n        parser = argparse.ArgumentParser(**kwargs)\n\n    # Note: keep this in sync with rllib/train.py\n    parser.add_argument(\n        \"--run\",\n        default=None,\n        type=str,\n        help=\"The algorithm or model to train. This may refer to the name \"\n        \"of a built-on algorithm (e.g. RLLib's DQN or PPO), or a \"\n        \"user-defined trainable function or class registered in the \"\n        \"tune registry.\")\n    parser.add_argument(\n        \"--stop\",\n        default=\"{}\",\n        type=json.loads,\n        help=\"The stopping criteria, specified in JSON. The keys may be any \"\n        \"field returned by 'train()' e.g. \"\n        \"'{\\\"time_total_s\\\": 600, \\\"training_iteration\\\": 100000}' to stop \"\n        \"after 600 seconds or 100k iterations, whichever is reached first.\")\n    parser.add_argument(\n        \"--config\",\n        default=\"{}\",\n        type=json.loads,\n        help=\"Algorithm-specific configuration (e.g. env, hyperparams), \"\n        \"specified in JSON.\")\n    parser.add_argument(\n        \"--resources-per-trial\",\n        default=None,\n        type=json_to_resources,\n        help=\"Override the machine resources to allocate per trial, e.g. \"\n        \"'{\\\"cpu\\\": 64, \\\"gpu\\\": 8}'. Note that GPUs will not be assigned \"\n        \"unless you specify them here. For RLlib, you probably want to \"\n        \"leave this alone and use RLlib configs to control parallelism.\")\n    parser.add_argument(\n        \"--num-samples\",\n        default=1,\n        type=int,\n        help=\"Number of times to repeat each trial.\")\n    parser.add_argument(\n        \"--checkpoint-freq\",\n        default=0,\n        type=int,\n        help=\"How many training iterations between checkpoints. \"\n        \"A value of 0 (default) disables checkpointing.\")\n    parser.add_argument(\n        \"--checkpoint-at-end\",\n        action=\"store_true\",\n        help=\"Whether to checkpoint at the end of the experiment. \"\n        \"Default is False.\")\n    parser.add_argument(\n        \"--sync-on-checkpoint\",\n        action=\"store_true\",\n        help=\"Enable sync-down of trial checkpoint to guarantee \"\n        \"recoverability. If unset, checkpoint syncing from worker \"\n        \"to driver is asynchronous, so unset this only if synchronous \"\n        \"checkpointing is too slow and trial restoration failures \"\n        \"can be tolerated.\")\n    parser.add_argument(\n        \"--keep-checkpoints-num\",\n        default=None,\n        type=int,\n        help=\"Number of best checkpoints to keep. Others get \"\n        \"deleted. Default (None) keeps all checkpoints.\")\n    parser.add_argument(\n        \"--checkpoint-score-attr\",\n        default=\"training_iteration\",\n        type=str,\n        help=\"Specifies by which attribute to rank the best checkpoint. \"\n        \"Default is increasing order. If attribute starts with min- it \"\n        \"will rank attribute in decreasing order. Example: \"\n        \"min-validation_loss\")\n    parser.add_argument(\n        \"--export-formats\",\n        default=None,\n        help=\"List of formats that exported at the end of the experiment. \"\n        \"Default is None. For RLlib, 'checkpoint' and 'model' are \"\n        \"supported for TensorFlow policy graphs.\")\n    parser.add_argument(\n        \"--max-failures\",\n        default=3,\n        type=int,\n        help=\"Try to recover a trial from its last checkpoint at least this \"\n        \"many times. Only applies if checkpointing is enabled.\")\n    parser.add_argument(\n        \"--scheduler\",\n        default=\"FIFO\",\n        type=str,\n        help=\"FIFO (default), MedianStopping, AsyncHyperBand, \"\n        \"HyperBand, or HyperOpt.\")\n    parser.add_argument(\n        \"--scheduler-config\",\n        default=\"{}\",\n        type=json.loads,\n        help=\"Config options to pass to the scheduler.\")\n\n    # Note: this currently only makes sense when running a single trial\n    parser.add_argument(\n        \"--restore\",\n        default=None,\n        type=str,\n        help=\"If specified, restore from this checkpoint.\")\n\n    return parser\n\n\ndef to_argv(config):\n    \"\"\"Converts configuration to a command line argument format.\"\"\"\n    argv = []\n    for k, v in config.items():\n        if \"-\" in k:\n            raise ValueError(\"Use '_' instead of '-' in `{}`\".format(k))\n        if v is None:\n            continue\n        if not isinstance(v, bool) or v:  # for argparse flags\n            argv.append(\"--{}\".format(k.replace(\"_\", \"-\")))\n        if isinstance(v, string_types):\n            argv.append(v)\n        elif isinstance(v, bool):\n            pass\n        else:\n            argv.append(json.dumps(v, cls=_SafeFallbackEncoder))\n    return argv\n\n\ndef create_trial_from_spec(spec, output_path, parser, **trial_kwargs):\n    \"\"\"Creates a Trial object from parsing the spec.\n\n    Arguments:\n        spec (dict): A resolved experiment specification. Arguments should\n            The args here should correspond to the command line flags\n            in ray.tune.config_parser.\n        output_path (str); A specific output path within the local_dir.\n            Typically the name of the experiment.\n        parser (ArgumentParser): An argument parser object from\n            make_parser.\n        trial_kwargs: Extra keyword arguments used in instantiating the Trial.\n\n    Returns:\n        A trial object with corresponding parameters to the specification.\n    \"\"\"\n    try:\n        args, _ = parser.parse_known_args(to_argv(spec))\n    except SystemExit:\n        raise TuneError(\"Error parsing args, see above message\", spec)\n    if \"resources_per_trial\" in spec:\n        trial_kwargs[\"resources\"] = json_to_resources(\n            spec[\"resources_per_trial\"])\n    return Trial(\n        # Submitting trial via server in py2.7 creates Unicode, which does not\n        # convert to string in a straightforward manner.\n        trainable_name=spec[\"run\"],\n        # json.load leads to str -> unicode in py2.7\n        config=spec.get(\"config\", {}),\n        local_dir=os.path.join(spec[\"local_dir\"], output_path),\n        # json.load leads to str -> unicode in py2.7\n        stopping_criterion=spec.get(\"stop\", {}),\n        remote_checkpoint_dir=spec.get(\"remote_checkpoint_dir\"),\n        checkpoint_freq=args.checkpoint_freq,\n        checkpoint_at_end=args.checkpoint_at_end,\n        sync_on_checkpoint=args.sync_on_checkpoint,\n        keep_checkpoints_num=args.keep_checkpoints_num,\n        checkpoint_score_attr=args.checkpoint_score_attr,\n        export_formats=spec.get(\"export_formats\", []),\n        # str(None) doesn't create None\n        restore_path=spec.get(\"restore\"),\n        trial_name_creator=spec.get(\"trial_name_creator\"),\n        loggers=spec.get(\"loggers\"),\n        # str(None) doesn't create None\n        sync_to_driver_fn=spec.get(\"sync_to_driver\"),\n        max_failures=args.max_failures,\n        **trial_kwargs)\n", "path": "python/ray/tune/config_parser.py"}]}