コード例 #1
0
 def __init__(self, groups=plugin_groups.keys(), search_path=None):
     super(PkgResourcesFactory, self).__init__()
     self._have_new_types = True
     self._groups = copy.copy(groups)
     self._search_path = search_path
     self.env = Environment(search_path)
     self.tree_analyser = PythonSourceTreeAnalyser()
コード例 #2
0
    def test_optproblems_solution(self):
        # test to make sure that at the specified solution point, the objective
        # values match what is given in the solution

        #find all the optproblems in lib
        startdirs = [os.path.dirname(openmdao.lib.optproblems.__file__),]
        psta = PythonSourceTreeAnalyser(startdirs, os.path.join('*','test','*'))
        opt_problems = psta.find_inheritors("openmdao.main.problem_formulation.OptProblem")

        for prob_name in opt_problems:
            #print "running %s"%prob_name
            prob_class = prob_name.split(".")[-1]
            prob_package = ".".join(prob_name.split(".")[:-1])
            prob_package = __import__(prob_package,globals(),locals(),[prob_class,],-1)

            prob = getattr(prob_package,prob_class)() #create instance of the OptProblem
            prob = set_as_top(prob)

            try:
                prob.check_solution(strict=True)
            except ValueError as err:
                self.fail("There is missing piece of the solution for %s%s"%(prob.__class__,str(err)))

            prob.architecture = OptProblemSolutionCheck()

            prob.run()

            error = prob.check_solution(strict=True)

            self.assertAccuracy(prob_name,error,.001)
コード例 #3
0
    def test_optproblems_solution(self):

        #find all the optproblems in lib
        startdirs = [
            os.path.dirname(openmdao.lib.optproblems.__file__),
        ]
        psta = PythonSourceTreeAnalyser(startdirs,
                                        os.path.join('*', 'test', '*'))
        opt_problems = psta.find_inheritors(
            "openmdao.main.problem_formulation.OptProblem")

        for prob_name in opt_problems:
            #print "running %s"%prob_name
            prob_class = prob_name.split(".")[-1]
            prob_package = ".".join(prob_name.split(".")[:-1])
            prob_package = __import__(prob_package, globals(), locals(), [
                prob_class,
            ], -1)

            prob = getattr(prob_package,
                           prob_class)()  #create instance of the OptProblem
            prob.architecture = OptProblemSolutionCheck()
            prob.configure()

            prob.run()

            error = prob.check_solution(strict=True)

            self.assertAccuracy(prob_name, error, .001)
コード例 #4
0
def build_optproblem_list(include=[], exclude=[]):
    """builds a list of optproblems
    
    include: (optional) list of optproblems names
        the names of the optproblems to test. Only optproblems in this list 
        will be tested. Each name should just be the class name (e.g. 'SellarProblem'). 
        Must be set to None, if excludes is specified. If not specified, 
        all OptProblems, except those in exclude are used. 
    
    exclude: (optional) list of optproblems names
        the names of the optproblems not to test. All optproblems from
        openmdao.lib.optproblems will be tested, except for the ones in this 
        list. Each name should just be the class name (e.g. 'SellarProblem'). 
        Must be set to None, if includes is specified. 
    """
    
    if include and exclude: 
        raise ValueError("Can't set both include and exlude")
    
    startdirs = [os.path.dirname(openmdao.lib.optproblems.__file__),
                 os.path.dirname(openmdao.main.__file__)]
    psta = PythonSourceTreeAnalyser(startdirs, os.path.join('*','test','*'))    
    opt_problems = psta.find_inheritors("openmdao.main.problem_formulation.OptProblem")
    
    probs = []
    for prob_name in opt_problems: 
            prob_class = prob_name.split(".")[-1]
            prob_package = ".".join(prob_name.split(".")[:-1])
            if  (not include and not exclude) or (include and prob_class in include) or \
                (exclude and prob_class not in exclude): 
                
                prob_package = __import__(prob_package,globals(),locals(),[prob_class,],-1)
                probs.append(getattr(prob_package,prob_class)()) #create instance of the OptProblem

    return probs
