alpaca/alpacka/agents/base.py
def solve(self, env, init_state=None, time_limit=None):
        """Solves a given environment using OnlineAgent.act().

        Args:
            env (gym.Env): Environment to solve.
            init_state (object): Reset the environment to this state.
                If None, then do normal gym_open_ai.Env.reset().
            time_limit (int or None): Maximum number of steps to make on the
                solved environment. None means no time limit.

        Yields:
            Network-dependent: A stream of Network inputs requested for
            inference.

        Returns:
            data.Episode: Episode object containing a batch of collected
            transitions and the return for the episode.
        """
        model_env = env

        if time_limit is not None:
            # Add the TimeLimitWrapper _after_ passing the model env to the
            # agent, so the states cloned/restored by the agent do not contain
            # the number of steps made so far - this would break state lookup
            # in some Agents.
            env = envs.TimeLimitWrapper(env, time_limit)

        if init_state is None:
            # Model-free case...
            observation = env.reset()
        else:
            # Model-based case...
            observation = env.restore_state(init_state)

        yield from self.reset(model_env, observation)

        transitions = []
        done = False
        info = {}
        while not done:
            # Forward network prediction requests to BatchStepper.
            (action, agent_info) = yield from self.act(observation)
            (next_observation, reward, done, info) = env.step(action)

            transitions.append(data.Transition(
                observation=observation,
                action=action,
                reward=reward,
                done=done,
                next_observation=next_observation,
                agent_info=agent_info,
            ))
            observation = next_observation

        transitions = [
            self.postprocess_transition(transition)
            for transition in transitions
        ]

        return_ = sum(transition.reward for transition in transitions)
        solved = info['solved'] if 'solved' in info else None
        transition_batch = data.nested_stack(transitions)
        return data.Episode(
            transition_batch=transition_batch,
            return_=return_,
            solved=solved,
        )
Solves a given environment using OnlineAgent.act().

        Args:
            env (gym.Env): Environment to solve.
            init_state (object): Reset the environment to this state.
                If None, then do normal gym_open_ai.Env.reset().
            time_limit (int or None): Maximum number of steps to make on the
                solved environment. None means no time limit.

        Yields:
            Network-dependent: A stream of Network inputs requested for
            inference.

        Returns:
            data.Episode: Episode object containing a batch of collected
            transitions and the return for the episode.
        
Solves a given environment using OnlineAgent.act().
Solves a given environment using OnlineAgent . act () .
def solve(self, env, init_state=None, time_limit=None):
        model_env = env
        if time_limit is not None:
            env = envs.TimeLimitWrapper(env, time_limit)
        if init_state is None:
            observation = env.reset()
        else:
            observation = env.restore_state(init_state)
        yield from self.reset(model_env, observation)
        transitions = []
        done = False
        info = {}
        while not done:
            (action, agent_info) = yield from self.act(observation)
            (next_observation, reward, done, info) = env.step(action)
            transitions.append(data.Transition(
                observation=observation,
                action=action,
                reward=reward,
                done=done,
                next_observation=next_observation,
                agent_info=agent_info,
            ))
            observation = next_observation
        transitions = [
            self.postprocess_transition(transition)
            for transition in transitions
        ]
        return_ = sum(transition.reward for transition in transitions)
        solved = info['solved'] if 'solved' in info else None
        transition_batch = data.nested_stack(transitions)
        return data.Episode(
            transition_batch=transition_batch,
            return_=return_,
            solved=solved,
        )
def solve ( self , env , init_state = None , time_limit = None ) : model_env = env if time_limit is not None : env = envs . TimeLimitWrapper ( env , time_limit ) if init_state is None : observation = env . reset ( ) else : observation = env . restore_state ( init_state ) yield from self . reset ( model_env , observation ) transitions = [ ] done = False info = { } while not done : ( action , agent_info ) = yield from self . act ( observation ) ( next_observation , reward , done , info ) = env . step ( action ) transitions . append ( data . Transition ( observation = observation , action = action , reward = reward , done = done , next_observation = next_observation , agent_info = agent_info , ) ) observation = next_observation transitions = [ self . postprocess_transition ( transition ) for transition in transitions ] return_ = sum ( transition . reward for transition in transitions ) solved = info [ 'solved' ] if 'solved' in info else None transition_batch = data . nested_stack ( transitions ) return data . Episode ( transition_batch = transition_batch , return_ = return_ , solved = solved , )
Solves a given environment using OnlineAgent.act().
Solves a given environment using OnlineAgent . act () .
"""Solves a given environment using OnlineAgent.act().

        Args:
            env (gym.Env): Environment to solve.
            init_state (object): Reset the environment to this state.
                If None, then do normal gym_open_ai.Env.reset().
            time_limit (int or None): Maximum number of steps to make on the
                solved environment. None means no time limit.

        Yields:
            Network-dependent: A stream of Network inputs requested for
            inference.

        Returns:
            data.Episode: Episode object containing a batch of collected
            transitions and the return for the episode.
        """ # Add the TimeLimitWrapper _after_ passing the model env to the # agent, so the states cloned/restored by the agent do not contain # the number of steps made so far - this would break state lookup # in some Agents. # Model-free case... # Model-based case... # Forward network prediction requests to BatchStepper.
A stream of Network inputs requested for
inference.
A stream of Network inputs requested for inference .
Network-dependent
Episode object containing a batch of collected
transitions and the return for the episode.
Episode object containing a batch of collected transitions and the return for the episode .
data.Episode
self
env
Environment to solve.
Environment to solve .
init_state
Reset the environment to this state.
If None, then do normal gym_open_ai.Env.reset().
Reset the environment to this state . If None then do normal gym_open_ai . Env . reset () .
time_limit
Maximum number of steps to make on the
solved environment. None means no time limit.
Maximum number of steps to make on the solved environment . None means no time limit .