You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.9 KiB

11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
  1. #!/usr/bin/python3
  2. import os
  3. import subprocess
  4. from concurrent.futures import ThreadPoolExecutor
  5. abs_path = os.getcwd()
  6. slippery_configs=[f"{abs_path}/slippery_prob_075.yaml",
  7. # f"{abs_path}/slippery_prob_08.yaml",
  8. f"{abs_path}/slippery_prob_085.yaml",
  9. # f"{abs_path}/slippery_prob_09.yaml",
  10. f"{abs_path}/slippery_prob_095.yaml",
  11. # f"{abs_path}/slippery_prob_1.yaml"
  12. ]
  13. slippery_probs=[[0.25, 0.75], # 0.75
  14. #[0.1, 0.2, 0.8], # 0.8
  15. [0.15,0.85], # 0.85
  16. #[0.05, 0.1, 0.9], # 0.9
  17. [0.05, 0.95], # 0.95
  18. # [0.01, 0.02, 0.98], # 0.98
  19. # [0.005,0.01, 0.99], # 0.99
  20. #[0, 0, 1] # 1
  21. ]
  22. prob_turn_intended = 1
  23. #shield_values = [0.85, 0.9, 0.95, 0.98, 0.99, 1]
  24. shield_values = [0.85, .95, 1]
  25. prob_confs = list(zip(slippery_probs, slippery_configs))
  26. counter = 1
  27. shielding = ["full", "none"]
  28. comparison_type = ["relative", "absolute"]
  29. comps = ["relative", "absolute"]
  30. NUM_TIMESTEPS=250000
  31. LOGDIR="../logresults/"
  32. ENV="MiniGrid-LavaSlipperyCliffS12-v0"
  33. tasks = list()
  34. NUM_WORKER=2
  35. def run_command(command, logname):
  36. log = open(f"{logname}.log", "w")
  37. print(f"running {command}")
  38. subprocess.call(command, shell=True, stdout=log)#.decode("utf-8").split('\n')
  39. close(log)
  40. # matrix for shielded runs
  41. for shield_value in shield_values:
  42. for sh_comp in comparison_type:
  43. for probs, config in prob_confs:
  44. command = f"echo \"Running experiment with shielding full, sh_value:{shield_value}, sh_comp:{sh_comp}, probvalues:{probs}, config{config}\""
  45. execute_command = f'./syncscript.sh {NUM_TIMESTEPS} {LOGDIR} {"70"} {ENV} full {sh_comp} {config} {probs[0]} {probs[1]} {0} {shield_value} {prob_turn_intended}'
  46. print(execute_command)
  47. logname = f"shielded_comp_{sh_comp}_value_{shield_value}_probvalues{'_'.join(format(p, '10.3f') for p in probs)}_{config.split('/')[-1]}".replace(" ", "")
  48. tasks.append((execute_command, logname))
  49. # loop for unshielded runs
  50. for probs, config in prob_confs:
  51. command = f"echo \"Running experiment with shielding none, sh_value:0.0, sh_comp:{sh_comp}, probvalues:{probs}, config{config}\""
  52. execute_command = f'./syncscript.sh {NUM_TIMESTEPS} {LOGDIR} {"70"} {ENV} none {sh_comp} {config} {probs[0]} {probs[1]} {0} {shield_value} {prob_turn_intended}'
  53. logname = f"unshielded_probvalues{'_'.join(format(p, '10.3f') for p in probs)}_{config.split('/')[-1]}".replace(" ", "")
  54. print(execute_command)
  55. tasks.append((execute_command, logname))
  56. print(f"Going to execute {len(tasks)} with {NUM_WORKER} threads... press Enter to start")
  57. input("")
  58. with ThreadPoolExecutor(max_workers=NUM_WORKER) as e:
  59. for task in tasks:
  60. print(f"submitted {task}")
  61. e.submit(run_command, f"echo {task[0]}", task[1])