Beispiel #1
0
def main():
    from argparse import ArgumentParser
    import inspect

    from openmdao.main.assembly import Assembly, set_as_top

    parser = ArgumentParser()
    parser.add_argument('-m', '--module', action='store', dest='module',
                        metavar='MODULE',
                        help='name of module that contains the class to be instantiated and graphed')
    parser.add_argument('-c', '--class', action='store', dest='klass',
                        help='specify class in module to plot graphs for')
    parser.add_argument('-f', '--fmt', action='store', dest='fmt', default='pdf',
                        help='specify output format')
    parser.add_argument('-r', '--recurse', action='store_true', dest='recurse',
                        help='if set, recurse down and plot all dependency, component,  and derivative graphs')
    parser.add_argument('-p', '--pseudos', action='store_false', dest='pseudos',
                        help='if set, include pseudo components in graphs')
    parser.add_argument('-w', '--workflow', action='store_true', dest='workflow',
                        help='if set, group graph components into workflows')


    options = parser.parse_args()

    if options.module is None:
        parser.print_help()
        sys.exit(-1)

    __import__(options.module)

    mod = sys.modules[options.module]

    if options.klass:
        obj = getattr(mod, options.klass)()
    else:
        def isasm(obj):
            try:
                return issubclass(obj, Assembly) and obj is not Assembly
            except:
                return False

        klasses = inspect.getmembers(mod, isasm)
        if len(klasses) > 1:
            print "found %d Assembly classes. you must specify 1" % len(klasses)
            for i, (cname, klass) in enumerate(klasses):
                print "%d) %s" % (i, cname)
            var = raw_input("\nEnter a number: ")
            obj = klasses[int(var)][1]()
            sys.exit(-1)
        elif klasses:
            obj = klasses[0][1]()
        else:
            print "No classes found"

    set_as_top(obj)
    if not obj.get_pathname():
        obj.name = 'top'

    plot_graphs(obj, recurse=options.recurse, fmt=options.fmt, pseudos=options.pseudos,
                workflow=options.workflow)
def main():
    from argparse import ArgumentParser
    import inspect

    from openmdao.main.assembly import Assembly, set_as_top

    parser = ArgumentParser()
    parser.add_argument('-m', '--module', action='store', dest='module',
                        metavar='MODULE',
                        help='name of module that contains the class to be instantiated and graphed')
    parser.add_argument('-c', '--class', action='store', dest='klass',
                        help='specify class in module to plot graphs for')
    parser.add_argument('-f', '--fmt', action='store', dest='fmt', default='pdf',
                        help='specify output format')
    parser.add_argument('-r', '--recurse', action='store_true', dest='recurse',
                        help='if set, recurse down and plot all dependency, component,  and derivative graphs')
    parser.add_argument('-p', '--pseudos', action='store_false', dest='pseudos',
                        help='if set, include pseudo components in graphs')
    parser.add_argument('-w', '--workflow', action='store_true', dest='workflow',
                        help='if set, group graph components into workflows')


    options = parser.parse_args()

    if options.module is None:
        parser.print_help()
        sys.exit(-1)

    __import__(options.module)

    mod = sys.modules[options.module]

    if options.klass:
        obj = getattr(mod, options.klass)()
    else:
        def isasm(obj):
            try:
                return issubclass(obj, Assembly) and obj is not Assembly
            except:
                return False

        klasses = inspect.getmembers(mod, isasm)
        if len(klasses) > 1:
            print "found %d Assembly classes. you must specify 1" % len(klasses)
            for i, (cname, klass) in enumerate(klasses):
                print "%d) %s" % (i, cname)
            var = raw_input("\nEnter a number: ")
            obj = klasses[int(var)][1]()
            sys.exit(-1)
        elif klasses:
            obj = klasses[0][1]()
        else:
            print "No classes found"

    set_as_top(obj)
    if not obj.get_pathname():
        obj.name = 'top'

    plot_graphs(obj, recurse=options.recurse, fmt=options.fmt, pseudos=options.pseudos,
                workflow=options.workflow)
