-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_bench.sh
executable file
·2477 lines (2195 loc) · 66.5 KB
/
run_bench.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
set -e
# To avoid running everything more than once, we will stick ALL (algo, env_id) pairs inside of $RLSCOPE_DIR/output/rlscope_bench/all.
#
# (1) On vs off policy:
# Run Atari Pong on all environments that support it (that we have annotated):
# - Ppo2 [sort of on-policy]
# - A2c [on-policy]
# - Dqn [off-policy]
# We can use this to compare on-policy vs off-policy
#
# (2) Compare environments:
# Run ALL bullet environments for at least one algorithm (ppo2).
#
# (3) Compare algorithms:
# Run ALL algorithms on 1 bullet environment (Walker)
#
# (4) Compare all RL workloads:
# Run ALL algorithms on ALL bullet environments
IS_ZSH="$(ps -ef | grep $$ | grep -v --perl-regexp 'grep|ps ' | grep zsh --quiet && echo yes || echo no)"
if [ "$IS_ZSH" = 'yes' ]; then
ROOT="$(readlink -f "$(dirname "${0:A}")")"
else
ROOT="$(readlink -f "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )")"
fi
source $ROOT/dockerfiles/sh/docker_runtime_common.sh
DRY_RUN=${DRY_RUN:-no}
DEBUG=${DEBUG:-no}
if [ "$DEBUG" = 'yes' ]; then
set -x
fi
CALIB_DIR=$RLSCOPE_DIR/calibration/microbench
CALIB_OPTS=( \
--cupti-overhead-json $CALIB_DIR/cupti_overhead.json \
--LD-PRELOAD-overhead-json $CALIB_DIR/LD_PRELOAD_overhead.json \
--python-clib-interception-tensorflow-json $CALIB_DIR/category_events.python_clib_interception.tensorflow.json \
--python-clib-interception-simulator-json $CALIB_DIR/category_events.python_clib_interception.simulator.json \
--python-annotation-json $CALIB_DIR/category_events.python_annotation.json \
)
_run_bench() {
local all_dir=$RLSCOPE_DIR/output/rlscope_bench/all
_do rls-bench --dir $all_dir "$@"
}
old_run_stable_baselines() {
sb_all_reps "$@"
}
sb_train() {
_run_bench "$@" stable-baselines
}
rlscope_analyze() {
rls-run "${CALIB_OPTS[@]}" "$@"
}
run_total_training_time_plot() {
_do rls-quick-expr --expr plot_fig --fig fig_13_overhead_correction \
"${CALIB_OPTS[@]}" \
--root-dir $RLSCOPE_DATA_DIR/rlscope/output/expr_total_training_time \
--debug-memoize "$@"
}
sb_analyze() {
_run_bench "$@" --analyze stable-baselines "${CALIB_OPTS[@]}"
}
sb_plot() {
_run_bench "$@" --analyze stable-baselines "${CALIB_OPTS[@]}" --mode plot
}
sb_all_reps() {
"$@" --repetition 1
"$@" --repetition 2
"$@" --repetition 3
}
sb_reps_first() {
sb_all_reps sb_train "$@"
sb_all_reps sb_analyze "$@"
sb_all_reps sb_plot "$@"
}
sb_one_rep() {
sb_train "$@"
sb_analyze "$@"
# SKIP plotting until we fix it, so we can process all the repetitions over night!
# sb_plot "$@"
}
sb_one_rep_plot() {
# sb_train "$@"
# sb_analyze "$@"
sb_plot "$@"
}
sb_reps_last() {
sb_one_rep --repetition 1 "$@"
sb_one_rep --repetition 2 "$@"
sb_one_rep --repetition 3 "$@"
}
# 1. Algo choice - medium complexity (Walker2D)
# - 511 + 383 + 270 + 44 = 1,208
# 2. Env choice (PPO2):
# - 1.4 + 4.8 + 14 + 14 + 23 + 124 + 489 + 511 + 565 = 1,746.2
# 3. Algo choice - low complexity (MountainCar)
# - 1.4 + 2.9 + 3.0 + 14 + 100 + 292 + 313 = 726.3
# 4. All RL workloads
# - NOTE: we SHOULD be able to skip analyzing all (algo, env) pairs...
# - 1.4 + 2.9 + 3.0 + 14 + 100 + 292 + 313 = 726.3
run_fig_algorithm_choice_1a_med_complexity() {
# logan
sb_reps_last --algo-env-group algorithm_choice_1a_med_complexity "$@"
}
run_fig_all_rl_workloads_plot_01() {
# logan
sb_one_rep_plot --repetition 1 "$@" --algo-env-group all_rl_workloads "$@"
}
run_fig_algorithm_choice_1a_med_complexity_plot_01() {
# logan
sb_one_rep_plot --repetition 1 "$@" --algo-env-group algorithm_choice_1a_med_complexity "$@"
}
run_fig_dqn_detailed_plot_01() {
# eco-13
sb_one_rep_plot --repetition 1 --algo-env-group dqn_detailed "$@"
}
run_fig_environment_choice() {
# eco-13
sb_reps_last --algo-env-group environment_choice "$@"
}
run_fig_environment_choice_plot_01() {
# eco-13
sb_one_rep_plot --repetition 1 --algo-env-group environment_choice "$@"
}
run_fig_algorithm_choice_1b_low_complexity() {
# eco-14
sb_reps_last --algo-env-group algorithm_choice_1b_low_complexity "$@"
}
run_fig_algorithm_choice_1b_low_complexity_plot_01() {
# eco-14
sb_one_rep_plot --repetition 1 --algo-env-group algorithm_choice_1b_low_complexity "$@"
}
#run_fig_all_rl_workloads() {
# sb_reps_last --algo-env-group all_rl_workloads "$@"
#}
run_stable_baselines_all() {
run_fig_algorithm_choice_1a_med_complexity "$@"
run_fig_environment_choice "$@"
run_fig_algorithm_choice_1b_low_complexity "$@"
# SKIP: until we can avoid runnning rls-run on all (algo, env) pairs.
# run_fig_all_rl_workloads "$@"
}
#run_fig_on_vs_off_policy() {
# sb_reps_last --algo-env-group on_vs_off_policy "$@"
#}
RUN_DEBUG_ARGS=(--subdir debug)
INSTRUMENTED_ARGS=(--instrumented)
_run_debug_ppo_full_training() {
local num_training_loop_iterations=1
local n_envs=8
local n_steps=2048
rls-quick-expr "${RUN_DEBUG_ARGS[@]}" --expr total_training_time --repetitions 1 --bullet --instrumented --n-timesteps $((n_envs*n_steps*num_training_loop_iterations)) --algo ppo2 --env MinitaurBulletEnv-v0 "$@"
}
_run_debug_dqn_full_training() {
rls-quick-expr "${RUN_DEBUG_ARGS[@]}" --expr total_training_time --repetitions 1 --instrumented --n-timesteps 20000 --algo dqn --env PongNoFrameskip-v4 "$@"
}
_run_debug_sac_full_training() {
rls-quick-expr "${RUN_DEBUG_ARGS[@]}" --expr total_training_time --repetitions 1 --instrumented --n-timesteps 20000 --algo sac --env AntBulletEnv-v0 "$@"
}
_run_debug_a2c_full_training() {
rls-quick-expr "${RUN_DEBUG_ARGS[@]}" --expr total_training_time --repetitions 1 --instrumented --n-timesteps 20000 --algo a2c --env HopperBulletEnv-v0 "$@"
}
_run_debug_ddpg_full_training() {
rls-quick-expr "${RUN_DEBUG_ARGS[@]}" --expr total_training_time --repetitions 1 --instrumented --n-timesteps 20000 --algo ddpg --env Walker2DBulletEnv-v0 "$@"
}
fig_9_simulator_choice_environments() {
# echo AirLearningEnv
# TODO: this was commented out; why?
echo PongNoFrameskip-v4
echo AntBulletEnv-v0
echo HalfCheetahBulletEnv-v0
echo HopperBulletEnv-v0
echo Walker2DBulletEnv-v0
}
fig_9_simulator_choice_algo() {
echo ppo2
}
fig_11_rl_framework_choice_environment() {
echo Walker2DBulletEnv-v0
}
fig_10_algo_choice_environment() {
echo Walker2DBulletEnv-v0
}
fig_10_algo_choice_algorithms() {
echo a2c
echo ddpg
echo ppo2
echo sac
}
tf_agents_fig_9_simulator_choice_algo() {
echo ddpg
}
tf_agents_fig_10_algo_choice_algos() {
echo ddpg
# Disable until --stable_baselines_hyperparams is supported...
# echo sac
# echo td3
}
tf_agents_fig_11_rl_framework_choice_algos() {
echo td3
}
stable_baselines_fig_11_rl_framework_choice_algos() {
echo a2c
echo ddpg
echo ppo2
echo sac
}
stable_baselines_fig_10_algo_choice_algos() {
echo a2c
echo ddpg
echo ppo2
echo sac
}
stable_baselines_fig_9_simulator_choice_algo() {
# Q: Is there a reason I changed this to DDPG...? It doesn't have atari hyperparams.
# echo ddpg
echo ppo2
}
reagent_fig_11_rl_framework_choice_algos() {
echo td3
}
reagent_fig_10_algo_choice_algos() {
echo td3
}
reagent_fig_9_simulator_choice_algo() {
echo td3
}
run_debug_ppo_full_training_instrumented() {
_run_debug_ppo_full_training "${INSTRUMENTED_ARGS[@]}" "$@"
}
run_debug_dqn_full_training_instrumented() {
_run_debug_dqn_full_training "${INSTRUMENTED_ARGS[@]}" "$@"
}
run_debug_sac_full_training_instrumented() {
_run_debug_sac_full_training "${INSTRUMENTED_ARGS[@]}" "$@"
}
run_debug_a2c_full_training_instrumented() {
_run_debug_a2c_full_training "${INSTRUMENTED_ARGS[@]}" "$@"
}
run_debug_ddpg_full_training_instrumented() {
_run_debug_ddpg_full_training "${INSTRUMENTED_ARGS[@]}" "$@"
}
run_debug_ppo_full_training_uninstrumented() {
_run_debug_ppo_full_training "$@"
}
run_debug_dqn_full_training_uninstrumented() {
_run_debug_dqn_full_training "$@"
}
run_debug_sac_full_training_uninstrumented() {
_run_debug_sac_full_training "$@"
}
run_debug_a2c_full_training_uninstrumented() {
_run_debug_a2c_full_training "$@"
}
run_debug_ddpg_full_training_uninstrumented() {
_run_debug_ddpg_full_training "$@"
}
run_debug_full_training_instrumented() {
run_debug_ppo_full_training_instrumented
run_debug_dqn_full_training_instrumented
run_debug_sac_full_training_instrumented
run_debug_a2c_full_training_instrumented
run_debug_ddpg_full_training_instrumented
}
run_debug_full_training_uninstrumented() {
run_debug_ppo_full_training_uninstrumented
run_debug_dqn_full_training_uninstrumented
run_debug_sac_full_training_uninstrumented
run_debug_a2c_full_training_uninstrumented
run_debug_ddpg_full_training_uninstrumented
}
run_full_training_instrumented() {
rls-quick-expr --expr total_training_time --instrumented "$@"
}
run_full_training_uninstrumented() {
rls-quick-expr --expr total_training_time "$@"
}
run_calibration_all() {
run_subtraction_calibration "$@"
run_subtraction_validation "$@"
}
NUM_REPS=5
run_subtraction_validation() {
if [ $# -lt 2 ]; then
log_error "ERROR: Saw $# arguments, but expect:"
log_error " run_subtraction_validation <algo> <environ>"
return 1
fi
# Default in the past: (HalfCheetahBulletEnv-v0, ppo2)
local algo="$1"
local environ="$2"
shift 2
_cmd() {
_do rls-quick-expr "${RUN_DEBUG_ARGS[@]}" --expr subtraction_validation --calibration-mode validation --repetitions $NUM_REPS --only-runs 2 --env "$environ" --algo "$algo" "$@"
}
_cmd "$@"
_cmd "$@" --plot
}
run_pyprof_calibration_fig_algorithm_choice_1a_med_complexity() {
rls-quick-expr --expr microbenchmark --algo-env-group algorithm_choice_1a_med_complexity "$@"
}
run_pyprof_calibration_fig_environment_choice() {
rls-quick-expr --expr microbenchmark --algo-env-group environment_choice "$@"
}
run_pyprof_calibration_iterations_20000() {
rls-quick-expr --expr microbenchmark --env HalfCheetahBulletEnv-v0 --algo ppo2 --iterations $((2*10**4)) "$@"
}
run_pyprof_calibration_all() {
run_pyprof_calibration_fig_environment_choice "$@"
run_pyprof_calibration_fig_algorithm_choice_1a_med_complexity "$@"
run_pyprof_calibration_iterations_20000 "$@"
}
run_subtraction_calibration() {
# if [ $# -lt 2 ]; then
# log_error "ERROR: Saw $# arguments, but expect:"
# log_error " run_subtraction_calibration <algo> <environ>"
# return 1
# fi
# # Default in the past: (HalfCheetahBulletEnv-v0, ppo2)
# local algo="$1"
# local environ="$2"
# shift 2
if [ $# -eq 0 ]; then
log_error "ERROR: Saw $# arguments, but expected arguments that select specific (algo, env) combinations like:"
log_error " run_subtraction_calibration --algo ppo2 --env HalfCheetahBulletEnv-v0"
log_error " run_subtraction_calibration --algo ppo2 --env Walker2DBulletEnv-v0"
log_error " run_subtraction_calibration --algo-env-group environment_choice"
return 1
fi
_cmd() {
_do rls-quick-expr "${RUN_DEBUG_ARGS[@]}" --expr subtraction_validation --calibration-mode calibration --repetitions $NUM_REPS --only-runs 2 "$@"
}
_cmd "$@"
_cmd "$@" --plot
}
run_subtraction_validation_long() {
_cmd() {
_do rls-quick-expr "${RUN_DEBUG_ARGS[@]}" --expr subtraction_validation --calibration-mode validation --repetitions $NUM_REPS --env HalfCheetahBulletEnv-v0 --algo ppo2 "$@"
}
# - Run using long iterations (most important...)
# - Re-plot stuff.
# - Run using different numbers of iterations
# - Re-plot stuff.
_cmd "$@" --num-runs 0 --long-run
_cmd "$@" --num-runs 0 --long-run --plot
# _cmd "$@" --num-runs 3
# _cmd "$@" --num-runs 3 --plot
}
run_debug_all() {
run_debug_full_training_uninstrumented
run_debug_full_training_instrumented
}
# If we want to include dqn in every single figure, we need to show a low complexity simulator (simulator time will be understated).
# If we want to show a medium complexity simulator (Walker2D) we cannot include dqn.
# So, lets do both and decide later.
# NOTE: we will run both LunarLander and LunarLanderContinuous for ppo so we can make sure these environment have identical complexity (except for the input type)
fig_1a_all_algo() {
# (1a) All algorithms (low complexity): LunarLander
# GOAL: 3 repetitions
rls-quick-expr --lunar "$@"
}
fig_1b_all_algo() {
# (1b) Mostly all algorithms (except dqn) (medium complexity): Walker2D
# GOAL: 3 repetitions
rls-quick-expr --env Walker2DBulletEnv-v0 "$@"
}
fig_2_all_env() {
# (2) All environments (low and medium complexity): ppo2
# GOAL: 3 repetitions
rls-quick-expr --lunar --atari --bullet --algo ppo2 "$@"
}
fig_3_all_algo_env() {
# (3) All (algo, env) combos
# GOAL: 1 repetition
rls-quick-expr --lunar --atari --bullet "$@"
}
fig_all() {
fig_1a_all_algo "$@"
fig_1b_all_algo "$@"
fig_2_all_env "$@"
fig_3_all_algo_env "$@"
}
fig_all_algo_then_all_env() {
fig_1a_all_algo "$@"
fig_1b_all_algo "$@"
fig_2_all_env "$@"
}
_run_reps() {
"$@" --repetitions 1
"$@" --repetitions 2
"$@" --repetitions 3
}
run_all() {
# Need 1 uninstrumented run for all (algo, env) pairs for generating nvidia-smi utilization figure (Figure 8)
fig_all --expr total_training_time --repetitions 1 "$@"
# Prioritize uninstrumented runs (needed for some figures).
fig_all_algo_then_all_env --expr total_training_time --repetitions 1 "$@"
# For generating non-extrapolated overhead breakdown.
fig_all_algo_then_all_env --expr total_training_time --repetitions 1 --instrumented "$@"
# For getting error bounds on "extrapolation justification" figure.
fig_all_algo_then_all_env --expr total_training_time --repetitions 3 "$@"
}
run_perf_debug() {
_do rls-run --rlscope-directory $RLSCOPE_DIR/output/perf_debug "${CALIB_OPTS[@]}"
}
run_perf_debug_short() {
_do rls-run --rlscope-directory $RLSCOPE_DIR/output/perf_debug_short "${CALIB_OPTS[@]}"
}
_find_extension() {
local root_dir="$1"
local extension_regex="$2"
shift 2
local regex="/(.*\.(${extension_regex}))$"
find "$root_dir" -type f | grep --perl-regexp "$regex"
}
setup_cmakelists_windows() {
local src_ext_regex="cpp|cc|c|cu"
local hdr_ext_regex="h|hpp|cuh"
local all_ext_regex="${src_ext_regex}|${hdr_ext_regex}"
local include_dirs=( \
./windows_includes \
./windows_includes/CUPTI/include \
./windows_includes/cuda/include \
./build \
./src \
./tensorflow \
)
local src_dirs=( \
./src \
./tensorflow \
./test \
)
local path=CMakeLists.windows.txt
if [ -e "$path" ]; then
rm "$path"
fi
# Header already included by main CMakeLists.txt file.
#
# cat <<EOF >> "$path"
#cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
#project(rlscope)
##https://github.com/robertmaynard/code-samples/blob/master/posts/cmake/CMakeLists.txt
#
## We want to be able to do std::move() for lambda captures (c++11 doesn't have that).
#set(CMAKE_CXX_STANDARD 14)
#set(CMAKE_CXX_STANDARD_REQUIRED ON)
#set(CMAKE_CXX_EXTENSIONS OFF)
#
#EOF
echo "include_directories(" >> "$path"
for direc in "${include_dirs[@]}"; do
echo " $direc" >> "$path"
done
echo ") # include_directories" >> "$path"
echo "" >> "$path"
echo "add_executable(dummy_exe" >> "$path"
for src_dir in "${src_dirs[@]}"; do
_find_extension "$src_dir" "$src_ext_regex" | sed 's/^/ /' >> "$path"
done
echo ") # add_executable" >> "$path"
echo "" >> "$path"
echo "> Success: wrote $path"
}
all_run() {
(
set -eu
calibrate=${calibrate:-yes}
max_passes=${max_passes:-}
repetitions=${repetitions:-5}
re_calibrate=${re_calibrate:-no}
re_plot=${re_plot:-no}
dry_run=${dry_run:-no}
stable_baselines_hyperparams=${stable_baselines_hyperparams:-yes}
subdir=${subdir:-}
fig=${fig:-all}
framework=${framework:-all}
if [ "$framework" = 'tf_agents' ] || [ "$framework" = 'all' ]; then
all_run_tf_agents
fi
if [ "$framework" = 'stable_baselines' ] || [ "$framework" = 'all' ]; then
all_run_stable_baselines
fi
if [ "$framework" = 'reagent' ] || [ "$framework" = 'all' ]; then
all_run_reagent
fi
)
}
all_run_tf_agents() {
(
set -eu
calibrate=${calibrate:-yes}
max_passes=${max_passes:-}
repetitions=${repetitions:-5}
re_calibrate=${re_calibrate:-no}
re_plot=${re_plot:-no}
dry_run=${dry_run:-no}
stable_baselines_hyperparams=${stable_baselines_hyperparams:-yes}
subdir=${subdir:-}
fig=${fig:-all}
if [ "$fig" = 'framework_choice' ] || [ "$fig" = 'all' ]; then
# Fig 11: RL framework choice
for algo in $(fig_framework_choice_algos); do
for env_id in $(fig_framework_choice_envs); do
# for use_tf_functions in no; do
for use_tf_functions in yes no; do
run_tf_agents
done
done
done
# Fig 11(b): RL framework choice DDPG
for algo in $(fig_framework_choice_algos_ddpg); do
for env_id in $(fig_framework_choice_envs); do
# for use_tf_functions in no; do
for use_tf_functions in yes no; do
run_tf_agents
done
done
done
fi
# NOTE: we generate algo and simulator choice using stable-baselines.
# if [ "$fig" = 'algo_choice' ] || [ "$fig" = 'all' ]; then
# # Fig 10: Algorithm choice
# # tf-agents
# #
# # ppo doesn't work (BUG in tf-agents)
# for algo in $(tf_agents_fig_10_algo_choice_algos); do
# env_id="$(fig_10_algo_choice_environment)"
# for use_tf_functions in yes no; do
# run_tf_agents
# done
# done
# fi
#
# if [ "$fig" = 'simulator_choice' ] || [ "$fig" = 'all' ]; then
# # Fig 9: Simulator choice
# # tf-agents
# #
# # ppo doesn't work (BUG in tf-agents). Use ddpg instead.
# for env_id in $(fig_9_simulator_choice_environments); do
# algo=$(tf_agents_fig_9_simulator_choice_algo)
# for use_tf_functions in yes no; do
# run_tf_agents
# done
# done
# fi
# if [ "$fig" = 'algo_choice' ] || [ "$fig" = 'all' ]; then
# plot_tf_agents_fig_10_algo_choice
# fi
# if [ "$fig" = 'simulator_choice' ] || [ "$fig" = 'all' ]; then
# plot_tf_agents_fig_9_simulator_choice
# fi
)
}
all_run_reagent() {
(
set -eu
calibrate=${calibrate:-yes}
max_passes=${max_passes:-}
repetitions=${repetitions:-5}
re_calibrate=${re_calibrate:-no}
re_plot=${re_plot:-no}
dry_run=${dry_run:-no}
stable_baselines_hyperparams=${stable_baselines_hyperparams:-yes}
subdir=${subdir:-}
fig=${fig:-all}
if [ "$fig" = 'framework_choice' ] || [ "$fig" = 'all' ]; then
# Fig 11: RL framework choice
for algo in $(fig_framework_choice_algos); do
for env_id in $(fig_framework_choice_envs); do
run_reagent
done
done
# NOTE: no Fig 11(b): doesn't implement DDPG.
fi
# # Fig 10: Algorithm choice
# # tf-agents
# #
# # ppo doesn't work (BUG in tf-agents)
# for algo in $(reagent_fig_10_algo_choice_algos); do
# env_id="$(fig_10_algo_choice_environment)"
# run_reagent
# done
#
# # Fig 9: Simulator choice
# # tf-agents
# #
# # ppo doesn't work (BUG in tf-agents). Use ddpg instead.
# for env_id in $(fig_9_simulator_choice_environments); do
# algo=$(reagent_fig_9_simulator_choice_algo)
# run_reagent
# done
# NOT useful just confusing.
# if [ "$fig" = 'framework_choice' ] || [ "$fig" = 'all' ]; then
# plot_reagent
# fi
)
}
_should_skip_algo() {
local algo="$1"
local only_algo="$2"
shift 2
[ "$only_algo" != "" ] && [ "$only_algo" != "$algo" ]
}
_should_skip_env() {
local env_id="$1"
local only_env_id="$2"
shift 2
[ "$only_env_id" != "" ] && [ "$only_env_id" != "$env_id" ]
}
all_run_stable_baselines() {
(
set -eu
calibrate=${calibrate:-yes}
max_passes=${max_passes:-}
repetitions=${repetitions:-5}
re_calibrate=${re_calibrate:-no}
# For debugging; only run $algo
only_algo=${algo:-}
# For debugging; only run $env
only_env_id=${env:-}
re_plot=${re_plot:-no}
dry_run=${dry_run:-no}
fig=${fig:-all}
if [ "$fig" = 'framework_choice' ] || [ "$fig" = 'all' ]; then
# Fig 11: RL framework choice
for algo in $(fig_framework_choice_algos); do
if _should_skip_algo "$algo" "$only_algo"; then
continue
fi
for env_id in $(fig_framework_choice_envs); do
if _should_skip_env "$env_id" "$only_env_id"; then
continue
fi
run_stable_baselines
done
done
# Fig 11(b): RL framework choice DDPG
for algo in $(fig_framework_choice_algos_ddpg); do
if _should_skip_algo "$algo" "$only_algo"; then
continue
fi
for env_id in $(fig_framework_choice_envs); do
if _should_skip_env "$env_id" "$only_env_id"; then
continue
fi
run_stable_baselines
done
done
fi
if [ "$fig" = 'algo_choice' ] || [ "$fig" = 'all' ] || [ "$fig" = 'algo_env' ]; then
# Fig 10: Algorithm choice
# tf-agents
#
# ppo doesn't work (BUG in tf-agents)
for algo in $(stable_baselines_fig_10_algo_choice_algos); do
env_id="$(fig_10_algo_choice_environment)"
run_stable_baselines
done
fi
if [ "$fig" = 'simulator_choice' ] || [ "$fig" = 'all' ] || [ "$fig" = 'algo_env' ]; then
# Fig 9: Simulator choice
# tf-agents
#
# ppo doesn't work (BUG in tf-agents). Use ddpg instead.
for env_id in $(fig_9_simulator_choice_environments); do
algo=$(stable_baselines_fig_9_simulator_choice_algo)
run_stable_baselines
done
fi
# if [ "$fig" = 'algo_choice' ] || [ "$fig" = 'all' ] || [ "$fig" = 'algo_env' ]; then
# plot_stable_baselines_fig_10_algo_choice
# fi
# if [ "$fig" = 'simulator_choice' ] || [ "$fig" = 'all' ] || [ "$fig" = 'algo_env' ]; then
# plot_stable_baselines_fig_9_simulator_choice
# fi
)
}
fig_framework_choice_algos() {
echo td3
}
fig_framework_choice_algos_ddpg() {
echo ddpg
}
fig_framework_choice_envs() {
echo Walker2DBulletEnv-v0
}
all_gen_tex() {
(
set -eu
gen_tex_framework_choice
gen_tex_framework_choice_uncorrected
)
}
gen_tex_framework_choice() {
(
set -eu
local args=(
--directory $(framework_choice_plots_direc)
--framework-choice-csv $(framework_choice_plots_direc)/OverlapStackedBarPlot.*.operation_training_time.csv
--framework-choice-ddpg-csv $(framework_choice_plots_ddpg_direc)/OverlapStackedBarPlot.*.operation_training_time.csv
--framework-choice-trans-csv $(framework_choice_plots_direc)/CategoryTransitionPlot.combined.csv
--framework-choice-ddpg-trans-csv $(framework_choice_plots_ddpg_direc)/CategoryTransitionPlot.combined.csv
)
_gen_tex_framework_choice "${args[@]}"
)
}
gen_tex_framework_choice_uncorrected() {
(
set -eu
# NOTE: we generate two tex files:
# (1) corrected_no/*.tex
# (2) corrected_no/*.uncorrected.tex
# Use "Uncorrected" prefix in \newcommand variable definition.
# (3) FrameworkChoiceUncorrected.tex
# Metrics computed by comparing values in corrected runs to those in uncorrected runs.
# (e.g. training time inflation).
_gen_tex() {
local args=(
--directory $(framework_choice_plots_uncorrected_direc)
--framework-choice-csv $(framework_choice_plots_uncorrected_direc)/OverlapStackedBarPlot.*.operation_training_time.csv
--framework-choice-ddpg-csv $(framework_choice_plots_ddpg_uncorrected_direc)/OverlapStackedBarPlot.*.operation_training_time.csv
--framework-choice-trans-csv $(framework_choice_plots_direc)/CategoryTransitionPlot.combined.csv
--framework-choice-ddpg-trans-csv $(framework_choice_plots_ddpg_direc)/CategoryTransitionPlot.combined.csv
)
_gen_tex_framework_choice "${args[@]}" "$@"
}
# # (1) corrected_no/*.tex
# _gen_tex "${args[@]}" "$@"
#
# # (2) corrected_no/*.uncorrected.tex
# local args=(
# --file-suffix ".uncorrected"
# --tex-variable-prefix "Uncorrected"
# )
# _gen_tex "${args[@]}" "$@"
# (3) FrameworkChoiceUncorrected.tex
local args=(
--directory $(framework_choice_plots_direc)
--framework-choice-csv $(framework_choice_plots_direc)/OverlapStackedBarPlot.*.operation_training_time.csv
--framework-choice-ddpg-csv $(framework_choice_plots_ddpg_direc)/OverlapStackedBarPlot.*.operation_training_time.csv
--framework-choice-uncorrected-csv $(framework_choice_plots_uncorrected_direc)/OverlapStackedBarPlot.*.operation_training_time.csv
--framework-choice-ddpg-uncorrected-csv $(framework_choice_plots_ddpg_uncorrected_direc)/OverlapStackedBarPlot.*.operation_training_time.csv
)
_gen_tex_framework_choice "${args[@]}" "$@"
)
}
_gen_tex_framework_choice() {
(
set -eu
dry_run=${dry_run:-no}
local args=(
rls-run
--task TexMetricsTask
)
if [ "${dry_run}" = 'yes' ]; then
args+=(
--dry-run
)
fi
if [ "${DEBUG}" = 'yes' ]; then
args+=(--pdb --debug --debug-single-thread)
fi
_do "${args[@]}" "$@"
)
}
_gen_tex_algo_choice() {
(
set -eu
dry_run=${dry_run:-no}
local args=(
rls-run
--task TexMetricsTask
# --directory $(stable_baselines_plots_direc)/stable_baselines_fig_10_algo_choice
# --algo-choice-csv $(stable_baselines_plots_direc)/stable_baselines_fig_10_algo_choice/OverlapStackedBarPlot.*.operation_training_time.csv
)
if [ "${dry_run}" = 'yes' ]; then
args+=(
--dry-run
)
fi
if [ "${DEBUG}" = 'yes' ]; then
args+=(--pdb --debug --debug-single-thread)
fi
_do "${args[@]}" "$@"
)
}
gen_tex_algo_choice() {
(
set -eu
dry_run=${dry_run:-no}
local args=(
--directory $(stable_baselines_plots_direc)/stable_baselines_fig_10_algo_choice
--algo-choice-csv $(stable_baselines_plots_direc)/stable_baselines_fig_10_algo_choice/OverlapStackedBarPlot.*.operation_training_time.csv
)
_do _gen_tex_algo_choice "${args[@]}" "$@"
)
}
gen_tex_algo_choice_uncorrected() {
(
set -eu
dry_run=${dry_run:-no}
# NOTE: we generate two tex files:
# (1) corrected_no/*.tex
# (2) corrected_no/*.uncorrected.tex
# Use "Uncorrected" prefix in \newcommand variable definition.
_gen_tex() {
local args=(
--directory $(stable_baselines_plots_direc)/stable_baselines_fig_10_algo_choice/corrected_no
--algo-choice-csv $(stable_baselines_plots_direc)/stable_baselines_fig_10_algo_choice/corrected_no/OverlapStackedBarPlot.*.operation_training_time.csv
)
_do _gen_tex_algo_choice "${args[@]}" "$@"
}
# (1) corrected_no/*.tex
_gen_tex "${args[@]}" "$@"
# (2) corrected_no/*.uncorrected.tex
local args=(
--file-suffix ".uncorrected"
--tex-variable-prefix "Uncorrected"
)
_gen_tex "${args[@]}" "$@"
)
}
plot_framework_choice() {
(
set -eu
calibrate=${calibrate:-yes}
max_passes=${max_passes:-}
repetitions=${repetitions:-3}
re_calibrate=${re_calibrate:-no}
re_plot=${re_plot:-no}
dry_run=${dry_run:-no}
stable_baselines_hyperparams=${stable_baselines_hyperparams:-yes}
# Fig: Framework comparison
# WANT: plot:
# - (DDPG, Walker)
# - stable-baselines
# - tf-agents: use_tf_functions=yes
# - tf-agents: use_tf_functions=no
local rlscope_dirs=()
for algo in $(fig_framework_choice_algos); do
for env_id in $(fig_framework_choice_envs); do
rlscope_dirs+=($(stable_baselines_rlscope_direc))
for use_tf_functions in yes no; do
rlscope_dirs+=($(tf_agents_rlscope_direc))
done
rlscope_dirs+=($(reagent_rlscope_direc))
done
done
# --y2-logscale
# --title "Framework choice"
local args=(
--rlscope-directories "${rlscope_dirs[@]}"
--output-directory $(framework_choice_plots_direc)
--OverlapStackedBarTask-hack-upper-right-legend-bbox-x 0.365
--CategoryTransitionPlotTask-hack-upper-right-legend-bbox-x 0.365
--GpuHwPlotTask-width 6
--GpuHwPlotTask-height 5
)
_plot_framework_choice "${args[@]}"
)
}
plot_framework_choice_ddpg() {
(
set -eu
calibrate=${calibrate:-yes}
max_passes=${max_passes:-}
repetitions=${repetitions:-3}
re_calibrate=${re_calibrate:-no}
re_plot=${re_plot:-no}
dry_run=${dry_run:-no}
stable_baselines_hyperparams=${stable_baselines_hyperparams:-yes}
# Fig 11(b): Framework comparison DDPG
local rlscope_dirs=()
for algo in $(fig_framework_choice_algos_ddpg); do
for env_id in $(fig_framework_choice_envs); do
rlscope_dirs+=($(stable_baselines_rlscope_direc))
for use_tf_functions in yes no; do
rlscope_dirs+=($(tf_agents_rlscope_direc))
done
# NOTE: ReAgent doesn't implement DDPG.