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', '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)
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)
def test_PythonSourceTreeAnalyser(self): def exclude(pname): keywords = set(["test", "docs", "examples", "optproblems"]) parts = set(pname.split(os.sep)) return keywords.intersection(parts) psta = PythonSourceTreeAnalyser(self.startdirs, exclude) 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] # 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", "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)
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)
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 be just 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 be just 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
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)
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 be just 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 for OptProblems") 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
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
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
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)
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) for key, val in plugin_groups.items(): dct[key] = set(psta.find_inheritors(val)) return dct
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") startdirs = [os.path.dirname(openmdao.main.__file__), os.path.dirname(openmdao.lib.__file__)] psta = PythonSourceTreeAnalyser(startdirs, os.path.join('*','test','*')) 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.lib.datatypes.float.Float' in psta.graph['openmdao.main.variable.Variable']) comps = psta.find_inheritors('openmdao.main.component.Component') 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] comps.remove('Driver') comps.remove('DriverUsesDerivatives') comps.remove('CaseIterDriverBase') comps.remove('PassthroughTrait') comps.remove('PassthroughProperty') from openmdao.main.api import get_available_types groups = [ 'openmdao.component', 'openmdao.driver', 'openmdao.variable'] types = set([x[0] for x in get_available_types(groups)]) types = [x.rsplit('.',1)[1] for x in types if x.startswith('openmdao.')] cset = set(comps) tset = set(types) noentrypts = cset-tset if noentrypts: self.fail("the following Components are not registered using entry points: %s" % noentrypts)
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
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
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
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) comps = psta.find_inheritors('openmdao.main.component.Component') comps.extend(psta.find_inheritors('openmdao.main.api.Component')) comps = set(comps) drivers = psta.find_inheritors('openmdao.main.driver.Driver') drivers.extend(psta.find_inheritors('openmdao.main.api.Driver')) drivers = set(drivers) comps = comps - drivers dct['openmdao.component'] = comps dct['openmdao.driver'] = drivers variables = psta.find_inheritors('openmdao.main.api.Variable') variables.extend(psta.find_inheritors('openmdao.main.variable.Variable')) dct['openmdao.variable'] = set(variables) return dct
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)
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)