コード例 #5
0
def build_arch_list(include=[], exclude=[]):
    """builds a list of architectures
    
    include: list of architecture names
        the names of the architectures to test. Only architectures in this list 
        will be tested. Each name should just be the class name (e.g. 'MDF', 'CO'). 
        Must be set to None, if excludes is specified
    
    exclude: list of architecture names
        the names of the architectures not to test. All architectures from
        openmdao.lib.architectures will be tested, except for the ones in this 
        list. Each name should just be the class name (e.g. 'MDF', 'CO'). 
        Must be set to None, if includes is specified 
    """
    
    if include and exclude: 
        raise ValueError("Can't set both include and exlude")
    
    startdirs = [os.path.dirname(openmdao.lib.architectures.__file__),
                 os.path.dirname(openmdao.main.__file__)]
    psta = PythonSourceTreeAnalyser(startdirs, os.path.join('*','test','*'))    
    architectures = psta.find_inheritors("openmdao.main.arch.Architecture")
    archs = []
    for arch_name in architectures: 
            arch_class = arch_name.split(".")[-1]
            arch_package = ".".join(arch_name.split(".")[:-1])
            if  (not include and not exclude) or (include and arch_class in include) or \
                (exclude and arch_class not in exclude): 
                
                arch_package = __import__(arch_package,globals(),locals(),[arch_class,],-1)
                archs.append(getattr(arch_package,arch_class)()) #create instance of the Architecture

    return archs
コード例 #6
0
def find_all_plugins(searchdir):
    """Return a dict containing lists of each plugin type found, keyed by
    plugin group name, e.g., openmdao.component, openmdao.variable, etc.
    """
    dct = {}
    psta = PythonSourceTreeAnalyser(searchdir, exclude=_exclude_funct)

    for key, lst in plugin_groups.items():
        epset = set(psta.find_inheritors(lst[0]))
        if epset:
            dct[key] = epset
    return dct
コード例 #7
0
    def test_PythonSourceTreeAnalyser(self):

        skipdirs = set(
            ['test', 'docs', 'examples', 'optproblems', 'build', 'dist'])

        psta = PythonSourceTreeAnalyser(self.startdirs,
                                        direxclude=lambda d: d in skipdirs)

        self.assertTrue('openmdao.main.component.Component' in
                        psta.graph['openmdao.main.container.Container'])
        self.assertTrue('openmdao.main.assembly.Assembly' in
                        psta.graph['openmdao.main.component.Component'])

        self.assertTrue('openmdao.main.datatypes.float.Float' in
                        psta.graph['openmdao.main.variable.Variable'])

        comps = psta.find_inheritors('openmdao.main.component.Component')
        icomps = psta.find_inheritors('IComponent')

        self.assertTrue('openmdao.main.assembly.Assembly' in icomps)

        comps.extend(psta.find_inheritors('openmdao.main.variable.Variable'))
        comps.extend(psta.find_inheritors('traits.api.Array'))
        comps = [x.rsplit('.', 1)[1] for x in comps]
        cset = set(comps)
        excludes = set([
            'Driver',
            'DriverUsesDerivatives',
            'DistributionCaseDriver',
            'CaseIterDriverBase',
            'PassthroughTrait',
            'PassthroughProperty',
            'OptProblem',
            'TraitArray',
            'Broadcast',  # utility class for bliss2000
            'SubSystemOpt',  # utility class for bliss2000
            'SubSystemObj'  # utility class for bliss2000
        ])
        cset = cset - excludes

        from openmdao.main.api import get_available_types
        types = set([x[0] for x in get_available_types()])
        types = [
            x.rsplit('.', 1)[1] for x in types if x.startswith('openmdao.')
        ]

        tset = set(types)
        noentrypts = cset - tset
        if noentrypts:
            self.fail(
                "the following Components are not registered using entry points: %s"
                % noentrypts)
