Created
May 6, 2022 08:51
-
-
Save benhid/171f2507e669d6fac47971b21c557e42 to your computer and use it in GitHub Desktop.
Grid search in bash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -xe | |
| # Usage: | |
| # ./run_grid_search.sh | |
| MAX_PARALLEL=5 | |
| pipeline() { | |
| python step_1.py --param-1 "$2" --param-2 "$3" >"$1"/log_step_1.txt | |
| python step_2.py --param-1 "$4" >"$1"/log_step_2.txt | |
| } | |
| cache_dir=output | |
| for i in 4 10 20 50; do | |
| for j in 4 10 20 50; do | |
| for k in 5 15 25; do | |
| run_dir="$cache_dir/$i-$j-$k" | |
| # Create parent directories if needed. | |
| mkdir -p $run_dir | |
| pipeline $run_dir $i $j $k & | |
| if [[ $(jobs -r -p | wc -l) -ge $MAX_PARALLEL ]]; then | |
| # Wait here for any job to be finished to start next one. | |
| wait -n | |
| fi | |
| done | |
| done | |
| done | |
| # No more jobs to be started but wait for pending jobs. | |
| wait | |
| echo "all done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment