def main(unused_argv): logging_util.setup() with open(FLAGS.problem) as f: problem = json.load(f) with open(FLAGS.output) as f: solutions = json.load(f) del solutions[1:] first_solution = solutions[0] for seed in problem['sourceSeeds']: if seed != first_solution['seed']: solutions.append({'problemId': problem['id'], 'seed': seed, 'tag': 'empty', 'solution': ''}) assert len(solutions) == len(problem['sourceSeeds']) full_sequence = first_solution['solution'] good = FLAGS.good if FLAGS.good is not None else 0 bad = FLAGS.bad if FLAGS.bad is not None else len(full_sequence) while bad - good > 1: middle = (good + bad) / 2 tag = 'bin%d' % middle first_solution['solution'] = full_sequence[:middle] first_solution['tag'] = tag with tempfile.NamedTemporaryFile() as f: json.dump(solutions, f) f.flush() with open(os.devnull, 'w') as devnull: output = subprocess.check_output([FLAGS.scorer, '--problem=%s' % FLAGS.problem, '--output=%s' % f.name], stderr=devnull) scores = map(int, output.split()) expected_score = sum(scores) / len(scores) first_solution['_score'] = expected_score print '======= good=%d, bad=%d, middle=%d, posting following solution:' % (good, bad, middle) json.dump(solutions, sys.stdout) sys.stdout.write('\n') requests.post( 'https://davar.icfpcontest.org/teams/116/solutions', headers={'Content-Type': 'application/json'}, auth=('', '5HCRz0UOZSsseufyW36DvmeWJKUS9mMPf1qXaAuGM9g='), data=json.dumps(solutions)) while True: try: content = requests.get('https://davar.icfpcontest.org/rankings.js').content leaderboard = json.loads(content.split(' = ', 1)[1]) except Exception: logging.exception('Uncaught exception') else: got_score = None for setting in leaderboard['data']['settings']: if setting['setting'] == problem['id']: for team in setting['rankings']: if team['teamId'] == 116: if tag in team['tags']: got_score = team['score'] if got_score is not None: if got_score == expected_score: good = middle else: bad = middle break time.sleep(60) print 'expected %d, got %d' % (expected_score, got_score) print '*** good=%d, bad=%d' % (good, bad)
def main(argv): logging_util.setup() solver_path = argv[1] solver_extra_args = argv[2:] solver_args = [solver_path] for p in FLAGS.powerphrase: solver_args.extend(['-p', p]) solver_args.extend(solver_extra_args) if FLAGS.cores: logging.warning('Ignoring CPU cores specified by -c') if FLAGS.timelimit: logging.warning('Ignoring time limit specified by -t') if FLAGS.memlimit: logging.warning('Ignoring memory limit specified by -m') tasks = supervisor_util.load_tasks(FLAGS.problem) solutions = [] for task in tasks: job = supervisor_util.SolverJob(solver_args, task) job.start() job.wait() solutions.append(job.solution) json.dump(solutions, sys.stdout) if FLAGS.show_scores: supervisor_util.show_scores(solutions) if FLAGS.report: supervisor_util.report_to_log_server(solutions)
def main(unused_argv): logging_util.setup() # Set defaults. if FLAGS.cores == 0: FLAGS.cores = supervisor_util.get_cores() if FLAGS.timelimit == 0: FLAGS.timelimit = 24 * 60 * 60 if FLAGS.memlimit == 0: FLAGS.memlimit = supervisor_util.get_free_memory() - 64 if not FLAGS.powerphrase: with open(os.path.join(os.path.dirname(__file__), '..', 'power_phrases.txt')) as f: FLAGS.powerphrase = f.read().splitlines() logging.info( 'Limits: %d cores, %d seconds, %d megabytes', FLAGS.cores, FLAGS.timelimit, FLAGS.memlimit) tasks = supervisor_util.load_tasks(FLAGS.problem) logging.info( 'Input: %d problems, %d tasks', len(FLAGS.problem), len(tasks)) num_threads = FLAGS.cores * 2 deadline = g_start_time + FLAGS.timelimit - 1 # Impose memory limit with cgroup. if not FLAGS.disable_cgroup: solver_memlimit = max(1, FLAGS.memlimit - 128) cgroup_memlimit_path = ( '/sys/fs/cgroup/memory/%s/memory.limit_in_bytes' % CGROUP_NAME) try: with open(cgroup_memlimit_path, 'w') as f: f.write(str(solver_memlimit * 1024 * 1024)) except Exception: logging.exception( 'Failed to set cgroup limit. Maybe you have not run "make"? ' 'If you want to run without cgroup, specify --disable_cgroup.') solutions = solve_tasks(tasks, num_threads, deadline) output_solutions = solutions if FLAGS.strip_extra_fields: output_solutions = copy.deepcopy(output_solutions) for solution in output_solutions: for key in solution.keys(): if key.startswith('_'): del solution[key] json.dump(output_solutions, sys.stdout) sys.stdout.flush() if FLAGS.show_scores: supervisor_util.show_scores(solutions) if FLAGS.report: supervisor_util.report_to_log_server(solutions, override_tag=FLAGS.report_tag)
def main(unused_argv): logging_util.setup() db = pymongo.MongoClient().natsubate db.leaderboard.ensure_index([('time', pymongo.ASCENDING)]) while True: try: content = requests.get('https://davar.icfpcontest.org/rankings.js').content ranking = json.loads(content.split(' = ', 1)[1]) db.leaderboard.update({'time': ranking['time']}, ranking, upsert=True) logging.info('%s', ranking['time']) except Exception: logging.exception('Uncaught exception') time.sleep(60)
def main(unused_argv): logging_util.setup() db = pymongo.MongoClient().natsubate init_problems(db) ensure_index(db) while True: solution = db.solutions.find_one({"_processed": None}) if not solution: solution = db.solutions.find_one({"_processed": {"$lt": PROCESSOR_VERSION}}) if not solution: time.sleep(3) continue try: process_solution(db, solution) except Exception: logging.exception("An unexpected exception during processing: %r" % solution) db.solutions.update({"_id": solution["_id"]}, {"$set": {"_processed": PROCESSOR_VERSION}})
def main(unused_argv): logging_util.setup() subprocess.check_call(['mkdir', '-p', FLAGS.output_dir]) best_solutions = requests.get( 'http://dashboard.natsubate.nya3.jp/state-of-the-art.json').json() all_solutions = requests.get( 'http://dashboard.natsubate.nya3.jp/all-solutions.json').json() best_solution_map = {} for solution in best_solutions: best_solution_map[(solution['problemId'], solution['seed'])] = solution interesting_solutions = [] good_solution_map = {} for solution in all_solutions: if solution['problemId'] in (24, 178116): continue if solution['tag'] == 'rewrakkuma': continue if solution['tag'] == 'handplay_viz': interesting_solutions.append(solution) continue key = (solution['problemId'], solution['seed'], solution['tag']) if (key not in good_solution_map or solution['_score'] > good_solution_map[key]['_score']): good_solution_map[key] = solution interesting_solutions.extend(good_solution_map.values()) for solution in interesting_solutions: solution['_target_score'] = best_solution_map[ (solution['problemId'], solution['seed'])]['_score'] for i, solution in enumerate(interesting_solutions): json_path = os.path.join(FLAGS.output_dir, '%08d.json' % i) with open(json_path, 'w') as f: json.dump([solution], f) print 'saved', json_path