def __init__(self, spec, aeb_space): self.spec = spec self.aeb_space = aeb_space aeb_space.env_space = self self.info_space = aeb_space.info_space self.envs = [] for e in range(len(self.spec['env'])): env = make_env(self.spec, e, env_space=self) self.envs.append(env) logger.info(util.self_desc(self))
def __init__(self, spec, body, a=None, global_nets=None): self.spec = spec self.a = a or 0 # for compatibility with agent_space self.agent_spec = spec['agent'][self.a] self.name = self.agent_spec['name'] assert not ps.is_list( global_nets ), f'single agent global_nets must be a dict, got {global_nets}' self.nlu = None if 'nlu' in self.agent_spec: params = deepcopy(ps.get(self.agent_spec, 'nlu')) NluClass = getattr(nlu, params.pop('name')) self.nlu = NluClass(**params) self.dst = None if 'dst' in self.agent_spec: params = deepcopy(ps.get(self.agent_spec, 'dst')) DstClass = getattr(dst, params.pop('name')) self.dst = DstClass(**params) if 'word_dst' in self.agent_spec: params = deepcopy(ps.get(self.agent_spec, 'word_dst')) DstClass = getattr(word_dst, params.pop('name')) self.dst = DstClass(**params) self.state_encoder = None if 'state_encoder' in self.agent_spec: params = deepcopy(ps.get(self.agent_spec, 'state_encoder')) StateEncoderClass = getattr(state_encoder, params.pop('name')) self.state_encoder = StateEncoderClass(**params) self.action_decoder = None if 'action_decoder' in self.agent_spec: params = deepcopy(ps.get(self.agent_spec, 'action_decoder')) ActionDecoderClass = getattr(action_decoder, params.pop('name')) self.action_decoder = ActionDecoderClass(**params) self.nlg = None if 'nlg' in self.agent_spec: params = deepcopy(ps.get(self.agent_spec, 'nlg')) NlgClass = getattr(nlg, params.pop('name')) self.nlg = NlgClass(**params) self.body = body body.agent = self AlgorithmClass = getattr(algorithm, ps.get(self.agent_spec, 'algorithm.name')) self.algorithm = AlgorithmClass(self, global_nets) if ps.get(self.agent_spec, 'memory'): MemoryClass = getattr(memory, ps.get(self.agent_spec, 'memory.name')) self.body.memory = MemoryClass(self.agent_spec['memory'], self.body) self.warmup_epi = ps.get(self.agent_spec, 'algorithm.warmup_epi') or -1 self.body.state, self.body.encoded_state, self.body.action = None, None, None logger.info(util.self_desc(self))
def __init__(self, agent, global_nets=None): ''' @param {*} agent is the container for algorithm and related components, and interfaces with env. ''' self.agent = agent self.algorithm_spec = agent.agent_spec['algorithm'] self.name = self.algorithm_spec['name'] self.net_spec = agent.agent_spec.get('net', None) if ps.get(agent.agent_spec, 'memory'): self.memory_spec = agent.agent_spec['memory'] self.body = self.agent.body self.init_algorithm_params() self.init_nets(global_nets) logger.info(util.self_desc(self))
def __init__(self, spec, e=None): super(MultiWozEnv, self).__init__(spec, e) self.action_dim = self.observation_dim = 0 util.set_attr(self, self.env_spec, [ 'observation_dim', 'action_dim', ]) worker_id = int(f'{os.getpid()}{self.e+int(ps.unique_id())}'[-4:]) self.u_env = MultiWozEnvironment(self.env_spec, worker_id, self.action_dim) self.evaluator = self.u_env.evaluator self.patch_gym_spaces(self.u_env) self._set_attr_from_u_env(self.u_env) logger.info(util.self_desc(self))
def __init__(self, spec, body, a=None, global_nets=None): self.spec = spec self.a = a or 0 # for multi-agent self.agent_spec = spec['agent'][self.a] self.name = self.agent_spec['name'] assert not ps.is_list(global_nets), f'single agent global_nets must be a dict, got {global_nets}' # set components self.body = body body.agent = self MemoryClass = getattr(memory, ps.get(self.agent_spec, 'memory.name')) self.body.memory = MemoryClass(self.agent_spec['memory'], self.body) AlgorithmClass = getattr(algorithm, ps.get(self.agent_spec, 'algorithm.name')) self.algorithm = AlgorithmClass(self, global_nets) logger.info(util.self_desc(self))
def __init__(self, spec, global_nets=None): self.spec = spec self.index = self.spec['meta']['session'] util.set_random_seed(self.spec) util.set_cuda_id(self.spec) util.set_logger(self.spec, logger, 'session') spec_util.save(spec, unit='session') self.agent, self.env = make_agent_env(self.spec, global_nets) with util.ctx_lab_mode('eval'): # env for eval self.eval_env = make_env(self.spec) self.agent.body.eval_env = self.eval_env self.num_eval = ps.get(self.agent.spec, 'meta.num_eval') self.warmup_epi = ps.get(self.agent.agent_spec, 'algorithm.warmup_epi') or -1 logger.info(util.self_desc(self))