Skip to content

Commit b99a042

Browse files
authored
Merge pull request #48 from renbytes/dev-tragedyOfCommons
Simulation - Tragedy of the Common
2 parents 15ecefb + d96e1b3 commit b99a042

22 files changed

Lines changed: 2371 additions & 76 deletions

File tree

‎.dockerignore‎

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Python
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
*.so
6+
.Python
7+
*.egg-info/
8+
dist/
9+
build/
10+
.pytest_cache/
11+
.coverage
12+
htmlcov/
13+
.tox/
14+
.mypy_cache/
15+
.ruff_cache/
16+
17+
# Virtual environments
18+
venv/
19+
env/
20+
ENV/
21+
.venv/
22+
23+
# IDEs
24+
.vscode/
25+
.idea/
26+
*.swp
27+
*.swo
28+
*~
29+
.DS_Store
30+
31+
# Git
32+
.git/
33+
.gitignore
34+
.github/
35+
36+
# Docker
37+
.dockerignore
38+
Dockerfile*
39+
docker-compose*.yml
40+
41+
# Project specific - LARGE DIRECTORIES
42+
data/
43+
mlruns/
44+
site/
45+
all_code_and_configs.txt
46+
arla_monorepo_workspace.egg-info/
47+
logs/
48+
*.log
49+
*.db
50+
*.sqlite
51+
52+
# Rust build artifacts
53+
**/target/
54+
**/*.so
55+
Cargo.lock
56+
57+
# Documentation
58+
docs/
59+
*.md
60+
!README.md # Keep README.md as it's needed by Poetry
61+
62+
# Environment files
63+
.env*
64+
!.env.example
65+
66+
# Notebooks
67+
*.ipynb
68+
.ipynb_checkpoints/
69+
70+
# Testing
71+
coverage.xml
72+
*.cover
73+
.hypothesis/
74+
75+
# Package managers
76+
poetry.lock.bak
77+
pip-log.txt
78+
79+
# OS files
80+
Thumbs.db
81+
.DS_Store
82+
83+
# Temporary files
84+
*.tmp
85+
*.bak
86+
*.swp
87+
*~
88+
89+
# Archives
90+
*.tar
91+
*.tar.gz
92+
*.zip
93+
*.gz
94+
95+
# Media files (if you have any)
96+
*.mp4
97+
*.avi
98+
*.mov
99+
*.jpg
100+
*.jpeg
101+
*.png
102+
*.gif
103+
!docs/**/*.png
104+
!docs/**/*.jpg

‎.github/workflows/docs.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ jobs:
5050
run: poetry install
5151

5252
- name: "Build and deploy documentation"
53-
run: poetry run mkdocs gh-deploy --force
53+
run: poetry run mkdocs gh-deploy --force

‎Dockerfile‎

Lines changed: 61 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,69 @@
1-
# Build stage
2-
FROM python:3.11.9-slim as builder
3-
4-
ENV POETRY_HOME="/opt/poetry"
5-
ENV POETRY_NO_INTERACTION=1
6-
ENV POETRY_VIRTUALENVS_CREATE=false
7-
ENV PATH="$POETRY_HOME/bin:$PATH"
8-
9-
RUN apt-get update \
10-
&& apt-get install -y --no-install-recommends \
11-
build-essential \
12-
cmake \
13-
git \
14-
graphviz-dev \
15-
libgraphviz-dev \
16-
pkg-config \
17-
curl \
18-
&& curl -sSL https://install.python-poetry.org | python -
1+
# ==============================================================================
2+
# ARLA Project Dockerfile - Optimized for Development Speed
3+
# ==============================================================================
194

20-
WORKDIR /app
21-
COPY . .
22-
RUN poetry install --without dev
23-
24-
# Runtime stage
255
FROM python:3.11.9-slim
266

