Skip to content

Gymlib + submodule infra #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
33ae995
added hello-tune submodule
wangpatrick57 Dec 25, 2024
41cd68e
moved hello-tune to the agents directory
wangpatrick57 Dec 25, 2024
61324bc
added gymlib library (can install successfully with pip install -e
wangpatrick57 Dec 25, 2024
a8d7c41
create conda with arg check and folder check
wangpatrick57 Dec 25, 2024
01ae5ce
implemented .python_version
wangpatrick57 Dec 25, 2024
0ee401b
added more checks
wangpatrick57 Dec 25, 2024
ca765c6
finished create_conda script
wangpatrick57 Dec 25, 2024
3d2cf51
now installing gymlib in create_conda.sh
wangpatrick57 Dec 25, 2024
93290ff
now using pyproject.toml instead of setup.py for gymlib
wangpatrick57 Dec 25, 2024
9ccb978
comments
wangpatrick57 Dec 25, 2024
a5b92c6
comments2
wangpatrick57 Dec 25, 2024
20f2994
gymlib magic 42 working!
wangpatrick57 Dec 25, 2024
03b6b90
submodule
wangpatrick57 Dec 25, 2024
ec21da5
moved build conda env to scripts
wangpatrick57 Dec 25, 2024
bd00b99
added underscore to helper py file
wangpatrick57 Dec 25, 2024
b7f728f
added build_dbgym_conda_env.sh
wangpatrick57 Dec 25, 2024
bbb19b6
removed check of not being in a conda env
wangpatrick57 Dec 25, 2024
e8fe745
moved stuff out of dependencies
wangpatrick57 Dec 25, 2024
56a3f5e
moved configs over to configs
wangpatrick57 Dec 25, 2024
7b897ef
renamed install_dependencies
wangpatrick57 Dec 25, 2024
95f0683
comment
wangpatrick57 Dec 25, 2024
8ebbc24
changed install dep step of ci
wangpatrick57 Dec 25, 2024
c1ed611
fmt and mypy now ignore agents
wangpatrick57 Dec 25, 2024
aa0130c
type annotated magic
wangpatrick57 Dec 25, 2024
1d81c23
now installing gymlib in ci
wangpatrick57 Dec 25, 2024
043ba5d
turned off e2e tests to make cis complete faster. this is ok because …
wangpatrick57 Dec 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ 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
pip install -e ./gymlib
./scripts/install_sysdeps.sh

- name: Check formatting
run: |
Expand All @@ -57,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
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ __pycache__/
.conda/
.idea/
test_clean_scratchspace/

workspace/
default_*_benchbase_config_*.xml
default_*_benchbase_config_*.xml
*.egg-info/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "agents/hello-tune"]
path = agents/hello-tune
url = git@github.com:wangpatrick57/hello-tune.git
1 change: 1 addition & 0 deletions agents/hello-tune
Submodule hello-tune added at 614687
5 changes: 0 additions & 5 deletions dependencies/install_dependencies.sh

This file was deleted.

1 change: 1 addition & 0 deletions gymlib/gymlib/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import magic
2 changes: 2 additions & 0 deletions gymlib/gymlib/magic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def get_magic_number() -> int:
return 42
12 changes: 12 additions & 0 deletions gymlib/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 = ["gymlib"]
75 changes: 75 additions & 0 deletions scripts/_build_conda_env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash
# This helper script creates a conda environment.
# You should not run this directly. 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 <env_name> <python_version_path> <requirements_path>"
exit 1
fi

env_name=$1
python_version_path=$2
requirements_path=$3

# 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

# 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'."
File renamed without changes.
32 changes: 32 additions & 0 deletions scripts/build_agent_conda_env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash
# This script creates a conda environment for a specific agent.
# - Name matches the agent name.
# - 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
# for your agent, just do that manually.
#
# Run it from the dbgym root folder (e.g. `./scripts/build_agent_conda_env.sh <agent_name>`).
#
# 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
# automatically by this script.

set -euo pipefail

if [ -z "$1" ]; then
echo "Usage: ./build_agent_conda_env.sh <agent_name>"
exit 1
fi

agent_name=$1

if [ ! -d "agents/$agent_name" ]; then
echo "Error: Agent folder '$agent_name' does not exist"
exit 1
fi

./scripts/_build_conda_env.sh "$agent_name" "agents/$agent_name/.python_version" "agents/$agent_name/requirements.txt"
7 changes: 7 additions & 0 deletions scripts/build_dbgym_conda_env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/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

./scripts/_build_conda_env.sh "dbgym" "scripts/configs/.python_version" "scripts/configs/requirements.txt"
5 changes: 3 additions & 2 deletions scripts/check_format.sh
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions scripts/configs/.python_version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.10.13
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 4 additions & 3 deletions scripts/format.sh
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions scripts/install_sysdeps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +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
3 changes: 2 additions & 1 deletion scripts/mypy.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#!/bin/bash
mypy --config-file scripts/mypy.ini .
# Ignore agents/ because those are all submodules.
mypy --config-file scripts/configs/mypy.ini . --exclude agents/
2 changes: 1 addition & 1 deletion scripts/run_integration_tests.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
python -m scripts.run_tests "integtest_*.py"
python -m scripts._run_tests "integtest_*.py"
2 changes: 1 addition & 1 deletion scripts/run_protox_e2e_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion scripts/run_unit_tests.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
python -m scripts.run_tests "unittest_*.py"
python -m scripts._run_tests "unittest_*.py"
Loading