Changeset 72a081d in sasmodels for sasmodels/compare.py


Ignore:
Timestamp:
Mar 19, 2016 6:52:46 AM (8 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
f3d7abd
Parents:
ce43de0
Message:

refactor product/mixture; add load model from path; default compare to -cutoff=0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/compare.py

    raf92b73 r72a081d  
    369369            model = MultiplicationModel(P, S) 
    370370        else: 
    371             raise ValueError("mixture models not handled yet") 
     371            raise ValueError("sasview mixture models not supported by compare") 
    372372    else: 
    373373        model = get_model(model_info['oldname']) 
     
    424424    Return a model calculator using the OpenCL calculation engine. 
    425425    """ 
    426     def builder(model_info): 
    427         try: 
    428             return core.build_model(model_info, dtype=dtype, platform="ocl") 
    429         except Exception as exc: 
    430             print(exc) 
    431             print("... trying again with single precision") 
    432             return core.build_model(model_info, dtype='single', platform="ocl") 
    433     if model_info['composition']: 
    434         composition_type, parts = model_info['composition'] 
    435         if composition_type == 'product': 
    436             P, S = [builder(p) for p in parts] 
    437             model = product.ProductModel(P, S) 
    438         else: 
    439             raise ValueError("mixture models not handled yet") 
    440     else: 
    441         model = builder(model_info) 
     426    try: 
     427        model = core.build_model(model_info, dtype=dtype, platform="ocl") 
     428    except Exception as exc: 
     429        print(exc) 
     430        print("... trying again with single precision") 
     431        model = core.build_model(model_info, dtype='single', platform="ocl") 
    442432    calculator = DirectModel(data, model, cutoff=cutoff) 
    443433    calculator.engine = "OCL%s"%DTYPE_MAP[dtype] 
     
    450440    if dtype == 'quad': 
    451441        dtype = 'longdouble' 
    452     def builder(model_info): 
    453         return core.build_model(model_info, dtype=dtype, platform="dll") 
    454  
    455     if model_info['composition']: 
    456         composition_type, parts = model_info['composition'] 
    457         if composition_type == 'product': 
    458             P, S = [builder(p) for p in parts] 
    459             model = product.ProductModel(P, S) 
    460         else: 
    461             raise ValueError("mixture models not handled yet") 
    462     else: 
    463         model = builder(model_info) 
     442    model = core.build_model(model_info, dtype=dtype, platform="dll") 
    464443    calculator = DirectModel(data, model, cutoff=cutoff) 
    465444    calculator.engine = "OMP%s"%DTYPE_MAP[dtype] 
     
    715694        print("expected parameters: model N1 N2") 
    716695 
    717     def _get_info(name): 
    718         try: 
    719             model_info = core.load_model_info(name) 
    720         except ImportError, exc: 
    721             print(str(exc)) 
    722             print("Use one of:\n    " + models) 
    723             sys.exit(1) 
    724         return model_info 
    725  
    726696    name = args[0] 
    727     if '*' in name: 
    728         parts = [_get_info(k) for k in name.split('*')] 
    729         model_info = product.make_product_info(*parts) 
    730     else: 
    731         model_info = _get_info(name) 
     697    try: 
     698        model_info = core.load_model_info(name) 
     699    except ImportError, exc: 
     700        print(str(exc)) 
     701        print("Could not find model; use one of:\n    " + models) 
     702        sys.exit(1) 
    732703 
    733704    invalid = [o[1:] for o in flags 
     
    749720        'res'       : 0.0, 
    750721        'accuracy'  : 'Low', 
    751         'cutoff'    : 1e-5, 
     722        'cutoff'    : 0.0, 
    752723        'seed'      : -1,  # default to preset 
    753724        'mono'      : False, 
Note: See TracChangeset for help on using the changeset viewer.