@@ -22,48 +22,51 @@ def to_gres_options(stdout):
2222 For example with a single GRES defined of `gpu:H200:8' the following
2323 entries are returned:
2424 - ['None', 'none']
25- - ['Any gpu (max count: 8 )', 'gpu']
26- - ['H200 gpu' (max count: 8 )', 'gpu:H200']
25+ - ['Any gpu (max count=8, partitions=standard,long )', 'gpu']
26+ - ['H200 gpu (max count=8, partitions=standard,long )', 'gpu:H200']
2727
2828 [1] https://osc.github.io/ood-documentation/latest/how-tos/app-development/interactive/form-widgets.html#form-widgets
2929 [2] https://slurm.schedmd.com/srun.html#OPT_gres
3030 """ # noqa: E501 pylint: disable=line-too-long
3131
3232 gres_data = {}
33- # key=gres_opt, what would be passed to --gres
34- # value=[ label, max_count]
35- gres_data ["none" ] = [ " None" , 0 ]
33+ # key=gres_opt - 'name' or 'name:type', i.e. what would be passed to --gres
34+ # value={ label:str , max_count: int, partitions=[]}
35+ gres_data ["none" ] = { 'label' : ' None' , 'max_count' : 0 , 'partitions' :[ 'all' ]}
3636
3737 for line in stdout .splitlines ():
38- partition , gres_definitions = ( # pylint: disable=unused-variable
39- line .split ()
40- ) # e.g. 'part1 gpu:H200:8(S:0-1),test:foo:1', or 'part2 (null)'
38+ # line examples:
39+ # 'part1 gpu:H200:8(S:0-1),test:foo:1'
40+ # 'part2 (null)'
41+ # - First example shows multiple GRES per partition
42+ # - Core suffix e.g. '(S:0-1)' only exists for auto-detected gres
43+ # - stackhpc.openhpc role guarantees that name:type:count all exist
44+ partition , gres_definitions = (line .split ())
4145 for gres in gres_definitions .split ("," ):
4246 if "(null)" in gres :
4347 continue
4448 gres_name , gres_type , gres_count_cores = gres .split (":" , maxsplit = 2 )
45- gres_count = gres_count_cores .split ("(" )[
46- 0
47- ] # may or may not have the e.g. '(S:0-1)' core definition
49+ gres_count = gres_count_cores .split ("(" )[0 ]
4850 for gres_opt in [gres_name , f"{ gres_name } :{ gres_type } " ]:
4951 if gres_opt not in gres_data :
5052 label = (
5153 f"{ gres_type } { gres_name } "
5254 if ":" in gres_opt
5355 else f"Any { gres_opt } "
5456 )
55- gres_data [gres_opt ] = [ label , gres_count ]
56- elif len ( gres_data [ gres_name ]) == 1 :
57- raise ValueError ( gres_data [gres_name ] )
58- elif gres_count > gres_data [gres_name ][1 ]:
59- gres_data [gres_opt ][1 ] = gres_count
57+ gres_data [gres_opt ] = { ' label' : label , 'max_count' : gres_count , 'partitions' :[ partition ]}
58+ else :
59+ gres_data [gres_opt ][ 'partitions' ]. append ( partition )
60+ if gres_count > gres_data [gres_name ]['max_count' ]:
61+ gres_data [gres_opt ]['max_count' ] = gres_count
6062
6163 gres_options = []
6264 for gres_opt in gres_data : # pylint: disable=consider-using-dict-items
63- max_count = gres_data [gres_opt ][1 ]
64- label = gres_data [gres_opt ][0 ]
65+ max_count = gres_data [gres_opt ]['max_count' ]
66+ partitions = gres_data [gres_opt ]['partitions' ]
67+ label = gres_data [gres_opt ]['label' ]
6568 if gres_opt != "none" :
66- label += f" (max count: { max_count } )"
69+ label += f" (max count= { max_count } , partitions= { ',' . join ( partitions ) } )"
6770 gres_options .append ((label , gres_opt ))
6871 return gres_options
6972
0 commit comments