Submodules module

class, param_list=None, data=None)[source]

Bases: object

Storing fit result


Bases: exceptions.Exception

Exception raise to stop the fit


add_data fill a self.data_list with data to fit

Parameters:data – Data to add in the list
Returns:list of data data_list
Returns:saved model

return self.selected value


Remove one element from the list

Parameters:data – Data to remove from data_list

set_model save a copy of the model

Parameters:model – the model being set

set self.selected to 0 or 1 for other values raise an exception

Parameters:value – integer between 0 or 1
class, y, dx=None, dy=None, smearer=None, data=None, lam=None, dlam=None)[source]

Bases: sas.sascalc.dataloader.data_info.Data1D

Wrapper class for SAS data FitData1D inherits from DataLoader.data_info.Data1D. Implements a way to get residuals from data.


Return the range of data.x to fit


Compute residuals.

If self.smearer has been set, use if to smear the data before computing chi squared.

Parameters:fn – function that return model value
residuals_deriv(model, pars=[])[source]
Returns:residuals derivatives .
Note:in this case just return empty array
set_fit_range(qmin=None, qmax=None)[source]

to set the fit range


Number of measurement points in data set after masking, etc.

class, data=None, err_data=None)[source]

Bases: sas.sascalc.dataloader.data_info.Data2D

Wrapper class for SAS data


return the range of data.x to fit


return the residuals

residuals_deriv(model, pars=[])[source]
Returns:residuals derivatives .
Note:in this case just return empty array
set_data(sas_data2d, qmin=None, qmax=None)[source]

Determine the correct qx_data and qy_data within range to fit

set_fit_range(qmin=None, qmax=None)[source]

To set the fit range


Set smearer


Number of measurement points in data set after masking, etc.

Parameters:id – id is key in the dictionary containing the model to return
Returns:a model at this id or None if no FitArrange element was created with this id

return the self.selected value of the fit problem of id

Parameters:id – the id of the problem

remove fitarrange in id

select_problem_for_fit(id, value)[source]

select a couple of model and data at the id position in dictionary and set in self.selected value to value

Parameters:value – the value to allow fitting. can only have the value one or zero
set_data(data, id, smearer=None, qmin=None, qmax=None)[source]

Receives plottable, creates a list of data to fit,set data in a FitArrange object and adds that object in a dictionary with key id.

  • data – data added
  • id – unique key corresponding to a fitArrange object with data
set_model(model, id, pars=[], constraints=[], data=None)[source]

set a model on a given in the fit engine.

  • model – sas.models type
  • id – is the key of the fitArrange dictionary where model is saved as a value
  • pars – the list of parameters to fit
  • constraints – list of tuple (name of parameter, value of parameters) the value of parameter must be a string to constraint 2 different parameters. Example: we want to fit 2 model M1 and M2 both have parameters A and B. constraints can be constraints = [(M1.A, M2.B+2), (M1.B= M2.A *5),...,]

pars must contains only name of existing model’s parameters


Bases: object

Abstract interface for fit thread handler.

The methods in this class are called by the optimizer as the fit progresses.

Note that it is up to the optimizer to call the fit handler correctly, reporting all status changes and maintaining the ‘done’ flag.


Fit was aborted.

done = False

True when the fit job is complete


Model had an error; print traceback


Fit is complete; best results are reported


Called when a result is observed which is better than previous results from the fit.

result is a FitResult object, with parameters, #calls and fitness.

progress(current, expected)[source]

Called each cycle of the fit, reporting the current and the expected amount of work. The meaning of these values is optimizer dependent, but they can be converted into a percent complete using (100*current)//expected.

Progress is updated each iteration of the fit, whatever that means for the particular optimization algorithm. It is called after any calls to improvement for the iteration so that the update handler can control I/O bandwidth by suppressing intermediate improvements until the fit is complete.

result = None

The current best result of the fit

class, sas_data=None, **kw)[source]

Fit wrapper for SAS models.


Override eval method of model.

Parameters:x – the x value used to compute a function
eval_derivs(x, pars=[])[source]

Evaluate the model and derivatives wrt pars at x.

pars is a list of the names of the parameters for which derivatives are desired.

This method needs to be specialized in the model to evaluate the model function. Alternatively, the model can implement is own version of residuals which calculates the residuals directly instead of calling eval.


return a list of value of paramter to fit

Parameters:fitparams – list of paramaters name to fit
set_params(paramlist, params)[source]

Set value for parameters to fit

Parameters:params – list of value for parameters to fit module

BumpsFitting module runs the bumps optimizer.



Fit a model using bumps.

fit(msg_q=None, q=None, handler=None, curr_thread=None, ftol=1.49012e-08, reset_flag=False)[source]
class, max_step, pars, dof)[source]

Bases: object


Bases: object

ConvergenceMonitor contains population summary statistics to show progress of the fit. This is a list [ (best, 0%, 25%, 50%, 75%, 100%) ] or just a list [ (best, ) ] if population size is 1.


Bases: object

class, max_step, pars, dof)[source]

Bases: object

