9
9
10
10
11
11
@click .group ()
12
- @click .option ('--gpu' , required = False , type = int )
13
- @click .option ('--seed' , type = int , default = None )
12
+ @click .option ('--gpu' , required = False , type = int , help = 'How many gpus you allow Rainy to use' )
13
+ @click .option ('--seed' , type = int , default = None , help = 'Random seed set before training' )
14
+ @click .option ('--override' , type = str , default = '' , help = 'Override string(See README for detail)' )
14
15
@click .pass_context
15
- def rainy_cli (ctx : dict , gpu : Tuple [int ], seed : Optional [int ]) -> None :
16
+ def rainy_cli (ctx : dict , gpu : Tuple [int ], seed : Optional [int ], override : str ) -> None :
16
17
ctx .obj ['gpu' ] = gpu
17
18
ctx .obj ['config' ].seed = seed
19
+ if len (override ) > 0 :
20
+ import builtins
21
+ try :
22
+ exec (override , builtins .__dict__ , {'config' : ctx .obj ['config' ]})
23
+ except Exception as e :
24
+ print ('!!! Your override string \' {}\' contains an error !!!' .format (override ))
25
+ raise e
18
26
19
27
20
- @rainy_cli .command ()
28
+ @rainy_cli .command (help = 'Train agents' )
21
29
@click .pass_context
22
- @click .option ('--comment' , type = str , default = None )
23
- @click .option ('--prefix' , type = str , default = '' )
30
+ @click .option ('--comment' , type = str , default = None , help = 'Comment wrote to fingerprint.txt' )
31
+ @click .option ('--prefix' , type = str , default = '' , help = 'Prefix of the log directory' )
24
32
def train (ctx : dict , comment : Optional [str ], prefix : str ) -> None :
25
33
c = ctx .obj ['config' ]
26
34
scr = ctx .obj ['script_path' ]
@@ -33,11 +41,12 @@ def train(ctx: dict, comment: Optional[str], prefix: str) -> None:
33
41
print ("random play: {}, trained: {}" .format (ag .random_episode (), ag .eval_episode ()))
34
42
35
43
36
- @rainy_cli .command ()
37
- @click .option ('--save' , is_flag = True )
38
- @click .option ('--render' , is_flag = True )
39
- @click .option ('--replay' , is_flag = True )
40
- @click .option ('--action-file' , type = str , default = 'random-actions.json' )
44
+ @rainy_cli .command (help = 'Run the random agent and show its result' )
45
+ @click .option ('--save' , is_flag = True , help = 'Save actions' )
46
+ @click .option ('--render' , is_flag = True , help = 'Render the agent' )
47
+ @click .option ('--replay' , is_flag = True , help = 'Show replay(works with special environments)' )
48
+ @click .option ('--action-file' , type = str ,
49
+ default = 'best-actions.json' , help = 'Name of the action file' )
41
50
@click .pass_context
42
51
def random (ctx : dict , save : bool , render : bool , replay : bool , action_file : str ) -> None :
43
52
c = ctx .obj ['config' ]
@@ -46,11 +55,12 @@ def random(ctx: dict, save: bool, render: bool, replay: bool, action_file: str)
46
55
run .random_agent (ag , render = render , replay = replay , action_file = action_file )
47
56
48
57
49
- @rainy_cli .command ()
58
+ @rainy_cli .command (help = 'Load a save file and restart training' )
50
59
@click .pass_context
51
60
@click .argument ('logdir' )
52
- @click .option ('--model' , type = str , default = run .SAVE_FILE_DEFAULT )
53
- @click .option ('--additional-steps' , type = int , default = 100 )
61
+ @click .option ('--model' , type = str , default = run .SAVE_FILE_DEFAULT , help = 'Name of the save file' )
62
+ @click .option ('--additional-steps' , type = int ,
63
+ default = 100 , help = 'The number of additional training steps' )
54
64
def retrain (ctx : dict , logdir : str , model : str , additional_steps : int ) -> None :
55
65
c = ctx .obj ['config' ]
56
66
log = c .logger .retrive (logdir )
@@ -60,12 +70,13 @@ def retrain(ctx: dict, logdir: str, model: str, additional_steps: int) -> None:
60
70
print ("random play: {}, trained: {}" .format (ag .random_episode (), ag .eval_episode ()))
61
71
62
72
63
- @rainy_cli .command ()
64
- @click .argument ('logdir' , required = True , type = str )
65
- @click .option ('--model' , type = str , default = run .SAVE_FILE_DEFAULT )
66
- @click .option ('--render' , is_flag = True )
67
- @click .option ('--replay' , is_flag = True )
68
- @click .option ('--action-file' , type = str , default = 'best-actions.json' )
73
+ @rainy_cli .command (help = 'Load a save file and evaluate the agent' )
74
+ @click .argument ('logdir' )
75
+ @click .option ('--model' , type = str , default = run .SAVE_FILE_DEFAULT , help = 'Name of the save file' )
76
+ @click .option ('--render' , is_flag = True , help = 'Render the agent' )
77
+ @click .option ('--replay' , is_flag = True , help = 'Show replay(works with special environments)' )
78
+ @click .option ('--action-file' , type = str ,
79
+ default = 'best-actions.json' , help = 'Name of the action file' )
69
80
@click .pass_context
70
81
def eval (ctx : dict , logdir : str , model : str , render : bool , replay : bool , action_file : str ) -> None :
71
82
c = ctx .obj ['config' ]
@@ -80,19 +91,19 @@ def eval(ctx: dict, logdir: str, model: str, render: bool, replay: bool, action_
80
91
)
81
92
82
93
83
- @rainy_cli .command ()
84
- @click .option ('--log-dir ' , type = str )
85
- @click .option ('--vi-mode' , is_flag = True )
94
+ @rainy_cli .command (help = 'Open an ipython shell with rainy imported' )
95
+ @click .option ('--logdir ' , type = str , help = 'Name of the directly where the log file' )
96
+ @click .option ('--vi-mode' , is_flag = True , help = 'Open ipython shell with vi-mode enabled' )
86
97
@click .pass_context
87
- def ipython (ctx : dict , log_dir : Optional [str ], vi_mode : bool ) -> None :
98
+ def ipython (ctx : dict , logdir : Optional [str ], vi_mode : bool ) -> None :
88
99
config , make_agent = ctx .obj ['config' ], ctx .obj ['make_agent' ] # noqa
89
- if log_dir is not None :
90
- log = ExperimentLog (log_dir ) # noqa
100
+ if logdir is not None :
101
+ log = ExperimentLog (logdir ) # noqa
91
102
else :
92
103
open_log = ExperimentLog # noqa
93
104
try :
94
105
from ptpython .ipython import embed
95
- del ctx , log_dir
106
+ del ctx , logdir
96
107
import rainy # noqa
97
108
embed (vi_mode = vi_mode )
98
109
except ImportError :
0 commit comments