Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: remove resolve_agent and use build_agent to build trained model agent #333

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions handyrl/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ def build_agent(raw, env=None):
elif raw.startswith('rulebase'):
key = raw.split('-')[1] if '-' in raw else None
return RuleBasedAgent(key)

if env is not None:
model = load_model(model_path, env.net())
agent = Agent(model)
return agent

return None


Expand Down Expand Up @@ -383,14 +389,7 @@ def eval_main(args, argv):
num_games = int(argv[1]) if len(argv) >= 2 else 100
num_process = int(argv[2]) if len(argv) >= 3 else 1

def resolve_agent(model_path):
agent = build_agent(model_path, env)
if agent is None:
model = load_model(model_path, env.net())
agent = Agent(model)
return agent

main_agent = resolve_agent(model_paths[0])
main_agent = build_agent(model_paths[0], env)
critic = None

print('%d process, %d games' % (num_process, num_games))
Expand All @@ -399,7 +398,7 @@ def resolve_agent(model_path):
print('seed = %d' % seed)

opponent = model_paths[1] if len(model_paths) > 1 else 'random'
agents = [main_agent] + [resolve_agent(opponent) for _ in range(len(env.players()) - 1)]
agents = [main_agent] + [build_agent(opponent, env) for _ in range(len(env.players()) - 1)]

evaluate_mp(env, agents, critic, env_args, {'default': {}}, num_process, num_games, seed)

Expand Down