Skip to content

Commit

Permalink
Merge branch 'vara-dev' into f-FixesPackagingBug
Browse files Browse the repository at this point in the history
  • Loading branch information
vulder authored Sep 22, 2023
2 parents 07c0edb + af451e3 commit 83cac3e
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 27 deletions.
4 changes: 4 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@
# modules that require this module before setting the type checking flag.
import scipy.stats # isort:skip

# Matplotlib >=3.8 has a type-checking-flag-guarded import of a symbol that does
# not exist in the shipped version.
import matplotlib.pyplot # isort:skip

# The autodocs typehints plugin does not resolve circular imports caused by type
# annotations, so we have to manually break the circles.
import rich.console # isort:skip
Expand Down
1 change: 1 addition & 0 deletions docs/source/vara-ts-api/tools/vara-cs-gui.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The gui is started by::

The gui provides 3 Strategies to generate case studies:
- Manual revision selection: Select revision from the revision history of a project. Multiple revisions can be selected by holding `ctrl` and ranges by holding `shift`. Revisions which are blocked because of bugs in the compilation of the project are marked blue.

.. figure:: vara-cs-gui-manual.png

- Random Sampling: Sample a number of revisions using a random a Normal or HalfNormal Distribution.
Expand Down
14 changes: 14 additions & 0 deletions tests/experiment/test_workload_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ def test_workload_commands_tags_selected(self) -> None:
)
self.assertEqual(len(commands), 1)

def test_workload_commands_requires(self) -> None:
revision = Revision(Xz, Variant(Xz.SOURCE[0], "c5c7ceb08a"))
project = Xz(revision=revision)
binary = Xz.binaries_for_revision(ShortCommitHash("c5c7ceb08a"))[0]

commands = wu.workload_commands(
project, binary, [wu.WorkloadCategory.EXAMPLE]
)
self.assertEqual(len(commands), 1)
commands = wu.workload_commands(
project, binary, [wu.WorkloadCategory.MEDIUM]
)
self.assertEqual(len(commands), 1)


class TestWorkloadFilenames(unittest.TestCase):

Expand Down
13 changes: 12 additions & 1 deletion tests/utils/test_git_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import unittest
from pathlib import Path

from benchbuild.utils.revision_ranges import RevisionRange
from benchbuild.utils.revision_ranges import RevisionRange, SingleRevision

from varats.project.project_util import (
get_local_project_git,
Expand Down Expand Up @@ -568,6 +568,17 @@ def test_specification_validity_range_multiple_binaries(self) -> None:
self.assertIn("SingleLocalMultipleRegions", self.rv_map)
self.assertIn("SingleLocalSimple", self.rv_map)

def test_specification_single_revision(self) -> None:
"""Check if we can add binaries that are only valid with a single
revision."""
self.rv_map.specify_binary(
"build/bin/SingleLocalMultipleRegions",
BinaryType.EXECUTABLE,
only_valid_in=SingleRevision("162db88346")
)

self.assertIn("SingleLocalMultipleRegions", self.rv_map)

def test_specification_binaries_with_special_name(self) -> None:
"""Check if we can add binaries that have a special name."""
self.rv_map.specify_binary(
Expand Down
28 changes: 27 additions & 1 deletion varats-core/varats/experiment/workload_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
Command,
)

from varats.experiment.experiment_util import get_extra_config_options
from varats.project.project_util import ProjectBinaryWrapper
from varats.project.varats_project import VProject
from varats.report.report import KeyedReportAggregate, ReportTy
Expand Down Expand Up @@ -92,8 +93,33 @@ def workload_commands(
)
]

# Filter commands that have required args set.
extra_options = set(get_extra_config_options(project))

def requires_any_filter(prj_cmd: ProjectCommand) -> bool:
if hasattr(
prj_cmd.command, "requires_any"
) and prj_cmd.command.requires_any:
args = set(prj_cmd.command._args).union(extra_options)
return bool(args.intersection(prj_cmd.command.requires_any))
return True

def requires_all_filter(prj_cmd: ProjectCommand) -> bool:
if hasattr(
prj_cmd.command, "requires_all"
) and prj_cmd.command.requires_all:
args = set(prj_cmd.command._args).union(extra_options)
return bool(prj_cmd.command.requires_all.issubset(args))
return True

available_cmds = filter(
requires_all_filter, filter(requires_any_filter, project_cmds)
)

