Skip to content

Commit

Permalink
fix(meta_handling.py): remove unnecessary if statement for func_name
Browse files Browse the repository at this point in the history
fix(meta_handling.py): remove unnecessary if statement for workload_params
fix(meta_handling.py): remove unnecessary if statement for workload_params
fix(meta_handling.py): remove unnecessary if statement for workload_params
fix(meta_handling.py): remove unnecessary if statement for workload_params
fix(meta_handling.py): remove unnecessary if statement for workload_params
fix(meta_handling.py): remove unnecessary if statement for workload_params
fix(meta_handling.py): remove unnecessary if statement for workload_params
fix(meta_handling.py): remove unnecessary if statement for workload_params
fix(meta_handling.py): remove unnecessary if statement for workload_params
fix(meta_handling.py): remove unnecessary if statement for workload_params
fix(meta_handling.py): remove unnecessary if statement for workload_params
fix(meta_handling.py): remove unnecessary if statement for workload_params
fix(meta_handling.py): remove unnecessary if statement for workload_params
fix(meta_handling.py): remove unnecessary if statement for workload_params
fix
  • Loading branch information
realSAH committed Jun 28, 2023
1 parent 2d931b4 commit af73a29
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
35 changes: 17 additions & 18 deletions myresources/crocodile/cluster/meta_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,39 +41,38 @@ def get_py_script(kwargs, rel_full_path, func_name, func_class, workload_params:

def get_execution_line(func_name, func_class, rel_full_path, workload_params: WorkloadParams or None, parallelize: bool) -> str:
final_func = f"""module{('.' + func_class) if func_class is not None else ''}.{func_name}"""
if parallelize:
assert workload_params is not None
kwargs_split = tb.L(range(workload_params.idx_start, workload_params.idx_end, 1)).split(to=workload_params.jobs).apply(lambda sub_list: WorkloadParams(idx_start=sub_list[0], idx_end=sub_list[-1] + 1, idx_max=workload_params.idx_max, jobs=workload_params.jobs))
# Note: like MachineLoadCalculator get_kwargs, the behaviour is to include the edge cases on both ends of subsequent intervals.
base_func = f"""
if func_name is None: return f"""
res = None # in case the file did not define it.
# --------------------------------- SCRIPT AS IS
{tb.P.home().joinpath(rel_full_path).read_text()}
# --------------------------------- END OF SCRIPT AS IS
"""
base_func = ""
if workload_params is not None: base_func += f"""
print(f"This machine will execute ({(workload_params.idx_end - workload_params.idx_start) / workload_params.idx_max * 100:.2f}%) of total job workload.")
print(f"This share of workload will be split among {workload_params.jobs} of threads on this machine.")
kwargs_workload = {list(kwargs_split.apply(lambda a_kwargs: a_kwargs.__dict__))}
"""
if not parallelize: base_func += f"""
workload_params = WorkloadParams(**{workload_params.__dict__})
"""
else: return f"""
kwargs_workload = {list(workload_params.split_to_jobs().apply(lambda a_kwargs: a_kwargs.__dict__))}
workload_params = []
for idx, x in enumerate(kwargs_workload):
tb.S(x).print(as_config=True, title=f"Instance {{idx}}")
workload_params.append(WorkloadParams(**x))
print("\\n" * 2)
res = tb.L(workload_params).apply(lambda a_workload_params: {final_func}(workload_params=a_workload_params, **func_kwargs), jobs={workload_params.jobs})
# res = tb.P(res[0]).parent if type(res[0]) is str else res
# res = {final_func}(workload_params=workload_params, **func_kwargs)
# res = {final_func}(workload_params=workload_params, **func_kwargs.__dict__)
"""
return base_func

if func_name is not None and workload_params is None: return f"""
if workload_params is None: return base_func + f"""
res = {final_func}(**func_kwargs.__dict__)
"""
elif func_name is not None and workload_params is not None: return f"""
if workload_params is not None: return base_func + f"""
res = {final_func}(workload_params=workload_params, **func_kwargs.__dict__)
"""
return f"""
res = None # in case the file did not define it.
# --------------------------------- SCRIPT AS IS
{tb.P.home().joinpath(rel_full_path).read_text()}
# --------------------------------- END OF SCRIPT AS IS
"""


# kwargs_for_fire = ' '.join(tb.S(func_kwargs or {}).apply(lambda k, v: f"--{k}={v if type(v) is not str else repr(v)}"))

Expand Down
5 changes: 5 additions & 0 deletions myresources/crocodile/cluster/remote_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,13 @@ class WorkloadParams:
idx_end: int = 1000
idx_max: int = 1000
jobs: int = 3
job_id: int = 0
@property
def save_suffix(self) -> str: return f"machine_{self.idx_start}_{self.idx_end}"
def split_to_jobs(self, jobs=None):
# Note: like MachineLoadCalculator get_kwargs, the behaviour is to include the edge cases on both ends of subsequent intervals.
return tb.L(range(self.idx_start, self.idx_end, 1)).split(to=jobs or self.jobs).apply(lambda sub_list: WorkloadParams(idx_start=sub_list[0], idx_end=sub_list[-1] + 1, idx_max=self.idx_max, jobs=jobs or self.jobs))
def print(self): tb.S(self.__dict__).print(as_config=True, title=f"Job Workload")


@dataclass
Expand Down
1 change: 0 additions & 1 deletion myresources/crocodile/cluster/script_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
else:
module = tb.P.home().joinpath(rel_full_path).readit() # uses runpy to read .py files.
exec_obj = module # for README.md generation.
# TODO: replace the above with a simple import statement that can be tested at local machine side.

# execution_line

Expand Down

0 comments on commit af73a29

Please sign in to comment.