コード例 #8
0
    def __init__(self, watchdir, use_observer=True, observer=None):
        super(ProjDirFactory, self).__init__()
        self._lock = threading.RLock()
        self.watchdir = watchdir
        self.imported = {}  # imported files vs (module, ctor dict)
        try:
            self.analyzer = PythonSourceTreeAnalyser()

            added_set = set()
            changed_set = set()
            deleted_set = set()
            for pyfile in find_files(self.watchdir, "*.py"):
                self.on_modified(pyfile, added_set, changed_set, deleted_set)

            if use_observer:
                self._start_observer(observer)
                self.publish_updates(added_set, changed_set, deleted_set)
            else:
                self.observer = None  # sometimes for debugging/testing it's easier to turn observer off
        except Exception as err:
            logger.error(str(err))
コード例 #9
0
def _find_all_plugins(searchdir):
    """Return a dict containing lists of each plugin type found, keyed by
    plugin group name, e.g., openmdao.component, openmdao.variable, etc.
    """
    dct = {}
    modnames = [
        'openmdao.main', 'openmdao.lib.datatypes', 'openmdao.lib.components',
        'openmdao.lib.drivers', 'openmdao.lib.surrogatemodels',
        'openmdao.lib.doegenerators', 'openmdao.lib.differentiators',
        'openmdao.lib.optproblems', 'openmdao.lib.casehandlers',
        'openmdao.lib.architectures'
    ]

    modules = []
    for mod in modnames:
        try:
            __import__(mod)
        except ImportError:
            print 'skipping import of %s' % mod
        else:
            modules.append(sys.modules[mod])

    dirs = [os.path.dirname(m.__file__) for m in modules] + [searchdir]
    psta = PythonSourceTreeAnalyser(dirs, exclude=_exclude_funct)

    comps = psta.find_inheritors('IComponent')
    comps = set(comps)

    drivers = psta.find_inheritors('IDriver')
    drivers = set(drivers)

    comps = comps - drivers

    dct['openmdao.component'] = comps
    dct['openmdao.driver'] = drivers

    variables = psta.find_inheritors('IVariable')
    dct['openmdao.variable'] = set(variables)

    return dct
コード例 #10
0
    def test_PythonSourceTreeAnalyser(self):
        try:
            import openmdao.main
            import openmdao.lib
        except ImportError:
            # don't perform this test if openmdao.main
            # and openmdao.lib aren't present
            raise SkipTest("this test requires openmdao.main and openmdao.lib")

        def exclude_tests(pname):
            parts = pname.split(os.sep)
            return 'test' in parts

        startdirs = [
            os.path.dirname(openmdao.main.__file__),
            os.path.dirname(openmdao.lib.__file__)
        ]
        psta = PythonSourceTreeAnalyser(startdirs, exclude_tests)

        self.assertTrue('openmdao.main.component.Component' in
                        psta.graph['openmdao.main.container.Container'])
        self.assertTrue('openmdao.main.assembly.Assembly' in
                        psta.graph['openmdao.main.component.Component'])

        self.assertTrue('openmdao.main.datatypes.float.Float' in
                        psta.graph['openmdao.main.variable.Variable'])

        comps = psta.find_inheritors('openmdao.main.component.Component')
        icomps = psta.find_inheritors('IComponent')

        self.assertTrue('openmdao.main.assembly.Assembly' in icomps)

        comps.extend(psta.find_inheritors('openmdao.main.variable.Variable'))
        comps.extend(psta.find_inheritors('enthought.traits.api.Array'))
        comps = [
            x.rsplit('.', 1)[1] for x in comps
            if '.examples.' not in x and '.optproblems.' not in x
        ]
        cset = set(comps)
        excludes = set([
            'Driver',
            'DriverUsesDerivatives',
            'DistributionCaseDriver',
            'CaseIterDriverBase',
            'PassthroughTrait',
            'PassthroughProperty',
            'OptProblem',
            'TraitArray',
        ])
        cset = cset - excludes

        from openmdao.main.api import get_available_types
        types = set([x[0] for x in get_available_types()])
        types = [
            x.rsplit('.', 1)[1] for x in types if x.startswith('openmdao.')
        ]

        tset = set(types)
        noentrypts = cset - tset
        if noentrypts:
            self.fail(
                "the following Components are not registered using entry points: %s"
                % noentrypts)