Skip to content

Commit

Permalink
Merge pull request #217 from Lux-AI-Challenge/v2.1.8
Browse files Browse the repository at this point in the history
V2.1.8
  • Loading branch information
StoneT2000 authored Feb 20, 2023
2 parents 87cd543 + 42e1185 commit 5c4724c
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 14 deletions.
21 changes: 21 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
# ChangeLog

### v2.1.8

fix bug on mac where non python kits assumed a windows platform

store replay seed and player paths on CLI tool.

visualizer shows the player paths as well as seed on kaggle and local replays


### v2.1.7
removed omegaconf as dependency


### v2.1.6

some bug fixes

### v2.1.5

verbosity is nicer and more bug fixes

### v2.1.4

Fix bug with action formatter not handling lists
Expand Down
2 changes: 1 addition & 1 deletion lux-eye-s2/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lux-ai/lux-eye-s2",
"version": "2.1.7",
"version": "2.1.9",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
11 changes: 7 additions & 4 deletions lux-eye-s2/src/episode/kaggle-environments.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { parseLuxAIS2Episode } from './luxai-s2';
import { Episode } from './model';
import { Episode, EpisodeMetadata } from './model';

export function isKaggleEnvironmentsEpisode(data: any): boolean {
return typeof data === 'object' && data.steps !== undefined;
Expand All @@ -9,9 +9,12 @@ export function parseKaggleEnvironmentsEpisode(data: any): Episode {
const observations = [];
const actions = [];

let teamNames: [string, string] | undefined = undefined;
const extra: Partial<EpisodeMetadata> = {};
if (typeof data.info === 'object' && data.info.TeamNames !== undefined) {
teamNames = data.info.TeamNames;
extra.teamNames = data.info.TeamNames;
}
if (typeof data.configuration == 'object' && data.configuration.seed !== undefined) {
extra.seed = data.configuration.seed;
}

for (const step of data.steps) {
Expand All @@ -26,5 +29,5 @@ export function parseKaggleEnvironmentsEpisode(data: any): Episode {
});
}

return parseLuxAIS2Episode({ observations, actions }, teamNames);
return parseLuxAIS2Episode({ observations, actions }, extra);
}
25 changes: 21 additions & 4 deletions lux-eye-s2/src/episode/luxai-s2.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
Board,
Episode,
EpisodeMetadata,
Faction,
Factory,
FactoryAction,
Expand Down Expand Up @@ -128,11 +129,27 @@ export function isLuxAIS2Episode(data: any): boolean {
return typeof data === 'object' && data.observations !== undefined && data.actions !== undefined;
}

