Exemple #1
0
    def train(self, filenames, steps=1):
        #state_actions = ssbm.readStateActions(filename)
        #feed_dict = feedStateActions(state_actions)
        experiences = util.async_map(ssbm.readStateActions_pickle, filenames)()
        experiences = util.deepZip(*experiences)
        experiences = util.deepMap(np.array, experiences)

        input_dict = dict(
            util.deepValues(util.deepZip(self.experience, experiences)))
        """
    saved_data = self.sess.run(self.saved_data, input_dict)
    handles = [t.handle for t in saved_data]
    
    saved_dict = dict(zip(self.placeholders, handles))
    """

        if self.debug:
            self.debugGrads(input_dict)

        for _ in range(steps):
            results = tfl.run(self.sess, self.run_dict, input_dict)

            summary_str = results['summary']
            global_step = results['global_step']
            self.writer.add_summary(summary_str, global_step)
Exemple #2
0
    def __init__(self, **kwargs):
        Default.__init__(self, **kwargs)

        self.toggle = False

        self.user = os.path.expanduser(self.user)

        self.state = ssbm.GameMemory()
        # track players 1 and 2 (pids 0 and 1)
        self.sm = state_manager.StateManager([0, 1])
        self.write_locations()

        if self.tag is not None:
            random.seed(self.tag)

        self.pids = [1]
        self.cpus = {1: None}
        self.characters = {1: self.p2}

        self.pids.append(0)
        cpu_level = None if self.human else self.cpu
        if cpu_level == 0:
            cpu_level = random.choice(list(range(1, 10)),
                                      p=([.06, .04] + [.03] * 5 + [.05, 0.7]))
        print('Playing against CPU Level: ' + str(cpu_level))
        self.cpus[0] = cpu_level
        self.characters[0] = self.p1

        print('Creating MemoryWatcher.')
        mwType = memory_watcher.MemoryWatcher
        if self.zmq:
            mwType = memory_watcher.MemoryWatcherZMQ
        self.mw = mwType(self.user + '/MemoryWatcher/MemoryWatcher')

        pipe_dir = self.user + '/Pipes/'
        print('Creating Pads at %s. Open dolphin now.' % pipe_dir)
        util.makedirs(self.user + '/Pipes/')

        paths = [pipe_dir + 'phillip%d' % i for i in self.pids]
        self.get_pads = util.async_map(Pad, paths)

        self.init_stats()
Exemple #3
0
def ntw():
    return async_map(get_ntw, listen('nmcli', 'm', immediate=True))
Exemple #4
0
def bri():
    return async_map(get_bri, watch(backlight + 'brightness'))
Exemple #5
0
#!/usr/bin/python

from asyncio import run

from config import bar
from util import async_map, drain, concat


def echo(text):
    print(text, flush=True)


if __name__ == '__main__':
    run(drain(async_map(echo, concat(bar))))
Exemple #6
0
    def __init__(self, **kwargs):
        Default.__init__(self, **kwargs)

        self.model = self.agent.model
        self.rlConfig = self.model.rlConfig

        if self.dump:
            try:
                import zmq
            except ImportError as err:
                print("ImportError: {0}".format(err))
                sys.exit("Install pyzmq to dump experiences")

            context = zmq.Context()

            self.socket = context.socket(zmq.PUSH)
            self.sock_addr = "tcp://%s:%d" % (self.dump,
                                              util.port(self.model.name))
            print("Connecting to " + self.sock_addr)
            self.socket.connect(self.sock_addr)

            self.dump_size = self.rlConfig.experience_length
            self.dump_state_actions = (self.dump_size *
                                       ssbm.SimpleStateAction)()

            self.dump_frame = 0
            self.dump_count = 0

        self.first_frame = True
        self.action_counter = 0
        self.toggle = False

        self.user = os.path.expanduser(self.user)

        self.state = ssbm.GameMemory()
        # track players 1 and 2 (pids 0 and 1)
        self.sm = state_manager.StateManager([0, 1])
        self.write_locations()

        if self.tag is not None:
            random.seed(self.tag)

        self.pids = [1]
        self.agents = {1: self.agent}
        self.characters = {1: self.agent.char or self.p2}

        reload_every = self.rlConfig.experience_length
        self.agent.reload_every = reload_every

        enemy = None
        if self.self_play:
            enemy = agent.Agent(reload_every=self.self_play * reload_every,
                                swap=True,
                                **kwargs)
        elif self.enemy:
            with open(self.enemy + 'agent', 'r') as f:
                import json
                enemy_kwargs = json.load(f)
            enemy_kwargs.update(reload_every=None,
                                swap=True,
                                dump=None,
                                path=self.enemy)
            enemy = agent.Agent(**enemy_kwargs)

        if enemy:
            self.pids.append(0)
            self.agents[0] = enemy
            self.characters[0] = enemy.char or self.p1

        self.menu_managers = {
            i: MenuManager(characters[c], pid=i)
            for i, c in self.characters.items()
        }

        print('Creating MemoryWatcher.')
        mwType = memory_watcher.MemoryWatcher
        if self.zmq:
            mwType = memory_watcher.MemoryWatcherZMQ
        self.mw = mwType(self.user + '/MemoryWatcher/MemoryWatcher')

        pipe_dir = self.user + '/Pipes/'
        print('Creating Pads at %s. Open dolphin now.' % pipe_dir)
        util.makedirs(self.user + '/Pipes/')

        paths = [pipe_dir + 'phillip%d' % i for i in self.pids]
        self.get_pads = util.async_map(Pad, paths)

        self.init_stats()

        # sets the game mode and random stage
        self.movie = movie.Movie(movie.endless_netplay +
                                 movie.stages[self.stage])
