Populate step info in environment, and finish notebook
This commit is contained in:
@@ -31,7 +31,7 @@ game:
|
|||||||
- UDP
|
- UDP
|
||||||
|
|
||||||
agents:
|
agents:
|
||||||
- ref: client_1_green_user
|
- ref: client_2_green_user
|
||||||
team: GREEN
|
team: GREEN
|
||||||
type: GreenWebBrowsingAgent
|
type: GreenWebBrowsingAgent
|
||||||
observation_space:
|
observation_space:
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ game:
|
|||||||
- UDP
|
- UDP
|
||||||
|
|
||||||
agents:
|
agents:
|
||||||
- ref: client_1_green_user
|
- ref: client_2_green_user
|
||||||
team: GREEN
|
team: GREEN
|
||||||
type: GreenWebBrowsingAgent
|
type: GreenWebBrowsingAgent
|
||||||
observation_space:
|
observation_space:
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ class PrimaiteGame:
|
|||||||
self.update_agents(sim_state)
|
self.update_agents(sim_state)
|
||||||
|
|
||||||
# Apply all actions to simulation as requests
|
# Apply all actions to simulation as requests
|
||||||
self.apply_agent_actions()
|
agent_actions = self.apply_agent_actions() # noqa
|
||||||
|
|
||||||
# Advance timestep
|
# Advance timestep
|
||||||
self.advance_timestep()
|
self.advance_timestep()
|
||||||
@@ -131,12 +131,15 @@ class PrimaiteGame:
|
|||||||
|
|
||||||
def apply_agent_actions(self) -> None:
|
def apply_agent_actions(self) -> None:
|
||||||
"""Apply all actions to simulation as requests."""
|
"""Apply all actions to simulation as requests."""
|
||||||
|
agent_actions = {}
|
||||||
for agent in self.agents:
|
for agent in self.agents:
|
||||||
obs = agent.observation_manager.current_observation
|
obs = agent.observation_manager.current_observation
|
||||||
rew = agent.reward_function.current_reward
|
rew = agent.reward_function.current_reward
|
||||||
action_choice, options = agent.get_action(obs, rew)
|
action_choice, options = agent.get_action(obs, rew)
|
||||||
|
agent_actions[agent.agent_name] = (action_choice, options)
|
||||||
request = agent.format_request(action_choice, options)
|
request = agent.format_request(action_choice, options)
|
||||||
self.simulation.apply_request(request)
|
self.simulation.apply_request(request)
|
||||||
|
return agent_actions
|
||||||
|
|
||||||
def advance_timestep(self) -> None:
|
def advance_timestep(self) -> None:
|
||||||
"""Advance timestep."""
|
"""Advance timestep."""
|
||||||
|
|||||||
BIN
src/primaite/notebooks/_package_data/uc2_network.png
Normal file
BIN
src/primaite/notebooks/_package_data/uc2_network.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 69 KiB |
File diff suppressed because it is too large
Load Diff
@@ -29,7 +29,7 @@ class PrimaiteGymEnv(gymnasium.Env):
|
|||||||
# make ProxyAgent store the action chosen my the RL policy
|
# make ProxyAgent store the action chosen my the RL policy
|
||||||
self.agent.store_action(action)
|
self.agent.store_action(action)
|
||||||
# apply_agent_actions accesses the action we just stored
|
# apply_agent_actions accesses the action we just stored
|
||||||
self.game.apply_agent_actions()
|
agent_actions = self.game.apply_agent_actions()
|
||||||
self.game.advance_timestep()
|
self.game.advance_timestep()
|
||||||
state = self.game.get_sim_state()
|
state = self.game.get_sim_state()
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ class PrimaiteGymEnv(gymnasium.Env):
|
|||||||
reward = self.agent.reward_function.current_reward
|
reward = self.agent.reward_function.current_reward
|
||||||
terminated = False
|
terminated = False
|
||||||
truncated = self.game.calculate_truncated()
|
truncated = self.game.calculate_truncated()
|
||||||
info = {}
|
info = {"agent_actions": agent_actions} # tell us what all the agents did for convenience.
|
||||||
if self.game.save_step_metadata:
|
if self.game.save_step_metadata:
|
||||||
self._write_step_metadata_json(action, state, reward)
|
self._write_step_metadata_json(action, state, reward)
|
||||||
return next_obs, reward, terminated, truncated, info
|
return next_obs, reward, terminated, truncated, info
|
||||||
@@ -172,7 +172,7 @@ class PrimaiteRayMARLEnv(MultiAgentEnv):
|
|||||||
# 1. Perform actions
|
# 1. Perform actions
|
||||||
for agent_name, action in actions.items():
|
for agent_name, action in actions.items():
|
||||||
self.agents[agent_name].store_action(action)
|
self.agents[agent_name].store_action(action)
|
||||||
self.game.apply_agent_actions()
|
agent_actions = self.game.apply_agent_actions()
|
||||||
|
|
||||||
# 2. Advance timestep
|
# 2. Advance timestep
|
||||||
self.game.advance_timestep()
|
self.game.advance_timestep()
|
||||||
@@ -186,7 +186,7 @@ class PrimaiteRayMARLEnv(MultiAgentEnv):
|
|||||||
rewards = {name: agent.reward_function.current_reward for name, agent in self.agents.items()}
|
rewards = {name: agent.reward_function.current_reward for name, agent in self.agents.items()}
|
||||||
terminateds = {name: False for name, _ in self.agents.items()}
|
terminateds = {name: False for name, _ in self.agents.items()}
|
||||||
truncateds = {name: self.game.calculate_truncated() for name, _ in self.agents.items()}
|
truncateds = {name: self.game.calculate_truncated() for name, _ in self.agents.items()}
|
||||||
infos = {}
|
infos = {"agent_actions": agent_actions}
|
||||||
terminateds["__all__"] = len(self.terminateds) == len(self.agents)
|
terminateds["__all__"] = len(self.terminateds) == len(self.agents)
|
||||||
truncateds["__all__"] = self.game.calculate_truncated()
|
truncateds["__all__"] = self.game.calculate_truncated()
|
||||||
if self.game.save_step_metadata:
|
if self.game.save_step_metadata:
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ game:
|
|||||||
- UDP
|
- UDP
|
||||||
|
|
||||||
agents:
|
agents:
|
||||||
- ref: client_1_green_user
|
- ref: client_2_green_user
|
||||||
team: GREEN
|
team: GREEN
|
||||||
type: GreenWebBrowsingAgent
|
type: GreenWebBrowsingAgent
|
||||||
observation_space:
|
observation_space:
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ game:
|
|||||||
- UDP
|
- UDP
|
||||||
|
|
||||||
agents:
|
agents:
|
||||||
- ref: client_1_green_user
|
- ref: client_2_green_user
|
||||||
team: GREEN
|
team: GREEN
|
||||||
type: GreenWebBrowsingAgent
|
type: GreenWebBrowsingAgent
|
||||||
observation_space:
|
observation_space:
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ game:
|
|||||||
- UDP
|
- UDP
|
||||||
|
|
||||||
agents:
|
agents:
|
||||||
- ref: client_1_green_user
|
- ref: client_2_green_user
|
||||||
team: GREEN
|
team: GREEN
|
||||||
type: GreenWebBrowsingAgent
|
type: GreenWebBrowsingAgent
|
||||||
observation_space:
|
observation_space:
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ game:
|
|||||||
- UDP
|
- UDP
|
||||||
|
|
||||||
agents:
|
agents:
|
||||||
- ref: client_1_green_user
|
- ref: client_2_green_user
|
||||||
team: GREEN
|
team: GREEN
|
||||||
type: GreenWebBrowsingAgent
|
type: GreenWebBrowsingAgent
|
||||||
observation_space:
|
observation_space:
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ game:
|
|||||||
- UDP
|
- UDP
|
||||||
|
|
||||||
agents:
|
agents:
|
||||||
- ref: client_1_green_user
|
- ref: client_2_green_user
|
||||||
team: GREEN
|
team: GREEN
|
||||||
type: GreenWebBrowsingAgent
|
type: GreenWebBrowsingAgent
|
||||||
observation_space:
|
observation_space:
|
||||||
|
|||||||
Reference in New Issue
Block a user