27-
RUN apt-get update \
28-
&& apt-get install -y --no-install-recommends \
29-
graphviz \
30-
gifsicle \
7+
# Set environment variables for Poetry
8+
ENV POETRY_HOME="/opt/poetry" \
9+
POETRY_NO_INTERACTION=1 \
10+
POETRY_VIRTUALENVS_CREATE=true \
11+
POETRY_VIRTUALENVS_IN_PROJECT=true \
12+
POETRY_CACHE_DIR=/opt/poetry-cache \
13+
PATH="$POETRY_HOME/bin:$PATH"
14+
15+
# Install system dependencies
16+
RUN apt-get update && apt-get install -y --no-install-recommends \
17+
build-essential \
18+
cmake \
19+
git \
20+
graphviz \
21+
graphviz-dev \
22+
libgraphviz-dev \
23+
pkg-config \
24+
curl \
25+
gifsicle \
26+
&& curl -sSL https://install.python-poetry.org | python - \
27+
&& apt-get clean \
3128
&& rm -rf /var/lib/apt/lists/*
3229

30+
# Set working directory
3331
WORKDIR /app
34-
COPY --from=builder /usr/local/lib/python3.11/site-packages/ /usr/local/lib/python3.11/site-packages/
35-
COPY --from=builder /usr/local/bin/ /usr/local/bin/
36-
COPY --from=builder /app .
3732

33+
# Create the full directory structure that Poetry expects
34+
RUN mkdir -p \
35+
/app/agent-core/src/agent_core \
36+
/app/agent-engine/src/agent_engine \
37+
/app/agent-sim/src/agent_sim \
38+
/app/agent-concurrent/src/agent_concurrent \
39+
/app/agent-persist/src/agent_persist \
40+
/app/simulations \
41+
/app/data \
42+
/app/mlruns
43+
44+
# Copy all pyproject.toml files first for dependency resolution
45+
COPY pyproject.toml poetry.lock* ./
46+
COPY agent-core/pyproject.toml ./agent-core/pyproject.toml
47+
COPY agent-engine/pyproject.toml ./agent-engine/pyproject.toml
48+
COPY agent-sim/pyproject.toml ./agent-sim/pyproject.toml
49+
COPY agent-concurrent/pyproject.toml ./agent-concurrent/pyproject.toml
50+
COPY agent-persist/pyproject.toml ./agent-persist/pyproject.toml
51+
52+
# Create minimal __init__.py files so packages can be found
53+
RUN touch /app/agent-core/src/agent_core/__init__.py && \
54+
touch /app/agent-engine/src/agent_engine/__init__.py && \
55+
touch /app/agent-sim/src/agent_sim/__init__.py && \
56+
touch /app/agent-concurrent/src/agent_concurrent/__init__.py && \
57+
touch /app/agent-persist/src/agent_persist/__init__.py
58+
59+
# Install all dependencies including local packages in editable mode
60+
# This will work now because the directory structure exists
61+
RUN $POETRY_HOME/bin/poetry install --without dev --no-root && \
62+
$POETRY_HOME/bin/poetry run pip install -e ./agent-core -e ./agent-engine -e ./agent-sim -e ./agent-concurrent -e ./agent-persist && \
63+
rm -rf $POETRY_CACHE_DIR
64+
65+
# Set Python path
66+
ENV PYTHONPATH="/app/agent-core/src:/app/agent-engine/src:/app/agent-sim/src:/app/agent-concurrent/src:/app/agent-persist/src:/app/simulations"
67+
68+
# Default command - keep container running
3869
CMD ["tail", "-f", "/dev/null"]

‎Makefile‎

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,47 @@ RENDER_DIR ?= data/gif_renders
2323
FPS ?= 15
2424
WORKERS ?= 4
2525

26+
# --- Build Configuration ---
27+
# Enable Docker BuildKit for better caching and parallel builds
28+
export DOCKER_BUILDKIT=1
29+
export COMPOSE_DOCKER_CLI_BUILD=1
2630

2731
# --- Core Docker Commands ---
2832

2933
## up: Build images, start services, and initialize the database.
3034
up:
3135
@echo "🚀 Building images and starting all services..."
32-
@docker compose up -d --build
33-
@echo "⏳ Waiting 10 seconds for services to stabilize..."
34-
@sleep 10
36+
@echo " Using BuildKit for optimized caching..."
37+
@DOCKER_BUILDKIT=1 COMPOSE_DOCKER_CLI_BUILD=1 docker compose up -d --build
38+
@echo "⏳ Waiting for services to be healthy..."
39+
@docker compose exec -T db sh -c 'until pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB; do sleep 1; done' || true
40+
@docker compose exec -T redis sh -c 'until redis-cli ping; do sleep 1; done' || true
3541
@echo "🔑 Initializing database tables..."
3642
@make init-db
3743
@echo "✅ All services are up and the database is initialized."
44+
@echo ""
45+
@echo "📊 Service Status:"
46+
@docker compose ps
47+
@echo ""
48+
@echo "🔗 Available endpoints:"
49+
@echo " - Application shell: docker compose exec app bash"
50+
@echo " - MLflow UI: http://localhost:5001 (admin/password)"
51+
@echo " - Dozzle logs: http://localhost:9999"
52+
@echo " - PostgreSQL: localhost:5432"
53+
@echo " - Redis: localhost:6379"
54+
55+
## up-rebuild: Force rebuild all images from scratch (ignores cache).
56+
up-rebuild:
57+
@echo "🔨 Force rebuilding all images from scratch..."
58+
@DOCKER_BUILDKIT=1 docker compose build --no-cache
59+
@echo "🚀 Starting services with fresh images..."
60+
@docker compose up -d
61+
@echo "⏳ Waiting for services to be healthy..."
62+
@docker compose exec -T db sh -c 'until pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB; do sleep 1; done' || true
63+
@docker compose exec -T redis sh -c 'until redis-cli ping; do sleep 1; done' || true
64+
@echo "🔑 Initializing database tables..."
65+
@make init-db
66+
@echo "✅ All services are up with fresh builds."
3867

3968
## down: Stop and remove all containers, networks, and volumes.
4069
down:
@@ -49,7 +78,7 @@ logs:
4978
## init-db: Connects to the DB and creates all necessary tables.
5079
init-db:
5180
@echo "Initializing database and creating tables..."
52-
@docker compose exec app poetry run python -m agent_sim.infrastructure.database.init_db
81+
@docker compose exec app /opt/poetry/bin/poetry run python -m agent_sim.infrastructure.database.init_db
5382

5483
## setup: Create the .env file from the example template.
5584
setup:
@@ -67,7 +96,7 @@ run:
6796
@sleep 5
6897
@echo "▶️ Submitting experiment from: $(FILE)"
6998
# This command will now succeed because the 'app' container is running.
70-
@docker compose exec app poetry run agentsim run-experiment $(FILE)
99+
@docker compose exec app /opt/poetry/bin/poetry run agentsim run-experiment $(FILE)
71100

72101
## run-local: Run a single, local simulation for quick testing and debugging.
73102
run-local:

‎agent-sim/src/agent_sim/infrastructure/tasks/celery_app.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
REDIS_URL = os.getenv("REDIS_URL", "redis://localhost:6379/0")
2525

26-
# --- MODIFIED: Explicitly list all modules containing tasks ---
2726
app = Celery(
2827
"agent_sim",
2928
include=[
@@ -32,9 +31,9 @@
3231
# which helps resolve import paths when the task is executed.
3332
"simulations.berry_sim.run",
3433
"simulations.schelling_sim.run",
34+
"simulations.tragedy_of_the_commons.run",
3535
],
3636
)
37-
# --- END MODIFICATION ---
3837

3938
app.conf.worker_pool_restarts = True
4039
app.conf.worker_pool = "prefork"

0 commit comments

Comments
 (0)