From ec1bf89c1de4567ed881757f9b78c8c20b292d2d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ma=C3=ABl=20Madon?= <mael.madon@irit.fr>
Date: Fri, 28 Jan 2022 16:56:11 +0100
Subject: [PATCH] made changes for absolute path in python

---
 1_full_expe.py                         |  2 +-
 1_one_instance.py                      | 35 +++++++++++++-------------
 scripts/{run_batsim_exp.py => util.py} |  3 +++
 3 files changed, 22 insertions(+), 18 deletions(-)
 rename scripts/{run_batsim_exp.py => util.py} (94%)

diff --git a/1_full_expe.py b/1_full_expe.py
index c4c4709..f6532df 100644
--- a/1_full_expe.py
+++ b/1_full_expe.py
@@ -8,6 +8,6 @@ jun1_unix_time, nov30_unix_time = mktime(strptime('Sun Jun  1 00:00:00 2014')),
 jun1, nov30 = (int) (jun1_unix_time - begin_trace), (int) (nov30_unix_time - begin_trace)
 
 start_date = randint(jun1, nov30 - 72 * 3600)
-
+print(jun1)
 # For every start date
 #   Call the one_instance file with this date
\ No newline at end of file
diff --git a/1_one_instance.py b/1_one_instance.py
index dc7a96f..49fd848 100755
--- a/1_one_instance.py
+++ b/1_one_instance.py
@@ -1,14 +1,14 @@
 #!/usr/bin/env python3
 
 import time
-import sys
+# import sys
 import os
 import subprocess
 import argparse
-sys.path.insert(0, '/scripts')
+# sys.path.insert(0, '/scripts')
 
 import scripts.swf_to_batsim_split_by_user as split_user
-from scripts.run_batsim_exp import *
+from scripts.util import *
 #import swf_moulinette
 
 
@@ -17,11 +17,11 @@ def prepare_input_data(expe_num, start_date):
     end_date = start_date + 72*3600
     to_keep = f"submit_time >= {start_date} and submit_time <= {end_date}"
 
-    if not os.path.exists(f'workload/expe{expe_num}'):
-        os.makedirs(f'workload/expe{expe_num}')
+    if not os.path.exists(f'{WL_DIR}/expe{expe_num}'):
+        os.makedirs(f'{WL_DIR}/expe{expe_num}')
     split_user.generate_workload(
-        input_swf='workload/MC_selection_article.swf',
-        output_folder=f'workload/expe{expe_num}',
+        input_swf=f'{WL_DIR}/MC_selection_article.swf',
+        output_folder=f'{WL_DIR}/expe{expe_num}',
         keep_only=to_keep,
         job_grain=10,
         job_walltime_factor=8)
@@ -34,11 +34,12 @@ def run_expe(expe_num, user_category, window_size):
         w_size = '05'
     else:
         w_size = f"{window_size}"
-    EXPE_FILE = f"out/expe{expe_num}/{user_category}_window{w_size}"
-    wl_folder = f'workload/expe{expe_num}'
-    pf = "platform/average_metacentrum.xml"
-    wl = "workload/empty_workload.json"
-    uf = "sched_input/user_description_file.json"
+    EXPE_DIR = f"{ROOT_DIR}/out/expe{expe_num}/{user_category}_window{w_size}"
+    EXPE_FILE = f"{EXPE_DIR}.yaml"
+    wl_folder = f'{WL_DIR}/expe{expe_num}'
+    pf = f"{ROOT_DIR}/platform/average_metacentrum.xml"
+    wl = f"{WL_DIR}/empty_workload.json"
+    uf = f"{ROOT_DIR}/sched_input/user_description_file.json"
 
     # Demand response window, from 12 to (12 + window_size) on day2
     dm_window = [(24+12)*3600, (24+12+window_size)*3600]
@@ -54,23 +55,23 @@ def run_expe(expe_num, user_category, window_size):
     data = {}
     data["dm_window"] = dm_window
     data["log_user_stats"] = True
-    data["log_folder"] = EXPE_FILE
+    data["log_folder"] = EXPE_DIR
     data["users"] = [user_description(user) for user in user_names]
     with open(uf, 'w') as user_description_file:
         json.dump(data, user_description_file)
 
     # Generate and run robin instance
     batcmd = gen_batsim_cmd(
-        pf, wl, EXPE_FILE, "--energy --enable-compute-sharing --enable-dynamic-jobs --acknowledge-dynamic-jobs --enable-profile-reuse")
+        pf, wl, EXPE_DIR, "--energy --enable-compute-sharing --enable-dynamic-jobs --acknowledge-dynamic-jobs --enable-profile-reuse")
     schedcmd = f"batsched -v bin_packing_energy --queue_order=desc_size --variant_options_filepath={uf}"
-    instance = RobinInstance(output_dir=EXPE_FILE,
+    instance = RobinInstance(output_dir=EXPE_DIR,
                             batcmd=batcmd,
                             schedcmd=schedcmd,
                             simulation_timeout=30, ready_timeout=5,
                             success_timeout=10, failure_timeout=0
                             )
-    instance.to_file(robin_filename)
-    ret = run_robin(robin_filename)
+    instance.to_file(EXPE_FILE)
+    ret = run_robin(EXPE_FILE)
 
 
 
diff --git a/scripts/run_batsim_exp.py b/scripts/util.py
similarity index 94%
rename from scripts/run_batsim_exp.py
rename to scripts/util.py
index 2910d08..69bcc59 100644
--- a/scripts/run_batsim_exp.py
+++ b/scripts/util.py
@@ -5,6 +5,9 @@ import subprocess
 import filecmp
 from collections import namedtuple
 
+ROOT_DIR = os.path.realpath(os.path.join(os.path.dirname(__file__), '..'))
+WL_DIR = f'{ROOT_DIR}/workload'
+
 class RobinInstance(object):
     def __init__(self, output_dir, batcmd, schedcmd, simulation_timeout, ready_timeout, success_timeout, failure_timeout):
         self.output_dir = output_dir
-- 
GitLab