コード例 #1
0
def test_Model_metafile(clgen_cache_dir, abc_model_config):
    """A newly instantiated model's cache has a metafile."""
    del clgen_cache_dir
    m = models.Model(abc_model_config)
    assert (m.cache.path / 'META.pbtxt').is_file()
    assert pbutil.ProtoIsReadable(m.cache.path / 'META.pbtxt',
                                  internal_pb2.ModelMeta())
コード例 #2
0
def GeneratorFromFlag(config_class,
                      generator_class) -> base_generator.GeneratorServiceBase:
    """Instantiate a generator from the --generator_config flag."""
    if not pbutil.ProtoIsReadable(FLAGS.generator_config, config_class()):
        raise app.UsageError(
            f'--generator_config is not a {config_class.__name__} proto')
    config = pbutil.FromFile(pathlib.Path(FLAGS.generator_config),
                             config_class())
    return generator_class(config)
コード例 #3
0
ファイル: dpack.py プロジェクト: BeauJoh/phd
def InitManifest(package_dir: pathlib.Path,
                 contents: typing.List[pathlib.Path], update: bool) -> None:
    """Write the MANIFEST.pbtxt file for a package."""
    manifest = CreatePackageManifest(package_dir, contents)
    manifest_path = package_dir / 'MANIFEST.pbtxt'
    if update and pbutil.ProtoIsReadable(manifest_path,
                                         dpack_pb2.DataPackage()):
        old = pbutil.FromFile(manifest_path, dpack_pb2.DataPackage())
        MergeManifests(manifest, old)
    elif manifest_path.is_file():
        raise OSError('Refusing to overwrite MANIFEST.pbtxt file.')
    pbutil.ToFile(manifest, manifest_path)
    logging.info('Wrote %s', manifest_path.absolute())
コード例 #4
0
def main(argv):
    """Main entry point."""
    if len(argv) > 1:
        raise app.UsageError("Unknown arguments: '{}'.".format(' '.join(
            argv[1:])))

    config = pathlib.Path(FLAGS.generator)
    if not pbutil.ProtoIsReadable(config, generator_pb2.ClgenGenerator()):
        raise app.UsageError(
            '--generator is not a deepsmith.ClgenGenerator proto')
    generator_config = pbutil.FromFile(config, generator_pb2.ClgenGenerator())
    output_directory = pathlib.Path(FLAGS.output_directory)
    GenerateTestcases(generator_config, output_directory, FLAGS.num_testcases)
コード例 #5
0
ファイル: ls_models.py プロジェクト: BeauJoh/phd
def LsModels(cache_root: pathlib.Path) -> None:
    for model_dir in (cache_root / 'model').iterdir():
        meta_file = model_dir / 'META.pbtxt'
        if pbutil.ProtoIsReadable(meta_file, internal_pb2.ModelMeta()):
            model = models.Model(
                pbutil.FromFile(meta_file, internal_pb2.ModelMeta()).config)
            telemetry = list(model.TrainingTelemetry())
            num_epochs = model.config.training.num_epochs
            n = len(telemetry)
            print(f'{model_dir} {n} / {num_epochs} epochs')
        elif meta_file.is_file():
            logging.warning('Meta file %s cannot be read.', meta_file)
        else:
            logging.warning('Meta file %s not found.', meta_file)
コード例 #6
0
def ShouldImportRepo(session: orm.session.Session,
                     metafile: pathlib.Path) -> bool:
    """Determine if the repository described by a metafile should be imported.

  A repository should be imported iff:
    * The metafile is a valid GitHubRepoMetadata proto.
    * The clone directory specified in the metafile appears to be a github repo.
    * The repo does not exist in the contentfiles database.
  """
    if not (metafile.is_file() and pbutil.ProtoIsReadable(
            metafile, scrape_repos_pb2.GitHubRepoMetadata())):
        return False
    meta = pbutil.FromFile(metafile, scrape_repos_pb2.GitHubRepoMetadata())
    clone_dir = metafile.parent / f'{meta.owner}_{meta.name}'
    if not (clone_dir / '.git').is_dir():
        return False
    return not contentfiles.GitHubRepository.IsInDatabase(session, meta)
コード例 #7
0
ファイル: scraper.py プロジェクト: BeauJoh/phd
  def MakeRepositoryMetas(self,
                          repos: typing.List[Repository.Repository]) -> None:
    """Make meta files for a list of repositories.

    Args:
      repos: A list of GitHub Repository instances.
    """
    logging.debug('Scraping %s repositories', humanize.intcomma(len(repos)))
    for repo in repos:
      self.i += 1
      concat_name = '_'.join([repo.owner.login, repo.name])
      clone_dir = self.destination_directory / concat_name
      meta_path = pathlib.Path(str(clone_dir) + '.pbtxt')
      if not pbutil.ProtoIsReadable(meta_path,
                                    scrape_repos_pb2.GitHubRepoMetadata()):
        meta = GetRepositoryMetadata(repo)
        logging.debug('%s', meta)
        pbutil.ToFile(meta, meta_path)
コード例 #8
0
ファイル: opencl_fuzz.py プロジェクト: 50417/phd
def ResultProtoFromFlag(flag: typing.Optional[str]) -> deepsmith_pb2.Result:
    """Read a result proto from a --flag path.

  Args:
    flag: The value of the flag which points to a result proto.

  Returns:
    The Result proto.

  Raises:
    UsageError: If the flag is not set or the flag does not point to a Result
      proto.
  """
    if not flag:
        raise app.UsageError('Path is not set.')
    path = pathlib.Path(flag)
    if not path.is_file():
        raise app.UsageError(f"File not found: '{path}'.")
    if not pbutil.ProtoIsReadable(path, deepsmith_pb2.Result()):
        raise app.UsageError(f"Cannot read Result proto: '{path}'.")
    return pbutil.FromFile(path, deepsmith_pb2.Result())
