def test_fix(self):
     g = FunctionWrapper( "Gaussian", Height=8.5, Sigma=1.2, PeakCentre=15)
     
     g.fix("Sigma")
     g_str = str(g)
     self.assertEqual(g_str.count("ties="),1)
     self.assertEqual(g_str.count("ties=(Sigma=1.2)"),1)
     
     g0 = FunctionWrapper( "Gaussian", Height=7.5, Sigma=1.2, PeakCentre=10)
     g1 = FunctionWrapper( "Gaussian", Height=8.5, Sigma=1.2, PeakCentre=11)
     c = CompositeFunctionWrapper(g0, g1)
     
     c.fix("f1.Sigma")
     c_str = str(c)
     self.assertEqual(c_str.count("ties="),1)
     self.assertEqual(c_str.count("ties=(Sigma=1.2"),1)
     
     # remove non-existent tie and test it has no effect
     c.untie("f1.Height")
     cu_str = str(c)
     self.assertEqual(c_str, cu_str)
     
     # remove actual tie
     c.untie("f1.Sigma")
     cz_str = str(c)
     self.assertEqual(cz_str.count("ties="),0)
 def test_fix(self):
     g = FunctionWrapper( "Gaussian", Height=8.5, Sigma=1.2, PeakCentre=15)
     
     g.fix("Sigma")
     g_str = str(g)
     self.assertEqual(g_str.count("ties="),1)
     self.assertEqual(g_str.count("ties=(Sigma=1.2)"),1)
     
     g0 = FunctionWrapper( "Gaussian", Height=7.5, Sigma=1.2, PeakCentre=10)
     g1 = FunctionWrapper( "Gaussian", Height=8.5, Sigma=1.2, PeakCentre=11)
     c = CompositeFunctionWrapper(g0, g1)
     
     c.fix("f1.Sigma")
     c_str = str(c)
     self.assertEqual(c_str.count("ties="),1)
     self.assertEqual(c_str.count("ties=(Sigma=1.2"),1)
     
     # remove non-existent tie and test it has no effect
     c.untie("f1.Height")
     cu_str = str(c)
     self.assertEqual(c_str, cu_str)
     
     # remove actual tie
     c.untie("f1.Sigma")
     cz_str = str(c)
     self.assertEqual(cz_str.count("ties="),0)
def do_a_fit(x, function, guess, target, fixes=None, atol=0.01):
    r"""Carry out a fit and compare to target parameters

    Parameters
    ----------
    x : sequence of floats
        Domain values for evaluating the function .
    function : str
        Registered function name.
    guess : dict
        Parameter names with their initial values.
    target : dict
        Parameter names with the values to be obtained after the fit.
    fixes : list
        List of fitting parameters to fix during the fit
    atol : float
        Absolute tolerance parameter when evaluating expected_output against
        output values.

    Returns
    -------
    list
        [0] Evaluation of the comparison between evaluated and expected values.
        [1] output of the call to Fit algorithm
    """
    target_model = FunctionWrapper(function, **target)
    y = target_model(x)
    e = np.ones(len(x))
    w = CreateWorkspace(x, y, e, Nspec=1)
    model = FunctionWrapper(function, **guess)
    if fixes is not None:
        [model.fix(p) for p in fixes]
    fit = Fit(model, w, NIterations=2000)
    otarget = OrderedDict(target)
    return np.allclose([fit.Function[p] for p in otarget.keys()],
                       list(otarget.values()), atol), fit