示例#1
0
def validate(args):
    """Validates test data"""
    if args.name is not None:
        model = DEFAULT_MODEL_DICT[args.name]
        if not args.test_data:
            test_wrapper(model.validate_from_preset_test, pdb)
            print("Model validated with test data")
            return True
    elif args.file is not None:
        if args.file.endswith(".yaml"):
            EquationModel.from_file(args.file)
        elif args.file.endswith(".py"):
            # This should define config
            with open(args.file) as this_file:
                code = compile(this_file.read(), args.file, 'exec')
                exec(code, globals())
            config = globals().get('config')
            model = PyModel(**config)

    if args.test_data is not None:
        td_data = loadfn(args.test_data)
        for td_datum in td_data:
            test_wrapper(model.test, args.pdb, **td_datum)
        print("{} validated with test data".format(model.name))
    return True
示例#2
0
def add_builtin_models_to_registry(register_symbols=True):
    _EQUATION_MODEL_NAMES_LIST.clear()
    # Load equation models
    equation_model_dir = os.path.join(os.path.dirname(__file__))
    equation_module_files = glob(equation_model_dir + '/*.yaml')

    if register_symbols:
        from propnet.symbols import add_builtin_symbols_to_registry
        add_builtin_symbols_to_registry()
    for filename in equation_module_files:
        model_path = os.path.join(equation_model_dir, filename)
        model = EquationModel.from_file(model_path,
                                        is_builtin=True,
                                        overwrite_registry=True)
        globals()[model.name] = model
        _EQUATION_MODEL_NAMES_LIST.append(model.name)
示例#3
0
from pkgutil import iter_modules
import os
from propnet.core.models import EquationModel, PyModuleModel,\
    PyModuleCompositeModel
from propnet.models import python, composite
from glob import glob

DEFAULT_MODELS = []
DEFAULT_COMPOSITE_MODELS = []

# Load equation models
EQUATION_MODEL_DIR = os.path.join(os.path.dirname(__file__), "serialized")
EQUATION_MODULE_FILES = glob(EQUATION_MODEL_DIR + '/*.yaml')
for filename in EQUATION_MODULE_FILES:
    model_path = os.path.join(EQUATION_MODEL_DIR, filename)
    model = EquationModel.from_file(model_path)
    DEFAULT_MODELS.append(model)

# Load python models
MODULE_LIST = iter_modules(python.__path__)
for _, module_name, _ in MODULE_LIST:
    module_path = "propnet.models.python.{}".format(module_name)
    DEFAULT_MODELS.append(PyModuleModel(module_path))

DEFAULT_MODEL_DICT = {d.name: d for d in DEFAULT_MODELS}
DEFAULT_MODEL_NAMES = list(DEFAULT_MODEL_DICT.keys())

# Load composite models
COMPOSITE_MODULE_LIST = iter_modules(composite.__path__)
for _, module_name, _ in COMPOSITE_MODULE_LIST:
    module_path = "propnet.models.composite.{}".format(module_name)