def test_name_collisions(): param_space = ParameterSpace() for _ in range(4): param = Parameter(name=f'param_{_}') param_space.add(param) param_space.add(Parameter(name='param_0')) assert len(Logger.ERRORS) == 1 Logger.purge()
def test_dict_conversion(): param_orig = Parameter(name='temperature') param_dict = param_orig.to_dict() param_dict['low'] = 0. param_dict['high'] = 273. param_conv = Parameter().from_dict(param_dict) assert param_conv.low == param_dict['low'] assert param_conv.high == param_dict['high'] assert param_conv.name == param_orig.name
def test_json_conversion(): param_orig = Parameter(name='temperature') param_json = param_orig.to_json() param_dict = json.loads(param_json) param_dict['low'] = 0. param_dict['high'] = 273. param_conv = Parameter().from_json(json.dumps(param_dict)) assert param_conv.low == param_dict['low'] assert param_conv.high == param_dict['high'] assert param_conv.name == param_orig.name
def test_single_parameter(): param_space = ParameterSpace() param = Parameter() param_space.add(param) assert param_space.param_names == ['parameter'] for attr in ['name', 'type', 'low', 'high']: assert getattr(param_space[0], attr) == getattr(param, attr)
def test_parameter_ordering(): param_space = ParameterSpace() for _ in range(4): param = Parameter(name='param_{}'.format(_)) param_space.add(param) for _, param in enumerate(param_space): assert param.name == 'param_{}'.format(_)
def test_from_functions(): param_0 = Parameter(name='p0', type='continuous', low=0.0, high=1.0) param_1 = Parameter(name='p1', type='continuous', low=0.0, high=1.0) param_space = ParameterSpace() param_space.add([param_0, param_1]) # from array paramvector0 = ParameterVector().from_array([0.1, 0.2], param_space) # from dictionary paramvector1 = ParameterVector().from_dict({'p0': 0.1, 'p1': 0.2}) for attr0, attr1 in zip(paramvector0.attrs, paramvector1.attrs): assert attr0 == attr1 for prop0, prop1 in zip(paramvector0.props, paramvector1.props): assert prop0 == prop1
Args: goal (str): The optimization goal, either 'minimize' or 'maximize'. Default is 'minimize'. disp (bool): Set to True to print convergence messages. maxiter (int): Maximum number of iterations to perform. gtol (float): Gradient norm must be less than gtol before successful termination. norm (float): Order of norm (Inf is max, -Inf is min). eps (float or ndarray): If jac is approximated, use this value for the step size. init_guess (array, optional): initial guess for the optimization init_guess_method (str): method to construct initial guesses if init_guess is not provided. Choose from: random init_guess_seed (str): random seed for init_guess_method """ WrapperScipy.__init__(**locals()) #=============================================================================== if __name__ == '__main__': from olympus import Parameter, ParameterSpace param_space = ParameterSpace() param_space.add(Parameter(name='param_0')) param_space.add(Parameter(name='param_1')) planner = ConjugateGradient() planner.set_param_space(param_space=param_space) param = planner.ask() print('PARAM', param)
def two_param_space(): param_space = ParameterSpace() param_space.add(Parameter(name='param_0')) param_space.add(Parameter(name='param_1')) return param_space
def test_multiple_parameters(): param_space = ParameterSpace() params = [Parameter(name=f'param_{_}') for _ in range(4)] param_space.add(params) assert param_space.param_names == [f'param_{_}' for _ in range(4)]
def test_abstract_parameter_set_low_high_invalid(): param = Parameter(low=1.0, high=0.0) assert len(Logger.WARNINGS) >= 1
def test_abstract_parameter_dict_conversion(name, param_type, low, high): param_orig = Parameter(name = name, type = param_type, low = low, high = high) param_dict = param_orig.to_dict() param_conv = Parameter().from_dict(param_dict) for attr in ['name', 'type', 'low', 'high']: assert param_conv.get(attr) == param_orig.get(attr)
def test_abstract_parameter(name, paramtype, low, high): param = Parameter(name=name, type=paramtype, low=low, high=high) for attr, value in {'name': name, 'type': paramtype, 'low': low, 'high': high}.items(): assert param[attr] == value
def test_abstract_parameter_defaults(): param = Parameter() for attr, value in {'name': 'parameter', 'type': 'continuous', 'low': 0.0, 'high': 1.0}.items(): assert param[attr] == value
def test_update(): param = Parameter(name='temperature') param.update('name', 'pressure') assert param.name == 'pressure'
def test_set_get_methods_generation(): param = Parameter(name='temperature') param.set_name('pressure') assert param.get_name() == 'pressure'
def test_contains(): param = Parameter() assert 'name' in param