コード例 #9
0
ファイル: dpack.py プロジェクト: BeauJoh/phd
def _IsManifest(path: pathlib.Path) -> bool:
    """Check if a path contains a DataPackafe file."""
    return pbutil.ProtoIsReadable(path, dpack_pb2.DataPackage())
コード例 #10
0
ファイル: cloner.py プロジェクト: BeauJoh/phd
def IsRepoMetaFile(f: str):
    """Determine if a path is a GitHubRepoMetadata message."""
    return (fs.isfile(f) and pbutil.ProtoIsReadable(
        f, scrape_repos_pb2.GitHubRepoMetadata()))
コード例 #11
0
from absl import app
from absl import flags
from absl import logging
from phd.lib.labm8 import pbutil

from system.machines.proto import data_tiers_pb2

FLAGS = flags.FLAGS

flags.DEFINE_string('data_tiers', None,
                    'The path of the directory to package.')
flags.DEFINE_bool('summary', False, 'TODO')

flags.register_validator(
    'data_tiers',
    lambda path: pbutil.ProtoIsReadable(path, data_tiers_pb2.DataTiers()),
    message='--data_tiers must be a DataTiers message.')


def _SetDirectorySize(tier: data_tiers_pb2.Directory):
    path = pathlib.Path(tier.path).expanduser()
    if not path.is_dir():
        logging.warning("Directory '%s' not found", path)
        return

    os.chdir(path)
    excludes = [
        '--exclude={}'.format(pathlib.Path(e).expanduser())
        for e in tier.exclude
    ]
    cmd = ['du', '-b', '-s', '.'] + excludes
コード例 #12
0
ファイル: test_protos_are_valid.py プロジェクト: BeauJoh/phd
def DirContainsProtos(data_path: str, proto_class) -> None:
    """Assert that contains protos of the given class."""
    for path in bazelutil.DataPath(data_path).iterdir():
        assert pbutil.ProtoIsReadable(
            bazelutil.DataPath(data_path) / path, proto_class())
コード例 #13
0
def main(argv):
    """Main entry point."""
    if len(argv) > 1:
        raise app.UsageError('Unrecognized arguments')

    if FLAGS.ls_env:
        env.PrintOpenClEnvironments()
        return

    start_time = time.time()

    if FLAGS.rerun_result:
        result_to_rerun_path = pathlib.Path(FLAGS.rerun_result)
        if not result_to_rerun_path.is_file():
            raise app.UsageError(
                '--rerun_result must be the path of a Result proto.')
        if not pbutil.ProtoIsReadable(result_to_rerun_path,
                                      deepsmith_pb2.Result()):
            raise app.UsageError(
                "Cannot read Result proto: '{result_to_rerun_path}'.")
        result_to_rerun = pbutil.FromFile(result_to_rerun_path,
                                          deepsmith_pb2.Result())
        # harness_class = cldrive.CldriveHarness if result_to_rerun.

    # Parse flags and instantiate testing objects.
    if not FLAGS.interesting_results_dir:
        raise app.UsageError('--interesting_results_dir must be set')
    interesting_results_dir = pathlib.Path(FLAGS.interesting_results_dir)
    if interesting_results_dir.exists(
    ) and not interesting_results_dir.is_dir():
        raise app.UsageError('--interesting_results_dir must be a directory')
    logging.info('Recording interesting results in %s.',
                 interesting_results_dir)

    logging.info('Preparing generator.')
    if FLAGS.generator == 'clgen':
        generator = GeneratorFromFlag(generator_pb2.ClgenGenerator,
                                      clgen_pretrained.ClgenGenerator)
        harness_class = cldrive.CldriveHarness
        config_class = harness_pb2.CldriveHarness
        filters = opencl_filters.ClgenOpenClFilters()
    elif FLAGS.generator == 'clsmith':
        generator = GeneratorFromFlag(generator_pb2.ClsmithGenerator,
                                      clsmith.ClsmithGenerator)
        harness_class = cl_launcher.ClLauncherHarness
        config_class = harness_pb2.ClLauncherHarness
        # TODO(cec): Replace with CLSmith filters.
        filters = difftests.FiltersBase()
    else:
        raise app.UsageError(
            f"Unrecognized value for --generator: '{FLAGS.generator}'")
    logging.info('%s:\n %s', type(generator).__name__, generator.config)

    logging.info('Preparing device under test.')
    config = GetBaseHarnessConfig(config_class)
    config.opencl_env.extend([FLAGS.dut])
    config.opencl_opt.extend([FLAGS.opencl_opt])
    dut_harness = harness_class(config)
    assert len(dut_harness.testbeds) == 1

    logging.info('Preparing gold standard testbed.')
    config = GetBaseHarnessConfig(config_class)
    config.opencl_env.extend(
        [gpu.cldrive.env.OclgrindOpenCLEnvironment().name])
    config.opencl_opt.extend([True])
    gs_harness = harness_class(config)
    assert len(gs_harness.testbeds) >= 1

    TestingLoop(FLAGS.min_interesting_results,
                FLAGS.max_testing_time_seconds,
                FLAGS.batch_size,
                generator,
                dut_harness,
                gs_harness,
                filters,
                interesting_results_dir,
                start_time=start_time)