def main():
    from argparse import ArgumentParser
    import inspect

    from openmdao.main.assembly import Assembly, set_as_top

    parser = ArgumentParser()
    parser.add_argument(
        '-m',
        '--module',
        action='store',
        dest='module',
        metavar='MODULE',
        help=
        'name of module that contains the class to be instantiated and graphed'
    )
    parser.add_argument('-c',
                        '--class',
                        action='store',
                        dest='klass',
                        help='boolean expression to filter hosts')
    parser.add_argument(
        '-r',
        '--recurse',
        action='store_true',
        dest='recurse',
        help=
        'if set, recurse down and plot all dependency and derivative graphs')

    options = parser.parse_args()

    if options.module is None:
        parser.print_help()
        sys.exit(-1)

    __import__(options.module)

    mod = sys.modules[options.module]

    if options.klass:
        obj = getattr(mod, options.klass)()
    else:

        def isasm(obj):
            return issubclass(obj, Assembly)

        klasses = inspect.getmembers(mod, isasm)
        if len(klasses) > 1:
            print "found %d Assembly classes.  pick one" % len(klasses)
            for i, klass in enumerate(klasses):
                print "%d) %s" % (i, klass.__name__)
            var = raw_input("\nEnter a number: ")
            obj = klasses[int(var)]

    set_as_top(obj)
    if not obj.get_pathname():
        obj.name = 'top'

    plot_graphs(obj, recurse=options.recurse)
def main():
    from argparse import ArgumentParser
    import inspect

    from openmdao.main.assembly import Assembly, set_as_top

    parser = ArgumentParser()
    parser.add_argument(
        "-m",
        "--module",
        action="store",
        dest="module",
        metavar="MODULE",
        help="name of module that contains the class to be instantiated and graphed",
    )
    parser.add_argument("-c", "--class", action="store", dest="klass", help="boolean expression to filter hosts")
    parser.add_argument(
        "-r",
        "--recurse",
        action="store_true",
        dest="recurse",
        help="if set, recurse down and plot all dependency and derivative graphs",
    )

    options = parser.parse_args()

    if options.module is None:
        parser.print_help()
        sys.exit(-1)

    __import__(options.module)

    mod = sys.modules[options.module]

    if options.klass:
        obj = getattr(mod, options.klass)()
    else:

        def isasm(obj):
            return issubclass(obj, Assembly)

        klasses = inspect.getmembers(mod, isasm)
        if len(klasses) > 1:
            print "found %d Assembly classes.  pick one" % len(klasses)
            for i, klass in enumerate(klasses):
                print "%d) %s" % (i, klass.__name__)
            var = raw_input("\nEnter a number: ")
            obj = klasses[int(var)]

    set_as_top(obj)
    if not obj.get_pathname():
        obj.name = "top"

    plot_graphs(obj, recurse=options.recurse)
Beispiel #5
0
    def __init__(self, projpath):
        """Initializes a Project containing the project found in the 
        specified directory or creates a new project if one doesn't exist.
        
        projpath: str
            Path to the project's directory.
        """
        self.path = expand_path(projpath)
        modeldir = os.path.join(self.path, 'model')
        self.activate()
        if os.path.isdir(projpath):
            # locate file containing state, create it if it doesn't exist
            statefile = os.path.join(projpath, '_project_state')
            if os.path.exists(statefile):
                try:
                    with open(statefile, 'r') as f:
                        self.__dict__ = pickle.load(f)
                except Exception, e:
                    print 'Unable to restore project state:', e
                    self.top = Assembly()
            else:
                self.top = set_as_top(Assembly())

            self.path = expand_path(
                projpath)  # set again in case loading project state changed it
def make_graph(nodes=(), connections=()):
    scope = set_as_top(Assembly())
    sub = scope.add('sub', Assembly())
    dep = ExprMapper(sub)
    for name in nodes:
        if name.startswith('parent.'):
            scope.add(name.split('.', 1)[1], Simple())
        else:
            sub.add(name, Simple())
            #dep.add(name)
    for src, dest in connections:
        if '.' not in src and not sub.contains(src):
            if dest.startswith('parent.'):
                iotype = 'out'
            else:
                iotype = 'in'
            sub.add(src, Int(1, iotype=iotype))
        if '.' not in dest and not sub.contains(dest):
            if src.startswith('parent.'):
                iotype = 'in'
            else:
                iotype = 'out'
            sub.add(dest, Int(1, iotype=iotype))
        dep.connect(ExprEvaluator(src, sub), ExprEvaluator(dest, sub), sub)
    return dep, sub
