Skip to content

Commit

Permalink
Merge pull request #4 from AntaresSimulatorTeam/feature/ts-generator
Browse files Browse the repository at this point in the history
Time series generation tool
  • Loading branch information
flomnes authored Mar 19, 2024
2 parents 6a46e2b + bde0deb commit 122c1be
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
11 changes: 8 additions & 3 deletions scripts/antares_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def remove_outputs(study_path):
for f in files:
shutil.rmtree(f)

def launch_solver(solver_path, study_path, use_ortools = False, ortools_solver = "sirius", named_mps_problems = False):
def launch_solver(solver_path, study_path, use_ortools = False, ortools_solver = "sirius", named_mps_problems = False, ts_generator_path = ""):
# Clean study output
remove_outputs(study_path)

Expand All @@ -62,18 +62,23 @@ def launch_solver(solver_path, study_path, use_ortools = False, ortools_solver =
command.append('--ortools-solver='+ortools_solver)
if named_mps_problems:
command.append('--named-mps-problems')
if ts_generator_path != "":
cluster_to_gen_file = open(study_path / "clustersToGen.txt", 'r')
cluster_to_gen = cluster_to_gen_file.readline().rstrip() # remove new line char
cluster_to_gen_file.close()
command = [ts_generator_path, cluster_to_gen, str(study_path)]

process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=None)
stdout, stderr = process.communicate()
exit_code = process.wait()

return (exit_code == 0)

def generate_reference_values(solver_path, path, use_ortools, ortools_solver, named_mps_problems):
def generate_reference_values(solver_path, path, use_ortools, ortools_solver, named_mps_problems, ts_generator_path):

enable_study_output(path, True)

result = launch_solver(solver_path,path, use_ortools, ortools_solver, named_mps_problems)
result = launch_solver(solver_path,path, use_ortools, ortools_solver, named_mps_problems, ts_generator_path)

output_path = path / 'output'
list_dir = list_directories(output_path)
Expand Down
27 changes: 17 additions & 10 deletions scripts/generate_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,31 @@
root = Path(args.root).resolve()
solver_path = Path(args.solver).resolve()

def find_solver(solver):
def find_binary(path, binary_name):
if sys.platform.startswith("win"):
suffix=".exe"
else:
suffix=""

solver_path = Path(solver)
if solver_path.is_file():
return solver.resolve()
if solver_path.is_dir():
binary_path = Path(path)
if binary_path.is_file():
return path.resolve()
if binary_path.is_dir():
results = []
for x in solver_path.iterdir():
if x.is_file() and (f"antares-solver{suffix}" == x.name):
for x in binary_path.iterdir():
if x.is_file() and (f"antares-{binary_name}{suffix}" == x.name):
results.append(x)
assert(len(results) == 1)
return results[0].resolve()
raise RuntimeError("Missing solver")
raise RuntimeError("Missing {binary_name}")

solver_path = find_solver(args.solver)

solver_path = find_binary(args.solver, "solver")
print(f"Found solver {solver_path}")

ts_generator_path = find_binary(args.solver, "ts-generator")
print(f"Found ts-generator {ts_generator_path}")

studies = antares_utils.list_studies(root)

def solver_config(study_name):
Expand All @@ -50,10 +54,13 @@ def solver_config(study_name):

# Do we need named MPS problems ?
named_mps_problems = (study.parent.name == 'valid-named-mps')
# Are we testing the time series generator ?
if study.parent.name != 'ts-generator':
ts_generator_path = ""
# What optimization solver to use ?
(opt_solver, use_ortools) = solver_config(study.parent.name)

result = antares_utils.generate_reference_values(solver_path, study, use_ortools, opt_solver, named_mps_problems)
result = antares_utils.generate_reference_values(solver_path, study, use_ortools, opt_solver, named_mps_problems, ts_generator_path)
ret.append(result)
print('OK' if result else 'KO')

Expand Down

0 comments on commit 122c1be

Please sign in to comment.