Skip to content

Commit

Permalink
Iniitial work on fixing get_command_from_result
Browse files Browse the repository at this point in the history
  • Loading branch information
pagmatt committed Apr 18, 2023
1 parent 101eb56 commit ccbfabe
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 2 additions & 0 deletions sem/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,11 @@ def command(results_dir, result_id):

click.echo("Simulation command:")
click.echo(sem.utils.get_command_from_result(campaign.db.get_script(),
campaign.dir,
result))
click.echo("Debug command:")
click.echo(sem.utils.get_command_from_result(campaign.db.get_script(),
campaign.dir,
result,
debug=True))

Expand Down
4 changes: 2 additions & 2 deletions sem/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ def run_simulations(self, parameter_list, data_folder, stop_on_errors=False):
if return_code != 0:
with open(stdout_file_path, 'r') as stdout_file, open(
stderr_file_path, 'r') as stderr_file:
complete_command = sem.utils.get_command_from_result(self.script, current_result)
complete_command_debug = sem.utils.get_command_from_result(self.script, current_result, debug=True)
complete_command = sem.utils.get_command_from_result(self.script, self.path, current_result)
complete_command_debug = sem.utils.get_command_from_result(self.script, self.path, current_result, debug=True)
error_message = ('\nSimulation exited with an error.\n'
'Params: %s\n'
'Stderr: %s\n'
Expand Down
12 changes: 9 additions & 3 deletions sem/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import io
import os
import math
import copy
import warnings
Expand Down Expand Up @@ -99,21 +100,26 @@ def list_param_combinations(param_ranges):
return [param_ranges_copy]


def get_command_from_result(script, result, debug=False):
def get_command_from_result(script, path, result, debug=False):
"""
Return the command that is needed to obtain a certain result.
Args:
params (dict): Dictionary containing parameter: value pairs.
path (str): The path to the ns-3 folder, used to discern which
build system (waf/CMake) is used
debug (bool): Whether the command should include the debugging
template.
"""
command = "python3 "
command += "./ns3 run " if os.path.exists(os.path.join(path, "ns3")) else " ./waf --run "

if not debug:
command = "python3 waf --run \"" + script + " " + " ".join(
command += script + " " + " ".join(
['--%s=%s' % (param, value) for param, value in
result['params'].items()]) + "\""
else:
command = "python3 waf --run " + script + " --command-template=\"" +\
command += script + " --command-template=\"" +\
"gdb --args %s " + " ".join(['--%s=%s' % (param, value) for
param, value in
result['params'].items()]) + "\""
Expand Down

0 comments on commit ccbfabe

Please sign in to comment.