Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trajectory visualization #38

Closed
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
8f6ecd7
up canvas to 2.6 because npm throw error on installation 2.5
bmielnicki Jul 26, 2020
d01ccd7
add visualization folder with event visualization code
bmielnicki Jul 26, 2020
e9c3f9b
fill in method for event visualization
bmielnicki Jul 26, 2020
583310e
merge master to trajectory visualization branch
bmielnicki Jul 29, 2020
edd4800
deleting currently not used require.js from package-lock.json
bmielnicki Jul 29, 2020
e715fa1
agent evaluator introduction tutorial notebook
bmielnicki Aug 2, 2020
176ae86
undo unwanted change done in merge
bmielnicki Aug 4, 2020
4640f91
minor tutorial notebook change
bmielnicki Aug 4, 2020
10b19d9
add basic documentation to visualization code
bmielnicki Aug 5, 2020
cfb54bb
delete empty file
bmielnicki Aug 5, 2020
11882c4
better look of the code in markdown
bmielnicki Aug 5, 2020
359a8b0
Merge remote-tracking branch 'overcooked_ai_remote/master' into traje…
bmielnicki Aug 11, 2020
819b95c
add support for ep infos
bmielnicki Aug 13, 2020
ff7bb85
adding line identifying file is pasted successfully
bmielnicki Aug 13, 2020
b3178a1
changed naming convention from item to object, add line identifying f…
bmielnicki Aug 13, 2020
4835b23
add identifying file line, add generating box_id (in case of multiple…
bmielnicki Aug 13, 2020
0a69b18
add json dumping of np arrays
bmielnicki Aug 13, 2020
38da97b
visualization tests
bmielnicki Aug 13, 2020
4a97a21
push extraction of most events into overcooked_mdp - add object_id to…
bmielnicki Aug 13, 2020
7edba54
add visualization tests to full suite
bmielnicki Aug 13, 2020
2ae5e7d
undo updating canvas version
bmielnicki Aug 13, 2020
a3a2161
merge
bmielnicki Aug 13, 2020
d9f3241
adding visualization tests to proper directory
bmielnicki Aug 13, 2020
82ac6c4
cleaning unused files after merge
bmielnicki Aug 13, 2020
b75ef32
Merge branch 'master' into trajectory_visualization_merged
bmielnicki Aug 15, 2020
fc9383f
fix test to not raise error on any dollar sign (e.g. jquery code)
bmielnicki Aug 18, 2020
71e97d8
__eq__ and __hash__ now uses object_id
bmielnicki Aug 18, 2020
8f258d8
renamed one letter variables
bmielnicki Aug 18, 2020
e6111b3
Merge remote-tracking branch 'upstream/master' into trajectory_visual…
bmielnicki Aug 18, 2020
9216142
undo using object_id in __eq__ and __hash__ - this made tests fail
bmielnicki Aug 18, 2020
7601c77
add visualization tests to pythontests.yml
bmielnicki Aug 18, 2020
7cbb986
add updated expected_extracted_events with potting and delivery events
bmielnicki Aug 18, 2020
d3455a6
read visualization files in the way that hopefully will also work on OSX
bmielnicki Aug 18, 2020
8211232
fix osx testing error
bmielnicki Aug 19, 2020
c7a74b8
change tests to use ids independent checks
bmielnicki Aug 19, 2020
086b265
adds ids independent equal methods and change __eq__ methods to use o…
bmielnicki Aug 19, 2020
67a2f88
Merge branch 'trajectory_visualization_merged' of https://github.com/…
bmielnicki Aug 19, 2020
ae9bd97
Merge branch 'master' into trajectory_visualization_merged
bmielnicki Aug 19, 2020
3806752
add visualization/web/ to package data to install it despite not bein…
bmielnicki Sep 7, 2020
79465d7
- refactor visualization code (more based on css)\n- add custom css u…
bmielnicki Sep 7, 2020
cd6e895
update test after updating visualization code
bmielnicki Sep 7, 2020
5c10435
put load_text_file function into utils
bmielnicki Sep 7, 2020
cdb97af
delete tutorial notebook - this will be separate pull request after m…
bmielnicki Sep 7, 2020
8583189
merge
bmielnicki Sep 7, 2020
ab11f49
resolve conflict ommited by accident
bmielnicki Sep 7, 2020
bbff343
add fixed imports
bmielnicki Sep 7, 2020
4534881
Merge branch 'master' into trajectory_visualization_merged
bmielnicki Sep 25, 2020
9a0c33c
Merge branch 'master' into trajectory_visualization_merged
bmielnicki Oct 22, 2020
2e6546c
split event_chart.js into the part where it is run from python and pa…
bmielnicki Oct 23, 2020
30cb8d3
Merge branch 'master' into trajectory_visualization_merged
bmielnicki Oct 23, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .github/workflows/pythontests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ jobs:
architecture: 'x64'
- name: Install dependencies
run: python -m pip install --upgrade pip
- name: Setup
run: pip install .
- name: Setup # needs -e flag to read overcooked_ai/visualization non python files
run: pip install -e .
- name: Run tests
run: |
python testing/overcooked_test.py
python testing/overcooked_test.py
python testing/visualization_test.py
## This should be uncommented once the planners are updated ##
# osx_full_tests:
# runs-on: macos-latest
Expand Down Expand Up @@ -46,11 +47,12 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install coverage
- name: Setup # needs -e flag for coverage tests to work
- name: Setup # needs -e flag for coverage tests to work and to read overcooked_ai/visualization non python files
run: pip install -e .
- name: Run tests and generate coverage report
run: |
coverage run testing/overcooked_test.py
coverage run -a testing/visualization_test.py
coverage report
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
Expand Down
38 changes: 28 additions & 10 deletions src/overcooked_ai_py/agents/benchmarking.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
import numpy as np
from IPython.display import display

from overcooked_ai_py.utils import save_pickle, load_pickle, cumulative_rewards_from_rew_list, save_as_json, load_from_json, mean_and_std_err, append_dictionaries, merge_dictionaries, rm_idx_from_dict, take_indexes_from_dict
from overcooked_ai_py.utils import save_pickle, load_pickle, cumulative_rewards_from_rew_list, save_as_json, load_from_json, mean_and_std_err, append_dictionaries, merge_dictionaries, rm_idx_from_dict, take_indexes_from_dict, NumpyArrayEncoder
from overcooked_ai_py.planning.planners import NO_COUNTERS_PARAMS, MediumLevelPlanner
from overcooked_ai_py.mdp.layout_generator import LayoutGenerator
from overcooked_ai_py.agents.agent import AgentPair, CoupledPlanningAgent, RandomAgent, GreedyHumanModel
from overcooked_ai_py.mdp.overcooked_mdp import OvercookedGridworld, Action, OvercookedState
from overcooked_ai_py.mdp.overcooked_env import OvercookedEnv
from overcooked_ai_py.visualization.extract_events import extract_events
from overcooked_ai_py.visualization.visualization_utils import run_html_in_ipython, run_html_in_web, create_chart_html


class AgentEvaluator(object):
Expand Down Expand Up @@ -162,7 +164,7 @@ def _check_trajectories_dynamics(trajectories):

next_state, reward, done, info = simulation_env.step(actions[i])

assert states[i + 1] == next_state, "States differed (expected vs actual): {}\n\nexpected dict: \t{}\nactual dict: \t{}".format(
assert states[i + 1].ids_independent_equal(next_state), "States differed (expected vs actual): {}\n\nexpected dict: \t{}\nactual dict: \t{}".format(
simulation_env.display_states(states[i + 1], next_state), states[i+1].to_dict(), next_state.to_dict()
)
assert rewards[i] == reward, "{} \t {}".format(rewards[i], reward)
Expand Down Expand Up @@ -259,19 +261,24 @@ def make_trajectories_json_serializable(trajectories):
dict_traj['ep_dones'] = [list(lst) for lst in dict_traj['ep_dones']]
dict_traj['ep_returns'] = [int(val) for val in dict_traj['ep_returns']]
dict_traj['ep_lengths'] = [int(val) for val in dict_traj['ep_lengths']]

# NOTE: Currently saving to JSON does not support ep_infos (due to nested np.arrays) or metadata
del dict_traj['ep_infos']
# NOTE: Currently saving to JSON does not support metadata
dict_traj['ep_infos'] = json.loads(json.dumps(dict_traj['ep_infos'], cls=NumpyArrayEncoder))
del dict_traj['metadatas']
return dict_traj

@staticmethod
def load_traj_from_json(filename):
traj_dict = load_from_json(filename)
return AgentEvaluator.load_traj_from_json_obj(traj_dict)

@staticmethod
def load_traj_from_json_obj(obj):
# currently ep_infos is not changed back to numpy arrays/tuples from lists
traj_dict = copy.deepcopy(obj)
traj_dict["ep_states"] = [[OvercookedState.from_dict(ob) for ob in curr_ep_obs] for curr_ep_obs in traj_dict["ep_states"]]
traj_dict["ep_actions"] = [[tuple(tuple(a) if type(a) is list else a for a in j_a) for j_a in ep_acts] for ep_acts in traj_dict["ep_actions"]]
return traj_dict

############################
# TRAJ MANINPULATION UTILS #
############################
Expand Down Expand Up @@ -379,8 +386,19 @@ def update(t = 1.0):
display(out, t)

# EVENTS VISUALIZATION METHODS #

@staticmethod
def events_visualization(trajs, traj_index):
# TODO
pass
def events_visualization(trajs, traj_index=0, ipython=False, chart_settings=None):
"""
Displays chart with visualization of events (when items pickups happened etc.)
ipython - chooses between opening chart
in default browser or below ipython cell (for ipython=True)
chart_settings - json with various chart settings that overwrittes default ones
for more info see create_chart_html function with comments aboutr default chart settings
"""
events = extract_events(trajs, traj_index)
html = create_chart_html(events, chart_settings)
if ipython:
run_html_in_ipython(html)
else:
run_html_in_web(html)

Large diffs are not rendered by default.

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion src/overcooked_ai_py/mdp/overcooked_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ def reset(self):
"cumulative_shaped_rewards_by_agent": np.array([0] * self.mdp.num_players)
}
self.game_stats = {**events_dict, **rewards_dict}
self.events_list = []

def is_done(self):
"""Whether the episode is over."""
Expand Down Expand Up @@ -235,6 +236,7 @@ def _prepare_info_dict(self, joint_agent_action_info, mdp_infos):
def _add_episode_info(self, env_info):
env_info["episode"] = {
"ep_game_stats": self.game_stats,
"events_list": self.events_list,
"ep_sparse_r": sum(self.game_stats["cumulative_sparse_rewards_by_agent"]),
"ep_shaped_r": sum(self.game_stats["cumulative_shaped_rewards_by_agent"]),
"ep_sparse_r_by_agent": self.game_stats["cumulative_sparse_rewards_by_agent"],
Expand All @@ -257,7 +259,10 @@ def _update_game_stats(self, infos):
for idx, event_by_agent in enumerate(event_occurred_by_idx):
if event_by_agent:
self.game_stats[event_type][idx].append(self.state.timestep)


for event in infos["events_list"]:
event["timestep"] = self.state.timestep
self.events_list.append(event)

####################
# TRAJECTORY LOGIC #
Expand Down
Loading