1+ import json
2+
13import click
24
35from paperspace import commands
46
57
8+ class ChoiceType (click .Choice ):
9+ """Takes a string-keyed map and converts cli-provided parameter to corresponding value"""
10+
11+ def __init__ (self , type_map , case_sensitive = True ):
12+ super (ChoiceType , self ).__init__ (tuple (type_map .keys ()), case_sensitive = case_sensitive )
13+ self .type_map = type_map
14+
15+ def convert (self , value , param , ctx ):
16+ value = super (ChoiceType , self ).convert (value , param , ctx )
17+ return self .type_map [value ]
18+
19+
20+ EXPERIMENT_TYPES_MAP = {
21+ "GRPC" : 2 ,
22+ "MPI" : 3 ,
23+ }
24+
25+
26+ def json_string (val ):
27+ """Wraps json.loads so the cli help shows proper option's type name instead of 'LOADS'"""
28+ return json .loads (val )
29+
30+
631def del_if_value_is_none (d ):
732 """Remove all elements with value == None"""
833 for key , val in list (d .items ()):
@@ -26,29 +51,112 @@ def create():
2651
2752
2853@create .command ()
29- @click .option ("--name" , required = True )
30- @click .option ("--experimentTypeId" , "experimentTypeId" , type = int , required = True )
31- @click .option ("--workerCount" , "workerCount" , type = int , required = True )
32- @click .option ("--workerContainer" , "workerContainer" , required = True )
33- @click .option ("--workerMachineType" , "workerMachineType" , required = True )
34- @click .option ("--workerCommand" , "workerCommand" , required = True )
35- @click .option ("--parameterServerContainer" , "parameterServerContainer" , required = True )
36- @click .option ("--parameterServerMachineType" , "parameterServerMachineType" , required = True )
37- @click .option ("--parameterServerCommand" , "parameterServerCommand" , required = True )
38- @click .option ("--parameterServerCount" , "parameterServerCount" , type = int , required = True )
39- @click .option ("--ports" , type = int )
40- @click .option ("--workspaceUrl" , "workspaceUrl" )
41- @click .option ("--projectHandler" , "projectHandler" )
42- @click .option ("--workingDirectory" , "workingDirectory" )
43- @click .option ("--artifactDirectory" , "artifactDirectory" )
44- @click .option ("--clusterId" , "clusterId" , type = int )
45- # @click.option("--experimentEnv", type=dict)
46- @click .option ("--workerContainerUser" , "workerContainerUser" )
47- @click .option ("--workerRegistryUsername" , "workerRegistryUsername" )
48- @click .option ("--workerRegistryPassword" , "workerRegistryPassword" )
49- @click .option ("--parameterServerContainerUser" , "parameterServerContainerUser" )
50- @click .option ("--parameterServerRegistryContainerUser" , "parameterServerRegistryContainerUser" )
51- @click .option ("--parameterServerRegistryPassword" , "parameterServerRegistryPassword" )
54+ @click .option (
55+ "--name" ,
56+ required = True ,
57+ )
58+ @click .option (
59+ "--experimentTypeId" ,
60+ "experimentTypeId" ,
61+ type = ChoiceType (EXPERIMENT_TYPES_MAP , case_sensitive = False ),
62+ required = True ,
63+ )
64+ @click .option (
65+ "--workerCount" ,
66+ "workerCount" ,
67+ type = int ,
68+ required = True ,
69+ )
70+ @click .option (
71+ "--workerContainer" ,
72+ "workerContainer" ,
73+ required = True ,
74+ )
75+ @click .option (
76+ "--workerMachineType" ,
77+ "workerMachineType" ,
78+ required = True ,
79+ )
80+ @click .option (
81+ "--workerCommand" ,
82+ "workerCommand" ,
83+ required = True ,
84+ )
85+ @click .option (
86+ "--parameterServerContainer" ,
87+ "parameterServerContainer" ,
88+ required = True ,
89+ )
90+ @click .option (
91+ "--parameterServerMachineType" ,
92+ "parameterServerMachineType" ,
93+ required = True ,
94+ )
95+ @click .option (
96+ "--parameterServerCommand" ,
97+ "parameterServerCommand" ,
98+ required = True ,
99+ )
100+ @click .option (
101+ "--parameterServerCount" ,
102+ "parameterServerCount" ,
103+ type = int ,
104+ required = True ,
105+ )
106+ @click .option (
107+ "--ports" ,
108+ type = int ,
109+ )
110+ @click .option (
111+ "--workspaceUrl" ,
112+ "workspaceUrl" ,
113+ )
114+ @click .option (
115+ "--projectHandler" ,
116+ "projectHandler" ,
117+ )
118+ @click .option (
119+ "--workingDirectory" ,
120+ "workingDirectory" ,
121+ )
122+ @click .option (
123+ "--artifactDirectory" ,
124+ "artifactDirectory" ,
125+ )
126+ @click .option (
127+ "--clusterId" ,
128+ "clusterId" ,
129+ type = int ,
130+ )
131+ @click .option (
132+ "--experimentEnv" ,
133+ "experimentEnv" ,
134+ type = json_string ,
135+ )
136+ @click .option (
137+ "--workerContainerUser" ,
138+ "workerContainerUser" ,
139+ )
140+ @click .option (
141+ "--workerRegistryUsername" ,
142+ "workerRegistryUsername" ,
143+ )
144+ @click .option (
145+ "--workerRegistryPassword" ,
146+ "workerRegistryPassword" ,
147+ )
148+ @click .option (
149+ "--parameterServerContainerUser" ,
150+ "parameterServerContainerUser" ,
151+ )
152+ @click .option (
153+ "--parameterServerRegistryContainerUser" ,
154+ "parameterServerRegistryContainerUser" ,
155+ )
156+ @click .option (
157+ "--parameterServerRegistryPassword" ,
158+ "parameterServerRegistryPassword" ,
159+ )
52160def multinode (** kwargs ):
53161 del_if_value_is_none (kwargs )
54162 commands .create_experiments (kwargs )
0 commit comments