@@ -137,8 +137,9 @@ def from_defaults(
137137 job_queue : str ,
138138 image : str ,
139139 command : str = "" ,
140- memory : str = "1024" ,
141- vcpus : str = "1" ,
140+ memory : Union [str , int ] = 1024 ,
141+ vcpus : Union [str , int ] = 1 ,
142+ gpu : Union [str , int ] = 0 ,
142143 environment : Optional [Mapping [str , str ]] = None ,
143144 mount_point_configs : Optional [List [MountPointConfiguration ]] = None ,
144145 job_role_arn : Optional [str ] = None ,
@@ -147,10 +148,10 @@ def from_defaults(
147148 defaults ["command" ] = command
148149 defaults ["job_queue" ] = job_queue
149150 defaults ["environment" ] = environment or {}
150- defaults ["memory" ] = memory
151151 defaults ["image" ] = image
152- defaults ["vcpus" ] = vcpus
153- defaults ["gpu" ] = "0"
152+ defaults ["memory" ] = str (memory )
153+ defaults ["vcpus" ] = str (vcpus )
154+ defaults ["gpu" ] = str (gpu )
154155 defaults ["platform_capabilities" ] = ["EC2" ]
155156 defaults ["job_role_arn" ] = job_role_arn or JsonNull .INSTANCE
156157
@@ -170,10 +171,7 @@ def from_defaults(
170171 environment = sfn .JsonPath .string_at ("$.request.environment" ),
171172 memory = sfn .JsonPath .string_at ("$.request.memory" ),
172173 vcpus = sfn .JsonPath .string_at ("$.request.vcpus" ),
173- # TODO: Handle GPU parameter better - right now, we cannot handle cases where it is
174- # not specified. Setting to zero causes issues with the Batch API.
175- # If it is set to zero, then the json list of resources are not properly set.
176- # gpu=sfn.JsonPath.string_at("$.request.gpu"),
174+ gpu = sfn .JsonPath .string_at ("$.request.gpu" ),
177175 mount_points = sfn .JsonPath .string_at ("$.request.mount_points" ),
178176 volumes = sfn .JsonPath .string_at ("$.request.volumes" ),
179177 platform_capabilities = sfn .JsonPath .string_at ("$.request.platform_capabilities" ),
@@ -201,70 +199,3 @@ def from_defaults(
201199
202200 submit_job .definition = start .next (merge ).next (submit_job .definition )
203201 return submit_job
204-
205-
206- class SubmitJobWithDefaultsFragment (EnvBaseStateMachineFragment , AWSBatchMixins ):
207- def __init__ (
208- self ,
209- scope : constructs .Construct ,
210- id : str ,
211- env_base : EnvBase ,
212- job_queue : str ,
213- command : str = "" ,
214- memory : str = "1024" ,
215- vcpus : str = "1" ,
216- environment : Optional [Mapping [str , str ]] = None ,
217- mount_point_configs : Optional [List [MountPointConfiguration ]] = None ,
218- platform_capabilities : Optional [Union [List [Literal ["EC2" , "FARGATE" ]], str ]] = None ,
219- job_role_arn : Optional [str ] = None ,
220- ):
221- super ().__init__ (scope , id , env_base )
222- defaults : dict [str , Any ] = {}
223- defaults ["command" ] = command
224- defaults ["job_queue" ] = job_queue
225- defaults ["environment" ] = environment or {}
226- defaults ["memory" ] = memory
227- defaults ["vcpus" ] = vcpus
228- defaults ["gpu" ] = "0"
229- defaults ["platform_capabilities" ] = platform_capabilities or ["EC2" ]
230- defaults ["job_role_arn" ] = job_role_arn or JsonNull .INSTANCE
231-
232- if mount_point_configs :
233- mount_points , volumes = self .convert_to_mount_point_and_volumes (mount_point_configs )
234- defaults ["mount_points" ] = mount_points
235- defaults ["volumes" ] = volumes
236-
237- start = sfn .Pass (
238- self ,
239- "Start" ,
240- parameters = {
241- "input" : sfn .JsonPath .object_at ("$" ),
242- "default" : defaults ,
243- },
244- )
245- merge_chain = CommonOperation .merge_defaults (
246- self , f"{ id } " , defaults = defaults , input_path = "$.input" , result_path = "$.request"
247- )
248-
249- submit_job = SubmitJobFragment (
250- self ,
251- "SubmitJobCore" ,
252- env_base = self .env_base ,
253- name = "SubmitJobCore" ,
254- image = sfn .JsonPath .string_at ("$.request.image" ),
255- command = sfn .JsonPath .string_at ("$.request.command" ),
256- job_queue = sfn .JsonPath .string_at ("$.request.job_queue" ),
257- environment = sfn .JsonPath .string_at ("$.request.environment" ),
258- memory = sfn .JsonPath .string_at ("$.request.memory" ),
259- vcpus = sfn .JsonPath .string_at ("$.request.vcpus" ),
260- # TODO: Handle GPU parameter better - right now, we cannot handle cases where it is
261- # not specified. Setting to zero causes issues with the Batch API.
262- # If it is set to zero, then the json list of resources are not properly set.
263- # gpu=sfn.JsonPath.string_at("$.request.gpu"),
264- mount_points = sfn .JsonPath .string_at ("$.request.mount_points" ),
265- volumes = sfn .JsonPath .string_at ("$.request.volumes" ),
266- platform_capabilities = sfn .JsonPath .string_at ("$.request.platform_capabilities" ),
267- job_role_arn = sfn .JsonPath .string_at ("$.request.job_role_arn" ),
268- ).to_single_state ()
269-
270- self .definition = start .next (merge_chain ).next (submit_job )
0 commit comments