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

Add multi-trial iteration to evaluator in code upload challenge example #69

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
9 changes: 7 additions & 2 deletions code_upload_challenge_evaluation/agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,18 @@ def unpack_for_grpc(entity):


flag = None
step_count = 0

while not flag:
action = 0 if step_count % 2 == 0 else 1
base = unpack_for_grpc(
stub.act_on_environment(
evaluation_pb2.Package(SerializedEntity=pack_for_grpc(1))
evaluation_pb2.Package(SerializedEntity=pack_for_grpc(action))
).SerializedEntity
)
flag = base["feedback"][2]
flag = base["all_complete"]
if base["feedback"][2]:
step_count = 0
step_count += 1
print("Agent Feedback", base["feedback"])
print("*" * 100)
39 changes: 27 additions & 12 deletions code_upload_challenge_evaluation/environment/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

LOCAL_EVALUATION = os.environ.get("LOCAL_EVALUATION")
EVALUATION_COMPLETED = False
MAX_EVALUATION_ITERATIONS = 10


class evaluator_environment:
Expand All @@ -38,29 +39,43 @@ def __init__(self, challenge_pk, phase_pk, submission_pk, server):
self.phase_pk = phase_pk
self.submission_pk = submission_pk
self.server = server
self.iteration = 0
self.sum_score = 0

def get_action_space(self, request, context):
message = pack_for_grpc(env.get_action_space())
return evaluation_pb2.Package(SerializedEntity=message)

def act_on_environment(self, request, context):
global EVALUATION_COMPLETED
global env
if not env.feedback or not env.feedback[2]:
action = unpack_for_grpc(request.SerializedEntity)
env.next_score()
env.feedback = env.env.step(action)
feedback = env.feedback
score = env.score
if env.feedback[2]:
if not LOCAL_EVALUATION:
update_submission_result(
env, self.challenge_pk, self.phase_pk, self.submission_pk
)
self.sum_score += env.score
self.iteration += 1
avg_score = self.sum_score/float(self.iteration)
if LOCAL_EVALUATION:
print("Trial {0} Complete. Trial Score: {1}. Average Score: {2}.".format(self.iteration, env.score,
avg_score))
if self.iteration >= MAX_EVALUATION_ITERATIONS:
if not LOCAL_EVALUATION:
update_submission_result(
avg_score, self.challenge_pk, self.phase_pk, self.submission_pk
)
else:
print("Final Score: {0}".format(avg_score))
print("Stopping Evaluation!")
EVALUATION_COMPLETED = True
else:
print("Final Score: {0}".format(env.score))
print("Stopping Evaluation!")
EVALUATION_COMPLETED = True
env = evaluator_environment()
return evaluation_pb2.Package(
SerializedEntity=pack_for_grpc(
{"feedback": env.feedback, "current_score": env.score,}
{"feedback": feedback, "current_score": score, "all_complete": self.iteration >= MAX_EVALUATION_ITERATIONS}
)
)

Expand All @@ -84,23 +99,23 @@ def get_action_space(env):
return list(range(env.action_space.n))


def update_submission_result(env, challenge_pk, phase_pk, submission_pk):
def update_submission_result(avg_score, challenge_pk, phase_pk, submission_pk):
submission_data = {
"submission_status": "finished",
"submission": submission_pk,
}
submission_data = {
"challenge_phase": phase_pk,
"submission": submission_pk,
"stdout": "standard_ouput",
"stdout": "standard_output",
"stderr": "standard_error",
"submission_status": "FINISHED",
"result": json.dumps(
[
{
"split": "train_split",
"show_to_participant": True,
"accuracies": {"score": env.score},
"accuracies": {"score": avg_score},
}
]
),
Expand All @@ -116,7 +131,7 @@ def main():
BODY = os.environ.get("BODY")
# Sample example for BODY
# BODY = "{'submitted_image_uri': '937891341272.dkr.ecr.us-east-1.amazonaws.com/cartpole-challenge-203-participant-team-265:bb55f57f-ae44-4e76-96c2-e1ebb5d7b65a', 'submission_pk': 1351, 'phase_pk': '527', 'challenge_pk': '203'}"
BODY = BODY.replace("'", '"')
BODY = BODY.repl=ace("'", '"')
BODY = json.loads(BODY)
challenge_pk = BODY["challenge_pk"]
phase_pk = BODY["phase_pk"]
Expand Down
102 changes: 13 additions & 89 deletions code_upload_challenge_evaluation/utils/evaluation_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.