1+ from random import randint , seed
2+ import sys
3+ import os
4+ import time
5+
6+ seed (42 )
7+
8+ def create_job (job_index , priority , problem_size , min_replicas , max_replicas , timesteps ):
9+ with open ("charm-template.yaml" , "r" ) as file :
10+ template = file .read ()
11+
12+ odf = 2
13+ num_chares = odf * max_replicas
14+ num_chares = 2 ** (num_chares - 1 ).bit_length ()
15+ chare_size = problem_size // num_chares
16+
17+ job_yaml = template .format (
18+ job_index = job_index ,
19+ priority = priority ,
20+ problem_size = problem_size ,
21+ chare_size = chare_size ,
22+ timesteps = timesteps ,
23+ min_replicas = min_replicas ,
24+ max_replicas = max_replicas ,
25+ )
26+
27+ with open (f"jobs/charm-job-{ job_index } .yaml" , "w" ) as file :
28+ file .write (job_yaml )
29+
30+
31+ def generate_jobs ():
32+ for job_index in range (10 ):
33+ priority = randint (1 , 5 )
34+ problem_size = 2 ** (randint (9 , 12 ))
35+ min_replicas = randint (1 , 3 )
36+ max_replicas = randint (min_replicas + 1 , 8 )
37+ timesteps = 100 * randint (20 , 30 )
38+ create_job (job_index , priority , problem_size , min_replicas , max_replicas , timesteps )
39+
40+
41+ def submit_jobs ():
42+ for job_index in range (10 ):
43+ job_file = f"jobs/charm-job-{ job_index } .yaml"
44+ print (f"Submitting { job_file } " )
45+ # Here you would submit the job using your cluster's job submission command
46+ os .system (f"kubectl apply -f { job_file } " )
47+ # For this example, we'll just print the command
48+ #print(f"kubectl apply -f {job_file}")
49+ time .sleep (10 )
50+
51+
52+ if __name__ == "__main__" :
53+ if sys .argv [1 ] == "generate_jobs" :
54+ generate_jobs ()
55+ elif sys .argv [1 ] == "submit" :
56+ submit_jobs ()
57+ else :
58+ print ("Invalid argument. Use 'generate_jobs' to generate job files or 'submit' to submit them." )
59+ sys .exit (1 )
0 commit comments