def check_agent_meta(coordinator): status = coordinator.get_agent_meta(0) name = status['name'] name_ok,name_issue = check_name(name) if not name_ok: fail_check(name_issue) pass_check('Agent Name [%s] Passes Minimum Qualifications' % name) address = status['address'] if address == None or address == '': warn_check('Ethereum address is missing. Your agent will not qualify for a prize. To qualify for prizes, please update your agent to include a valid ethereum address.') else: appears_valid = sanity_check_address(address) if not appears_valid: fail_check('Ethereum address did not pass the format check. Please supply a valid ethereum address matching ^0x[a-fA-F0-9]{40}$ or remove the address entirely.') else: pass_check('Agent Ethereum Address [%s] Passes Format Validation' % address) if status['pic'] == None or status['pic'] == '': warn_check('No usable e-mail address was provided. Your bot will not feature a gravatar. Provide an e-mail address to load a gravatar during the competition.') else: pass_check('Gravatar [%s] Loaded From E-Mail Address Supplied' % status['pic'])
def validate_agent_is_directory(directory): is_directory = os.path.isdir(directory) if is_directory: pass_check('Agent Path is Directory') else: fail_check('Agent Path Not Directory (please pass directory to --agent)')
def validate_agent_size(directory): threshold = 1440000 size = get_size(directory) if size < threshold: pass_check('Agent Size OK (%s Bytes)' % "{:,}".format(size)) else: fail_check('Agent Too Large (%s Bytes, Threshold: %s Bytes, Overage: %s Bytes)' % ("{:,}".format(size),"{:,}".format(threshold),"{:,}".format(size-threshold)))
def validate_agent_handler(directory): file_path = os.path.join(directory,'handler.py') exists = os.path.isfile(file_path) if exists: pass_check('Required Agent Handler Found') else: fail_check('Agent Handler Not Found (please add handler.py to agent directory)')
def load_qualification_config(game): dir_path = os.path.dirname(os.path.realpath(__file__)) qualification_detail_path = os.path.join(dir_path,'qualification',game,'qualification.json') qualification_rounds = [] try: with open(qualification_detail_path) as file: qualification_rounds = json.load(file) except: fail_check('Unable to load qualification data. Please verify qualification configuration file exists at %s' % qualification_detail_path) return qualification_rounds
def check_pull_image(coordinator): print('Verifying Latest Host Image...') has_image = coordinator.has_host_image() if has_image: pass_check('Latest Host Image Found') else: print('Latest Host Image Not Found, Pulling...') print('(This process might take a few minutes)') try: coordinator.pull_host_image() pass_check('Latest Host Image Obtained') except: fail_check('Failed to Obtain Host Image. Check Network Connection & Try Again.')
def check_environment(): print('Checking Host Platform...') if os.name == 'nt': warn_check('It appears that you are running an operating system that the tool has not been tested on.') # Quick docker test print('Checking Docker API...') id = None try: client = docker.from_env() info = client.info() id = info['ID'] except: fail_check('Failed to connect to docker client. Please make sure that docker and the docker API are installed correctly and that the current user has permission to interact with docker.') if id is None or id == '': warn_check('Unable to find docker engine ID. This might indicate an issue interacting with the docker API environment. Make sure the python docker API is installed correctly.')
parser.add_argument("--template", required=False, help="template to use to create agent") parser.add_argument("--ls", action='store_true', required=False, help="list available templates") args = parser.parse_args() try: from profanity import profanity except: fail_check( 'Profanity library missing. Please install this library with pip install profanity.' ) from qualification.core import check_name, copytree, sanity_check_address templates = [] template_info = {} def has_handler(folder): handler_path = os.path.join(folder, 'handler.py') return os.path.isfile(handler_path) for subdir, dirs, files in os.walk('examples'): if has_handler(subdir):
def qualify(coordinator,current_round,agent_path,cutoff=1000,trials=15,visualize=False,visualization_delay=False): coordinator.shared_state_initialization = current_round['shared_config'] with tempfile.TemporaryDirectory() as temp_path: wins = 0 score = current_round['passing_score'] steps_to_finish = [] t = trange(trials, desc=str(score) + " Score / " + str(wins) + " Wins") for trial in t: coordinator.start_new_game() try: # Reload agent without reloading docker instance if(args.stage_path): temp_path = os.path.abspath(args.stage_path) coordinator.add_isolated_agent(args.agent,staging_path=temp_path,reuse_loaded_instance=True) except: fail_check('Failed to add agent. Check handler for syntax errors. Also, check your docker configuration or try --unrestrict-networking') for i in range(current_round['random_agents']): if args.use_accumulating_opponents: coordinator.add_agent(RandomAccumulatingAgent('Random Acc Agent [%i]' % i)) else: coordinator.add_agent(RandomAgent('Random Agent [%i]' % i)) agent_env_steps = 0 while not coordinator.shared_state.any_agent_won: keys = coordinator.environments[0].keys pickups = coordinator.environments[0].status['pickups'] attacks = coordinator.environments[0].status['attacks'] label = '%s\nTrial %i/%i, Step %i\nScore %s [Maximum to Pass: %s]\n%i Keys, %i Attacks, %i Pickups' %(current_round['name'],trial+1,trials,agent_env_steps, score,current_round['passing_score'],keys,attacks, pickups) coordinator.process_turn(visualize,visualization_label=label) if visualize: time.sleep(visualization_delay) agent_env_steps = coordinator.environments[0].total_steps if agent_env_steps > cutoff: break; trial_steps = coordinator.environments[0].total_steps steps_to_finish.append(trial_steps) score = round(np.mean(steps_to_finish),2) won = coordinator.environments[0].keys if won: wins += 1 t.set_description(str(score) + " Score [Below " + str(current_round['passing_score']) +" to Pass] / " + str(wins) + " Total Wins") ok = score <= current_round['passing_score'] return ok,score
parser.add_argument("--visualize", required=False, action='store_true', help="simple visualization of agent on qualification rounds") parser.add_argument("--visualization-delay", required=False, default=0.01, type=float, help="controls the speed of the visualization by adding a delay after each agent turn. Increase delay to slow down visualization.") parser.add_argument("--seed", required=False, default=42, help="seed to use for some of randomization behavior (not applied to docker agents)") parser.add_argument("--round", required=False, default=None, help="target a specific qualification round by code") parser.add_argument("--round-ls", required=False, action='store_true', help="list all qualification rounds (codes and names)") parser.add_argument("--use-accumulating-opponents", required=False, action='store_true', help="controls random action opponent drop behavior (set to true to have random agents hold keys)") parser.add_argument("--output", required=False, default=None, help="specify a target path to write the qualified submission") parser.add_argument("--verify", required=False, default=None, help="specify a target path to a qualified submission to verify it would be accepted. Includes checking files, running agent, and verifying qualification token.") parser.add_argument("--stage-path", required=False, default=None, help="specify a target staging path name for qualification. This name will be postfixed with the number of the contained agent.") args = parser.parse_args() try: import docker except: fail_check('Docker / pydocker not installed. Please install docker (https://docs.docker.com/install/) and then install the python docker API with pip install docker.') try: import gym except: fail_check('OpenAI gym missing. Please install this library with pip install gym.') try: from profanity import profanity except: fail_check('Profanity library missing. Please install this library with pip install profanity.') try: import numpy as np except: fail_check('Numpy library missing. Please install this library with pip install numpy.')