Ignore:
Timestamp:
Apr 23, 2015 9:54:49 PM (6 years ago)
Author:
toby
Message:

fix bug on with unused constraints and with chained equivalences; improve diagnostics from constraint errors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIImapvars.py

    r1778 r1805  
    353353                if mv not in indepVarList: indepVarList.append(mv)
    354354                for v,m in zip(varlist,invmultarr):
     355                    if v in indepVarList:
     356                        errmsg += '\nVariable '+v+' is used to set values in a constraint before its value is set in another constraint\n'
    355357                    if m == 0: zeromult = True
    356358                    if v in varyList:
     
    380382
    381383    # check for errors:
    382     if debug:
    383         print 'indepVarList',indepVarList
    384         print 'depVarList',depVarList
    385         print 'multdepVarList',multdepVarList
    386     inboth = set(indepVarList).intersection(set(depVarList))
    387     if len(inboth) > 0:
    388         errmsg += "\nThe following parameters(s) are used as both dependent and independent variables in Equivalence relations:\n"
    389         s = ''
    390         for var in sorted(inboth):
    391             if s != "": s+= ", "
    392             s += str(var)
    393         errmsg += '\t'+ s + '\n'
    394384    if len(multdepVarList) > 0:
    395         errmsg += "\nThe following parameters(s) are used in multiple Equivalence relations as dependent variables:\n"
     385        errmsg += "\nThe following parameters(s) are used in conflicting Equivalence relations as dependent variables:\n"
    396386        s = ''
    397387        for var in sorted(set(multdepVarList)):
     
    582572                for v,m in zip(varlist,invmultarr):
    583573                    if parmDict is not None and v not in parmDict:
    584                         print "Dropping equivalence for variable "+str(v)+". Not defined in this refinement"
     574                        print "Dropping equivalence for dep. variable "+str(v)+". Not defined in this refinement"
    585575                        continue
    586576                    if m == 0: zeromult = True
     
    609599                    s += str(v)           
    610600                msg += str(mv) + " => " + s + '\n'
    611 
    612     if debug: print 'indepVarList',indepVarList
    613     if debug: print 'depVarList',depVarList
    614     # check for errors:
    615     inboth = set(indepVarList).intersection(set(depVarList))
    616     if len(inboth) > 0:
    617         msg += "\nThe following parameters(s) are used as both dependent and independent variables in Equivalence relations:\n"
    618         s = ''
    619         for var in sorted(inboth):
    620             if s != "": s+= ", "
    621             s += str(var)
    622         msg += '\t'+ s + '\n'
    623     if len(multdepVarList) > 0:
    624         msg += "\nThe following parameters(s) are used in multiple Equivalence relations as dependent variables:\n"
    625         s = ''
    626         for var in sorted(set(multdepVarList)):
    627             if s != "": s+= ", "
    628             s += str(var)           
    629         msg += '\t'+ s + '\n'
     601    # save the lists of dep. and indep. vars (after dropping unused)
     602    global dependentVars,independentVars
     603    dependentVars = depVarList
     604    independentVars = indepVarList
    630605    equivVarList = list(set(indepVarList).union(set(depVarList)))
    631606
     
    817792
    818793    '''
    819     dependentVars = []
    820     global dependentParmList
    821     for lst in dependentParmList:
    822         for itm in lst: dependentVars.append(itm)
    823794    return dependentVars
    824795
     
    830801
    831802    '''
    832     independentVars = []
    833     global indParmList,fixedDict
    834     for lst in indParmList:
    835         for name in lst:
    836             if name in fixedDict: continue
    837             independentVars.append(name)
    838803    return independentVars
    839804
     
    922887    return s1
    923888
    924 def VarRemapShow(varyList):
     889def VarRemapShow(varyList,inputOnly=False):
    925890    '''List out the saved relationships. This should be done after the constraints have been
    926891    defined using :func:`StoreEquivalence`, :func:`GroupConstraints` and :func:`GenerateConstraints`.
     
    959924            if mv in varyList: s += ' VARY'
    960925            s += '\n'
     926    if inputOnly: return s
    961927    s += 'Inverse variable mapping relations:\n'
    962928    for varlist,mapvars,invmultarr in zip(dependentParmList,indParmList,invarrayList):
     
    1013979    defined using :func:`StoreEquivalence`,
    1014980    :func:`GroupConstraints` and :func:`GenerateConstraints` and
    1015     before any variable refinement is done
    1016     to complete the parameter dictionary by defining independent
    1017     parameters and satisfying the constraint equations.
     981    before any variable refinement is done. This completes the parameter
     982    dictionary by defining independent parameters and it satisfies the
     983    constraint equations in the initial parameters
    1018984
    1019985    :param dict parmDict: a dict containing parameter values keyed by the
Note: See TracChangeset for help on using the changeset viewer.