From 0c5429874671b169262cddd21e0a3adb64f4f901 Mon Sep 17 00:00:00 2001 From: Vasilis Valatsos Date: Thu, 13 Jun 2024 18:44:38 +0200 Subject: [PATCH] Made tensorboard aggregator and changed slightly scripts --- LICENSE | 0 README.md | 0 agent.py | 0 aggregator.py | 39 ++++++++++++++++++++++++++++++++++++ args.py | 0 default_bus_layout.tres | 0 icon.svg | 0 main.py | 0 poetry.lock | 23 ++++++++++++++++++++- policy.py | 0 pyproject.toml | 2 +- shell.nix | 11 ---------- stable_baselines3_example.py | 0 13 files changed, 62 insertions(+), 13 deletions(-) mode change 100644 => 100755 LICENSE mode change 100644 => 100755 README.md mode change 100644 => 100755 agent.py create mode 100644 aggregator.py mode change 100644 => 100755 args.py mode change 100644 => 100755 default_bus_layout.tres mode change 100644 => 100755 icon.svg mode change 100644 => 100755 main.py mode change 100644 => 100755 poetry.lock mode change 100644 => 100755 policy.py mode change 100644 => 100755 pyproject.toml delete mode 100644 shell.nix mode change 100644 => 100755 stable_baselines3_example.py diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/agent.py b/agent.py old mode 100644 new mode 100755 diff --git a/aggregator.py b/aggregator.py new file mode 100644 index 0000000..79759e1 --- /dev/null +++ b/aggregator.py @@ -0,0 +1,39 @@ +from glob import glob + +import tensorboard_reducer as tbr + +from policy import policies + +strict_steps=False +overwrite = True +reduce_ops = ("mean", "min", "max") + +for policy_name in policies: + print(f"Calculating {policy_name}") + + # Define glob pattern to find the directories + input_event_dirs = sorted(glob(f"tnsrbrd/sb3/{policy_name}_[0-9]")) + print(f"Found {input_event_dirs}") + + # Define output dir + events_output_dir = f"tnsrbrd/results/{policy_name}" + + # Load TB events + events_dict = tbr.load_tb_events(input_event_dirs, strict_steps=False, verbose=True) + + # Get number of steps and other params + n_scalars = len(events_dict) + n_steps, n_events = list(events_dict.values())[0].shape + + print(f"Loaded {n_events} TensorBoard runs with {n_scalars} scalars and {n_steps} steps each") + print(", ".join(events_dict)) + + # Reduce events + reduced_events = tbr.reduce_events(events_dict, reduce_ops, verbose=True) + + for op in reduce_ops: + print(f"Writing '{op}' reduction to '{events_output_dir}-{op}'") + + tbr.write_tb_events(reduced_events, events_output_dir, overwrite) + + print(f"Reduction of {policy_name} done.") diff --git a/args.py b/args.py old mode 100644 new mode 100755 diff --git a/default_bus_layout.tres b/default_bus_layout.tres old mode 100644 new mode 100755 diff --git a/icon.svg b/icon.svg old mode 100644 new mode 100755 diff --git a/main.py b/main.py old mode 100644 new mode 100755 diff --git a/poetry.lock b/poetry.lock old mode 100644 new mode 100755 index cd5ded8..07401df --- a/poetry.lock +++ b/poetry.lock @@ -1990,6 +1990,27 @@ files = [ {file = "tensorboard_data_server-0.7.2-py3-none-manylinux_2_31_x86_64.whl", hash = "sha256:ef687163c24185ae9754ed5650eb5bc4d84ff257aabdc33f0cc6f74d8ba54530"}, ] +[[package]] +name = "tensorboard-reducer" +version = "0.3.1" +description = "Reduce multiple TensorBoard runs to new event (or CSV) files" +optional = false +python-versions = ">=3.8" +files = [ + {file = "tensorboard-reducer-0.3.1.tar.gz", hash = "sha256:4e414d2c84c330e837c0acd728a2f74317d086003e87cb76429a24f082dbf66b"}, + {file = "tensorboard_reducer-0.3.1-py2.py3-none-any.whl", hash = "sha256:0196a8ec49b3c4535fe42a13dd5407953622e169985fc0ad5f7528bdfba5afbf"}, +] + +[package.dependencies] +numpy = ">=1.19" +pandas = ">=1.0.0" +tensorboard = ">=2.0" +tqdm = ">=4.0" + +[package.extras] +excel = ["openpyxl"] +test = ["pytest", "pytest-cov", "torch (>=1.6)"] + [[package]] name = "tifffile" version = "2024.5.10" @@ -2204,4 +2225,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.11" -content-hash = "2d575ca622be4eb61953716f1811accd9330cdbd4ad0ceee31700058e486e7e6" +content-hash = "130e4f2fe889802eb5d4d17d949cced5e88a8248c0fe9f25faabd232c2647259" diff --git a/policy.py b/policy.py old mode 100644 new mode 100755 diff --git a/pyproject.toml b/pyproject.toml old mode 100644 new mode 100755 index d49e673..77db7b4 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,6 @@ version = "0.1.0" description = "Godot training env for MARL" authors = ["Vasilis Valatsos "] readme = "README.md" -package-mode = false [tool.poetry.dependencies] python = "^3.11" @@ -15,6 +14,7 @@ lz4 = "^4.3.3" godot-rl = {url = "https://github.com/edbeeching/godot_rl_agents/archive/refs/heads/main.zip"} pettingzoo = "^1.24.3" tensorboard = "^2.16.2" +tensorboard-reducer = "^0.3.1" [build-system] diff --git a/shell.nix b/shell.nix deleted file mode 100644 index f655597..0000000 --- a/shell.nix +++ /dev/null @@ -1,11 +0,0 @@ -with import {}; - -mkShell { - NIX_LD_LIBRARY_PATH = lib.makeLibraryPath [ - stdenv.cc.cc - ]; - NIX_LD = lib.fileContents "${stdenv.cc}/nix-support/dynamic-linker"; - shellHook = '' - export LD_LIBRARY_PATH=$NIX_LD_LIBRARY_PATH - ''; -} diff --git a/stable_baselines3_example.py b/stable_baselines3_example.py old mode 100644 new mode 100755