Esempio n. 1
0
 def __init__(self, app, master):
     super().__init__(master,
                      text="Effects/Samples - shift+click to assign sample",
                      padding=4)
     self.app = app
     self.effects = {num: None for num in range(16)}
     f = ttk.Frame(self)
     self.buttons = []
     for i in range(1, 9):
         b = ttk.Button(f,
                        text="# {:d}".format(i),
                        width=14,
                        state=tk.DISABLED)
         b.bind("<ButtonRelease>", self.do_button_release)
         b.effect_nr = i
         b.pack(side=tk.LEFT)
         self.buttons.append(b)
     f.pack()
     f = ttk.Frame(self)
     for i in range(9, 17):
         b = ttk.Button(f,
                        text="# {:d}".format(i),
                        width=14,
                        state=tk.DISABLED)
         b.bind("<ButtonRelease>", self.do_button_release)
         b.effect_nr = i
         b.pack(side=tk.LEFT)
         self.buttons.append(b)
     f.pack()
     self.after(2000, lambda: Pyro4.Future(self.load_settings)(True))
Esempio n. 2
0
def get_prediction(client_id: str,
                   scan_path: str,
                   fmt: str,
                   timeout: float = None,
                   config: dict = None) -> 'Future':
    dispatcher = Pyro4.Proxy('PYRONAME:dispatcher')
    dispatcher.put_work(
        Workitem(client_id, scan_path, fmt=fmt, timeout=timeout,
                 config=config))
    get_result = Pyro4.Future(dispatcher.get_result)
    return get_result(client_id)
Esempio n. 3
0
def init_workers(workers, config, weights):
    results = []
    print('start workers initialization')
    for worker in workers:
        res = Pyro4.Future(worker.initialize)(config, pickle.dumps(weights))
        results.append(res)

    while len(results) > 0:
        for res in results:
            if res.ready:
                results.remove(res)

    print('finish workers initialization')
Esempio n. 4
0
def wait_run_end(workers_results, model, timeout=None):
    # TODO: use timeout
    weights = pickle.dumps(model.get_weights())

    for w, res in workers_results.items():

        while not res.ready:
            sleep(1)

        res = utils.unpickle(res.value)
        grads = res["grads"]
        model.add_grads(grads)

        new_res = Pyro4.Future(w.run)(weights)
        workers_results[w] = new_res
Esempio n. 5
0
def run_maml(args):
    config = utils.load_config(args.config)
    train_params = config["train_params"]

    # open and close env just to get right action and obs space
    env = sonic_utils.make_from_config(config['env_params'], True)
    env.close()

    # init model
    model = CNNPolicy(
        env.observation_space, env.action_space, train_params["vf_coef"],
        train_params["ent_coef"], train_params["lr_meta"], train_params["max_grad_norm"]

    )

    workers = find_workers("worker")
    init_workers(workers, config, model.get_weights())

    # start run
    workers_results = {w: Pyro4.Future(w.run)() for w in workers}

    savedir = utils.prepare_exp_dir(config, args.exp_name)

    updates = 0
    while True:
        # first zero all grads
        model.optimizer.zero_grad()

        # then apply add grads from remote workers
        wait_run_end(workers_results, model)

        # apply gradient
        model.optimizer.step()

        updates += 1

        # save last weights
        if config['log']['save_last']:
            fpath = savedir / 'last.pt'
            model.save(fpath)

        # save on save period
        if updates % config['log']["save_interval"] == 0 or updates == 1:
            fpath = savedir / '{}.pt'.format(updates)
            model.save(fpath)
Esempio n. 6
0
from __future__ import print_function
import Pyro4


def myfunction(a, b, extra=None):
    print(">>> myfunction called with: a={0}, b={1}, extra={2}".format(a, b, extra))
    return a + b


print("\n* just a single future call:")
future = Pyro4.Future(myfunction)
result = future(5, 6)
# we can do stuff here in the meantime...
print("result value=", result.value)
assert result.value == 11

print("\n* several calls chained:")
future = Pyro4.Future(myfunction)
future.then(myfunction, 10)
future.then(myfunction, 20, extra="something")
# the callables will be invoked like so:  function(asyncvalue, normalarg, kwarg=..., kwarg=...)
# (the value from the previous call is passed as the first argument to the next call)
result = future(5, 6)
# we can do stuff here in the meantime...
print("result value=", result.value)
assert result.value == 41
Esempio n. 7
0
import Pyro4
from time import sleep

def print_times(text = '', times = 1):
    outputs = []
    for i in range(times):
        print(text)
        sleep(0.5)
    outputs.append(text)
    return outputs


print_times_f = Pyro4.Future(print_times)