Skip to content

feature: Specify opponent by path#337

Open
sakami0000 wants to merge 4 commits intodevelopfrom
feature/opponent_path_specification
Open

feature: Specify opponent by path#337
sakami0000 wants to merge 4 commits intodevelopfrom
feature/opponent_path_specification

Conversation

@sakami0000
Copy link
Copy Markdown

@sakami0000 sakami0000 commented Dec 13, 2022

  • Agent specification at evaluation can be done by path.

src/agent.py

from handyrl.agent import RandomAgent
from handyrl.evaluation import register_agent


@register_agent(alias="transformer")
class TransformerAgent(RandomAgent):
    def __init__(self, temperature=0.0):
        self.temperature = temperature

    def action(self, env, player, show=False):
        action = model_predict(env, player, temperature=self.temperature)
        return action
python main.py -e random:src.agent.TransformerAgent 100 8
  • Arguments can be set by comma-separated style.
python main.py -e random:src.agent.TransformerAgent,temperature=1.0 100 8
  • Strings containing comma are given as arguments by enclosing them in quotation marks.

NOTE: The entire target value must be enclosed in another quotation marks because quotation marks are erased in python arguments.

python main.py -e random:'src.agent.TransformerAgent,hoge="hoge, fuga"' 100 8
  • Alias can be set by using handyrl.evaluation.register_agent.

NOTE: The agent class must be defined in the current context.

main.py

import src.agent
python main.py -e random:transformer,temperature=0.5 100 8
  • All of the above features can also be used in opponent specifications in config.yaml.
opponent: [
    'src.agent.TransformerAgent,temperature=0.5',
    'src.agent.TransformerAgent,temperature=0.5,hoge="hoge, fuga"'
]
  • Spaces before and after commas are automatically erased.
opponent: [
    'src.agent.TransformerAgent, temperature=0.5',
    'src.agent.TransformerAgent, temperature=0.5, hoge="hoge, fuga"'
]

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.

1 participant