Beispiel #1
0
def print_workspaces() -> None:
    """Print list of workspaces to standard output."""
    nemoa.set('mode', 'silent')
    workspaces = nemoa.list('workspaces', base='user')
    ui.info('Workspaces:\n')
    for workspace in workspaces:
        ui.info('    %s' % (workspace))
    ui.info('')
Beispiel #2
0
def print_workspaces() -> None:
    """Print list of workspaces to standard output."""
    nemoa.set('mode', 'silent')
    workspaces = nemoa.list('workspaces', base='user')
    ui.info('Workspaces:\n')
    for workspace in workspaces:
        ui.info('    %s' % (workspace))
    ui.info('')
Beispiel #3
0
def print_scripts(workspace: str) -> None:
    """Print list of scripts to standard output."""
    nemoa.set('mode', 'silent')

    if nemoa.open(workspace):
        ui.info('Scripts in workspace %s:\n' % (nemoa.get('workspace')))
        for script in nemoa.list('scripts'):
            ui.info('    %s' % (script))
        ui.info('')
Beispiel #4
0
def print_scripts(workspace: str) -> None:
    """Print list of scripts to standard output."""
    nemoa.set('mode', 'silent')

    if nemoa.open(workspace):
        ui.info('Scripts in workspace %s:\n' % (nemoa.get('workspace')))
        for script in nemoa.list('scripts'):
            ui.info('    %s' % (script))
        ui.info('')
Beispiel #5
0
    def print_workspaces():
        """Print list of workspaces to standard output."""

        import nemoa

        nemoa.set('mode', 'silent')
        workspaces = nemoa.list('workspaces', base='user')
        print('Workspaces:\n')
        for workspace in workspaces:
            print(('    %s' % (workspace)))
        print()

        return True
Beispiel #6
0
    def print_scripts(workspace):
        """Print list of scripts to standard output."""

        import nemoa

        nemoa.set('mode', 'silent')
        if not nemoa.open(workspace): return False
        print(('Scripts in workspace %s:\n' % (nemoa.get('workspace'))))
        for script in nemoa.list('scripts'):
            print(('    %s' % (script)))
        print()

        return True
Beispiel #7
0
    def update(self):
        """Update epoch and check termination criterions."""

        self._buffer['epoch'] += 1
        if self._buffer['epoch'] == self._config['updates']:
            self._buffer['continue'] = False

        if self._buffer['key_events']: self._update_keypress()
        if self._config.get('tracker_obj_tracking_enable', False):
            self._update_objective_function()
        if self._config.get('tracker_eval_enable', False):
            self._update_evaluation()

        if not self._buffer['continue']:
            nemoa.set('shell', 'buffmode', 'line')

        return self._buffer['continue']
Beispiel #8
0
    def optimize(self, config=None, **kwargs):
        """ """

        if not self._set_config(config, **kwargs): return None
        if not self._set_buffer_reset(): return None

        # get name of optimization algorithm
        name = self._config.get('algorithm', None)
        if not name:
            return nemoa.log(
                'error', """could not optimize '%s'
                (%s): no optimization algorithm has been set.""" %
                (self.model.name, self.model.system.type)) or None

        # get instance of optimization algorithm
        algorithm = self._get_algorithm(name, category='optimization')
        if not algorithm:
            return nemoa.log(
                'error', """could not optimize '%s':
                unsupported optimization algorithm '%s'.""" %
                (self.model.name, name)) or None

        # start optimization
        if algorithm.get('type', None) == 'algorithm':
            nemoa.log(
                'note', "optimize '%s' (%s) using %s." %
                (self.model.name, self.model.system.type, name))

            # start key events
            if not self._buffer['key_events_started']:
                nemoa.log('note', "press 'h' for help or 'q' to quit.")
                self._buffer['key_events_started'] = True
                nemoa.set('shell', 'buffmode', 'key')

        # 2Do retval, try / except etc.
        transformation = algorithm.get('reference', None)
        if not transformation: return None

        retval = transformation()
        retval &= self.model.network.initialize(self.model.system)

        return retval
Beispiel #9
0
def main():

    import nemoa

    try:
        import IPython
    except ImportError:
        return nemoa.log(
            'error', "could not execute interactive nemoa shell: "
            "ipython is required.")

    def about(*args, **kwargs):
        """Get meta information."""
        nemoa.log('note', nemoa.about(*args, **kwargs))
        return None

    def close(*args, **kwargs):
        """Close current workspace instance."""
        nemoa.close()
        return None

    def create(*args, **kwargs):
        """Create object instance from building script."""
        return nemoa.create(*args, **kwargs)

    def get(*args, **kwargs):
        """Wrapping function to nemoa.get()."""
        nemoa.log('note', nemoa.get(*args, **kwargs))
        return None

    def list(*args, **kwargs):
        """Wrapping function to nemoa.list()."""
        retval = nemoa.list(*args, **kwargs)
        if isinstance(retval, dict):
            for key, val in retval.items():
                if not val: continue
                if hasattr(val, '__iter__'):
                    nemoa.log('note', '%s: %s' % (key, ', '.join(val)))
                else:
                    nemoa.log('note', '%s: %s' % (key, val))
        elif hasattr(retval, '__iter__'):
            nemoa.log('note', ', '.join(retval))
        return None

    def open(*args, **kwargs):
        """Open object in current session."""
        return nemoa.open(*args, **kwargs)

    def optimize(*args, **kwargs):
        """Optimize model."""
        return nemoa.model.morphisms.optimize(*args, **kwargs)

    def path(*args, **kwargs):
        """Wrapping function to nemoa.path()."""
        nemoa.log('note', nemoa.path(*args, **kwargs))
        return None

    def run(*args, **kwargs):
        """Wrapping function to nemoa.run()."""
        nemoa.run(*args, **kwargs)
        return None

    def show(*args, **kwargs):
        """ """
        open(*args, **kwargs).show()
        return None

    def set(*args, **kwargs):
        """Wrapping function to nemoa.set()."""
        nemoa.set(*args, **kwargs)
        return None

    import os
    os.system('cls' if os.name == 'nt' else 'clear')
    nemoa.set('mode', 'shell')

    IPython.embed(banner1='nemoa %s\n' % nemoa.__version__)

    return True
Beispiel #10
0
 def set(*args, **kwargs):
     """Wrapping function to nemoa.set()."""
     nemoa.set(*args, **kwargs)
     return None
Beispiel #11
0
 def tearDown(self):
     # open previous workspace
     if nemoa.get('workspace') != self.workspace:
         nemoa.open(self.workspace)
     nemoa.set('mode', self.mode)
Beispiel #12
0
 def setUp(self):
     self.mode = nemoa.get('mode')
     self.workspace = nemoa.get('workspace')
     nemoa.set('mode', 'silent')
     # open workspace 'testsuite'
     nemoa.open('testsuite', base='site')
Beispiel #13
0
 def tearDown(self):
     nemoa.set('mode', self.mode)
Beispiel #14
0
 def setUp(self):
     self.mode = nemoa.get('mode')
     self.workspace = nemoa.get('workspace')
     nemoa.set('mode', 'silent')