Skip to content

Pcg V1.01#78

Open
xluox wants to merge 19 commits intomasterfrom
PCG
Open

Pcg V1.01#78
xluox wants to merge 19 commits intomasterfrom
PCG

Conversation

@xluox
Copy link
Contributor

@xluox xluox commented Apr 29, 2022

  • Add a random seed to make sure the same maps are generated every time.
  • Update PCG to generate multiple maps at a time
  • Update vec_env to read in PCG/maps folder

@xluox xluox requested a review from vwxyzjn April 29, 2022 01:28
self.initiate_units(root, "units")
tree = ET.ElementTree(root)
tree.write("./maps/filename.xml")
tree.write(os.path.join("PCG/maps/", "pcg_map" + "_" + str(mapKey) + ".xml"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the output directory should be configurable (not hard coded like this).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what kind of configurable output directory you are expecting?


# prepare training maps
self.cycle_maps = list(map(lambda i: os.path.join(self.microrts_path, i), cycle_maps))
self.pcg_map_path = os.path.join(PCG.__path__[0], "maps")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This input PCG map path should be configurable.

@vwxyzjn
Copy link
Collaborator

vwxyzjn commented Apr 29, 2022

Could you add some brief documentation in the README.md that explains how to run these?

@vwxyzjn
Copy link
Collaborator

vwxyzjn commented May 19, 2022

Hey Yifu sorry for the delay.

I suggest do not modify the vec_env.py and instead use the following paradigm instead:

# pre-generate maps to a directory 
python pcg.py --width 16 --height 16 --num-maps 200 --output-dir pcg_maps
# run the training script with the pre-generated maps
python ppo_gridnet.py --track --maps-dir pcg_maps

In the ppo_gridnet.py, you can basically include all the map names in a maps variable, say, pcg_maps and then we can directly pass to the env creation API

    envs = MicroRTSGridModeVecEnv(
        num_selfplay_envs=args.num_selfplay_envs,
        num_bot_envs=args.num_bot_envs,
        partial_obs=args.partial_obs,
        max_steps=2000,
        render_theme=2,
        ai2s=[microrts_ai.coacAI for _ in range(args.num_bot_envs - 6)]
        + [microrts_ai.randomBiasedAI for _ in range(min(args.num_bot_envs, 2))]
        + [microrts_ai.lightRushAI for _ in range(min(args.num_bot_envs, 2))]
        + [microrts_ai.workerRushAI for _ in range(min(args.num_bot_envs, 2))],
        map_paths=[args.train_maps[0]],
        reward_weight=np.array([10.0, 1.0, 1.0, 0.2, 1.0, 4.0]),
        cycle_maps=pcg_maps,
    )

xluox added 2 commits June 8, 2022 19:51
Add flag to turn on varying wall rings and non varying wall rings
@vwxyzjn
Copy link
Collaborator

vwxyzjn commented Jun 10, 2022

Thanks Yifu! Have you successfully run training with this?

@xluox
Copy link
Contributor Author

xluox commented Jun 10, 2022

Thanks Yifu! Have you successfully run training with this?

Yes

@vwxyzjn
Copy link
Collaborator

vwxyzjn commented Jun 10, 2022

Everything looks good, except one last thing. Would you mind adding a section in the README.md file in the roof folder of this project to explain how to run things? Once you add that I think we are ready to merge.

Something like below (note that #76 is merged so you need to specify the evaluation maps now) Basically, we want to provide instructions so that people can run it with copy-and-paste commands.

Training with Procedural Content Generation

You can train the agent with procedurally generated maps now thanks to @xluox! Try running:

poetry run python pcg/pcg.py -xxxxx xxx
poetry run python ppo_gridnet.py \
    --train-maps maps/16x16/basesWorkers16x16B.xml maps/16x16/basesWorkers16x16C.xml maps/16x16/basesWorkers16x16D.xml maps/16x16/basesWorkers16x16E.xml maps/16x16/basesWorkers16x16F.xml \
    --eval-maps maps/16x16/basesWorkers16x16B.xml maps/16x16/basesWorkers16x16C.xml maps/16x16/basesWorkers16x16D.xml maps/16x16/basesWorkers16x16E.xml maps/16x16/basesWorkers16x16F.xml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants