Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring : move exe finding from command building to main program #6

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions scripts/antares_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ def find_studies_in_batch_dir(batch_name):

return studies

def get_headers(df) -> set :
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_headers is unused. It is removed.

return set(df.columns)

def remove_possibly_remaining_outputs(study_path):
output_path = study_path / 'output'
shutil.rmtree(output_path, ignore_errors=True)
Expand Down
11 changes: 7 additions & 4 deletions scripts/generate_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,23 @@
from run_command_building import *
import sys

# Parsing args
# Parsing command line args
parser = argparse.ArgumentParser()
parser.add_argument("batch_name", help="Batch directory (containing studies)",
type=str)
parser.add_argument("path_where_to_find_exe", help="Path to executable",
type=str)
# Storing args
# Storing command line args
args = parser.parse_args()
batch_name = args.batch_name
path_where_to_find_exe = Path(args.path_where_to_find_exe)

# Find exe path
if not path_where_to_find_exe.is_dir() and not path_where_to_find_exe.is_file():
raise RuntimeError("Path where to find an executable does not exist")

exe_identifier = exe_id_from_batch_name(batch_name)
exe_path = find_exe_path(path_where_to_find_exe, exe_identifier)
print(f"Found executabled : {exe_path}")

# Looking for studies in batch directory
study_path_collection = antares_utils.find_studies_in_batch_dir(batch_name)
Expand All @@ -29,7 +32,7 @@
antares_utils.remove_possibly_remaining_outputs(study_path)
antares_utils.enable_study_output(study_path, True)

command_to_run = make_command_to_run(path_where_to_find_exe, batch_name, study_path)
command_to_run = make_command_to_run(exe_path, batch_name, study_path)
result = run_command(command_to_run)
ret.append(result)
print('OK' if result else 'KO')
Expand Down
21 changes: 7 additions & 14 deletions scripts/run_command_building.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
import subprocess
import sys

def exe_id_from_batch_name(batch_name):
exe_identifier = "solver" # Default value
if batch_name == "ts-generator":
exe_identifier = "ts-generator"
return exe_identifier

def find_exe_path(path_to_search_exe_in, exe_identifier):
searched_exe = f"antares-{exe_identifier}"
if sys.platform.startswith("win"):
Expand All @@ -14,33 +20,20 @@ def find_exe_path(path_to_search_exe_in, exe_identifier):
return path_item.resolve()
raise RuntimeError("Missing {searched_exe}")

def make_command_to_run(path_where_to_find_exe, batch_name, study_path):
def make_command_to_run(exe_path, batch_name, study_path):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make_command_to_run function is now simplified.
Code about finding the executable path was moved elsewhere (into the main program)

command_to_run = []
exe_path = Path()
exe_identifier = "solver" # Default value

if batch_name == "ts-generator":
exe_identifier = "ts-generator"
exe_path = find_exe_path(path_where_to_find_exe, exe_identifier)
print(f"Found executabled : {exe_path}")

cluster_to_gen_file = open(study_path / "clustersToGen.txt", 'r')
cluster_to_gen = cluster_to_gen_file.readline().rstrip()
cluster_to_gen_file.close()
command_to_run = [exe_path, cluster_to_gen, str(study_path)]

else:
exe_path = find_exe_path(path_where_to_find_exe, exe_identifier)
print(f"Found executabled : {exe_path}")

command_to_run = [exe_path, "-i", str(study_path)]
if batch_name == "valid-milp":
command_to_run.append('--use-ortools')
command_to_run.append('--ortools-solver=coin')

if batch_name == "valid-named-mps":
command_to_run.append('--named-mps-problems')

return command_to_run

def run_command(command):
Expand Down