Пример #1
0
def test_feature_extraction(
    server_setup,
    get_interface_params,
    discoverable_plugins,
    ond_config_with_feature_extraction,
):
    """
    Test feature extraction.

    Args:
        server_setup (tuple): Tuple containing url and result directory
        get_interface_params (tuple): Tuple to configure par interface
        discoverable_plugins (dict): Dictionary with the plugins
        ond_config_with_feature_extraction (str): Path to json file

    Return:
        None
    """
    config_directory, config_name = get_interface_params
    par_interface = ParInterface(config_name, config_directory)
    ond = SailOn(discoverable_plugins, "", par_interface,
                 ond_config_with_feature_extraction)
    ond.run_protocol()
    local_interface = LocalInterface(config_name, config_directory)
    SailOn(discoverable_plugins, "", local_interface,
           ond_config_with_feature_extraction)
    ond.run_protocol()
Пример #2
0
def test_initialize(server_setup, get_interface_params, discoverable_plugins,
                    ond_config):
    """
    Test ond protocol initialization.

    Args:
        server_setup (tuple): Tuple containing url and result directory
        get_interface_params (tuple): Tuple to configure par interface
        discoverable_plugins (dict): Dictionary with the plugins
        ond_config (str): Path to json file

    Return:
        None
    """
    config_directory, config_name = get_interface_params
    par_interface = ParInterface(config_name, config_directory)
    SailOn(discoverable_plugins, "", par_interface, ond_config)
    local_interface = LocalInterface(config_name, config_directory)
    SailOn(discoverable_plugins, "", local_interface, ond_config)
Пример #3
0
def test_reaction_baseline(
    server_setup,
    get_ar_interface_params,
    discoverable_plugins,
    ond_config_with_reaction_baseline,
):
    """
    Test reaction baseline with a detector.

    Args:
        server_setup (tuple): Tuple containing url and result directory
        get_ar_interface_params (tuple): Tuple to configure par interface
        discoverable_plugins (dict): Dictionary with the plugins
        ond_config_with_reaction_baseline(str): Path to json file

    Return:
        None
    """
    config_directory, config_name = get_ar_interface_params
    local_interface = LocalInterface(config_name, config_directory)
    ond = SailOn(discoverable_plugins, "", local_interface,
                 ond_config_with_reaction_baseline)
    ond.run_protocol()
Пример #4
0
    def run_protocol(
        self, config: Dict[str, Any],
        extra_plugins: Dict[str, Any] = dict()) -> None:
        """Run the protocol by printout out the config.

        Args:

            Config passed in uses 3 parameters to control the launching of the protocols
            - protocol: either 'ond' or 'condda' to define which protocol to run
            - harness:  either 'local' or 'par' to define which harness to use
            - workdir: a directory to save all the information from the run including
                - Config
                - Output of algorithm

        Example:
            >>> from sailon_tinker_launcher.main import *
            >>> dpath = ub.ensure_app_cache_dir('tinker/tests')
            >>> config = get_debug_config()
            >>> self = LaunchSailonProtocol()
            >>> self.run_protocol(config)
            >>> assert(self.working_folder.exists())
            >>> ub.delete(str(self.working_folder), verbose=False)

        """

        # Setup working folder and create new config for this run
        self.working_folder, working_config_fp, privileged_config, config = self.setup_experiment(
            config)

        # Now experiment setup, start a new logger for this
        fh = logging.FileHandler(
            self.working_folder /
            f'{datetime.now().strftime("%Y_%m_%d-%I_%M_%S_%p")}.log')
        fh.setLevel(logging.DEBUG)
        formatter = logging.Formatter(
            '[%(asctime)s][%(name)s][%(levelname)s] - %(message)s')
        fh.setFormatter(formatter)
        logging.getLogger().addHandler(fh)
        log.info(f'Config Filepath: {working_config_fp}')
        log.info(f'Config: \n{json.dumps(config, indent=4)}')

        # Load the harness
        # This config is not used but will throw error if not pointed at
        harnness_config_path = Path(protocol_folder.__file__).parent
        if privileged_config['harness'] == 'local':
            log.info('Loading Local Harness')
            harness = LocalInterface('configuration.json',
                                     str(harnness_config_path))
            harness.result_directory = config['detectors']['csv_folder']
            harness.file_provider.results_folder = config['detectors'][
                'csv_folder']
        elif privileged_config['harness'] == 'par':
            log.info('Loading Par Harness')
            harness = ParInterface('configuration.json',
                                   str(harnness_config_path))
            harness.folder = config['detectors']['csv_folder']
        else:
            raise AttributeError(
                f'Valid harnesses "local" or "par".  '
                f'Given harness "{privileged_config["harness"]}" ')

        # Get the plugins
        plugins = ub.dict_union(discoverable_plugins('tinker'), extra_plugins)

        log.debug('Plugins found:')
        log.debug(plugins)
        # Load the protocol
        if privileged_config['protocol'] == 'ond':
            log.info('Running OND Protocol')
            run_protocol = OND(discovered_plugins=plugins,
                               algorithmsdirectory='',
                               harness=harness,
                               config_file=str(working_config_fp))
        elif privileged_config['protocol'] == 'condda':
            log.info('Running Condda Protocol')
            run_protocol = Condda(discovered_plugins=plugins,
                                  algorithmsdirectory='',
                                  harness=harness,
                                  config_file=str(working_config_fp))
        else:
            raise AttributeError(
                f'Please set protocol to either "ond" or "condda".  '
                f'"{privileged_config["protocol"]}" in the config files')

        # Run the protocol
        run_protocol.run_protocol()
        log.info('Protocol Finished')

        logging.getLogger().removeHandler(fh)