class, data, fitted=[], constraints={}, initial_values=None, **kw)[source]

Bases: object

Wrap SAS model as a bumps fitness object


Flag a set of parameters as fitted parameters.

update()[source][source], handler, curr_thread)[source] module

class, y=None, dx=None, dy=None)[source]

This class is loading values from given file or value giving by the user


return the file’s path


Return x, y, dx, dy


Return plottable


Store path into a variable.If the user doesn’t give a path as a parameter a pop-up window appears to select the file.

Parameters:path – the path given by the user

Store the values loaded from file in local variables module

class, s_model)[source]

Bases: sas.sascalc.calculator.BaseComponent.BaseComponent

Use for P(Q)*S(Q); function call must be in the order of P(Q) and then S(Q): The model parameters are combined from both models, P(Q) and S(Q), except 1) ‘radius_effective’ of S(Q) which will be calculated from P(Q) via calculate_ER(), and 2) ‘scale’ in P model which is synchronized w/ volfraction in S then P*S is multiplied by a new parameter, ‘scale_factor’. The polydispersion is applicable only to P(Q), not to S(Q).


P(Q) refers to ‘form factor’ model while S(Q) does to ‘structure factor’.


Evaluate the model in cartesian coordinates

Parameters:x – input q[], or [qx[], qy[]]
Returns:scattering function P(q[])
fill_description(p_model, s_model)[source]

Fill the description for P(Q)*S(Q)


Get SLD profile of p_model if exists

Returns:(r, beta) where r is a list of radius of the transition points beta is a list of the corresponding SLD values


This works only for func_shell num = 2 (exp function).


Evaluate the model

Parameters:x – input q-value (float or [float, float] as [r, theta])
Returns:(scattering function value)

Evaluate the model

Parameters:x – input q-value (float or [float, float] as [qx, qy])
Returns:scattering function value
setParam(name, value)[source]

Set the value of a model parameter

  • name – name of the parameter
  • value – value of the parameter
set_dispersion(parameter, dispersion)[source]

Set the dispersion object for a model parameter

Parameters:parameter – name of the parameter [string]
Dispersion:dispersion object of type DispersionModel module

Parameter expression evaluator.

For systems in which constraints are expressed as string expressions rather than python code, compile_constraints() can construct an expression evaluator that substitutes the computed values of the expressions into the parameters.

The compiler requires a symbol table, an expression set and a context. The symbol table maps strings containing fully qualified names such as ‘M1.c[3].full_width’ to parameter objects with a ‘value’ property that can be queried and set. The expression set maps symbol names from the symbol table to string expressions. The context provides additional symbols for the expressions in addition to the usual mathematical functions and constants.

The expressions are compiled and interpreted by python, with only minimal effort to make sure that they don’t contain bad code. The resulting constraints function returns 0 so it can be used directly in a fit problem definition.

Extracting the symbol table from the model depends on the structure of the model. If fitness.parameters() is set correctly, then this should simply be a matter of walking the parameter data, remembering the path to each parameter in the symbol table. For compactness, dictionary elements should be referenced by .name rather than [“name”]. Model name can be used as the top level.

Getting the parameter expressions applied correctly is challenging. The following monkey patch works by overriding model_update in FitProblem so that after setp(p) is called and, the constraints expression can be applied before telling the underlying fitness function that the model is out of date:

# Override model update so that parameter constraints are applied
problem._model_update = problem.model_update
def model_update():
problem.model_update = model_update

Ideally, this interface will change, exprs, context={})[source]

Build and return a function to evaluate all parameter expressions in the proper order.


symtab is the symbol table for the model: { ‘name’: parameter }

exprs is the set of computed symbols: { ‘name’: ‘expression’ }

context is any additional context needed to evaluate the expression


updater function which sets parameter.value for each expression


AssertionError - model, parameter or function is missing

SyntaxError - improper expression syntax

ValueError - expressions have circular dependencies

This function is not terribly sophisticated, and it would be easy to trick. However it handles the common cases cleanly and generates reasonable messages for the common errors.

This code has not been fully audited for security. While we have removed the builtins and the ability to import modules, there may be other vectors for users to perform more than simple function evaluations. Unauthenticated users should not be running this code.

Parameter names are assumed to contain only _.a-zA-Z0-9#[]

Both names are provided for inverse functions, e.g., acos and arccos.

Should try running the function to identify syntax errors before running it in a fit.

Use help(fn) to see the code generated for the returned function fn. dis.dis(fn) will show the corresponding python vm instructions.[source]

This parameter set has no constraints between the parameters.[source]

Order elements from pairs so that b comes before a in the ordered list for all pairs (a,b).[source][source] module

class'Plugin Model')[source]

Bases: sas.sascalc.calculator.BaseComponent.BaseComponent


Function to be implemented by the plug-in writer

is_multiplicity_model = False

Evaluate the model

Parameters:x – input x, or [x, phi] [radian]
Returns:function value

Evaluate the model

Parameters:x – input x, or [x, y]
Returns:function value

Set default details

Module contents