from __future__ import division from __future__ import print_function import itertools import six from pysc2 import maps from pysc2 import run_configs from pysc2.lib import app import gflags as flags from s2clientprotocol import data_pb2 as sc_data from s2clientprotocol import sc2api_pb2 as sc_pb flags.DEFINE_enum("command", None, ["csv", "python"], "What to generate.") flags.mark_flag_as_required("command") FLAGS = flags.FLAGS def get_data(): run_config = run_configs.get() with run_config.start() as controller: m = maps.get("Sequencer") # Arbitrary ladder map. create = sc_pb.RequestCreateGame(local_map=sc_pb.LocalMap( map_path=m.path, map_data=run_config.map_data(m.path))) create.player_setup.add(type=sc_pb.Participant) create.player_setup.add(type=sc_pb.Computer, race=sc_pb.Random, difficulty=sc_pb.VeryEasy) join = sc_pb.RequestJoinGame(race=sc_pb.Random,
# Format: flags.DEFINE_<type>(flag_name, default_value, help_text) # Example: # https://github.com/google/python-gflags/blob/master/examples/validator.py flags.DEFINE_string('rules', None, ('Path to rules file (yaml/json). ' 'If GCS bucket, include full path, e.g. ' ' "gs://<bucketname>/path/to/file".')) flags.DEFINE_string('output_path', None, ('Output path (do not include filename). If GCS location, ' 'the format of the path should be ' '"gs://bucket-name/path/for/output".')) flags.DEFINE_string('organization_id', None, 'Organization id') flags.mark_flag_as_required('rules') flags.mark_flag_as_required('organization_id') def main(_): """Run the scanner.""" logger = LogUtil.setup_logging(__name__) file_path = FLAGS.rules output_path = FLAGS.output_path logger.info(('Initializing the rules engine: ' '\n rules: {}').format(file_path)) rules_engine = OrgRulesEngine(rules_file_path=file_path) rules_engine.build_rule_book()
flags.DEFINE_integer("step_mul", 8, "Game steps per agent step.") flags.DEFINE_string("agent", "pysc2.agents.a3cAgent.py", "Which agent to run") flags.DEFINE_enum("agent_race", None, sc2_env.races.keys(), "Agent's race.") flags.DEFINE_enum("bot_race", None, sc2_env.races.keys(), "Bot's race.") flags.DEFINE_enum("difficulty", None, sc2_env.difficulties.keys(), "Bot's strength.") flags.DEFINE_bool("profile", False, "Whether to turn on code profiling.") flags.DEFINE_bool("trace", False, "Whether to trace the code execution.") flags.DEFINE_integer("parallel", 1, "How many instances to run in parallel.") flags.DEFINE_bool("save_replay", True, "Whether to save a replay at the end.") flags.DEFINE_string("map", None, "Name of a map to use.") flags.mark_flag_as_required("map") # Define hyperparameters and constants s_size = 7056 # Observations are greyscale frames of 84 * 84 * 1 # sc2 api agent defaults to do 2500 steps before quitting max_episode_length = 2500 gamma = .99 # discount rate for advantage estimation and reward discounting a_size = 3 # Agent can do NO_OP, MOVE_SCREEN, or SELECT_ARMY # If you want to import a pretrained model or pick up where you left off, set load_model to true # and model_path to the location load_model = False model_path = './model'
test_loss_opt, test_loss_final = eval.eval_model( sess, nnms_model, frames_data_test, global_step=step_id, n_eval_frames=config.n_eval_frames, out_dir=test_out_dir, full_eval=full_eval, nms_thres=config.nms_thres, one_class=is_one_class, class_ix=class_ix) write_scalar_summary(test_loss_opt, 'test_loss_opt', summary_writer, step_id) config.update_results(step_id, train_loss_opt, train_loss_final, test_loss_opt, test_loss_final, np.mean(step_times)) config.save_results() saver.save(sess, config.model_file, global_step=step_id) logging.info('all done.') return if __name__ == '__main__': gflags.mark_flag_as_required('data_dir') gflags.mark_flag_as_required('log_dir') gflags.mark_flag_as_required('config_path') app.run()
from pysc2 import run_configs from pysc2.lib import features from pysc2.lib import point from pysc2.lib import protocol from pysc2.lib import remote_controller from pysc2.lib import app import gflags as flags from pysc2.lib import gfile from s2clientprotocol import sc2api_pb2 as sc_pb FLAGS = flags.FLAGS flags.DEFINE_integer("parallel", 1, "How many instances to run in parallel.") flags.DEFINE_integer("step_mul", 8, "How many game steps per observation.") flags.DEFINE_string("replays", None, "Path to a directory of replays.") flags.mark_flag_as_required("replays") size = point.Point(16, 16) interface = sc_pb.InterfaceOptions( raw=True, score=False, feature_layer=sc_pb.SpatialCameraSetup(width=24)) size.assign_to(interface.feature_layer.resolution) size.assign_to(interface.feature_layer.minimap_resolution) def sorted_dict_str(d): return "{%s}" % ", ".join("%s: %s" % (k, d[k]) for k in sorted(d, key=d.get, reverse=True)) class ReplayStats(object): """Summary stats of the replays seen so far."""
from pysc2 import run_configs from pysc2.lib import features from pysc2.lib import point from pysc2.lib import protocol from pysc2.lib import remote_controller from pysc2.lib import app import gflags as flags from pysc2.lib import gfile from s2clientprotocol import sc2api_pb2 as sc_pb FLAGS = flags.FLAGS flags.DEFINE_integer("parallel", 1, "How many instances to run in parallel.") flags.DEFINE_integer("step_mul", 8, "How many game steps per observation.") flags.DEFINE_string("replays", None, "Path to a directory of replays.") flags.mark_flag_as_required("replays") size = point.Point(16, 16) interface = sc_pb.InterfaceOptions( raw=True, score=False, feature_layer=sc_pb.SpatialCameraSetup(width=24)) size.assign_to(interface.feature_layer.resolution) size.assign_to(interface.feature_layer.minimap_resolution) def sorted_dict_str(d): return "{%s}" % ", ".join("%s: %s" % (k, d[k]) for k in sorted(d, key=d.get, reverse=True))
#!/usr/bin/env python from pysc2.lib import app, features, point from pysc2.env.environment import TimeStep, StepType from pysc2 import run_configs from s2clientprotocol import sc2api_pb2 as sc_pb import gflags as flags import importlib FLAGS = flags.FLAGS flags.DEFINE_string("replay", None, "Path to a replay file.") flags.DEFINE_string("agent", None, "Path to an agent.") flags.mark_flag_as_required("replay") flags.mark_flag_as_required("agent") class ReplayEnv: def __init__(self, replay_file_path, agent, player_id=1, screen_size_px=(64, 64), minimap_size_px=(64, 64), discount=1., step_mul=1): self.agent = agent self.discount = discount self.step_mul = step_mul self.run_config = run_configs.get()
flags.DEFINE_string("agent", "pysc2.agents.random_agent.RandomAgent", "Which agent to run") flags.DEFINE_enum("agent_race", None, sc2_env.races.keys(), "Agent's race.") flags.DEFINE_enum("bot_race", None, sc2_env.races.keys(), "Bot's race.") flags.DEFINE_enum("difficulty", None, sc2_env.difficulties.keys(), "Bot's strength.") flags.DEFINE_bool("profile", False, "Whether to turn on code profiling.") flags.DEFINE_bool("trace", False, "Whether to trace the code execution.") flags.DEFINE_integer("parallel", 1, "How many instances to run in parallel.") flags.DEFINE_bool("save_replay", True, "Whether to save a replay at the end.") flags.DEFINE_string("map", None, "Name of a map to use.") flags.mark_flag_as_required("map") def run_thread(agent_cls, map_name, visualize): with sc2_env.SC2Env( map_name, agent_race=FLAGS.agent_race, bot_race=FLAGS.bot_race, difficulty=FLAGS.difficulty, step_mul=FLAGS.step_mul, game_steps_per_episode=FLAGS.game_steps_per_episode, screen_size_px=(FLAGS.screen_resolution, FLAGS.screen_resolution), minimap_size_px=(FLAGS.minimap_resolution, FLAGS.minimap_resolution), visualize=visualize) as env: env = available_actions_printer.AvailableActionsPrinter(env) agent = agent_cls()
from google.cloud.security.common.util.errors import EmailSendError from google.cloud.security.common.util.log_util import LogUtil from google.cloud.security.common.util import retryable_exceptions FLAGS = flags.FLAGS flags.DEFINE_string('email_recipient', None, 'Email address of the notification recipient.') flags.DEFINE_string('email_sender', None, 'Email address of the notification sender.') flags.DEFINE_string('sendgrid_api_key', None, 'API key to authenticate with SendGrid email service.') flags.mark_flag_as_required('email_recipient') flags.mark_flag_as_required('email_sender') flags.mark_flag_as_required('sendgrid_api_key') class EmailUtil(object): """Utility for sending emails.""" def __init__(self, api_key): """Initialize the email util. Args: api_key: String of the sendgrid api key to auth email service. """ self.logger = LogUtil.setup_logging(__name__) self.sendgrid = sendgrid.SendGridAPIClient(apikey=api_key)
""" import unicodedata import gflags as flags from google.apputils import app FLAGS = flags.FLAGS flags.DEFINE_string('nam_file', None, 'Location of nam file') def main(_): with open(FLAGS.nam_file, 'r') as f: for line in f: print _ReformatLine(line) def _ReformatLine(line): if line.startswith('0x'): codepoint = int(line[2:6], 16) out = unichr(codepoint) + ' ' + unicodedata.name(unichr(codepoint), '') return '0x%04X %s' % (codepoint, out) else: return line if __name__ == '__main__': flags.mark_flag_as_required('nam_file') app.run()