Skip to content

Commit

Permalink
Merge pull request #150 from martius-lab/various
Browse files Browse the repository at this point in the history
Various
  • Loading branch information
luator authored Jan 21, 2025
2 parents 54721bc + 9e6e06f commit eac8850
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 7 deletions.
2 changes: 1 addition & 1 deletion comprl-hockey-agent/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
numpy
comprl @ git+https://github.com/martius-lab/teamproject-competition-server.git#egg=comprl&subdirectory=comprl
hockey @ git+https://[email protected]/martius-lab/laser-hockey-env.git@cc48daa135e2cca3e620b90431e57870f61d043c
hockey @ git+https://[email protected]/martius-lab/hockey-env.git
6 changes: 3 additions & 3 deletions comprl-hockey-agent/run_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class RandomAgent(Agent):
def get_step(self, observation: list[float]) -> list[float]:
return np.random.uniform(-1, 1, 4).tolist()

def on_start_game(self, game_id: int) -> None:
def on_start_game(self, game_id) -> None:
print("game started")

def on_end_game(self, result: bool, stats: list[float]) -> None:
Expand Down Expand Up @@ -45,8 +45,8 @@ def get_step(self, observation: list[float]) -> list[float]:
action = self.hockey_agent.act(observation).tolist()
return action

def on_start_game(self, game_id: int) -> None:
print(f"Game started (ID: {game_id})")
def on_start_game(self, game_id) -> None:
print(f"Game started")

def on_end_game(self, result: bool, stats: list[float]) -> None:
text_result = "won" if result else "lost"
Expand Down
12 changes: 11 additions & 1 deletion comprl-hockey-game/comprl-hockey.def
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ from: ubuntu:24.04
echo "deb http://archive.ubuntu.com/ubuntu noble universe" >> /etc/apt/sources.list
apt-get update

apt-get install -y python3-dev python3-pip python3-full swig git
apt-get install -y curl python3-dev python3-pip python3-full swig git

git clone https://github.com/martius-lab/teamproject-competition-server \
--depth 1 -b "{{ COMPRL_GIT_BRANCH }}" /comprl
Expand All @@ -30,6 +30,7 @@ from: ubuntu:24.04

%environment
export COMPRL_CONFIG_PATH="/comprl-config/config.toml"
export NTFY_TOPIC="comprl-server-monitor"


%runscript
Expand All @@ -38,10 +39,14 @@ from: ubuntu:24.04


%startscript
curl -d "Start comprl.server" ntfy.sh/${NTFY_TOPIC}

. /venv/bin/activate
# assumes that the config is bound at that path
python -m comprl.server --config "${COMPRL_CONFIG_PATH}"

curl -H "Priority: urgent" -H "Tags: warning" -d "comprl.server terminated. Exit code: $?" ntfy.sh/${NTFY_TOPIC}


%help
Running the container with `instance start` will run the comprl server.
Expand All @@ -58,10 +63,15 @@ from: ubuntu:24.04
export AGENT_TYPE=strong

%appstart agent
curl -d "Start agent ${AGENT_TYPE}" ntfy.sh/${NTFY_TOPIC}

. /venv/bin/activate
cd /comprl/comprl-hockey-agent
python ./run_client.py --args --agent "${AGENT_TYPE}"

curl -H "Priority: urgent" -H "Tags: warning" -d "Agent terminated. Exit code: $?" ntfy.sh/${NTFY_TOPIC}


%apphelp agent
Run an example agent (using `apptainer instance start --app agent ...`).
You need to provide the access token via the environment variable
Expand Down
24 changes: 24 additions & 0 deletions comprl-hockey-game/prepare_database.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

# extract databasepath from config.toml
DB_PATH=$(python -c "
import tomllib
with open('config.toml', 'rb') as f:
config = tomllib.load(f)
print(config['CompetitionServer']['database_path'])
")

if [ -e "${DB_PATH}" ]; then
echo "Database ${DB_PATH} already exists."
exit 1
fi


# create database
python -m comprl.scripts.create_database ./config.toml

python ../comprl-web-reflex/create_database_tables.py "${DB_PATH}"

# add bot users
comprl-users add "${DB_PATH}" bot-weak --role bot --password $(uuidgen)
comprl-users add "${DB_PATH}" bot-strong --role bot --password $(uuidgen)
2 changes: 1 addition & 1 deletion comprl-hockey-game/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
comprl
numpy
hockey @ git+https://[email protected]/martius-lab/laser-hockey-env.git@cc48daa135e2cca3e620b90431e57870f61d043c
hockey @ git+https://[email protected]/martius-lab/hockey-env.git
7 changes: 6 additions & 1 deletion comprl-web-reflex/comprl-web-reflex.def
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ from: python:3.12
export DEBIAN_FRONTEND=noninteractive

apt-get update
apt-get install -y git caddy redis-server
apt-get install -y git caddy redis-server curl

git clone https://github.com/martius-lab/teamproject-competition-server --depth 1 -b "{{ COMPRL_GIT_BRANCH }}" /comprl

Expand Down Expand Up @@ -49,9 +49,14 @@ from: python:3.12
%environment
export REDIS_URL=redis://localhost
export COMPRL_CONFIG_PATH="/comprl-config/config.toml"
export NTFY_TOPIC="comprl-server-monitor"

%startscript
curl -d "Start comprl web interface" ntfy.sh/${NTFY_TOPIC}

. /venv/bin/activate
redis-server --daemonize yes
cd /comprl/comprl-web-reflex
reflex run --env prod "$@"

curl -H "Priority: urgent" -H "Tags: warning" -d "comprl web interface terminated. Exit code: $?" ntfy.sh/${NTFY_TOPIC}

0 comments on commit eac8850

Please sign in to comment.