diff --git a/environment.yml b/environment.yml index b91a9b4..4dd0f7b 100644 --- a/environment.yml +++ b/environment.yml @@ -1,33 +1,33 @@ name: rl -channels: - - pytorch - - conda-forge - - https://conda.anaconda.org/NLeSC - - defaults +#channels: +# - pytorch +# - conda-forge +# - https://conda.anaconda.org/NLeSC +# - defaults dependencies: - - jupyterlab - - line_profiler - - matplotlib>3.2 - - nb_conda_kernels - - numpy>1.18 - - pillow - - pip - - python=3.7.7 - - pytorch=1.6.0 - - requests - - scikit-learn - - sqlite - - torchvision=0.7.0 +# - jupyterlab +# - line_profiler +# - matplotlib>3.2 +# - nb_conda_kernels +# - numpy>1.18 +# - pillow +# - pip +# - python=3.7.7 +# - pytorch=1.6.0 +# - requests +# - scikit-learn +# - sqlite +# - torchvision=0.7.0 - tqdm - werkzeug - pip: - - atari-py - - black +# - atari-py +# - black - gym==0.17.2 - imageio - - pandas - - pyro-ppl +# - pandas +# - pyro-ppl - pymongo==3.11.0 - sacred==0.8.1 - - scipy - - stable-baselines==2.10.0 +# - scipy +# - stable-baselines==2.10.0 diff --git a/experiments/cluster_your_jets.ipynb b/experiments/cluster_your_jets.ipynb index 4086e18..0acc674 100644 --- a/experiments/cluster_your_jets.ipynb +++ b/experiments/cluster_your_jets.ipynb @@ -7,6 +7,66 @@ "# Using an RL agent to cluster a given set of particles (BYOJ)" ] }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "182.83333333333334" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "366/3+365/6" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "6.25" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "150/24" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "13.883888888888889" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "49982/3600" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -52,7 +112,7 @@ "logger = logging.getLogger(\"We\")\n", "logging.basicConfig(format=\"%(asctime)s %(levelname).1s: %(message)s\", datefmt=\"%y-%m-%d %H:%M\")\n", "\n", - "silence_list = [\"matplotlib\", \"showerSim\", \"hierarchical-trellis\"]\n", + "silence_list = [\"matplotlib\", \"ginkgo\", \"ClusterTrellis\"]\n", "for key in logging.Logger.manager.loggerDict:\n", " logging.getLogger(key).setLevel(logging.INFO)\n", " for check_key in silence_list:\n", @@ -85,12 +145,12 @@ "outputs": [], "source": [ "settings = {\n", - " \"n_max\": 20,\n", - " \"n_min\": 2,\n", - " \"w_jet\": True,\n", + " \"n_max\": 40,\n", + " \"n_min\": 4,\n", + " \"w_jet\": False,\n", " \"w_rate\": 3.0,\n", " \"qcd_rate\": 1.5,\n", - " \"pt_min\": 4.0**2,\n", + " \"pt_min\": 1.1**2,\n", " \"qcd_mass\": 30.0,\n", " \"w_mass\": 80.0,\n", " \"jet_momentum\": 400.0,\n", @@ -115,7 +175,106 @@ "metadata": {}, "outputs": [], "source": [ - "state_dict_filename = \"./data/runs/mcts_nn_m_20200930_092039_1010/model.pty\"" + "# state_dict_filename = \"./data/runs/mcts_nn_m_20200930_092039_1010/model.pty\"\n", + "state_dict_filename = \"./data/runs/mcts_nn_xs_20210324_154917_1003/model.pty\"" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "torch" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "OrderedDict([('actor.latent_net.0.weight',\n", + " tensor([[-0.0773, -0.0353, 0.0150, ..., -0.0535, 0.0250, 0.0297],\n", + " [ 0.0606, 0.0317, 0.0693, ..., -0.0630, -0.0599, 0.0054],\n", + " [ 0.0266, 0.0457, -0.0330, ..., 0.0749, -0.0161, -0.0620],\n", + " ...,\n", + " [-0.0609, -0.0652, -0.0117, ..., -0.0288, -0.0721, 0.0424],\n", + " [-0.0339, -0.0633, 0.0649, ..., -0.0611, 0.0072, 0.0507],\n", + " [ 0.0079, 0.0251, 0.0506, ..., 0.0232, 0.0685, -0.0386]])),\n", + " ('actor.latent_net.0.bias',\n", + " tensor([ 0.0012, -0.0326, -0.0127, 0.0258, -0.0139, 0.0442, 0.0569, -0.0441,\n", + " 0.0384, 0.0185, 0.0048, -0.0620, 0.0468, 0.0061, 0.0323, 0.0628,\n", + " -0.0348, -0.0601, -0.0473, 0.0348, -0.0514, -0.0099, -0.0504, 0.0282,\n", + " -0.0150, -0.0101, 0.0395, -0.0543, -0.0660, -0.0538, 0.0201, 0.0733,\n", + " -0.0620, 0.0135, 0.0252, 0.0399, 0.0016, 0.0613, -0.0096, 0.0751,\n", + " -0.0385, 0.0651, -0.0708, 0.0654, -0.0034, 0.0344, -0.0026, 0.0369,\n", + " -0.0668, 0.0434, 0.0721, 0.0041, 0.0275, 0.0786, 0.0104, 0.0191,\n", + " 0.0032, 0.0429, -0.0276, -0.0195, -0.0303, -0.0134, 0.0650, 0.0568,\n", + " 0.0768, 0.0085, 0.0688, 0.0627, -0.0091, 0.0356, -0.0452, -0.0330,\n", + " 0.0345, 0.0707, 0.0205, -0.0273, -0.0572, 0.0186, -0.0577, 0.0460,\n", + " 0.0634, -0.0206, -0.0308, -0.0687, -0.0555, 0.0408, 0.0762, -0.0651,\n", + " -0.0152, -0.0307, -0.0281, 0.0198, 0.0229, 0.0537, 0.0081, -0.0332,\n", + " 0.0676, -0.0306, -0.0570, -0.0290])),\n", + " ('actor.latent_net.2.weight',\n", + " tensor([[-0.0589, -0.0847, -0.0252, ..., 0.0637, -0.0570, -0.0077],\n", + " [-0.0789, 0.0260, 0.0652, ..., -0.0383, 0.0315, -0.0103],\n", + " [ 0.0266, -0.0511, 0.0277, ..., -0.0172, -0.0751, -0.0763],\n", + " ...,\n", + " [-0.0532, 0.0152, 0.0548, ..., 0.0618, -0.0567, 0.0047],\n", + " [-0.0325, 0.0173, -0.0028, ..., -0.0558, 0.0378, 0.0756],\n", + " [ 0.0270, 0.0033, -0.0628, ..., -0.0414, -0.0160, -0.0730]])),\n", + " ('actor.latent_net.2.bias',\n", + " tensor([-0.0788, -0.0342, 0.0216, 0.0438, -0.0124, -0.0130, -0.0357, 0.0263,\n", + " 0.0425, -0.0128, -0.0155, 0.0838, -0.0317, -0.0952, -0.0465, 0.0561,\n", + " -0.0782, 0.0753, 0.0779, -0.0048, 0.0541, -0.1007, -0.0430, -0.0608,\n", + " 0.0645, -0.0590, -0.0265, 0.0621, -0.0748, 0.0216, 0.0983, -0.0749,\n", + " -0.1026, -0.0770, -0.0615, -0.0390, 0.0788, -0.0881, -0.0482, 0.0396,\n", + " -0.0392, -0.0588, 0.0777, -0.0199, -0.0405, -0.0863, -0.0108, 0.0765,\n", + " 0.0368, -0.0154, 0.0846, -0.0026, -0.0193, 0.0869, -0.0580, -0.0338,\n", + " 0.0990, -0.0595, 0.0160, -0.0634, 0.0639, 0.0897, -0.0016, -0.0309,\n", + " 0.0183, -0.0869, -0.0453, -0.0781, 0.0036, -0.0292, 0.0787, -0.0398,\n", + " -0.0931, 0.0616, 0.0247, -0.0644, 0.0727, -0.0760, -0.0519, -0.0594,\n", + " 0.0875, 0.0641, 0.0238, 0.0946, 0.0634, 0.0523, -0.0067, -0.0095,\n", + " 0.0590, 0.0725, -0.0215, 0.0124, 0.0902, -0.0558, -0.0242, 0.0924,\n", + " 0.0194, 0.0439, -0.0944, -0.0234])),\n", + " ('actor.head_nets.0.0.weight',\n", + " tensor([[ 0.1090, -0.0408, -0.0461, 0.0580, 0.1046, -0.0872, 0.0221, 0.0483,\n", + " -0.0134, 0.1039, -0.0740, 0.0483, -0.0469, 0.0135, -0.0850, 0.0443,\n", + " -0.0822, 0.1095, -0.0265, -0.0696, -0.0923, -0.0953, -0.0428, 0.0958,\n", + " -0.0650, -0.1137, -0.0926, 0.0283, -0.0614, -0.0274, 0.1103, 0.0557,\n", + " -0.0926, -0.1061, 0.0677, 0.0698, -0.0462, 0.0892, -0.0918, 0.1145,\n", + " -0.0137, -0.0470, 0.1255, 0.0680, 0.0779, 0.0400, -0.0373, 0.0737,\n", + " -0.0969, 0.1015, 0.0047, 0.0868, 0.0465, -0.0669, -0.0226, -0.0416,\n", + " -0.0688, -0.0946, 0.0837, -0.0921, -0.0542, 0.0913, 0.0421, 0.0682,\n", + " 0.0004, -0.0506, 0.0481, 0.0920, 0.0519, 0.0141, 0.0572, 0.0191,\n", + " -0.0933, -0.0231, -0.0995, -0.1213, 0.0791, 0.0282, -0.0820, -0.1220,\n", + " -0.0778, -0.0754, -0.0487, 0.0173, -0.0211, 0.0362, 0.0283, 0.0275,\n", + " -0.0735, 0.0488, -0.1216, -0.0600, -0.0667, -0.0405, 0.0645, -0.0786,\n", + " -0.1304, 0.0290, -0.0601, -0.0285]])),\n", + " ('actor.head_nets.0.0.bias', tensor([0.0391]))])" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "torch.load(state_dict_filename)" ] }, { @@ -127,7 +286,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -150,15 +309,19 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 8, "metadata": {}, "outputs": [ { - "name": "stderr", + "name": "stdout", "output_type": "stream", "text": [ - "20-12-15 12:56 I: Generating 3 jets\n", - "20-12-15 12:56 I: Done\n" + " N const = 18\n", + " N const = 20\n", + " N const = 23\n", + " N const = 18\n", + " N const = 21\n", + " N const = 20\n" ] } ], @@ -166,6 +329,26 @@ "jets = grl.generate(n=3)" ] }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(jets)" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -190,17 +373,14 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "20-12-15 12:56 I: Clustering 3 jets\n", - "100%|██████████| 3/3 [02:00<00:00, 40.07s/it]\n", - "20-12-15 12:58 I: Saving clustered jets at reclustered_jets.pickle\n", - "20-12-15 12:58 I: Done\n" + "100%|██████████| 3/3 [07:50<00:00, 156.90s/it]\n" ] } ], @@ -208,6 +388,28 @@ "clustered_jets, log_likelihoods, illegal_actions, costs = grl.cluster(jets, filename=\"reclustered_jets.pickle\")" ] }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "([-100.49293088912964, -89.16798186302185, -97.30661630630493],\n", + " [0, 0, 0],\n", + " [344247, 236349, 362693])" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + " log_likelihoods, illegal_actions, costs" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -852,9 +1054,9 @@ ], "metadata": { "kernelspec": { - "display_name": "Python (rl)", + "display_name": "Python 3", "language": "python", - "name": "rl" + "name": "python3" }, "language_info": { "codemirror_mode": { @@ -866,7 +1068,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.7" + "version": "3.7.3" } }, "nbformat": 4, diff --git a/experiments/config.py b/experiments/config.py index d221aa5..d0ab6b3 100644 --- a/experiments/config.py +++ b/experiments/config.py @@ -35,18 +35,19 @@ def env_config(): illegal_reward = -100.0 illegal_actions_patience = 3 - n_max = 20 - n_min = 2 + n_max = 40 + n_min = 4 n_target = 1 min_reward = -100.0 state_rescaling = 0.01 padding_value = -1.0 - w_jet = True + w_jet = False w_rate = 3.0 qcd_rate = 1.5 - pt_min = 4.0 ** 2 + # pt_min = 4.0 ** 2 + pt_min = 1.1 ** 2 qcd_mass = 30.0 w_mass = 80.0 jet_momentum = 400.0 @@ -73,7 +74,8 @@ def agent_config(): # noinspection PyUnusedLocal @ex.config def train_config(): - pretrain_steps = 50000 + # pretrain_steps = 50000 + pretrain_steps = 1000 pretrain_n_mc_target = 1 pretrain_n_mc_min = 0 pretrain_n_mc_max = 10 @@ -81,7 +83,8 @@ def train_config(): pretrain_planning_mode = "mean" # {"max", "mean"}, refers to PUCT pretrain_c_puct = 1.0 - train_steps = 10000 + # train_steps = 10000 + train_steps = 1000 train_n_mc_target = 1 train_n_mc_min = 0 train_n_mc_max = 20 @@ -89,7 +92,8 @@ def train_config(): train_planning_mode = "mean" # {"max", "mean"}, refers to PUCT train_c_puct = 1.0 - imitation_steps = 1000000 + # imitation_steps = 1000000 + imitation_steps = 1 learning_rate = 1.0e-3 lr_decay = 0.01 @@ -110,7 +114,8 @@ def eval_config(): eval_jets = 500 eval_repeats = 1 - eval_filename = "./data/eval/eval2.pickle" + # eval_filename = "./data/eval/eval2.pickle" + eval_filename = "./data/eval/debug.pickle" redraw_eval_jets = False diff --git a/experiments/evaluate_dataset.py b/experiments/evaluate_dataset.py new file mode 100644 index 0000000..5c3eabd --- /dev/null +++ b/experiments/evaluate_dataset.py @@ -0,0 +1,48 @@ +import sys +import numpy as np +import logging +import torch + +# sys.path.append("../") +from ginkgo_rl import GinkgoRLInterface, PolicyMCTSAgent + +logger = logging.getLogger("We") +logging.basicConfig(format="%(asctime)s %(levelname).1s: %(message)s", datefmt="%y-%m-%d %H:%M") + +silence_list = ["matplotlib", "ginkgo", "ClusterTrellis"] +for key in logging.Logger.manager.loggerDict: + logging.getLogger(key).setLevel(logging.INFO) + for check_key in silence_list: + if check_key in key: + logging.getLogger(key).setLevel(logging.ERROR) + break + + +settings = { + "n_max": 40, + "n_min": 4, + "w_jet": False, + "w_rate": 3.0, + "qcd_rate": 1.5, + "pt_min": 1.1**2, + "qcd_mass": 30.0, + "w_mass": 80.0, + "jet_momentum": 400.0, + "jetdir": (1, 1, 1), + "beamsize": 20, + "n_mc_target": 2, + "n_mc_max": 50, + "device": torch.device("cpu"), +} + + +state_dict_filename = "/Users/sebastianmacaluso/Dropbox/Documents/Physics_projects/simulator/ginkgo-rl/experiments/data/runs/mcts_nn_xs_20210324_154917_1003/model.pty" + +grl = GinkgoRLInterface(state_dict_filename, **settings) + +jets = grl.generate(n=1) +print("Jets = ", jets) + +clustered_jets, log_likelihoods, illegal_actions, costs = grl.cluster(jets, filename="reclustered_jets.pickle") + +print(" log_likelihoods, illegal_actions, costs = ", log_likelihoods, illegal_actions, costs) \ No newline at end of file diff --git a/experiments/experiment.py b/experiments/experiment.py index 42cb6c5..0ab5394 100755 --- a/experiments/experiment.py +++ b/experiments/experiment.py @@ -5,6 +5,7 @@ import torch import os import numpy as np +import time sys.path.append("../") from experiments.config import ex, config, env_config, agent_config, train_config, technical_config @@ -50,7 +51,7 @@ def setup_run(name, run_name, seed): def setup_logging(debug): """ Sets up logging """ - silence_list = ["matplotlib", "showerSim", "hierarchical-trellis"] + silence_list = ["matplotlib", "ginkgo", "ClusterTrellis"] for key in logging.Logger.manager.loggerDict: logging.getLogger(key).setLevel(logging.DEBUG if debug else logging.INFO) @@ -420,7 +421,7 @@ def save_agent(agent, algorithm, policy, run_name): @ex.automain def main(): """ Main entry point for experiments """ - + startTime = time.time() logger.info(f"Hi!") check_config() @@ -432,7 +433,10 @@ def main(): train(env, agent) save_agent(agent) - result = eval(agent, env) + # result = eval(agent, env) + + endTime = time.time() -startTime + logger.info(f"Total time = {endTime}") logger.info(f"That's all, have a nice day!") - return result + # return result diff --git a/experiments/hpc/run1.sh b/experiments/hpc/run1.sh index a8e3bb6..6b7316f 100755 --- a/experiments/hpc/run1.sh +++ b/experiments/hpc/run1.sh @@ -1,14 +1,20 @@ -#!/usr/bin/env bash - -#SBATCH --job-name=ginkgo-rl -#SBATCH --output=log_ginkgo_rl_run1_%a.log +#!/bin/bash #SBATCH --nodes=1 +#SBATCH --ntasks-per-node=1 #SBATCH --cpus-per-task=1 +#SBATCH --time=30:00 #SBATCH --mem=16GB -#SBATCH --time=5-00:00:00 -# #SBATCH --gres=gpu:1 +#SBATCH --job-name=ginkgo-rl +#SBATCH --mail-type=END +#SBATCH --mail-user=sm4511@nyu.edu +#SBATCH --output=logs/log_ginkgo_rl_run1_%a.log +#SBATCH --gres=gpu:1 + + +##SBATCH --time=5-00:00:00 + -dir=/scratch/jb6504/ginkgo-rl/experiments +dir=/scratch/sm4511/ginkgo-rl/experiments seed=$((SLURM_ARRAY_TASK_ID + 1000)) setup=$((SLURM_ARRAY_TASK_ID)) diff --git a/experiments/hpc/run2.sh b/experiments/hpc/run2.sh index e39ec04..4f5c3d4 100755 --- a/experiments/hpc/run2.sh +++ b/experiments/hpc/run2.sh @@ -1,41 +1,51 @@ -#!/usr/bin/env bash - -#SBATCH --job-name=ginkgo-rl -#SBATCH --output=log_ginkgo_rl_run2_%a.log +#!/bin/bash #SBATCH --nodes=1 +#SBATCH --ntasks-per-node=1 #SBATCH --cpus-per-task=1 +#SBATCH --time=30:00 #SBATCH --mem=16GB -#SBATCH --time=5-00:00:00 -# #SBATCH --gres=gpu:1 +#SBATCH --job-name=ginkgo-rl +#SBATCH --mail-type=END +#SBATCH --mail-user=sm4511@nyu.edu +#SBATCH --output=logs/log_ginkgo_rl_run1_%a.log +#SBATCH --gres=gpu:1 -dir=/scratch/jb6504/ginkgo-rl/experiments +##SBATCH --time=5-00:00:00 + +dir=/scratch/sm4511/ginkgo-rl/experiments seed=$((SLURM_ARRAY_TASK_ID + 1000)) setup=$((SLURM_ARRAY_TASK_ID / 5)) cd $dir -source activate rl +#source activate rl + +singularity exec --nv \ + --overlay /scratch/sm4511/pytorch1.7.0-cuda11.0.ext3:ro \ + /scratch/work/public/singularity/cuda11.0-cudnn8-devel-ubuntu18.04.sif \ + bash -c "source /ext3/env.sh; python -u $SCRATCH/ginkgo-rl/experiments/experiment.py with mcts_s seed=$seed database=False" + -case ${setup} in -0) python -u experiment.py with mcts_xs "seed=$seed" "database=False";; -1) python -u experiment.py with mcts_s "seed=$seed" "database=False";; -2) python -u experiment.py with mcts_m "seed=$seed" "database=False";; -3) python -u experiment.py with mcts_l "seed=$seed" "database=False";; -4) python -u experiment.py with lfd "seed=$seed" "database=False";; -5) python -u experiment.py with lfd_mcts_s "seed=$seed" "database=False";; -6) python -u experiment.py with mcts_exploit "seed=$seed" "database=False";; -7) python -u experiment.py with mcts_explore "seed=$seed" "database=False";; -8) python -u experiment.py with mcts_raw "seed=$seed" "database=False";; -9) python -u experiment.py with mcts_puct_decisions "seed=$seed" "database=False";; -10) python -u experiment.py with mcts_no_beamsearch "seed=$seed" "database=False";; -11) python -u experiment.py with mcts_random "seed=$seed" "database=False";; -12) python -u experiment.py with random "seed=$seed" "database=False";; -13) python -u experiment.py with lfd_mcts_xs "seed=$seed" "database=False";; -14) python -u experiment.py with lfd_mcts_m "seed=$seed" "database=False";; -15) python -u experiment.py with lfd_mcts_l "seed=$seed" "database=False";; -16) python -u experiment.py with lfd_mleteacher "seed=$seed" "database=False";; -17) python -u experiment.py with lfd_mcts_mleteacher_xs "seed=$seed" "database=False";; -18) python -u experiment.py with lfd_mcts_mleteacher_s "seed=$seed" "database=False";; -19) python -u experiment.py with lfd_mcts_mleteacher_m "seed=$seed" "database=False";; -20) python -u experiment.py with lfd_mcts_mleteacher_l "seed=$seed" "database=False";; -*) echo "Nothing to do for job ${SLURM_ARRAY_TASK_ID}" ;; -esac +#case ${setup} in +#0) python -u experiment.py with mcts_xs "seed=$seed" "database=False";; +#1) python -u experiment.py with mcts_s "seed=$seed" "database=False";; +#2) python -u experiment.py with mcts_m "seed=$seed" "database=False";; +#3) python -u experiment.py with mcts_l "seed=$seed" "database=False";; +#4) python -u experiment.py with lfd "seed=$seed" "database=False";; +#5) python -u experiment.py with lfd_mcts_s "seed=$seed" "database=False";; +#6) python -u experiment.py with mcts_exploit "seed=$seed" "database=False";; +#7) python -u experiment.py with mcts_explore "seed=$seed" "database=False";; +#8) python -u experiment.py with mcts_raw "seed=$seed" "database=False";; +#9) python -u experiment.py with mcts_puct_decisions "seed=$seed" "database=False";; +#10) python -u experiment.py with mcts_no_beamsearch "seed=$seed" "database=False";; +#11) python -u experiment.py with mcts_random "seed=$seed" "database=False";; +#12) python -u experiment.py with random "seed=$seed" "database=False";; +#13) python -u experiment.py with lfd_mcts_xs "seed=$seed" "database=False";; +#14) python -u experiment.py with lfd_mcts_m "seed=$seed" "database=False";; +#15) python -u experiment.py with lfd_mcts_l "seed=$seed" "database=False";; +#16) python -u experiment.py with lfd_mleteacher "seed=$seed" "database=False";; +#17) python -u experiment.py with lfd_mcts_mleteacher_xs "seed=$seed" "database=False";; +#18) python -u experiment.py with lfd_mcts_mleteacher_s "seed=$seed" "database=False";; +#19) python -u experiment.py with lfd_mcts_mleteacher_m "seed=$seed" "database=False";; +#20) python -u experiment.py with lfd_mcts_mleteacher_l "seed=$seed" "database=False";; +#*) echo "Nothing to do for job ${SLURM_ARRAY_TASK_ID}" ;; +#esac diff --git a/experiments/plot_results.ipynb b/experiments/plot_results.ipynb index 48daf46..c0748cd 100644 --- a/experiments/plot_results.ipynb +++ b/experiments/plot_results.ipynb @@ -865,9 +865,9 @@ ], "metadata": { "kernelspec": { - "display_name": "Python (rl)", + "display_name": "Python 3", "language": "python", - "name": "rl" + "name": "python3" }, "language_info": { "codemirror_mode": { @@ -879,7 +879,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.7" + "version": "3.8.5" } }, "nbformat": 4, diff --git a/ginkgo_rl/agents/imitation_learning.py b/ginkgo_rl/agents/imitation_learning.py index db1ac2f..4479963 100644 --- a/ginkgo_rl/agents/imitation_learning.py +++ b/ginkgo_rl/agents/imitation_learning.py @@ -10,8 +10,8 @@ from .mcts import PolicyMCTSAgent # Workaround for now until Trellis is better packaged -sys.path.append("/Users/johannbrehmer/work/projects/shower_rl/hierarchical-trellis/src") -from run_physics_experiment_invM import compare_map_gt_and_bs_trees as compute_trellis +# sys.path.append("/Users/johannbrehmer/work/projects/shower_rl/hierarchical-trellis/src") +from ClusterTrellis.run_experiments import compare_map_gt_and_bs_trees as compute_trellis logger = logging.getLogger(__name__) diff --git a/ginkgo_rl/envs/ginkgo_likelihood.py b/ginkgo_rl/envs/ginkgo_likelihood.py index 02f6130..9ef3049 100644 --- a/ginkgo_rl/envs/ginkgo_likelihood.py +++ b/ginkgo_rl/envs/ginkgo_likelihood.py @@ -2,8 +2,8 @@ from gym import Env from gym.spaces import Discrete, Box, MultiDiscrete import logging -from showerSim.invMass_ginkgo import Simulator as GinkgoSim -from showerSim.likelihood_invM import split_logLH as ginkgo_log_likelihood +from ginkgo.invMass_ginkgo import Simulator as GinkgoSim +from ginkgo.likelihood_invM import split_logLH as ginkgo_log_likelihood import torch import copy diff --git a/ginkgo_rl/eval/evaluator.py b/ginkgo_rl/eval/evaluator.py index b44fa5e..22d9fdc 100644 --- a/ginkgo_rl/eval/evaluator.py +++ b/ginkgo_rl/eval/evaluator.py @@ -14,18 +14,20 @@ # Workaround for now until Trellis is better packaged try: - sys.path.append("/Users/johannbrehmer/work/projects/shower_rl/hierarchical-trellis/src") - sys.path.append("/scratch/jb6504/hierarchical-trellis/src") - from run_physics_experiment_invM import compare_map_gt_and_bs_trees as compute_trellis + # sys.path.append("/Users/johannbrehmer/work/projects/shower_rl/hierarchical-trellis/src") + # sys.path.append("/scratch/jb6504/hierarchical-trellis/src") + # from run_physics_experiment_invM import compare_map_gt_and_bs_trees as compute_trellis + from ClusterTrellis.run_experiments import compare_map_gt_and_bs_trees as compute_trellis except Exception: logger.warning("Error importing hierarchical trellis code.") compute_trellis = None try: - sys.path.insert(0, "/Users/johannbrehmer/work/projects/shower_rl/ReclusterTreeAlgorithms/scripts") - sys.path.insert(0, "/scratch/jb6504/ReclusterTreeAlgorithms/scripts") - sys.path.insert(0, "/scratch/jb6504/ReclusterTreeAlgorithms") - import beamSearchOptimal_invM as beam_search + # sys.path.insert(0, "/Users/johannbrehmer/work/projects/shower_rl/ReclusterTreeAlgorithms/scripts") + # sys.path.insert(0, "/scratch/jb6504/ReclusterTreeAlgorithms/scripts") + # sys.path.insert(0, "/scratch/jb6504/ReclusterTreeAlgorithms") + # import beamSearchOptimal_invM as beam_search + from StandardHC import beamSearchOptimal_invM as beam_search except Exception: logger.warning("Error importing beam search code.") beam_search = None diff --git a/run2.sh b/run2.sh new file mode 100755 index 0000000..72638ce --- /dev/null +++ b/run2.sh @@ -0,0 +1,53 @@ +#!/bin/bash +#SBATCH --nodes=1 +#SBATCH --ntasks-per-node=1 +#SBATCH --cpus-per-task=1 +#SBATCH --time=30:00:00 +#SBATCH --mem=32GB +#SBATCH --job-name=ginkgo-rl +#SBATCH --mail-type=END +#SBATCH --mail-user=sm4511@nyu.edu +#SBATCH --output=logs/log_ginkgo_rl_run1_%a.log +#SBATCH --gres=gpu:1 + + + +dir=/scratch/sm4511/ginkgo-rl/experiments +seed=$((SLURM_ARRAY_TASK_ID + 1000)) +setup=$((SLURM_ARRAY_TASK_ID / 5)) + +cd $dir +#source activate rl + +singularity exec --nv \ + --overlay /scratch/sm4511/pytorch1.7.0-cuda11.0.ext3:ro \ + /scratch/work/public/singularity/cuda11.0-cudnn8-devel-ubuntu18.04.sif \ + bash -c "source /ext3/env.sh; python -u $SCRATCH/ginkgo-rl/experiments/experiment.py with mcts_l seed=$seed database=False" + + +#case ${setup} in +#0) python -u experiment.py with mcts_xs "seed=$seed" "database=False";; +#1) python -u experiment.py with mcts_s "seed=$seed" "database=False";; +#2) python -u experiment.py with mcts_m "seed=$seed" "database=False";; +#3) python -u experiment.py with mcts_l "seed=$seed" "database=False";; +#4) python -u experiment.py with lfd "seed=$seed" "database=False";; +#5) python -u experiment.py with lfd_mcts_s "seed=$seed" "database=False";; +#6) python -u experiment.py with mcts_exploit "seed=$seed" "database=False";; +#7) python -u experiment.py with mcts_explore "seed=$seed" "database=False";; +#8) python -u experiment.py with mcts_raw "seed=$seed" "database=False";; +#9) python -u experiment.py with mcts_puct_decisions "seed=$seed" "database=False";; +#10) python -u experiment.py with mcts_no_beamsearch "seed=$seed" "database=False";; +#11) python -u experiment.py with mcts_random "seed=$seed" "database=False";; +#12) python -u experiment.py with random "seed=$seed" "database=False";; +#13) python -u experiment.py with lfd_mcts_xs "seed=$seed" "database=False";; +#14) python -u experiment.py with lfd_mcts_m "seed=$seed" "database=False";; +#15) python -u experiment.py with lfd_mcts_l "seed=$seed" "database=False";; +#16) python -u experiment.py with lfd_mleteacher "seed=$seed" "database=False";; +#17) python -u experiment.py with lfd_mcts_mleteacher_xs "seed=$seed" "database=False";; +#18) python -u experiment.py with lfd_mcts_mleteacher_s "seed=$seed" "database=False";; +#19) python -u experiment.py with lfd_mcts_mleteacher_m "seed=$seed" "database=False";; +#20) python -u experiment.py with lfd_mcts_mleteacher_l "seed=$seed" "database=False";; +#*) echo "Nothing to do for job ${SLURM_ARRAY_TASK_ID}" ;; +#esac + +## to submit(for 3 jobs): sbatch --array 0-2 submitHPC_HCmanager.s \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..e440d70 --- /dev/null +++ b/setup.py @@ -0,0 +1,21 @@ +import setuptools + + +setuptools.setup( + name="ginkgo-rl", + version="0.0.1", + description="Reinforcement Learning algorithm for Ginkgo Jets", + url="https://github.com/johannbrehmer/ginkgo-rl", + author="", + author_email="", + license="MIT", + packages=setuptools.find_packages(where="./"), + package_dir={"": "./"}, + zip_safe=False, + classifiers=[ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + ], + python_requires='>=3.6', +)