mantidproject / mantid

Main repository for Mantid code
https://www.mantidproject.org
GNU General Public License v3.0
210 stars 123 forks source link

Fit function attributes: Allow validation of attribute values #33114

Closed martyngigg closed 2 years ago

martyngigg commented 2 years ago

Is your feature request related to a problem? Please describe. Fit functions define attributes to pass through values that are not part of the optimization set but can change how the function is evaluated, e.g the number of iterations of a loop. Our current system does not allow any validation/restriction on values that are allowed for these attributes beyond throwing exceptions in Function::setAttributeValue.

Recently it was desired to create a function that would accept a string attribute for the unit of evaluation of the function but the users want to ensure that the string could only have 2 values. Our code currently has very limited for possibilities for this at the framework level and the it is not possible to change the control at the GUI level at all without handwriting the code for that function.

Describe the solution you'd like

Extend the attribute system within fit functions to allow validators used for algorithm properties to be used with fit functions, e.g when writing a fit function I can do:

#include "MantidKernel/ListValidator.h"

using Mantid::Kernel::StringListValidator;

void FuncWithFixedAttributeValues::init() {
  declareAttribute("Unit", "K", StringListValidator({"K", "meV"}));
}

I see this feature being broken down in to several parts:

Describe alternatives you've considered The alternative is separate functions for each attribute value but this grows combinatorially with multiple attribute values.

Additional context

SilkeSchomann commented 2 years ago

Closed as all sub tasks are finished.