diff --git a/README.md b/README.md index d65dbd5..4fc1d27 100644 --- a/README.md +++ b/README.md @@ -58,40 +58,56 @@ How to train CodeScholar: Refer to the [training README](./codescholar/representation/README.md) for a detailed description of how to train CodeScholar. -How to run pre-trained CodeScholar: +How to use CodeScholar: ----------------------- - -```bash -# start an elasticsearch server (hosts programs) -docker run --rm -p 9200:9200 -p 9300:9300 -e "xpack.security.enabled=false" -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:8.7.0 -``` - -```bash -# start a redis server (hosts embeddings) -docker run --rm -p 6379:6379 redis -``` -```bash -# index the dataset using /search/elastic_search.py -cd codescholar/search -python elastic_search.py --dataset -``` - -> TODO: index all embeddings into redis; currently index happens before each search - -```bash -# run the codescholar query (say np.mean) using /search/search.py -python search.py --dataset --seed np.mean -``` - -You can also use some arguments with the search query: -```bash ---min_idiom_size # minimum size of idioms to be saved ---max_idiom_size # maximum size of idioms to be saved ---max_init_beams # maximum beams to initialize search ---stop_at_equilibrium # stop search when diversity = reusability of idioms -``` -*note: see more configurations in [/search/search_config.py](./codescholar/search/search_config.py)* +1. Starting services + ```bash + # start codescholar services (elasticsearch and redis) + ./services.sh start + ``` +
+ what does this do? + + ```bash + # start an elasticsearch server (hosts programs) in a tmux session + docker run --rm -p 9200:9200 -p 9300:9300 -e "xpack.security.enabled=false" -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:8.7.0 + # start a redis server (hosts embeddings) + docker run --rm -p 6379:6379 redis + ``` +
+ +2. Indexing + ```bash + # index search space programs into elasticsearch + ./services.sh index + ``` +
+ what does this do? + + ```bash + # index the dataset using /search/elastic_search.py + cd codescholar/search + python elastic_search.py --dataset + ``` + + > TODO: index all embeddings into redis; currently index happens before each search +
+ +3. Searching + ```bash + # run the codescholar query (say np.mean) using /search/search.py + python search.py --dataset --seed np.mean + ``` + + You can also use some arguments with the search query: + ```bash + --min_idiom_size # minimum size of idioms to be saved + --max_idiom_size # maximum size of idioms to be saved + --max_init_beams # maximum beams to initialize search + --stop_at_equilibrium # stop search when diversity = reusability of idioms + ``` + *note: see more configurations in [/search/search_config.py](./codescholar/search/search_config.py)* How to run CodeScholar Streamlit App: --------------------------- diff --git a/codescholar/services.sh b/codescholar/services.sh new file mode 100755 index 0000000..2b0100f --- /dev/null +++ b/codescholar/services.sh @@ -0,0 +1,85 @@ +#!/bin/bash + +# Function to check if a tmux session exists +tmux_session_exists() { + tmux has-session -t "$1" 2>/dev/null +} + +# Function to start Elasticsearch in a tmux session +start_elasticsearch() { + if tmux_session_exists "elasticsearch"; then + echo "Elasticsearch tmux session already exists." + else + echo "Starting Elasticsearch in a tmux session..." + tmux new-session -d -s "elasticsearch" docker run --name codescholar-elasticsearch --rm -p 9200:9200 -p 9300:9300 -e "xpack.security.enabled=false" -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:8.7.0 + fi +} + +# Function to start Redis in a tmux session +start_redis() { + if tmux_session_exists "redis"; then + echo "Redis tmux session already exists." + else + echo "Starting Redis in a tmux session..." + tmux new-session -d -s "redis" docker run --name codescholar-redis --rm -p 6379:6379 redis + fi +} + +# Function to stop a service running in a tmux session +stop_service() { + if tmux_session_exists "$1"; then + echo "Stopping $1..." + tmux send-keys -t "$1" C-c + tmux kill-session -t "$1" + else + echo "No tmux session for $1 found." + fi +} + +# Function to run the indexing script +run_indexing() { + dataset_name="$1" + if [ -z "$dataset_name" ]; then + echo "Please provide a dataset name." + return 1 + fi + echo "Running the indexing script for dataset: $dataset_name" + tmux new-session -d -s "indexing" "cd search && python elastic_search.py --dataset $dataset_name" +} + +# Function to display the status of the indexing session +show_indexing_status() { + if tmux_session_exists "indexing"; then + echo "Indexing session status:" + tmux capture-pane -p -t "indexing" + else + echo "No indexing session found." + fi +} + +# Main logic based on the first argument +case "$1" in + start) + start_elasticsearch + start_redis + ;; + stop) + stop_service "elasticsearch" + stop_service "redis" + ;; + killall) + stop_service "elasticsearch" + stop_service "redis" + stop_service "indexing" + ;; + index) + run_indexing "$2" + ;; + status) + show_indexing_status + ;; + *) + echo "Usage: $0 {start|stop|killall|index }" + exit 1 + ;; +esac \ No newline at end of file