Beispiel #7
0
    def __init__(self, projpath):
        """Initializes a Project containing the project found in the 
        specified directory or creates a new project if one doesn't exist.
        
        projpath: str
            Path to the project's directory
        """
        self.path = expand_path(projpath)
        modeldir = os.path.join(self.path, 'model')
        self.activate()
        if os.path.isdir(projpath):
            # I don't think model dir and state should be manadatory
            # e.g. when creating a project from an existing non-Project directory
            # if not _is_valid_project_dir(projpath):
                # raise RuntimeError("Directory '%s' is not a valid OpenMDAO project directory")

            # locate file containing state, create it if it doesn't exist
            statefile = os.path.join(projpath, '_project_state')
            if os.path.exists(statefile):
                try:
                    with open(statefile, 'r') as f:
                        self.__dict__ = pickle.load(f)
                except Exception, e:
                    print 'Unable to restore project state:',e
                    self.top = Assembly()
            else:
                self.top = set_as_top(Assembly())
            
            self.path = expand_path(projpath) # set again in case loading project state changed it
def make_graph(nodes=(), connections=()):
    scope = set_as_top(Assembly())
    sub = scope.add('sub', Assembly())
    dep = ExprMapper(sub)
    for name in nodes:
        if name.startswith('parent.'):
            scope.add(name.split('.', 1)[1], Simple())
        else:
            sub.add(name, Simple())
            #dep.add(name)
    for src, dest in connections:
        if '.' not in src and not sub.contains(src):
            if dest.startswith('parent.'):
                iotype = 'out'
            else:
                iotype = 'in'
            sub.add(src, Int(1, iotype=iotype))
        if '.' not in dest and not sub.contains(dest):
            if src.startswith('parent.'):
                iotype = 'in'
            else:
                iotype = 'out'
            sub.add(dest, Int(1, iotype=iotype))
        dep.connect(ExprEvaluator(src, sub), ExprEvaluator(dest, sub), sub)
    return dep, sub
Beispiel #9
0
 def __init__(self, projpath):
     """Initializes a Project containing the project found in the 
     specified directory or creates a new project if one doesn't exist.
     
     projpath: str
         Path to the project's directory.
     """
     self.path = expand_path(projpath)
     modeldir = os.path.join(self.path, 'model')
     self.activate()
     if os.path.isdir(projpath):
         # locate file containing state, create it if it doesn't exist
         statefile = os.path.join(projpath, '_project_state')
         if os.path.exists(statefile):
             try:
                 with open(statefile, 'r') as f:
                     self.__dict__ = pickle.load(f)
             except Exception, e:
                 print 'Unable to restore project state:',e
                 self.top = Assembly()
         else:
             self.top = set_as_top(Assembly())
         
         self.path = expand_path(projpath) # set again in case loading project state changed it
Beispiel #10
0
            if os.path.exists(statefile):
                try:
                    with open(statefile, 'r') as f:
                        self.__dict__ = pickle.load(f)
                except Exception, e:
                    print 'Unable to restore project state:', e
                    self.top = Assembly()
            else:
                self.top = set_as_top(Assembly())

            self.path = expand_path(
                projpath)  # set again in case loading project state changed it
        else:  # new project
            os.makedirs(projpath)
            os.mkdir(modeldir)
            self.top = set_as_top(Assembly())

        self.save()

        SimulationRoot.chroot(self.path)

    @property
    def name(self):
        return os.path.basename(self.path)

    def activate(self):
        """Puts this project's directory on sys.path."""
        if self.path not in sys.path:
            sys.path = [self.path] + sys.path

    def deactivate(self):
Beispiel #11
0
            statefile = os.path.join(projpath, '_project_state')
            if os.path.exists(statefile):
                try:
                    with open(statefile, 'r') as f:
                        self.__dict__ = pickle.load(f)
                except Exception, e:
                    print 'Unable to restore project state:',e
                    self.top = Assembly()
            else:
                self.top = set_as_top(Assembly())
            
            self.path = expand_path(projpath) # set again in case loading project state changed it
        else:  # new project
            os.makedirs(projpath)
            os.mkdir(modeldir)
            self.top = set_as_top(Assembly())
            
        self.save()

        SimulationRoot.chroot(self.path)

    @property
    def name(self):
        return os.path.basename(self.path)
    
    def activate(self):
        """Puts this project's directory on sys.path."""
        if self.path not in sys.path:
            sys.path = [self.path]+sys.path
        
    def deactivate(self):