Skip to content

Commit 6954bdf

Browse files
committed
Add transparent setting
1 parent 2dda7fb commit 6954bdf

3 files changed

Lines changed: 26 additions & 2 deletions

File tree

codeclash/tournaments/pvp.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from codeclash.tournaments.tournament import AbstractTournament
1818
from codeclash.utils.atomic_write import atomic_write
1919
from codeclash.utils.aws import is_running_in_aws_batch, s3_log_sync
20-
from codeclash.utils.environment import copy_to_container
20+
from codeclash.utils.environment import copy_between_containers, copy_to_container
2121

2222

2323
class PvpTournament(AbstractTournament):
@@ -53,6 +53,10 @@ def metadata_file(self) -> Path:
5353
def rounds(self) -> int:
5454
return self.config["tournament"]["rounds"]
5555

56+
@property
57+
def transparent(self) -> bool:
58+
return self.config["tournament"].get("transparent", False)
59+
5660
def get_metadata(self) -> dict:
5761
# will be saved in end()
5862
return {
@@ -120,6 +124,21 @@ def run_edit_phase(self, round_num: int) -> None:
120124
)
121125
self._compress_round_folder(round_num - 1)
122126

127+
if self.transparent:
128+
# Copy agent's codebase to all other agents
129+
self.logger.info("Transparent mode enabled: copying codebases between agents...")
130+
for idx in range(len(self.agents)):
131+
agent = self.agents[idx]
132+
opponents = [a for j, a in enumerate(self.agents) if j != idx]
133+
self.logger.info(f"Copying {agent.name}'s codebase to other agents...")
134+
for opp in opponents:
135+
copy_between_containers(
136+
agent.environment,
137+
opp.environment,
138+
agent.environment.config.cwd,
139+
f"/{agent.name}/",
140+
)
141+
123142
with ThreadPoolExecutor() as executor:
124143
futures = [executor.submit(self.run_agent, agent, round_num) for agent in self.agents]
125144
for future in futures:

codeclash/utils/environment.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ def copy_between_containers(
2727
Be extremely careful with trailing slashes in src_path and dest_path, the behavior
2828
of docker cp is also different depending on whether the destination exists.
2929
"""
30-
print(f"Copy between containers: {src_path} -> {dest_path}")
30+
print(
31+
f"Copy between containers: {src_container.container_id}:{src_path} -> {dest_container.container_id}:{dest_path}"
32+
)
3133
# Some weird stuff happening on AWS where /tmp doesn't work properly
3234
dir = Path.home() / "tmp"
3335
dir.mkdir(parents=True, exist_ok=True)

main.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def get_output_path() -> Path:
3636
else:
3737
timestamp = time.strftime("%y%m%d%H%M%S")
3838
rounds = config["tournament"]["rounds"]
39+
transparent = config["tournament"].get("transparent", False)
3940
sims = config["game"]["sims_per_round"]
4041

4142
players = [p["name"] for p in config["players"]]
@@ -45,6 +46,8 @@ def get_output_path() -> Path:
4546
folder_name = (
4647
f"PvpTournament.{config['game']['name']}.r{rounds}.s{sims}.p{p_num}.{p_list}{suffix_part}.{timestamp}"
4748
)
49+
if transparent:
50+
folder_name += ".transparent"
4851
if is_running_in_aws_batch():
4952
# Also add a UUID just to be safe
5053
_uuid = str(uuid.uuid4())

0 commit comments

Comments
 (0)