export function parseLuxAIS2Episode(data: any, teamNames: [string, string] = ['Player A', 'Player B']): Episode {
export function parseLuxAIS2Episode(data: any, extra: Partial<EpisodeMetadata> = {}): Episode {
if (data.observations[0].board.valid_spawns_mask === undefined) {
throw new Error('Only Lux AI v1.1.0+ episodes are supported');
}

let metadata: EpisodeMetadata = { teamNames: ['Player A', 'Player B'], seed: undefined };
metadata = {
...metadata,
...extra,
};
if (data.metadata) {
if (data.metadata['players']) {
for (let i = 0; i < 2; i++) {
metadata.teamNames[i] = data.metadata['players'][`player_${i}`];
}
}
if (data.metadata['seed']) {
metadata.seed = data.metadata['seed'];
}
}

const steps: Step[] = [];

for (let i = 0; i < data.observations.length; i++) {
Expand Down Expand Up @@ -195,7 +212,7 @@ export function parseLuxAIS2Episode(data: any, teamNames: [string, string] = ['P
data.observations[1].teams[playerId] !== undefined ? data.observations[1].teams[playerId] : null;

teams.push({
name: teamNames[j],
name: metadata.teamNames[j],
faction: rawPlayer !== null ? rawPlayer.faction : Faction.None,

water: 0,
Expand Down Expand Up @@ -285,7 +302,7 @@ export function parseLuxAIS2Episode(data: any, teamNames: [string, string] = ['P

const rawTeam = obs.teams[playerId];
teams.push({
name: teamNames[j],
name: metadata.teamNames[j],
faction: rawTeam.faction,

water: rawTeam.water,
Expand All @@ -311,5 +328,5 @@ export function parseLuxAIS2Episode(data: any, teamNames: [string, string] = ['P
});
}

return { steps };
return { steps, metadata };
}
5 changes: 5 additions & 0 deletions lux-eye-s2/src/episode/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,9 @@ export interface Step {

export interface Episode {
steps: Step[];
metadata: EpisodeMetadata;
}
export interface EpisodeMetadata {
teamNames: [string, string];
seed?: number;
}
1 change: 1 addition & 0 deletions lux-eye-s2/src/pages/visualizer/TurnControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ export function TurnControl({ showHotkeysButton, showOpenButton }: TurnControlPr

<Group position="apart">
<Text>{isDay ? 'Day' : 'Night'}</Text>
{episode.metadata.seed && <Text>Seed: {episode.metadata.seed}</Text>}
{selectedTile !== null && (
<Text>
Tile: ({selectedTile.x}, {selectedTile.y})
Expand Down
2 changes: 2 additions & 0 deletions luxai_s2/luxai_runner/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ async def step(self, obs, step: int, reward: float = 0, info=dict()):
)
except asyncio.TimeoutError:
action, stderr = None, None
except:
action, stderr = None, None
time_used = time.time() - stime

if stderr != "" and stderr is not None:
Expand Down
14 changes: 11 additions & 3 deletions luxai_s2/luxai_runner/episode.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ def __init__(self, cfg: EpisodeConfig) -> None:
self.seed = cfg.seed if cfg.seed is not None else np.random.randint(9999999)
self.players = cfg.players

def save_replay(self, replay):
def save_replay(self, replay, metadata):
save_format = self.cfg.replay_options.save_format
if save_format not in ["json", "html"]:
raise ValueError(f"{save_format} is not a valid save format")

replay["metadata"] = metadata
replay["observations"] = [to_json(x) for x in replay["observations"]]
replay["actions"] = [to_json(x) for x in replay["actions"]]
replay["default_seed"] = self.cfg.seed
del replay["dones"]
del replay["rewards"]

Expand Down Expand Up @@ -102,11 +103,18 @@ async def run(self):
start_tasks += [player.proc.start()]
await asyncio.wait(start_tasks, return_when=asyncio.ALL_COMPLETED)

metadata = dict()

obs = self.env.reset(seed=self.seed)
env_cfg = self.env.state.env_cfg
state_obs = self.env.state.get_compressed_obs()
obs = to_json(state_obs)

metadata["seed"] = self.env.seed_val
metadata["players"] = dict()
for player_id, bot in players.items():
metadata["players"][player_id] = bot.main_file_path

if self.cfg.render:
self.env.render()
time.sleep(0.2)
Expand Down Expand Up @@ -181,7 +189,7 @@ async def run(self):
game_done = True
self.log.info(f"Final Scores: {rewards}")
if save_replay:
self.save_replay(replay)
self.save_replay(replay, metadata)

for player in players.values():
await player.proc.cleanup()
Expand Down
2 changes: 1 addition & 1 deletion luxai_s2/luxai_runner/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async def start(self):
base_file_path = os.path.basename(self.file_path)
if self.is_binary:
self._agent_process = await asyncio.create_subprocess_exec(
f"{cwd}\{base_file_path}" if "win" in sys.platform else f"./{base_file_path}",
f"{cwd}\{base_file_path}" if sys.platform.startswith('win') else f"./{base_file_path}",
stdin=asyncio.subprocess.PIPE,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
Expand Down
2 changes: 1 addition & 1 deletion luxai_s2/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def read(fname):
long_description="Code for the Lux AI Challenge Season 2",
packages=find_packages(exclude="kits"),
entry_points={"console_scripts": ["luxai-s2 = luxai_runner.cli:main"]},
version="2.1.7",
version="2.1.8",
python_requires=">=3.7",
install_requires=[
"numpy",
Expand Down

0 comments on commit 5c4724c

Please sign in to comment.