From 500d043ed9d0d6d14f56bf3967670a4f82c6950e Mon Sep 17 00:00:00 2001 From: fheinrich <fheinrich@techfak.uni-bielefeld.de> Date: Mon, 25 Mar 2024 13:43:42 +0100 Subject: [PATCH] Seed in study config --- cooperative_cuisine/configs/study/study_config.yaml | 4 ++++ cooperative_cuisine/study_server.py | 9 +++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cooperative_cuisine/configs/study/study_config.yaml b/cooperative_cuisine/configs/study/study_config.yaml index 0c2ef412..366615b0 100644 --- a/cooperative_cuisine/configs/study/study_config.yaml +++ b/cooperative_cuisine/configs/study/study_config.yaml @@ -4,6 +4,7 @@ levels: layout_path: LAYOUTS_DIR/overcooked-1/1-1-far-apart.layout item_info_path: CONFIGS_DIR/item_info.yaml name: "Level 1" + seed: 12345 config_overwrite: game: time_limit_seconds: 300 @@ -21,6 +22,7 @@ levels: layout_path: LAYOUTS_DIR/overcooked-1/1-4-bottleneck.layout item_info_path: CONFIGS_DIR/item_info.yaml name: "Level 2" + seed: 12345 config_overwrite: game: time_limit_seconds: 300 @@ -29,6 +31,7 @@ levels: layout_path: LAYOUTS_DIR/overcooked-1/1-5-circle.layout item_info_path: CONFIGS_DIR/item_info.yaml name: "Level 3" + seed: 12345 config_overwrite: game: time_limit_seconds: 300 @@ -41,6 +44,7 @@ levels: layout_path: LAYOUTS_DIR/overcooked-1/4-1-moving-counters.layout item_info_path: CONFIGS_DIR/item_info.yaml name: "Level 4" + seed: 12345 config_overwrite: game: time_limit_seconds: 300 diff --git a/cooperative_cuisine/study_server.py b/cooperative_cuisine/study_server.py index 27896e71..e136fa95 100644 --- a/cooperative_cuisine/study_server.py +++ b/cooperative_cuisine/study_server.py @@ -15,7 +15,6 @@ import argparse import asyncio import logging import os -import random import signal import subprocess import uuid @@ -70,6 +69,8 @@ class LevelConfig(BaseModel): """Path to the item info file.""" config_overwrite: dict[str, Any] | None = None """Overwrite parts of the `environment_config`""" + seed: int + """Seed for the level.""" class LevelInfo(BaseModel): @@ -108,13 +109,13 @@ class Study: game_port: The port number of the game server. """ with open(study_config_path, "r") as file: - env_config_f = file.read() + study_config_f = file.read() self.study_id = uuid.uuid4().hex[:UUID_CUTOFF] """Unique ID of the study.""" self.study_config: StudyConfig = yaml.load( - str(env_config_f), Loader=yaml.Loader + str(study_config_f), Loader=yaml.Loader ) """Configuration for the study which layouts, env_configs and item infos are used for the study levels.""" self.levels: list[dict] = self.study_config["levels"] @@ -203,7 +204,7 @@ class Study: deep_update(self.current_config, level.config_overwrite) environment_config = yaml.dump(self.current_config) - seed = int(random.random() * 1000000) + seed = level.seed creation_json = CreateEnvironmentConfig( manager_id=study_manager.server_manager_id, number_players=self.study_config["num_players"] -- GitLab