From 33ae995a32517ea2cd88ebff13d690ac145d76a7 Mon Sep 17 00:00:00 2001 From: Patrick Wang Date: Wed, 25 Dec 2024 14:09:19 -0500 Subject: [PATCH 01/26] added hello-tune submodule --- .gitmodules | 3 +++ hello-tune | 1 + 2 files changed, 4 insertions(+) create mode 100644 .gitmodules create mode 160000 hello-tune diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..46a1458c --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "hello-tune"] + path = hello-tune + url = git@github.com:wangpatrick57/hello-tune.git diff --git a/hello-tune b/hello-tune new file mode 160000 index 00000000..169405a6 --- /dev/null +++ b/hello-tune @@ -0,0 +1 @@ +Subproject commit 169405a6a55828471e7dc03eaf78f11a4953d43e From 41cd68edfcec69d36e4825bef8ae4627a0f219d1 Mon Sep 17 00:00:00 2001 From: Patrick Wang Date: Wed, 25 Dec 2024 14:10:27 -0500 Subject: [PATCH 02/26] moved hello-tune to the agents directory --- .gitmodules | 4 ++-- hello-tune => agents/hello-tune | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename hello-tune => agents/hello-tune (100%) diff --git a/.gitmodules b/.gitmodules index 46a1458c..434ddc1e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ -[submodule "hello-tune"] - path = hello-tune +[submodule "agents/hello-tune"] + path = agents/hello-tune url = git@github.com:wangpatrick57/hello-tune.git diff --git a/hello-tune b/agents/hello-tune similarity index 100% rename from hello-tune rename to agents/hello-tune From 61324bc7fd36938a8c0ac57d83f5c80bccfa5886 Mon Sep 17 00:00:00 2001 From: Patrick Wang Date: Wed, 25 Dec 2024 14:19:07 -0500 Subject: [PATCH 03/26] added gymlib library (can install successfully with pip install -e --- .gitignore | 4 ++-- gymlib/__init__.py | 0 gymlib/magic.py | 2 ++ gymlib/setup.py | 9 +++++++++ 4 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 gymlib/__init__.py create mode 100644 gymlib/magic.py create mode 100644 gymlib/setup.py diff --git a/.gitignore b/.gitignore index 4d6abb6e..9b3065ed 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,6 @@ __pycache__/ .conda/ .idea/ test_clean_scratchspace/ - workspace/ -default_*_benchbase_config_*.xml \ No newline at end of file +default_*_benchbase_config_*.xml +*.egg-info/ \ No newline at end of file diff --git a/gymlib/__init__.py b/gymlib/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/gymlib/magic.py b/gymlib/magic.py new file mode 100644 index 00000000..f8fb186d --- /dev/null +++ b/gymlib/magic.py @@ -0,0 +1,2 @@ +def get_magic_number(): + return 42 diff --git a/gymlib/setup.py b/gymlib/setup.py new file mode 100644 index 00000000..2e104820 --- /dev/null +++ b/gymlib/setup.py @@ -0,0 +1,9 @@ +from setuptools import setup, find_packages + +setup( + name="gymlib", + version="0.1.0", + packages=find_packages(), + install_requires=[], + python_requires=">=3.8", +) From a8d7c418aa8b0dc6902117cc13fb86e0973e68c8 Mon Sep 17 00:00:00 2001 From: Patrick Wang Date: Wed, 25 Dec 2024 14:24:33 -0500 Subject: [PATCH 04/26] create conda with arg check and folder check --- agents/create_conda.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100755 agents/create_conda.sh diff --git a/agents/create_conda.sh b/agents/create_conda.sh new file mode 100755 index 00000000..bf1e3918 --- /dev/null +++ b/agents/create_conda.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# This script creates a conda environment for a specific agent. +if [ -z "$1" ]; then + echo "Usage: ./create_conda.sh " + exit 1 +fi + +agent_name=$1 + +# Check if agent folder exists +if [ ! -d "agents/$agent_name" ]; then + echo "Error: Agent folder '$agent_name' does not exist" + exit 1 +fi + +echo "hello world!" \ No newline at end of file From 01ae5ce7e0dd597c28e1196bbe6def4d14f6df59 Mon Sep 17 00:00:00 2001 From: Patrick Wang Date: Wed, 25 Dec 2024 14:36:22 -0500 Subject: [PATCH 05/26] implemented .python_version --- agents/create_conda.sh | 27 ++++++++++++++++++++++++++- agents/hello-tune | 2 +- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/agents/create_conda.sh b/agents/create_conda.sh index bf1e3918..ff9f495c 100755 --- a/agents/create_conda.sh +++ b/agents/create_conda.sh @@ -1,5 +1,13 @@ #!/bin/bash # This script creates a conda environment for a specific agent. +# Preconditions: +# - conda is installed and the user has access to the conda command. +# - The user has already updated the folder of the agent they want to +# create a conda environment for (e.g. by calling submodule update). +# - There does not already exist a conda environment with the same name +# as the agent. + +# Check if agent name is provided. if [ -z "$1" ]; then echo "Usage: ./create_conda.sh " exit 1 @@ -13,4 +21,21 @@ if [ ! -d "agents/$agent_name" ]; then exit 1 fi -echo "hello world!" \ No newline at end of file +# Note: I am intentionally not using environment.yml. I am instead using +# requirements.txt and .python_version. This is for two reasons: +# 1. environment.yml sets the conda env name. However, I want to enforce +# that the conda env name is the same as the agent name. +# 2. requirements.txt can be used by pip and only contains packages and +# not any additional conda-specific syntax, making it more modular +# and flexible. + +# Read in .python_version if it exists. +if [ -f "agents/$agent_name/.python_version" ]; then + python_version=$(cat "agents/$agent_name/.python_version") +else + echo "Warning: .python_version not found in agents/$agent_name/. Using default Python 3.10." + python_version="3.10" +fi + +echo "hello world!" +echo "python_version: $python_version" \ No newline at end of file diff --git a/agents/hello-tune b/agents/hello-tune index 169405a6..c9060794 160000 --- a/agents/hello-tune +++ b/agents/hello-tune @@ -1 +1 @@ -Subproject commit 169405a6a55828471e7dc03eaf78f11a4953d43e +Subproject commit c90607947e6ea75d7d63d9bf6b2ea13a7456cc72 From 0ee401b2018e80302f464db45672d2507d4bbb03 Mon Sep 17 00:00:00 2001 From: Patrick Wang Date: Wed, 25 Dec 2024 14:42:16 -0500 Subject: [PATCH 06/26] added more checks --- agents/create_conda.sh | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/agents/create_conda.sh b/agents/create_conda.sh index ff9f495c..3afdc32c 100755 --- a/agents/create_conda.sh +++ b/agents/create_conda.sh @@ -1,13 +1,19 @@ #!/bin/bash # This script creates a conda environment for a specific agent. -# Preconditions: -# - conda is installed and the user has access to the conda command. -# - The user has already updated the folder of the agent they want to -# create a conda environment for (e.g. by calling submodule update). -# - There does not already exist a conda environment with the same name -# as the agent. - -# Check if agent name is provided. +# +# Before running this script, the user must update the folder of the agent +# they want to create a conda environment for (e.g. by calling submodule update). +# +# There are other things the user must do as well but these are all checked +# automaticallyby this script. + +# Check that conda is installed. +if ! command -v conda &> /dev/null; then + echo "Error: Conda is not installed" + exit 1 +fi + +# Input validation. if [ -z "$1" ]; then echo "Usage: ./create_conda.sh " exit 1 @@ -15,12 +21,24 @@ fi agent_name=$1 -# Check if agent folder exists if [ ! -d "agents/$agent_name" ]; then echo "Error: Agent folder '$agent_name' does not exist" exit 1 fi +# Checks relating to conda environments. +if conda info --envs | grep -q "^$agent_name "; then + echo "Error: Conda environment '$agent_name' already exists" + exit 1 +fi + +# Check that we're not in any conda environment +if [ ! -z "$CONDA_DEFAULT_ENV" ]; then + echo "Error: Must run from outside any conda environment (try 'conda deactivate')" + exit 1 +fi + + # Note: I am intentionally not using environment.yml. I am instead using # requirements.txt and .python_version. This is for two reasons: # 1. environment.yml sets the conda env name. However, I want to enforce @@ -29,7 +47,7 @@ fi # not any additional conda-specific syntax, making it more modular # and flexible. -# Read in .python_version if it exists. +# Set python_version variable. if [ -f "agents/$agent_name/.python_version" ]; then python_version=$(cat "agents/$agent_name/.python_version") else From ca765c609f3b4fc647a3a6cebbb419f3beb5cab4 Mon Sep 17 00:00:00 2001 From: Patrick Wang Date: Wed, 25 Dec 2024 15:03:09 -0500 Subject: [PATCH 07/26] finished create_conda script --- agents/create_conda.sh | 30 ++++++++++++++++++++++++++---- gymlib/setup.py | 2 +- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/agents/create_conda.sh b/agents/create_conda.sh index 3afdc32c..45adc2c1 100755 --- a/agents/create_conda.sh +++ b/agents/create_conda.sh @@ -1,9 +1,14 @@ #!/bin/bash # This script creates a conda environment for a specific agent. +# Run it from the dbgym root folder (e.g. `./agents/create_conda.sh `). +# +# The environment setup: +# - Name matches the agent name. +# - Python version from .python_version file (if exists). +# - Dependencies from requirements.txt file (if exists). # # Before running this script, the user must update the folder of the agent # they want to create a conda environment for (e.g. by calling submodule update). -# # There are other things the user must do as well but these are all checked # automaticallyby this script. @@ -38,7 +43,6 @@ if [ ! -z "$CONDA_DEFAULT_ENV" ]; then exit 1 fi - # Note: I am intentionally not using environment.yml. I am instead using # requirements.txt and .python_version. This is for two reasons: # 1. environment.yml sets the conda env name. However, I want to enforce @@ -55,5 +59,23 @@ else python_version="3.10" fi -echo "hello world!" -echo "python_version: $python_version" \ No newline at end of file +# Create conda environment with specified Python version +echo "Creating conda environment '$agent_name' with Python $python_version..." +eval "$(conda shell.bash hook)" +conda create -y -n "$agent_name" python="$python_version" + +# Install the packages. +conda activate "$agent_name" + +if [ -f "agents/$agent_name/requirements.txt" ]; then + echo "Installing pip requirements from agents/$agent_name/requirements.txt..." + pip install -r "agents/$agent_name/requirements.txt" +else + echo "Warning: requirements.txt not found in agents/$agent_name/." +fi + +conda deactivate + +# Success message. +echo "Conda environment '$agent_name' created successfully." +echo "It is not currently activated. To activate it, run 'conda activate $agent_name'." diff --git a/gymlib/setup.py b/gymlib/setup.py index 2e104820..5e4eacbc 100644 --- a/gymlib/setup.py +++ b/gymlib/setup.py @@ -1,4 +1,4 @@ -from setuptools import setup, find_packages +from setuptools import find_packages, setup setup( name="gymlib", From 3d2cf512e5f3bb078688fd0c72e3e2506e755753 Mon Sep 17 00:00:00 2001 From: Patrick Wang Date: Wed, 25 Dec 2024 15:06:22 -0500 Subject: [PATCH 08/26] now installing gymlib in create_conda.sh --- agents/create_conda.sh | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/agents/create_conda.sh b/agents/create_conda.sh index 45adc2c1..d030ea24 100755 --- a/agents/create_conda.sh +++ b/agents/create_conda.sh @@ -6,19 +6,21 @@ # - Name matches the agent name. # - Python version from .python_version file (if exists). # - Dependencies from requirements.txt file (if exists). +# - gymlib is installed. # # Before running this script, the user must update the folder of the agent # they want to create a conda environment for (e.g. by calling submodule update). # There are other things the user must do as well but these are all checked # automaticallyby this script. -# Check that conda is installed. +# 1. Checks. +# 1.1. Check that conda is installed. if ! command -v conda &> /dev/null; then echo "Error: Conda is not installed" exit 1 fi -# Input validation. +# 1.2. Input validation. if [ -z "$1" ]; then echo "Usage: ./create_conda.sh " exit 1 @@ -31,18 +33,19 @@ if [ ! -d "agents/$agent_name" ]; then exit 1 fi -# Checks relating to conda environments. +# 1.3. Checks relating to conda environments. if conda info --envs | grep -q "^$agent_name "; then echo "Error: Conda environment '$agent_name' already exists" exit 1 fi -# Check that we're not in any conda environment +# 1.4. Check that we're not in any conda environment if [ ! -z "$CONDA_DEFAULT_ENV" ]; then echo "Error: Must run from outside any conda environment (try 'conda deactivate')" exit 1 fi +# 2. Set up the environment. # Note: I am intentionally not using environment.yml. I am instead using # requirements.txt and .python_version. This is for two reasons: # 1. environment.yml sets the conda env name. However, I want to enforce @@ -51,7 +54,7 @@ fi # not any additional conda-specific syntax, making it more modular # and flexible. -# Set python_version variable. +# 2.1. Set python_version variable. if [ -f "agents/$agent_name/.python_version" ]; then python_version=$(cat "agents/$agent_name/.python_version") else @@ -59,12 +62,12 @@ else python_version="3.10" fi -# Create conda environment with specified Python version +# 2.2. Create conda environment with specified Python version. echo "Creating conda environment '$agent_name' with Python $python_version..." eval "$(conda shell.bash hook)" conda create -y -n "$agent_name" python="$python_version" -# Install the packages. +# 2.3. Install the packages. conda activate "$agent_name" if [ -f "agents/$agent_name/requirements.txt" ]; then @@ -74,8 +77,11 @@ else echo "Warning: requirements.txt not found in agents/$agent_name/." fi +# We always install gymlib so that the agent has access to it. +pip install -e gymlib + conda deactivate -# Success message. +# 2.4. Success message. echo "Conda environment '$agent_name' created successfully." echo "It is not currently activated. To activate it, run 'conda activate $agent_name'." From 93290ff3d4b72a4c800cc34f30555f925ecf5675 Mon Sep 17 00:00:00 2001 From: Patrick Wang Date: Wed, 25 Dec 2024 15:14:27 -0500 Subject: [PATCH 09/26] now using pyproject.toml instead of setup.py for gymlib --- agents/create_conda.sh | 12 ++++++++++-- gymlib/pyproject.toml | 12 ++++++++++++ gymlib/setup.py | 9 --------- 3 files changed, 22 insertions(+), 11 deletions(-) create mode 100644 gymlib/pyproject.toml delete mode 100644 gymlib/setup.py diff --git a/agents/create_conda.sh b/agents/create_conda.sh index d030ea24..0211a968 100755 --- a/agents/create_conda.sh +++ b/agents/create_conda.sh @@ -13,6 +13,8 @@ # There are other things the user must do as well but these are all checked # automaticallyby this script. +set -euo pipefail + # 1. Checks. # 1.1. Check that conda is installed. if ! command -v conda &> /dev/null; then @@ -40,7 +42,7 @@ if conda info --envs | grep -q "^$agent_name "; then fi # 1.4. Check that we're not in any conda environment -if [ ! -z "$CONDA_DEFAULT_ENV" ]; then +if [ -n "${CONDA_DEFAULT_ENV:-}" ]; then echo "Error: Must run from outside any conda environment (try 'conda deactivate')" exit 1 fi @@ -78,7 +80,13 @@ else fi # We always install gymlib so that the agent has access to it. -pip install -e gymlib +if [ -d "gymlib" ]; then + echo "Installing gymlib in editable mode..." + pip install -e ./gymlib +else + echo "Error: gymlib directory not found in $(pwd). Please ensure you're running this script from the right folder." + exit 1 +fi conda deactivate diff --git a/gymlib/pyproject.toml b/gymlib/pyproject.toml new file mode 100644 index 00000000..52bbea30 --- /dev/null +++ b/gymlib/pyproject.toml @@ -0,0 +1,12 @@ +[build-system] +requires = ["setuptools>=61.0"] +build-backend = "setuptools.build_meta" + +[project] +name = "gymlib" +version = "0.1.0" +requires-python = ">=3.8" +dependencies = [] + +[tool.setuptools] +py-modules = ["__init__"] \ No newline at end of file diff --git a/gymlib/setup.py b/gymlib/setup.py deleted file mode 100644 index 5e4eacbc..00000000 --- a/gymlib/setup.py +++ /dev/null @@ -1,9 +0,0 @@ -from setuptools import find_packages, setup - -setup( - name="gymlib", - version="0.1.0", - packages=find_packages(), - install_requires=[], - python_requires=">=3.8", -) From 9ccb978478b831c55afce4df02cc5430ad62ab88 Mon Sep 17 00:00:00 2001 From: Patrick Wang Date: Wed, 25 Dec 2024 15:15:35 -0500 Subject: [PATCH 10/26] comments --- agents/create_conda.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/agents/create_conda.sh b/agents/create_conda.sh index 0211a968..df7c0bdc 100755 --- a/agents/create_conda.sh +++ b/agents/create_conda.sh @@ -1,13 +1,15 @@ #!/bin/bash # This script creates a conda environment for a specific agent. -# Run it from the dbgym root folder (e.g. `./agents/create_conda.sh `). -# -# The environment setup: # - Name matches the agent name. # - Python version from .python_version file (if exists). # - Dependencies from requirements.txt file (if exists). # - gymlib is installed. # +# Using this script is *optional*. If you have a more complex environment setup +# for your agent, just do that manually. +# +# Run it from the dbgym root folder (e.g. `./agents/create_conda.sh `). +# # Before running this script, the user must update the folder of the agent # they want to create a conda environment for (e.g. by calling submodule update). # There are other things the user must do as well but these are all checked From a5b92c64897e49533c213bba69932b600ef9f6bb Mon Sep 17 00:00:00 2001 From: Patrick Wang Date: Wed, 25 Dec 2024 15:15:51 -0500 Subject: [PATCH 11/26] comments2 --- agents/create_conda.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agents/create_conda.sh b/agents/create_conda.sh index df7c0bdc..3a74b7af 100755 --- a/agents/create_conda.sh +++ b/agents/create_conda.sh @@ -13,7 +13,7 @@ # Before running this script, the user must update the folder of the agent # they want to create a conda environment for (e.g. by calling submodule update). # There are other things the user must do as well but these are all checked -# automaticallyby this script. +# automatically by this script. set -euo pipefail From 20f29947fc0279faf4c4370a4ee2681fed203f5b Mon Sep 17 00:00:00 2001 From: Patrick Wang Date: Wed, 25 Dec 2024 15:29:07 -0500 Subject: [PATCH 12/26] gymlib magic 42 working! --- agents/hello-tune | 2 +- gymlib/__init__.py | 0 gymlib/gymlib/__init__.py | 1 + gymlib/{ => gymlib}/magic.py | 0 gymlib/pyproject.toml | 2 +- 5 files changed, 3 insertions(+), 2 deletions(-) delete mode 100644 gymlib/__init__.py create mode 100644 gymlib/gymlib/__init__.py rename gymlib/{ => gymlib}/magic.py (100%) diff --git a/agents/hello-tune b/agents/hello-tune index c9060794..6228f0ae 160000 --- a/agents/hello-tune +++ b/agents/hello-tune @@ -1 +1 @@ -Subproject commit c90607947e6ea75d7d63d9bf6b2ea13a7456cc72 +Subproject commit 6228f0aece62c4202f3d5c8f3532634c2de60d9b diff --git a/gymlib/__init__.py b/gymlib/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/gymlib/gymlib/__init__.py b/gymlib/gymlib/__init__.py new file mode 100644 index 00000000..30e9d5c3 --- /dev/null +++ b/gymlib/gymlib/__init__.py @@ -0,0 +1 @@ +from . import magic diff --git a/gymlib/magic.py b/gymlib/gymlib/magic.py similarity index 100% rename from gymlib/magic.py rename to gymlib/gymlib/magic.py diff --git a/gymlib/pyproject.toml b/gymlib/pyproject.toml index 52bbea30..6f54fe22 100644 --- a/gymlib/pyproject.toml +++ b/gymlib/pyproject.toml @@ -9,4 +9,4 @@ requires-python = ">=3.8" dependencies = [] [tool.setuptools] -py-modules = ["__init__"] \ No newline at end of file +py-modules = ["gymlib"] \ No newline at end of file From 03b6b90afd60e1f846c7e21f5d17e9c0892c18e9 Mon Sep 17 00:00:00 2001 From: Patrick Wang Date: Wed, 25 Dec 2024 15:29:57 -0500 Subject: [PATCH 13/26] submodule --- agents/hello-tune | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agents/hello-tune b/agents/hello-tune index 6228f0ae..614687b7 160000 --- a/agents/hello-tune +++ b/agents/hello-tune @@ -1 +1 @@ -Subproject commit 6228f0aece62c4202f3d5c8f3532634c2de60d9b +Subproject commit 614687b70ebd85be84b10de63e74e4813a36b30e From ec21da5de6122daf95d0b2bcc3a7d0025a3663c3 Mon Sep 17 00:00:00 2001 From: Patrick Wang Date: Wed, 25 Dec 2024 17:22:26 -0500 Subject: [PATCH 14/26] moved build conda env to scripts --- agents/create_conda.sh => scripts/build_agent_conda_env.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename agents/create_conda.sh => scripts/build_agent_conda_env.sh (95%) diff --git a/agents/create_conda.sh b/scripts/build_agent_conda_env.sh similarity index 95% rename from agents/create_conda.sh rename to scripts/build_agent_conda_env.sh index 3a74b7af..10d488b7 100755 --- a/agents/create_conda.sh +++ b/scripts/build_agent_conda_env.sh @@ -8,7 +8,7 @@ # Using this script is *optional*. If you have a more complex environment setup # for your agent, just do that manually. # -# Run it from the dbgym root folder (e.g. `./agents/create_conda.sh `). +# Run it from the dbgym root folder (e.g. `./scripts/build_agent_conda_env.sh `). # # Before running this script, the user must update the folder of the agent # they want to create a conda environment for (e.g. by calling submodule update). @@ -26,7 +26,7 @@ fi # 1.2. Input validation. if [ -z "$1" ]; then - echo "Usage: ./create_conda.sh " + echo "Usage: ./build_agent_conda_env.sh " exit 1 fi From bd00b99e30995861887da0609531ec960c686dea Mon Sep 17 00:00:00 2001 From: Patrick Wang Date: Wed, 25 Dec 2024 17:25:10 -0500 Subject: [PATCH 15/26] added underscore to helper py file --- scripts/{run_tests.py => _run_tests.py} | 0 scripts/run_integration_tests.sh | 2 +- scripts/run_unit_tests.sh | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename scripts/{run_tests.py => _run_tests.py} (100%) diff --git a/scripts/run_tests.py b/scripts/_run_tests.py similarity index 100% rename from scripts/run_tests.py rename to scripts/_run_tests.py diff --git a/scripts/run_integration_tests.sh b/scripts/run_integration_tests.sh index 99ccfe8e..4578b373 100755 --- a/scripts/run_integration_tests.sh +++ b/scripts/run_integration_tests.sh @@ -1,2 +1,2 @@ #!/bin/bash -python -m scripts.run_tests "integtest_*.py" \ No newline at end of file +python -m scripts._run_tests "integtest_*.py" \ No newline at end of file diff --git a/scripts/run_unit_tests.sh b/scripts/run_unit_tests.sh index 72714776..929f1bcc 100755 --- a/scripts/run_unit_tests.sh +++ b/scripts/run_unit_tests.sh @@ -1,2 +1,2 @@ #!/bin/bash -python -m scripts.run_tests "unittest_*.py" \ No newline at end of file +python -m scripts._run_tests "unittest_*.py" From b7f728fb878549d73476c44c064c1cfdbe0f8ace Mon Sep 17 00:00:00 2001 From: Patrick Wang Date: Wed, 25 Dec 2024 17:35:04 -0500 Subject: [PATCH 16/26] added build_dbgym_conda_env.sh --- scripts/.python_version | 1 + scripts/_build_conda_env.sh | 81 ++++++++++++++++++++++ scripts/build_agent_conda_env.sh | 71 +------------------ scripts/build_dbgym_conda_env.sh | 6 ++ {dependencies => scripts}/requirements.txt | 0 5 files changed, 91 insertions(+), 68 deletions(-) create mode 100644 scripts/.python_version create mode 100755 scripts/_build_conda_env.sh create mode 100755 scripts/build_dbgym_conda_env.sh rename {dependencies => scripts}/requirements.txt (100%) diff --git a/scripts/.python_version b/scripts/.python_version new file mode 100644 index 00000000..920121e4 --- /dev/null +++ b/scripts/.python_version @@ -0,0 +1 @@ +3.10.13 \ No newline at end of file diff --git a/scripts/_build_conda_env.sh b/scripts/_build_conda_env.sh new file mode 100755 index 00000000..f60fe657 --- /dev/null +++ b/scripts/_build_conda_env.sh @@ -0,0 +1,81 @@ +#!/bin/bash +# This helper script creates a conda environment. +# You should not call this script directory. Instead, use build_agent_conda_env.sh or build_gym_conda_env.sh. + +set -euo pipefail + +# 1. Checks. +# 1.1. Check that conda is installed. +if ! command -v conda &> /dev/null; then + echo "Error: Conda is not installed" + exit 1 +fi + +# 1.2. Input validation. +if [ "$#" -lt 3 ]; then + echo "Usage: ./_build_conda_env.sh " + exit 1 +fi + +env_name=$1 +python_version_path=$2 +requirements_path=$3 + +# 1.3. Checks relating to conda environments. +if conda info --envs | grep -q "^$env_name "; then + echo "Error: Conda environment '$env_name' already exists" + exit 1 +fi + +# 1.4. Check that we're not in any conda environment +if [ -n "${CONDA_DEFAULT_ENV:-}" ]; then + echo "Error: Must run from outside any conda environment (try 'conda deactivate')" + exit 1 +fi + +# 2. Set up the environment. +# Note: I am intentionally not using environment.yml. I am instead using +# requirements.txt and .python_version. This is for two reasons: +# 1. environment.yml sets the conda env name. However, I want to enforce +# that the conda env name is the same as the agent name. +# 2. requirements.txt can be used by pip and only contains packages and +# not any additional conda-specific syntax, making it more modular +# and flexible. + +# 2.1. Set python_version variable. +if [ -f "$python_version_path" ]; then + python_version=$(cat "$python_version_path") +else + echo "Warning: .python_version not found in $python_version_path. Using default Python 3.10." + python_version="3.10" +fi + +# 2.2. Create conda environment with specified Python version. +echo "Creating conda environment '$env_name' with Python $python_version..." +eval "$(conda shell.bash hook)" +conda create -y -n "$env_name" python="$python_version" + +# 2.3. Install the packages. +conda activate "$env_name" + +if [ -f "$requirements_path" ]; then + echo "Installing pip requirements from $requirements_path..." + pip install -r "$requirements_path" +else + echo "Warning: $requirements_path not found. Skipping pip install." +fi + +# We always install gymlib so that the agent has access to it. +if [ -d "gymlib" ]; then + echo "Installing gymlib in editable mode..." + pip install -e ./gymlib +else + echo "Error: gymlib directory not found in $(pwd). Please ensure you're running this script from the right folder." + exit 1 +fi + +conda deactivate + +# 2.4. Success message. +echo "Conda environment '$env_name' created successfully." +echo "It is not currently activated. To activate it, run 'conda activate $env_name'." diff --git a/scripts/build_agent_conda_env.sh b/scripts/build_agent_conda_env.sh index 10d488b7..2014a5ab 100755 --- a/scripts/build_agent_conda_env.sh +++ b/scripts/build_agent_conda_env.sh @@ -1,8 +1,8 @@ #!/bin/bash # This script creates a conda environment for a specific agent. # - Name matches the agent name. -# - Python version from .python_version file (if exists). -# - Dependencies from requirements.txt file (if exists). +# - Python version from .python_version file in the agent's folder (if exists). +# - Dependencies from requirements.txt file in the agent's folder (if exists). # - gymlib is installed. # # Using this script is *optional*. If you have a more complex environment setup @@ -17,14 +17,6 @@ set -euo pipefail -# 1. Checks. -# 1.1. Check that conda is installed. -if ! command -v conda &> /dev/null; then - echo "Error: Conda is not installed" - exit 1 -fi - -# 1.2. Input validation. if [ -z "$1" ]; then echo "Usage: ./build_agent_conda_env.sh " exit 1 @@ -37,61 +29,4 @@ if [ ! -d "agents/$agent_name" ]; then exit 1 fi -# 1.3. Checks relating to conda environments. -if conda info --envs | grep -q "^$agent_name "; then - echo "Error: Conda environment '$agent_name' already exists" - exit 1 -fi - -# 1.4. Check that we're not in any conda environment -if [ -n "${CONDA_DEFAULT_ENV:-}" ]; then - echo "Error: Must run from outside any conda environment (try 'conda deactivate')" - exit 1 -fi - -# 2. Set up the environment. -# Note: I am intentionally not using environment.yml. I am instead using -# requirements.txt and .python_version. This is for two reasons: -# 1. environment.yml sets the conda env name. However, I want to enforce -# that the conda env name is the same as the agent name. -# 2. requirements.txt can be used by pip and only contains packages and -# not any additional conda-specific syntax, making it more modular -# and flexible. - -# 2.1. Set python_version variable. -if [ -f "agents/$agent_name/.python_version" ]; then - python_version=$(cat "agents/$agent_name/.python_version") -else - echo "Warning: .python_version not found in agents/$agent_name/. Using default Python 3.10." - python_version="3.10" -fi - -# 2.2. Create conda environment with specified Python version. -echo "Creating conda environment '$agent_name' with Python $python_version..." -eval "$(conda shell.bash hook)" -conda create -y -n "$agent_name" python="$python_version" - -# 2.3. Install the packages. -conda activate "$agent_name" - -if [ -f "agents/$agent_name/requirements.txt" ]; then - echo "Installing pip requirements from agents/$agent_name/requirements.txt..." - pip install -r "agents/$agent_name/requirements.txt" -else - echo "Warning: requirements.txt not found in agents/$agent_name/." -fi - -# We always install gymlib so that the agent has access to it. -if [ -d "gymlib" ]; then - echo "Installing gymlib in editable mode..." - pip install -e ./gymlib -else - echo "Error: gymlib directory not found in $(pwd). Please ensure you're running this script from the right folder." - exit 1 -fi - -conda deactivate - -# 2.4. Success message. -echo "Conda environment '$agent_name' created successfully." -echo "It is not currently activated. To activate it, run 'conda activate $agent_name'." +./scripts/_build_conda_env.sh "$agent_name" "agents/$agent_name/.python_version" "agents/$agent_name/requirements.txt" \ No newline at end of file diff --git a/scripts/build_dbgym_conda_env.sh b/scripts/build_dbgym_conda_env.sh new file mode 100755 index 00000000..f85b346d --- /dev/null +++ b/scripts/build_dbgym_conda_env.sh @@ -0,0 +1,6 @@ +#!/bin/bash +# This script builds the conda environment used by the gym itself (i.e. the orchestrator). + +set -euo pipefail + +./scripts/_build_conda_env.sh "dbgym" "scripts/.python_version" "scripts/requirements.txt" diff --git a/dependencies/requirements.txt b/scripts/requirements.txt similarity index 100% rename from dependencies/requirements.txt rename to scripts/requirements.txt From bbb19b6046d569e223ca631c9a909c2df65db8a4 Mon Sep 17 00:00:00 2001 From: Patrick Wang Date: Wed, 25 Dec 2024 17:36:30 -0500 Subject: [PATCH 17/26] removed check of not being in a conda env --- scripts/_build_conda_env.sh | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/scripts/_build_conda_env.sh b/scripts/_build_conda_env.sh index f60fe657..f112d160 100755 --- a/scripts/_build_conda_env.sh +++ b/scripts/_build_conda_env.sh @@ -21,18 +21,12 @@ env_name=$1 python_version_path=$2 requirements_path=$3 -# 1.3. Checks relating to conda environments. +# 1.3. Check that the environment doesn't already exist. if conda info --envs | grep -q "^$env_name "; then echo "Error: Conda environment '$env_name' already exists" exit 1 fi -# 1.4. Check that we're not in any conda environment -if [ -n "${CONDA_DEFAULT_ENV:-}" ]; then - echo "Error: Must run from outside any conda environment (try 'conda deactivate')" - exit 1 -fi - # 2. Set up the environment. # Note: I am intentionally not using environment.yml. I am instead using # requirements.txt and .python_version. This is for two reasons: From e8fe7453b755b6860c2fad71c3a7e72a624f51e1 Mon Sep 17 00:00:00 2001 From: Patrick Wang Date: Wed, 25 Dec 2024 17:39:53 -0500 Subject: [PATCH 18/26] moved stuff out of dependencies --- scripts/_build_conda_env.sh | 2 +- {dependencies => scripts}/apt_requirements.txt | 0 {dependencies => scripts}/install_dependencies.sh | 0 3 files changed, 1 insertion(+), 1 deletion(-) rename {dependencies => scripts}/apt_requirements.txt (100%) rename {dependencies => scripts}/install_dependencies.sh (100%) diff --git a/scripts/_build_conda_env.sh b/scripts/_build_conda_env.sh index f112d160..7685f104 100755 --- a/scripts/_build_conda_env.sh +++ b/scripts/_build_conda_env.sh @@ -1,6 +1,6 @@ #!/bin/bash # This helper script creates a conda environment. -# You should not call this script directory. Instead, use build_agent_conda_env.sh or build_gym_conda_env.sh. +# You should not run this directly. Instead, use build_agent_conda_env.sh or build_gym_conda_env.sh. set -euo pipefail diff --git a/dependencies/apt_requirements.txt b/scripts/apt_requirements.txt similarity index 100% rename from dependencies/apt_requirements.txt rename to scripts/apt_requirements.txt diff --git a/dependencies/install_dependencies.sh b/scripts/install_dependencies.sh similarity index 100% rename from dependencies/install_dependencies.sh rename to scripts/install_dependencies.sh From 56a3f5eb8ffb18316c3d6c29a184d7fa9cf8823f Mon Sep 17 00:00:00 2001 From: Patrick Wang Date: Wed, 25 Dec 2024 17:42:12 -0500 Subject: [PATCH 19/26] moved configs over to configs --- scripts/build_dbgym_conda_env.sh | 2 +- scripts/{ => configs}/.python_version | 0 scripts/{ => configs}/apt_requirements.txt | 0 scripts/{ => configs}/e2e_test_dbgym_config.yaml | 0 scripts/{ => configs}/mypy.ini | 0 scripts/{ => configs}/requirements.txt | 0 scripts/install_dependencies.sh | 6 +++--- scripts/mypy.sh | 2 +- scripts/run_protox_e2e_test.py | 2 +- 9 files changed, 6 insertions(+), 6 deletions(-) rename scripts/{ => configs}/.python_version (100%) rename scripts/{ => configs}/apt_requirements.txt (100%) rename scripts/{ => configs}/e2e_test_dbgym_config.yaml (100%) rename scripts/{ => configs}/mypy.ini (100%) rename scripts/{ => configs}/requirements.txt (100%) diff --git a/scripts/build_dbgym_conda_env.sh b/scripts/build_dbgym_conda_env.sh index f85b346d..fd8ab6f7 100755 --- a/scripts/build_dbgym_conda_env.sh +++ b/scripts/build_dbgym_conda_env.sh @@ -3,4 +3,4 @@ set -euo pipefail -./scripts/_build_conda_env.sh "dbgym" "scripts/.python_version" "scripts/requirements.txt" +./scripts/_build_conda_env.sh "dbgym" "scripts/configs/.python_version" "scripts/configs/requirements.txt" diff --git a/scripts/.python_version b/scripts/configs/.python_version similarity index 100% rename from scripts/.python_version rename to scripts/configs/.python_version diff --git a/scripts/apt_requirements.txt b/scripts/configs/apt_requirements.txt similarity index 100% rename from scripts/apt_requirements.txt rename to scripts/configs/apt_requirements.txt diff --git a/scripts/e2e_test_dbgym_config.yaml b/scripts/configs/e2e_test_dbgym_config.yaml similarity index 100% rename from scripts/e2e_test_dbgym_config.yaml rename to scripts/configs/e2e_test_dbgym_config.yaml diff --git a/scripts/mypy.ini b/scripts/configs/mypy.ini similarity index 100% rename from scripts/mypy.ini rename to scripts/configs/mypy.ini diff --git a/scripts/requirements.txt b/scripts/configs/requirements.txt similarity index 100% rename from scripts/requirements.txt rename to scripts/configs/requirements.txt diff --git a/scripts/install_dependencies.sh b/scripts/install_dependencies.sh index da6c7bad..02fdfaed 100755 --- a/scripts/install_dependencies.sh +++ b/scripts/install_dependencies.sh @@ -1,5 +1,5 @@ #!/bin/bash # You may want to create a conda environment before doing this -pip install -r dependencies/requirements.txt -cat dependencies/apt_requirements.txt | xargs sudo apt-get install -y -curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \ No newline at end of file +pip install -r scripts/configs/requirements.txt +cat scripts/configs/apt_requirements.txt | xargs sudo apt-get install -y +curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y diff --git a/scripts/mypy.sh b/scripts/mypy.sh index 0eb0c21f..5ad5cc9f 100755 --- a/scripts/mypy.sh +++ b/scripts/mypy.sh @@ -1,2 +1,2 @@ #!/bin/bash -mypy --config-file scripts/mypy.ini . \ No newline at end of file +mypy --config-file scripts/configs/mypy.ini . \ No newline at end of file diff --git a/scripts/run_protox_e2e_test.py b/scripts/run_protox_e2e_test.py index 34fc7931..f1f2ad77 100644 --- a/scripts/run_protox_e2e_test.py +++ b/scripts/run_protox_e2e_test.py @@ -26,7 +26,7 @@ # Be careful when changing these constants. In some places, the E2E test is hardcoded to work for these specific constants. DBMS = "postgres" AGENT = "protox" -E2ETEST_DBGYM_CONFIG_FPATH = Path("scripts/e2e_test_dbgym_config.yaml") +E2ETEST_DBGYM_CONFIG_FPATH = Path("scripts/configs/e2e_test_dbgym_config.yaml") def get_workspace_dpath(config_fpath: Path) -> Path: From 7b897ef804ff1bdfefcb71d66a54cc5adf3c37f9 Mon Sep 17 00:00:00 2001 From: Patrick Wang Date: Wed, 25 Dec 2024 17:42:44 -0500 Subject: [PATCH 20/26] renamed install_dependencies --- ...{install_dependencies.sh => install_system_dependencies.sh} | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) rename scripts/{install_dependencies.sh => install_system_dependencies.sh} (58%) diff --git a/scripts/install_dependencies.sh b/scripts/install_system_dependencies.sh similarity index 58% rename from scripts/install_dependencies.sh rename to scripts/install_system_dependencies.sh index 02fdfaed..5733db2a 100755 --- a/scripts/install_dependencies.sh +++ b/scripts/install_system_dependencies.sh @@ -1,5 +1,4 @@ #!/bin/bash -# You may want to create a conda environment before doing this -pip install -r scripts/configs/requirements.txt +# These are dependencies unrelated to Python that the dbgym needs. cat scripts/configs/apt_requirements.txt | xargs sudo apt-get install -y curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y From 95f0683443ff6b8610f5e3d5d2e682117aa53b0c Mon Sep 17 00:00:00 2001 From: Patrick Wang Date: Wed, 25 Dec 2024 17:43:02 -0500 Subject: [PATCH 21/26] comment --- scripts/{install_system_dependencies.sh => install_sysdeps.sh} | 1 + 1 file changed, 1 insertion(+) rename scripts/{install_system_dependencies.sh => install_sysdeps.sh} (82%) diff --git a/scripts/install_system_dependencies.sh b/scripts/install_sysdeps.sh similarity index 82% rename from scripts/install_system_dependencies.sh rename to scripts/install_sysdeps.sh index 5733db2a..452003a6 100755 --- a/scripts/install_system_dependencies.sh +++ b/scripts/install_sysdeps.sh @@ -1,4 +1,5 @@ #!/bin/bash +# "sysdeps" stands for "system dependencies". # These are dependencies unrelated to Python that the dbgym needs. cat scripts/configs/apt_requirements.txt | xargs sudo apt-get install -y curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y From 8ebbc24d7bfbf7109bd531dbc830c457e9cd39f2 Mon Sep 17 00:00:00 2001 From: Patrick Wang Date: Wed, 25 Dec 2024 17:56:16 -0500 Subject: [PATCH 22/26] changed install dep step of ci --- .github/workflows/tests.yaml | 3 ++- scripts/build_dbgym_conda_env.sh | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index dcb28420..2fec3117 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -30,7 +30,8 @@ jobs: # We need to do `. "$HOME/.cargo/env"` in each step for it to work. - name: Install dependencies run: | - ./dependencies/install_dependencies.sh + pip install -r ./scripts/configs/requirements.txt + ./scripts/install_sysdeps.sh - name: Check formatting run: | diff --git a/scripts/build_dbgym_conda_env.sh b/scripts/build_dbgym_conda_env.sh index fd8ab6f7..c550cc12 100755 --- a/scripts/build_dbgym_conda_env.sh +++ b/scripts/build_dbgym_conda_env.sh @@ -1,5 +1,6 @@ #!/bin/bash # This script builds the conda environment used by the gym itself (i.e. the orchestrator). +# This script is optional. You don't need to use conda if you don't want to (the CI doesn't use conda, for instance) set -euo pipefail From c1ed61160db606ee7bdfdb102ee397624f5557a7 Mon Sep 17 00:00:00 2001 From: Patrick Wang Date: Wed, 25 Dec 2024 17:59:39 -0500 Subject: [PATCH 23/26] fmt and mypy now ignore agents --- scripts/check_format.sh | 5 +++-- scripts/format.sh | 7 ++++--- scripts/mypy.sh | 3 ++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/scripts/check_format.sh b/scripts/check_format.sh index 74b4188b..d43030d6 100755 --- a/scripts/check_format.sh +++ b/scripts/check_format.sh @@ -1,5 +1,6 @@ #!/bin/bash set -euxo pipefail -black . --check -isort . --profile black -c +# Ignore agents/ because those are all submodules. +black . --check --exclude agents +isort . --profile black -c --skip agents diff --git a/scripts/format.sh b/scripts/format.sh index db5cc125..9406abfe 100755 --- a/scripts/format.sh +++ b/scripts/format.sh @@ -1,5 +1,6 @@ #!/bin/bash -set -euxo pipefail +set -euo pipefail -black . -isort . --profile black +# Ignore agents/ because those are all submodules. +black . --exclude agents +isort . --profile black --skip agents diff --git a/scripts/mypy.sh b/scripts/mypy.sh index 5ad5cc9f..462a5efa 100755 --- a/scripts/mypy.sh +++ b/scripts/mypy.sh @@ -1,2 +1,3 @@ #!/bin/bash -mypy --config-file scripts/configs/mypy.ini . \ No newline at end of file +# Ignore agents/ because those are all submodules. +mypy --config-file scripts/configs/mypy.ini . --exclude agents/ \ No newline at end of file From aa0130cc469e39456187e4dad942470b4933fa0b Mon Sep 17 00:00:00 2001 From: Patrick Wang Date: Wed, 25 Dec 2024 17:59:49 -0500 Subject: [PATCH 24/26] type annotated magic --- gymlib/gymlib/magic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gymlib/gymlib/magic.py b/gymlib/gymlib/magic.py index f8fb186d..4c95af05 100644 --- a/gymlib/gymlib/magic.py +++ b/gymlib/gymlib/magic.py @@ -1,2 +1,2 @@ -def get_magic_number(): +def get_magic_number() -> int: return 42 From 1d81c232e6738d56e4d177b4c15efdcd8528ac01 Mon Sep 17 00:00:00 2001 From: Patrick Wang Date: Wed, 25 Dec 2024 18:00:37 -0500 Subject: [PATCH 25/26] now installing gymlib in ci --- .github/workflows/tests.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 2fec3117..0b5f486d 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -31,6 +31,7 @@ jobs: - name: Install dependencies run: | pip install -r ./scripts/configs/requirements.txt + pip install -e ./gymlib ./scripts/install_sysdeps.sh - name: Check formatting From 043ba5db9dfbedd09924d0ca20e96a019b8ffc0c Mon Sep 17 00:00:00 2001 From: Patrick Wang Date: Wed, 25 Dec 2024 18:12:09 -0500 Subject: [PATCH 26/26] turned off e2e tests to make cis complete faster. this is ok because we are going to deprecate the part of the codebase these are testing anyways --- .github/workflows/tests.yaml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 0b5f486d..5e5d757d 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -59,12 +59,12 @@ jobs: export ./scripts/run_integration_tests.sh - - name: Run end-to-end tests - # End-to-end tests are like integration tests in that they require external systems to be running. - # Unlike integration tests though, they don't perform detailed checks for any individual module. - # - # Note that we need to run with a non-root user in order to start Postgres. This is configured in the .yaml - # file for our self-hosted GHA runners. - run: | - . "$HOME/.cargo/env" - python -m scripts.run_protox_e2e_test ssd + # - name: Run end-to-end tests + # # End-to-end tests are like integration tests in that they require external systems to be running. + # # Unlike integration tests though, they don't perform detailed checks for any individual module. + # # + # # Note that we need to run with a non-root user in order to start Postgres. This is configured in the .yaml + # # file for our self-hosted GHA runners. + # run: | + # . "$HOME/.cargo/env" + # python -m scripts.run_protox_e2e_test ssd