return list(
filter(lambda prj_cmd: prj_cmd.path.name == binary.name, project_cmds)
filter(
lambda prj_cmd: prj_cmd.path.name == binary.name, available_cmds
)
)


Expand Down
33 changes: 33 additions & 0 deletions varats-core/varats/project/project_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import benchbuild as bb
import pygit2
from benchbuild.command import Command
from benchbuild.source import Git
from benchbuild.utils.cmd import git
from plumbum import local
Expand Down Expand Up @@ -382,3 +383,35 @@ def copy_renamed_git_to_dest(src_dir: Path, dest_dir: Path) -> None:
for name in dirs:
if name == ".gitted":
os.rename(os.path.join(root, name), os.path.join(root, ".git"))


class VCommand(Command): # type: ignore [misc]
"""
Wrapper around benchbuild's Command class.
Attributes:
requires_any: sufficient args that must be available for successful execution.
requires_all: all args that must be available for successful execution.
"""

_requires: tp.Set[str]

def __init__(
self,
*args: tp.Any,
requires_any: tp.Optional[tp.Set[str]] = None,
requires_all: tp.Optional[tp.Set[str]] = None,
**kwargs: tp.Union[str, tp.List[str]],
) -> None:

super().__init__(*args, **kwargs)
self._requires_any = requires_any if requires_any else set()
self._requires_all = requires_all if requires_all else set()

@property
def requires_any(self) -> tp.Set[str]:
return self._requires_any

