Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ environment/src/skills/ground_truth_skills/*
/eval/open/mcts/runs/
/eval/open/independent_runs/summary_cache/
/eval/open/beam/summary_cache/
/summary_cache/
/venv_py311/
/eval/open/plots/
*.mp4
Expand Down
10 changes: 6 additions & 4 deletions env/src/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,16 @@ def eval_with_error(self, expr, timeout=60):
def handler(signum, frame):
raise TimeoutError()

signal.signal(signal.SIGALRM, handler)
signal.alarm(timeout)
# signal.signal(signal.SIGALRM, handler)
# signal.alarm(timeout)
alarm = threading.Timer(timeout, handler)
alarm.start()

try:
return self.namespace.eval_with_timeout(expr)
finally:
signal.alarm(0)

# signal.alarm(0)
alarm.cancel()

def eval(self, expr, timeout=60):
"Evaluate several lines of input, returning the result of the last line with a timeout"
Expand Down
42 changes: 25 additions & 17 deletions eval/open/beam/run_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from instance import FactorioInstance
from agents.utils.formatters.recursive_report_formatter import RecursiveReportFormatter
from models.game_state import GameState
from eval.open.db_client import SQLliteDBClient

os.environ.update({"FORCE_COLOR": "1", "TERM": "xterm-256color"})
load_dotenv()
Expand Down Expand Up @@ -73,23 +74,30 @@ async def get_version_to_use(resume_version: int = None) -> int:


async def create_db_client() -> DBClient:
"""Create and return a new database client."""
try:
max_connections = 5 # Per process
min_connections = 2
return DBClient(
max_conversation_length=40,
min_connections=min_connections,
max_connections=max_connections,
host=os.getenv("SKILLS_DB_HOST"),
port=os.getenv("SKILLS_DB_PORT"),
dbname=os.getenv("SKILLS_DB_NAME"),
user=os.getenv("SKILLS_DB_USER"),
password=os.getenv("SKILLS_DB_PASSWORD")
)
except Exception as e:
print(f"\033[91mError connecting to the database: {e}\033[91m")
raise
return SQLliteDBClient(
max_conversation_length=40,
min_connections=2,
max_connections=5,
database_file=os.getenv("SQLITE_DB_FILE"),
)

# """Create and return a new database client."""
# try:
# max_connections = 5 # Per process
# min_connections = 2
# return DBClient(
# max_conversation_length=40,
# min_connections=min_connections,
# max_connections=max_connections,
# host=os.getenv("SKILLS_DB_HOST"),
# port=os.getenv("SKILLS_DB_PORT"),
# dbname=os.getenv("SKILLS_DB_NAME"),
# user=os.getenv("SKILLS_DB_USER"),
# password=os.getenv("SKILLS_DB_PASSWORD")
# )
# except Exception as e:
# print(f"\033[91mError connecting to the database: {e}\033[91m")
# raise


async def run_model_search(model: str, instance_start: int, version: int, resume_version: int = None):
Expand Down
4 changes: 2 additions & 2 deletions eval/open/independent_runs/run_config_example_lab_play.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[
{"task": "iron_ore_throughput_16.json",
"model": "gpt-4o"}
{"task": "electronic_circuit_throughput_16.json",
"model": "open-router-anthropic/claude-3.5-sonnet"}
]
25 changes: 16 additions & 9 deletions eval/open/independent_runs/trajectory_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from agents import CompletionResult, CompletionReason
from agents.agent_abc import AgentABC
from agents.basic_agent import BasicAgent
from eval.open.db_client import PostgresDBClient, SQLliteDBClient
from eval.open.db_client import PostgresDBClient, SQLliteDBClient, DBClient
from eval.open.independent_runs.simple_evaluator import SimpleFactorioEvaluator
from models.conversation import Conversation
from models.message import Message
Expand Down Expand Up @@ -244,19 +244,26 @@ def create_factorio_instance(instance_id: int) -> FactorioInstance:
return instance


async def create_db_client() -> PostgresDBClient:
"""Create database client with connection pool"""
return PostgresDBClient(
async def create_db_client() -> DBClient:
return SQLliteDBClient(
max_conversation_length=40,
min_connections=2,
max_connections=5,
host=os.getenv("SKILLS_DB_HOST"),
port=os.getenv("SKILLS_DB_PORT"),
dbname=os.getenv("SKILLS_DB_NAME"),
user=os.getenv("SKILLS_DB_USER"),
password=os.getenv("SKILLS_DB_PASSWORD")
database_file=os.getenv("SQLITE_DB_FILE"),
)

# """Create database client with connection pool"""
# return PostgresDBClient(
# max_conversation_length=40,
# min_connections=2,
# max_connections=5,
# host=os.getenv("SKILLS_DB_HOST"),
# port=os.getenv("SKILLS_DB_PORT"),
# dbname=os.getenv("SKILLS_DB_NAME"),
# user=os.getenv("SKILLS_DB_USER"),
# password=os.getenv("SKILLS_DB_PASSWORD")
# )


async def run_trajectory(process_id: int, config: EvalConfig):
"""Entry point for running a single trajectory"""
Expand Down
28 changes: 28 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[project]
name = "factorio-learning-environment"
version = "0.1.0"
description = "Factorio Learning Environment"
readme = "README.md"
requires-python = ">=3.10"
dependencies = [
"dotenv>=0.9.9",
"pydantic>=2.10.6",
"tenacity>=9.0.0",
"anthropic>=0.49.0",
"openai>=1.66.3",
"psycopg2>=2.9.10",
"numpy>=2.2.3",
"lupa>=2.4",
"slpp>=1.2.3",
"factorio-rcon-py>=2.1.3",
"construct>=2.10.70",
"pillow>=11.1.0",
"scikit-image>=0.25.2",
]

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.build.targets.wheel]
packages = ["agents", "env/src/models"]
Loading