Esempio n. 1
0
    def create_driver(self, yml, **kwargs):
        r"""Create a driver instance from the yaml information.

        Args:
            yml (yaml): Yaml object containing driver information.

        Returns:
            object: An instance of the specified driver.

        """
        self.debug('Creating %s, a %s', yml['name'], yml['driver'])
        curpath = os.getcwd()
        if 'working_dir' in yml:
            os.chdir(yml['working_dir'])
        try:
            if (yml.get('copies', 1) > 1) and ('copy_index' not in yml):
                instance = DuplicatedModelDriver(yml,
                                                 namespace=self.namespace,
                                                 rank=self.rank,
                                                 duplicates=yml.pop(
                                                     'duplicates', None),
                                                 **kwargs)
            else:
                kwargs = dict(yml, **kwargs)
                instance = create_driver(yml=yml,
                                         namespace=self.namespace,
                                         rank=self.rank,
                                         **kwargs)
            yml['instance'] = instance
        finally:
            os.chdir(curpath)
        return instance
Esempio n. 2
0
    def createDriver(self, yml):
        r"""Create a driver instance from the yaml information.

        Args:
            yml (yaml): Yaml object containing driver information.

        Returns:
            object: An instance of the specified driver.

        """
        self.debug('Creating %s, a %s', yml['name'], yml['driver'])
        curpath = os.getcwd()
        if 'ClientDriver' in yml['driver']:
            yml.setdefault('comm_address', self.serverdrivers[yml['args']])
        if 'working_dir' in yml:
            os.chdir(yml['working_dir'])
        instance = create_driver(yml=yml,
                                 namespace=self.namespace,
                                 rank=self.rank,
                                 **yml)
        yml['instance'] = instance
        os.chdir(curpath)
        if 'ServerDriver' in yml['driver']:
            self.serverdrivers[yml['args']] = instance.comm_address
        return instance
Esempio n. 3
0
 def __init__(self, yml, duplicates=None, **kwargs):
     kwargs.update(yml)
     self.copies = []
     if duplicates is not None:
         for x in duplicates:
             ienv = copy.deepcopy(yml.get('env', {}))
             ienv.update(yml.pop('env_%s' % x['name'], {}))
             ienv.update(x.pop('env', {}))
             x['env'] = ienv
             ikws = copy.deepcopy(kwargs)
             ikws.update(x)
             self.copies.append(create_driver(yml=x, **ikws))
     else:
         for iyml in self.get_yaml_copies(yml):
             ikws = copy.deepcopy(kwargs)
             ikws.update(iyml)
             self.copies.append(create_driver(yml=iyml, **ikws))
     super(DuplicatedModelDriver, self).__init__(**kwargs)
Esempio n. 4
0
    def create_driver(self, yml):
        r"""Create a driver instance from the yaml information.

        Args:
            yml (yaml): Yaml object containing driver information.

        Returns:
            object: An instance of the specified driver.

        """
        self.debug('Creating %s, a %s', yml['name'], yml['driver'])
        curpath = os.getcwd()
        if 'working_dir' in yml:
            os.chdir(yml['working_dir'])
        try:
            instance = create_driver(yml=yml,
                                     namespace=self.namespace,
                                     rank=self.rank,
                                     **yml)
            yml['instance'] = instance
        finally:
            os.chdir(curpath)
        return instance
Esempio n. 5
0
def test_create_driver(scripts):
    r"""Test driver creation w/ and w/o args."""
    drivers.create_driver('Driver', 'test_io_driver')
    drivers.create_driver('ExecutableModelDriver',
                          'test_model_driver',
                          args=scripts['python'])