@property
def requires_all(self) -> tp.Set[str]:
return self._requires_all
19 changes: 12 additions & 7 deletions varats-core/varats/provider/patch/patch_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from varats.project.project_util import get_local_project_git_path
from varats.provider.provider import Provider, ProviderType
from varats.utils.filesystem_util import lock_file
from varats.utils.git_commands import pull_current_branch, fetch_repository
from varats.utils.git_util import (
CommitHash,
Expand Down Expand Up @@ -237,12 +238,10 @@ class PatchProvider(Provider):
def __init__(self, project: tp.Type[Project]):
super().__init__(project)

# BB only performs a fetch so our repo might be out of date
pull_current_branch(self._get_patches_repository_path())
self._update_local_patches_repo()
repo_path = self._get_patches_repository_path()

patches_project_dir = Path(
self._get_patches_repository_path() / self.project.NAME
)
patches_project_dir = repo_path / self.project.NAME

if not patches_project_dir.is_dir():
warnings.warn(
Expand Down Expand Up @@ -316,6 +315,12 @@ def create_default_provider(

@classmethod
def _get_patches_repository_path(cls) -> Path:
cls.patches_source.fetch()

return Path(target_prefix()) / cls.patches_source.local

@classmethod
def _update_local_patches_repo(cls):
lock_path = Path(target_prefix()) / "patch_provider.lock"

with lock_file(lock_path):
cls.patches_source.fetch()
pull_current_branch(cls._get_patches_repository_path())
16 changes: 15 additions & 1 deletion varats-core/varats/utils/filesystem_util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Utility functions for handling filesystem related tasks."""

import fcntl
import os.path
import typing as tp
from contextlib import contextmanager
from pathlib import Path


Expand All @@ -13,3 +15,15 @@ def __init__(self, folder: tp.Union[Path, str]) -> None:
f"Folder: '{str(folder)}' should be created "
"but was already present."
)


@contextmanager
def lock_file(lock_path: Path, lock_mode: int = fcntl.LOCK_EX) -> tp.Generator:
open_mode = os.O_RDWR | os.O_CREAT | os.O_TRUNC
lock_fd = os.open(lock_path, open_mode)
try:
fcntl.flock(lock_fd, lock_mode)
yield
finally:
fcntl.flock(lock_fd, fcntl.LOCK_UN)
os.close(lock_fd)
10 changes: 5 additions & 5 deletions varats-core/varats/utils/git_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,9 @@ def specify_binary(
override_entry_point = kwargs.get("override_entry_point", None)
if override_entry_point:
override_entry_point = Path(override_entry_point)
validity_range = kwargs.get("only_valid_in", None)
validity_range: AbstractRevisionRange = kwargs.get(
"only_valid_in", None
)
valid_exit_codes = kwargs.get("valid_exit_codes", None)

wrapped_binary = ProjectBinaryWrapper(
Expand All @@ -1072,6 +1074,7 @@ def specify_binary(
)

if validity_range:
validity_range.init_cache(self.__repo_location)
self.__revision_specific_mappings[validity_range].append(
wrapped_binary
)
Expand All @@ -1087,10 +1090,7 @@ def __getitem__(self,

for validity_range, wrapped_binaries \
in self.__revision_specific_mappings.items():
if revision in get_all_revisions_between(
validity_range.id_start, validity_range.id_end, ShortCommitHash,
self.__repo_location
):
if revision in map(ShortCommitHash, validity_range):
revision_specific_binaries.extend(wrapped_binaries)

revision_specific_binaries.extend(self.__always_valid_mappings)
Expand Down
5 changes: 4 additions & 1 deletion varats-core/varats/utils/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,10 @@ def bb_cfg() -> s.Configuration:
bb_cfg_path = Path(bb_root) / ".benchbuild.yml"
if bb_cfg_path.exists():
BB_CFG.load(local.path(bb_cfg_path))
BB_CFG.init_from_env()

# Environment should always override config files
BB_CFG.init_from_env()

_BB_CFG = BB_CFG
create_missing_bb_folders()
return _BB_CFG
Expand Down
12 changes: 7 additions & 5 deletions varats/varats/data/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def gini_coefficient(distribution: pd.Series) -> float:
Calculates the Gini coefficient of the data.
For more information see online
`gini coefficient <https://en.wikipedia.org/wiki/Gini_coefficient>`_.
`Gini coefficient <https://en.wikipedia.org/wiki/Gini_coefficient>`_.
Args:
distribution: sorted series to calculate the Gini coefficient for
Expand Down Expand Up @@ -141,10 +141,12 @@ class ConfusionMatrix(tp.Generic[T]):
"""
Helper class to automatically calculate classification results.
| Predicted Positive (PP) | Predicted Negative (PN)
--------------------|---------------------------|--------------------------
Actual Positive (P) | True Positive (TP) | False Negative (FN)
Actual Negative (N) | False Positive (FP) | True Negative (TN)
+---------------------+-------------------------+-------------------------+
| | Predicted Positive (PP) | Predicted Negative (PN) |
+---------------------+-------------------------+-------------------------+
| Actual Positive (P) | True Positive (TP) | False Negative (FN) |
| Actual Negative (N) | False Positive (FP) | True Negative (TN) |
+---------------------+-------------------------+-------------------------+
Reference: https://en.wikipedia.org/wiki/Precision_and_recall
"""
Expand Down
20 changes: 14 additions & 6 deletions varats/varats/projects/c_projects/xz.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import typing as tp

import benchbuild as bb
from benchbuild.command import Command, SourceRoot, WorkloadSet
from benchbuild.command import SourceRoot, WorkloadSet
from benchbuild.source import HTTPMultiple
from benchbuild.utils.cmd import autoreconf, make
from benchbuild.utils.revision_ranges import (
Expand All @@ -18,6 +18,7 @@
from varats.paper.paper_config import PaperConfigSpecificGit
from varats.project.project_domain import ProjectDomains
from varats.project.project_util import (
VCommand,
ProjectBinaryWrapper,
get_local_project_git_path,
BinaryType,
Expand Down Expand Up @@ -84,26 +85,33 @@ class Xz(VProject):

WORKLOADS = {
WorkloadSet(WorkloadCategory.EXAMPLE): [
Command(
VCommand(
SourceRoot("xz") / RSBinary("xz"),
"-k",
"geo-maps/countries-land-1km.geo.json",
# Use output_param to ensure input file
# gets appended after all arguments.
output_param=["{output}"],
output=SourceRoot("geo-maps/countries-land-250m.geo.json"),
label="countries-land-1km",
creates=["geo-maps/countries-land-1km.geo.json.xz"]
)
],
WorkloadSet(WorkloadCategory.MEDIUM): [
Command(
VCommand(
SourceRoot("xz") / RSBinary("xz"),
"-k",
"-9e",
"--compress",
"--threads=1",
"--format=xz",
"-vv",
"geo-maps/countries-land-250m.geo.json",
# Use output_param to ensure input file
# gets appended after all arguments.
output_param=["{output}"],
output=SourceRoot("geo-maps/countries-land-250m.geo.json"),
label="countries-land-250m",
creates=["geo-maps/countries-land-250m.geo.json.xz"]
creates=["geo-maps/countries-land-250m.geo.json.xz"],
requires_all={"--compress"},
)
],
}
Expand Down

0 comments on commit 83cac3e

Please sign in to comment.