Exemple #7
0
def wks():
    return async_map(get_wks, listen('bspc', 'subscribe'))
Exemple #8
0
def vol():
    return async_map(get_vol, listen('pactl', 'subscribe',
                                     immediate='sink #0'))
Exemple #9
0
    def __init__(self, **kwargs):
        for k, v in default_args.items():
            if k in kwargs and kwargs[k] is not None:
                setattr(self, k, kwargs[k])
            else:
                setattr(self, k, v)

        self.fps = 60 // self.act_every
        self.experience_length = self.experience_time * self.fps

        if self.dump:
            self.dump_dir = self.path + "/experience/"
            os.makedirs(self.dump_dir, exist_ok=True)
            self.dump_tag = "" if self.tag is None else str(self.tag) + "-"
            self.dump_size = self.experience_length
            self.dump_state_actions = (self.dump_size *
                                       ssbm.SimpleStateAction)()

            self.dump_frame = 0
            self.dump_count = 0

        self.reward_logfile = self.path + '/rewards.log'
        self.first_frame = True
        self.action_counter = 0
        self.toggle = False

        self.dolphin_dir = os.path.expanduser(self.dolphin_dir)

        self.state = ssbm.GameMemory()
        # track players 1 and 2 (pids 0 and 1)
        self.sm = state_manager.StateManager([0, 1])
        self.write_locations(self.dolphin_dir)

        self.fox = fox.Fox()
        if self.tag is not None:
            random.seed(self.tag)

        self.cpus = [0, 1] if self.self_play else [1]
        self.agents = []

        reload_every = self.experience_length
        if self.self_play:
            self.enemy = agent.Agent(reload_every=self.self_play *
                                     reload_every,
                                     swap=True,
                                     **kwargs)
            self.agents.append(self.enemy)
        self.agent = agent.Agent(reload_every=reload_every, **kwargs)
        self.agents.append(self.agent)

        self.characters = [self.p1, self.p2] if self.self_play else [self.p2]
        self.menu_managers = [
            MenuManager(characters[c], pid=i)
            for c, i in zip(self.characters, self.cpus)
        ]

        print('Creating MemoryWatcher.')
        mwType = memory_watcher.MemoryWatcher
        if self.zmq:
            mwType = memory_watcher.MemoryWatcherZMQ
        self.mw = mwType(self.dolphin_dir + '/MemoryWatcher/MemoryWatcher')

        pipe_dir = self.dolphin_dir + '/Pipes/'
        print('Creating Pads at %s. Open dolphin now.' % pipe_dir)
        os.makedirs(self.dolphin_dir + '/Pipes/', exist_ok=True)

        paths = [pipe_dir + 'phillip%d' % i for i in self.cpus]
        self.get_pads = util.async_map(Pad, paths)

        self.init_stats()

        # sets the game mode and random stage
        self.movie = movie.Movie(movie.endless_netplay_battlefield)