def __init__(self, Application, Parameters, AlwaysOn=None): """Initialize the ParameterIterBase Application : A CommandLineApplication subclass Parameters : A dict keyed by the application paramter, value by the range of parameters to enumerate over. For FlagParameters, unless specified in AlwaysOn, the value will cycle between True/False (on/off). For MixedParameters, include [None] specifically to utilize flag functionality. AlwaysOn : List of parameters that will always be on Parameters is checked against the applications known parameters, but only performed superficially: only keys are validated. AlwaysOn values must have entries within Parameters. NOTE: If the parameter is not specified in AlwaysOn, a False value is appended so that the parameter can be turned off. Multiple False states for a parameter will result if False is specified without adding the parameter to AlwaysOn. If a parameter has a default value, then that parameter is implicitly always on. """ self.AppParams = Application._parameters # Validate Parameters param_set = set(Parameters.keys()) app_param_set = set(self.AppParams.keys()) if not param_set.issubset(app_param_set): not_present = str(param_set.difference(app_param_set)) raise ValueError("Parameter(s) %s not present in app" % not_present) # Validate AlwaysOn alwayson_set = set(AlwaysOn) if not alwayson_set.issubset(param_set): not_present = str(alwayson_set.difference(param_set)) raise ValueError("AlwaysOn value(s) %s not in Parameters" % \ not_present) # Make sure all values are lists for k, v in list(Parameters.items()): if not isinstance(v, list): Parameters[k] = [v] _my_params = Parameters # Append "off states" to relevant parameters for k in param_set.difference(alwayson_set): _my_params[k].append(False) # Create seperate key/value lists preserving index relation self._keys, self._values = list(zip(*sorted(_my_params.items()))) # Construct generator self._generator = self._init_generator()
def __init__(self, Application, Parameters, AlwaysOn=None): """Initialize the ParameterIterBase Application : A CommandLineApplication subclass Parameters : A dict keyed by the application paramter, value by the range of parameters to enumerate over. For FlagParameters, unless specified in AlwaysOn, the value will cycle between True/False (on/off). For MixedParameters, include [None] specifically to utilize flag functionality. AlwaysOn : List of parameters that will always be on Parameters is checked against the applications known parameters, but only performed superficially: only keys are validated. AlwaysOn values must have entries within Parameters. NOTE: If the parameter is not specified in AlwaysOn, a False value is appended so that the parameter can be turned off. Multiple False states for a parameter will result if False is specified without adding the parameter to AlwaysOn. If a parameter has a default value, then that parameter is implicitly always on. """ self.AppParams = Application._parameters # Validate Parameters param_set = set(Parameters.keys()) app_param_set = set(self.AppParams.keys()) if not param_set.issubset(app_param_set): not_present = str(param_set.difference(app_param_set)) raise ValueError, "Parameter(s) %s not present in app" % not_present # Validate AlwaysOn alwayson_set = set(AlwaysOn) if not alwayson_set.issubset(param_set): not_present = str(alwayson_set.difference(param_set)) raise ValueError, "AlwaysOn value(s) %s not in Parameters" % \ not_present # Make sure all values are lists for k,v in Parameters.items(): if not isinstance(v, list): Parameters[k] = [v] _my_params = Parameters # Append "off states" to relevant parameters for k in param_set.difference(alwayson_set): _my_params[k].append(False) # Create seperate key/value lists preserving index relation self._keys, self._values = zip(*sorted(_my_params.items())) # Construct generator self._generator = self._init_generator()
def __extract_parameters(self, name): """Extracts parameters in self._<name>_parameters from self.Parameters Allows the program to conveniently access a subset of user- adjusted parameters, which are stored in the Parameters attribute. Relies on the convention of providing dicts named according to "_<name>_parameters" and "_<name>_synonyms". The main parameters object is expected to be initialized with the contents of these dicts. This method will throw an exception if either convention is not adhered to. """ parameters = getattr(self, '_' + name + '_parameters') result = Parameters(parameters) for key in result.keys(): result[key] = self.Parameters[key] return result