Example #1
0
def run_with_params(
         x0s, thetas,
        _theta, _main_method, _ls_method,
        test_params, test_ls_params):

    # Create the permutations of parameters
    permutations = list(itertools.product(
        *[*test_params.values(), *test_ls_params.values()]
    ))
    param_keys = [*test_params.keys()]
    ls_param_keys = [*test_ls_params.keys()]

    total_iterations = len(permutations) * len(x0s)
    bar = progressbar.ProgressBar(
        maxval=total_iterations,
        widgets=[
            progressbar.Percentage(), ' (',
            progressbar.Counter(), f'/{total_iterations}) ',
            progressbar.Bar('=', '[', ']'), ' ',
            progressbar.ETA(), ' ',
            progressbar.AdaptiveETA(),
        ]
    )
    bar.start()
    k = 0

    results = []
    for p in permutations:
        # Format the params
        params = {key: p[i] for i, key in enumerate(param_keys)}
        ls_params = {
            key: p[i + len(param_keys)]
            for i, key in enumerate(ls_param_keys)
        }

        ls_method = _ls_method(ls_params)
        main_method = _main_method(params, ls_method)
        current_config = Configuration(
            _theta, x0s, test_params, test_ls_params,
            _main_method, _ls_method, params, ls_params
        )

        # Test for each starting point and function
        for i, x0 in enumerate(x0s):
            theta = thetas[i]
            result = main_method(theta, np.array(x0))
            current_config.update(result)
            k += 1
            bar.update(k)

        results.append(current_config)
    bar.finish()

    return results
Example #2
0
    def get_cluster(self, cloud_provider=None, config=None, nodes=None):
        if not cloud_provider:
            cloud_provider = BotoCloudProvider("https://hobbes.gc3.uzh.ch/",
                                               "nova", "a-key", "s-key")
        if not config:
            config = Configuration().get_config(self.path)

        setup = Mock()
        configurator = Configurator(config)
        conf_login = configurator.cluster_conf['mycluster']['login']
        repository = PickleRepository(self.storage_path)

        cluster = Cluster(
            name="mycluster",
            cloud_provider=cloud_provider,
            setup_provider=setup,
            repository=repository,
            user_key_name=conf_login['user_key_name'],
            user_key_public=conf_login['user_key_public'],
            user_key_private=conf_login['user_key_private'],
        )

        if not nodes:
            nodes = {"compute": 2, "frontend": 1}

        for kind, num in nodes.iteritems():
            conf_kind = configurator.cluster_conf['mycluster']['nodes'][kind]
            cluster.add_nodes(kind, num, conf_kind['image_id'],
                              conf_login['image_user'], conf_kind['flavor'],
                              conf_kind['security_group'])

        return cluster
Example #3
0
    def test_get_frontend_node(self):
        """
        Get frontend node
        """
        config = Configuration().get_config(self.path)
        ssh_to = "frontend"
        config["mycluster"]["cluster"]["ssh_to"] = ssh_to

        cluster = self.get_cluster(config=config)
        cluster.ssh_to = ssh_to
        frontend = cluster.get_frontend_node()

        self.assertEqual(cluster.nodes['frontend'][0], frontend)
Example #4
0
    def test_dict_mixin(self):
        """Check that the node class can be seen as dictionary"""
        config = Configuration().get_config(self.path)
        ssh_to = "frontend"
        config["mycluster"]["cluster"]["ssh_to"] = ssh_to

        cluster = self.get_cluster(config=config)
        cluster.ssh_to = ssh_to
        frontend = cluster.get_frontend_node()

        dcluster = dict(cluster)
        self.assertEqual(dcluster['ssh_to'], ssh_to)
        self.assertEqual(dcluster['nodes'].keys(), cluster.nodes.keys())

        self.failUnlessRaises(KeyError, lambda x: x['_cloud_provider'],
                              dcluster)
        self.assertEqual(cluster['_cloud_provider'], cluster._cloud_provider)
Example #5
0
import os
from inspect import getsourcefile

from helpers import Configuration, Database
from saby_invoker import SabyInvoker
from server import flask_server
from neural_network import NeuralNetwork

# change directory to package directory
package_dir = os.path.dirname(os.path.abspath(getsourcefile(lambda: 0)))
os.chdir(package_dir)

#   read configuration from config file
Configuration.load_configuration()

#   connect to database
Database.connect_to_database()

#   init RpcInvoker
SabyInvoker.initialize()

#   init NeuralNetwork
NeuralNetwork.initialize()

#   run server on flask
flask_server.run()
# from api import get_user_info
# get_user_info(14893668, '00000003-007537f4-00bd-310e086f458d384b')
Example #6
0
#!/usr/bin/python3
# coding: utf-8

from optparse import OptionParser

import json
import time
import os

from helpers import Configuration
from helpers import TheMovieDatabase


TMDB = TheMovieDatabase.TMDB_Handle(Configuration.TMDB.get("api_key"), Configuration.TMDB.get("language"), Configuration.TMDB.isDebugOn())

MOVIE_EXTENSIONS = Configuration.loadExtensions("movie")
SUBTITLE_EXTENSIONS = Configuration.loadExtensions("subtitle")

PARSERS = Configuration.loadParsers()

# ============================================================================== #

def get_metadata(query, year="any"):
  results = TMDB.search_movie(query, year)
  if len(results) > 0:
    details = TMDB.get_movie_details(results[0]["id"])
    if details:
      metadata = {
        "title"              : details["title"],
        "tmdb_id"            : details["id"],
        "imdb_id"            : details["imdb_id"],
Example #7
0
 def setUp(self):
     file, path = tempfile.mkstemp()
     self.path = path
     self.config = Configuration().get_config(self.path)