def _parse_argument(self, scenario, key: str, value):
"""Some values of the scenario-file need to be changed upon writing,
such as the 'ta' (target algorithm), due to it's callback. Also,
the configspace, features, train_inst- and test-inst-lists are saved
to output_dir, if they exist.
Parameters:
-----------
scenario: Scenario
Scenario-file to be written
key: string
Name of the attribute in scenario-file
value: Any
Corresponding attribute
Returns:
--------
new value: string
The altered value, to be written to file
Sideeffects:
------------
- copies files pcs_fn, train_inst_fn, test_inst_fn and feature_fn to
output if possible, creates the files from attributes otherwise
"""
if key in ['pcs_fn', 'train_inst_fn', 'test_inst_fn', 'feature_fn']:
# Copy if file exists, else write to new file
if value is not None and os.path.isfile(value):
try:
return shutil.copy(value, scenario.output_dir_for_this_run)
except shutil.SameFileError:
return value # File is already in output_dir
elif key == 'pcs_fn' and scenario.cs is not None:
new_path = os.path.join(scenario.output_dir_for_this_run, "configspace.pcs")
self.write_pcs_file(scenario.cs, new_path)
elif key == 'train_inst_fn' and scenario.train_insts != [None]:
new_path = os.path.join(scenario.output_dir_for_this_run, 'train_insts.txt')
self.write_inst_file(scenario.train_insts, new_path)
elif key == 'test_inst_fn' and scenario.test_insts != [None]:
new_path = os.path.join(scenario.output_dir_for_this_run, 'test_insts.txt')
self.write_inst_file(scenario.test_insts, new_path)
elif key == 'feature_fn' and scenario.feature_dict != {}:
new_path = os.path.join(scenario.output_dir_for_this_run, 'features.txt')
self.write_inst_features_file(scenario.n_features,
scenario.feature_dict, new_path)
else:
return None
# New value -> new path
return new_path
elif key == 'ta' and value is not None:
# Reversing the callback on 'ta' (shlex.split)
return " ".join(value)
elif key in ['train_insts', 'test_insts', 'cs', 'feature_dict']:
# No need to log, recreated from files
return None
else:
return value
评论列表
文章目录