def test_run_local_web_server_for_auth(self): """Test whether or not to run the local web server for authentication.""" FLAGS.unparse_flags() self.assertFalse(auth._run_local_web_server_for_auth()) flags.FLAGS(sys.argv[:1] + ['--automatic_oauth']) FLAGS.mark_as_parsed() self.assertTrue(auth._run_local_web_server_for_auth())
def start(self): # importing here to lazy-load from pysc2.env import sc2_env # fail-safe if executed not as absl app if not flags.FLAGS.is_parsed(): flags.FLAGS([""]) # flags.FLAGS(sys.argv) sc2_envs = [] for i in range(self.batch_size): env = msg_multiproc.BaesSC2Env( map_name=self.id, render=self.render, reset_done=self.reset_done, max_ep_len=self.max_ep_len, screen_dim=self._screen_dim, minimap_dim=self._minimap_dim, step_mul=self.step_mul, ) sc2_envs.append(env) sc2_multiproc_env = msg_multiproc.MsgMultiProcEnv(sc2_envs) self._env = sc2_multiproc_env self._env.start()
def test_remove_creds(self): """Test whether or not to remove the local credentials.""" FLAGS.unparse_flags() self.assertFalse(auth._remove_creds()) flags.FLAGS(sys.argv[:1] + ['--remove_creds']) FLAGS.mark_as_parsed() self.assertTrue(auth._remove_creds())
def get_tempdir(self, name: Optional[str] = None) -> str: try: flags.FLAGS.test_tmpdir except flags.UnparsedFlagAccessError: # Need to initialize flags when running `pytest`. flags.FLAGS(sys.argv) return self.create_tempdir(name).full_path
def setup(self, path_to_conf_file): """Setup phase. Invoked by the scenario runner.""" flags.FLAGS([__file__, '--flagfile={}'.format(path_to_conf_file)]) self._logger = erdos.utils.setup_logging('erdos_agent', FLAGS.log_file_name) enable_logging() self.track = get_track() self._camera_setups = create_camera_setups(self.track) # Set the lidar in the same position as the center camera. self._lidar_transform = pylot.utils.Transform(CENTER_CAMERA_LOCATION, pylot.utils.Rotation()) self._lidar_setup = LidarSetup('lidar', 'sensor.lidar.ray_cast', self._lidar_transform) # Stores the waypoints we get from the challenge planner. self._waypoints = None # Stores the open drive string we get when we run in track 3. self._open_drive_data = None (camera_streams, can_bus_stream, global_trajectory_stream, open_drive_stream, point_cloud_stream, control_stream) = create_data_flow() self._camera_streams = camera_streams self._can_bus_stream = can_bus_stream self._global_trajectory_stream = global_trajectory_stream self._open_drive_stream = open_drive_stream self._sent_open_drive = False self._point_cloud_stream = point_cloud_stream self._control_stream = control_stream # Execute the data-flow. erdos.run_async()
def test_random_search_smoke_test(): with tempfile.TemporaryDirectory() as tmp: outdir = Path(tmp) flags.FLAGS.unparse_flags() flags.FLAGS(["argv0"]) random_search( make_env=make_env, outdir=outdir, patience=50, total_runtime=3, nproc=1, skip_done=False, ) assert (outdir / "random_search.json").is_file() assert (outdir / "random_search_progress.csv").is_file() assert (outdir / "random_search_best_actions.txt").is_file() assert (outdir / "optimized.bc").is_file() env = make_env() try: replay_actions_from_logs(env, Path(outdir)) assert (outdir / "random_search_best_actions_progress.csv").is_file() assert (outdir / "random_search_best_actions_commandline.txt").is_file() finally: env.close()
def setUp(self): temp_dir = self.get_temp_dir() if TransformerTaskTest.local_flags is None: misc.define_transformer_flags() # Loads flags, array cannot be blank. flags.FLAGS(['foo']) TransformerTaskTest.local_flags = flagsaver.save_flag_values() else: flagsaver.restore_flag_values(TransformerTaskTest.local_flags) FLAGS.model_dir = os.path.join(temp_dir, FIXED_TIMESTAMP) FLAGS.param_set = 'tiny' FLAGS.use_synthetic_data = True FLAGS.steps_between_evals = 1 FLAGS.train_steps = 2 FLAGS.validation_steps = 1 FLAGS.batch_size = 8 FLAGS.max_length = 1 FLAGS.num_gpus = 1 FLAGS.distribution_strategy = 'off' FLAGS.dtype = 'fp32' self.model_dir = FLAGS.model_dir self.temp_dir = temp_dir self.vocab_file = os.path.join(temp_dir, 'vocab') self.vocab_size = misc.get_model_params(FLAGS.param_set, 0)['vocab_size'] self.bleu_source = os.path.join(temp_dir, 'bleu_source') self.bleu_ref = os.path.join(temp_dir, 'bleu_ref') self.orig_policy = ( tf.compat.v2.keras.mixed_precision.experimental.global_policy())
def test_main(self): flags.FLAGS(['test', '--a', '2', '--b', '3' ]) self.assertEqual('Hello from Python! 2+3=5', generate_greeting())
def setup(self, path_to_conf_file): """Setup phase. Invoked by the scenario runner.""" # Disable Tensorflow logging. pylot.utils.set_tf_loglevel(logging.ERROR) # Parse the flag file. Users can use the different flags defined # across the Pylot directory. flags.FLAGS([__file__, '--flagfile={}'.format(path_to_conf_file)]) self.logger = erdos.utils.setup_logging('erdos_agent', FLAGS.log_file_name) self.csv_logger = erdos.utils.setup_csv_logging( 'erdos_agent_csv', FLAGS.csv_log_file_name) enable_logging() self.track = get_track() # Town name is only used when the agent is directly receiving # traffic lights from the simulator. self._town_name = None # Stores a simulator handle to the ego vehicle. This handle is only # used when the agent is using a perfect localization or perception. self._ego_vehicle = None # Stores ego-vehicle's yaw from last game time. This is used in the # naive localization solution. self._last_yaw = 0 # Stores the point cloud from the previous sensor reading. self._last_point_cloud = None if using_perfect_component(): from pylot.simulation.utils import get_world # The agent is using a perfect component. It must directly connect # to the simulator to send perfect data to the data-flow. _, self._world = get_world(FLAGS.simulator_host, FLAGS.simulator_port, FLAGS.simulator_timeout)
def __init__(self, context: Optional[Context] = None): """Constructs a beam based executor.""" super().__init__(context) self._beam_pipeline_args = None if context: if isinstance(context, BaseBeamExecutor.Context): self._beam_pipeline_args = context.beam_pipeline_args else: raise ValueError( 'BaseBeamExecutor found initialized with ' 'BaseExecutorSpec. Please use BeamEecutorSpec for ' 'Beam Components instead.') if self._beam_pipeline_args: self._beam_pipeline_args = dependency_utils.make_beam_dependency_flags( self._beam_pipeline_args) executor_class_path = '%s.%s' % (self.__class__.__module__, self.__class__.__name__) # TODO(zhitaoli): Rethink how we can add labels and only normalize them # if the job is submitted against GCP. with telemetry_utils.scoped_labels( {telemetry_utils.LABEL_TFX_EXECUTOR: executor_class_path}): self._beam_pipeline_args.extend( telemetry_utils.make_beam_labels_args()) # TODO(b/174174381): Don't use beam_pipeline_args to set ABSL flags. flags.FLAGS(sys.argv + self._beam_pipeline_args, known_only=True)
def get_wsgi_app(): FLAGS.set_default('server_type', 'external') FLAGS.set_default('demo_mode', True) # Parse flags without calling app.run(main), to avoid conflict with # gunicorn command line flags. unused = flags.FLAGS(sys.argv, known_only=True) return main(unused)
def test_frozen(self): flags.FLAGS([ 'keras_to_pb.py', '-i=%s' % self.model, '-o=%s' % self.output, '--frozen' ]) self.k2p._main(None)
def test_run_action_sensitivity_analysis(): actions = [0, 1] env = "llvm-v0" reward = "IrInstructionCountO3" benchmark = "cBench-v0/crc32" flags.FLAGS.unparse_flags() flags.FLAGS(["argv0", f"--env={env}", f"--benchmark={benchmark}"]) with tempfile.TemporaryDirectory() as tmp: tmp = Path(tmp) run_action_sensitivity_analysis( actions=actions, rewards_path=tmp / "rewards.txt", runtimes_path=tmp / "runtimes.txt", reward_space=reward, num_trials=2, max_warmup_steps=5, nproc=1, ) assert (tmp / "rewards.txt").is_file() assert (tmp / "runtimes.txt").is_file() run_sensitivity_analysis_eval( rewards_path=tmp / "rewards.txt", runtimes_path=tmp / "runtimes.txt", )
def setup(self, path_to_conf_file): """Setup phase code. Invoked by the scenario runner. """ # Disable Tensorflow logging. pylot.utils.set_tf_loglevel(logging.ERROR) flags.FLAGS([__file__, '--flagfile={}'.format(path_to_conf_file)]) self._logger = erdos.utils.setup_logging('erdos_agent', FLAGS.log_file_name) enable_logging() self.track = Track.SCENE_LAYOUT # Stores the waypoints we get from the challenge planner. self._waypoints = None (pose_stream, global_trajectory_stream, ground_obstacles_stream, traffic_lights_stream, lanes_stream, open_drive_stream, control_stream) = create_data_flow() self._pose_stream = pose_stream self._global_trajectory_stream = global_trajectory_stream self._ground_obstacles_stream = ground_obstacles_stream self._traffic_lights_stream = traffic_lights_stream self._open_drive_stream = open_drive_stream self._sent_open_drive = False self._control_stream = control_stream # These are used for the timestamp hack. self._past_timestamp = None self._past_control_message = None # Execute the data-flow. erdos.run_async()
def get_tempdir(self): try: flags.FLAGS.test_tmpdir except flags.UnparsedFlagAccessError: # Need to initialize flags when running `pytest`. flags.FLAGS(sys.argv) return self.create_tempdir().full_path
def setUp(self): super(EstimatorDistributedTrainingTest, self).setUp() flags.FLAGS(sys.argv) # Setup and cleanup test directory. self.test_subdirectory = os.path.join(flags.FLAGS.test_tmpdir, self.id()) shutil.rmtree(self.test_subdirectory, ignore_errors=True) os.makedirs(self.test_subdirectory)
def test_print_service_capabilities_smoke_test(env_name: str): flags.FLAGS(["argv0"]) try: with gym.make(env_name) as env: print_service_capabilities(env) except EnvironmentNotSupported: pass # Environment not supported on this test platform.
def __init__(self, context: Optional[Context] = None): """Constructs a beam based executor.""" self._context = context self._beam_pipeline_args = context.beam_pipeline_args if context else None if self._beam_pipeline_args: if beam: self._beam_pipeline_args = dependency_utils.make_beam_dependency_flags( self._beam_pipeline_args) executor_class_path = '%s.%s' % (self.__class__.__module__, self.__class__.__name__) # TODO(zhitaoli): Rethink how we can add labels and only normalize them # if the job is submitted against GCP. with telemetry_utils.scoped_labels( {telemetry_utils.LABEL_TFX_EXECUTOR: executor_class_path}): self._beam_pipeline_args.extend( telemetry_utils.make_beam_labels_args()) # TODO(b/174174381): Don't use beam_pipeline_args to set ABSL flags. flags.FLAGS(sys.argv + self._beam_pipeline_args, known_only=True) else: # TODO(b/156000550): We should not specialize `Context` to embed beam # pipeline args. Instead, the `Context` should consists of generic # purpose `extra_flags` which can be interpreted differently by # different implementations of executors. absl.logging.warning( 'Executor context\'s beam_pipeline_args is being ignored because ' 'Apache Beam is not installed.')
def test_conversion(self): command = self.default.copy() command.extend(["--net=%s"%path.join("tests", "dlconvert", "data","pytorch_model.py"), "--net_name=Net", "--input_shape=1,3,224,224"]) flags.FLAGS(command) self.p2k._main(None)
def __init__(self, agent_interface, env_kwargs): flags.FLAGS(sys.argv) self.env = sc2_env.SC2Env(**env_kwargs) self.render = env_kwargs['visualize'] self.agent_interface = agent_interface self.done = False self.timestep = None self.timestep_index = 0
def get_wsgi_app(): """Returns a LitApp instance for consumption by gunicorn.""" FLAGS.set_default("server_type", "external") FLAGS.set_default("demo_mode", True) # Parse flags without calling app.run(main), to avoid conflict with # gunicorn command line flags. unused = flags.FLAGS(sys.argv, known_only=True) return main(unused)
def get_wsgi_app(): FLAGS.set_default("server_type", "external") FLAGS.set_default("data_dir", "./t5_data/") FLAGS.set_default("initialize_index", False) # Parse flags without calling app.run(main), to avoid conflict with # gunicorn command line flags. unused = flags.FLAGS(sys.argv, known_only=True) return main(unused)
def test_run_random_walk_smoke_test(): flags.FLAGS(["argv0"]) env = gym.make("llvm-autophase-ic-v0") env.benchmark = "cBench-v0/crc32" try: run_random_walk(env=env, step_count=5) finally: env.close()
def test_conversion(self): flags.FLAGS([ 'pb_to_onnx.py', '-i=%s' % self.model, '-o=%s' % self.output, "--input_nodes=input:0", "--output_nodes=output/Softmax:0" ]) self.p2o._main(None)
def start(name, args): import sys from absl import flags flags.FLAGS(sys.argv[:1]) experiment_class = Experiment.experiments[name] logging.warning("Experiment %s running ...", name) experiment_class().run(args) logging.warning("Experiment %s end.", name)
def main_fun(argv, ctx): tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.INFO) define_cifar_flags() flags.FLAGS(argv) print("====== FLAGS: {}".format(flags.FLAGS)) with logger.benchmark_context(flags.FLAGS): return run(flags.FLAGS)
def test_GetInstanceConfigs_working_dir(): """Check the working directory of instance configs.""" with tempfile.TemporaryDirectory() as working_dir: flags.FLAGS(['argv[0]', '--working_dir', working_dir]) assert FLAGS.working_dir == working_dir configs = get_instances.GetInstanceConfigs() for instance in configs.instance: assert instance.working_dir == working_dir
def main_fun(argv, ctx): sys.argv = argv define_census_flags() flags.FLAGS(sys.argv) tf.logging.set_verbosity(tf.logging.INFO) with logger.benchmark_context(flags.FLAGS): run_census(flags.FLAGS, ctx)
def setUp(self): super(AutoEnsembleEstimatorV2Test, self).setUp() # Setup and cleanup test directory. # Flags are not automatically parsed at this point. flags.FLAGS(sys.argv) self.test_subdirectory = os.path.join(flags.FLAGS.test_tmpdir, self.id()) shutil.rmtree(self.test_subdirectory, ignore_errors=True) os.makedirs(self.test_subdirectory)
def get_wsgi_app(): """Return WSGI app for container-hosted demos.""" FLAGS.set_default("server_type", "external") FLAGS.set_default("demo_mode", True) # Parse flags without calling app.run(main), to avoid conflict with # gunicorn command line flags. unused = flags.FLAGS(sys.argv, known_only=True) return main(unused)