Creating an agent and a runnerΒΆ
Additionally to the environment, an an agent will be created and a runner will be used. The runner class will take care of initializing and termination of agents and environments, as well as the execution of multiple episodes. The class will handle all information exchange between agent and environment like presented in the high level code architecture shown below:
Since the inputs are used for both the agent and the environment, they are defined in advance. Although the Agent gets information of the environment, in this small example, its action is still a random number.
The environment is the same as above. Afterwards, the agent and the runner get defined, and the runner runs for one episode.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | import gym
import numpy as np
import pandas as pd
from openmodelica_microgrid_gym import Agent, Runner
class RndAgent(Agent):
def act(self, obs: pd.Series) -> np.ndarray:
return self.env.action_space.sample()
if __name__ == '__main__':
env = gym.make('openmodelica_microgrid_gym:ModelicaEnv-v1',
net='../net/net.yaml',
model_path='../omg_grid/grid.network.fmu')
agent = RndAgent()
runner = Runner(agent, env)
runner.run(1)
|