Skip to content

Commit

Permalink
Add CachedRevision.get_relative_exp_path() method. (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
jendrikseipp committed Aug 7, 2023
1 parent 59e319c commit 6650a2d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 27 deletions.
1 change: 1 addition & 0 deletions docs/news.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Lab
^^^
* Require *revision_cache* parameter in :class:`CachedRevision <lab.cached_revision.CachedRevision>` constructor (Jendrik Seipp).
* Add *subdir* option for :class:`CachedRevision <lab.cached_revision.CachedRevision>` to support solvers residing in monolithic repos (Jendrik Seipp).
* Add :meth:`CachedRevision <lab.cached_revision.CachedRevision.get_relative_exp_path>` method (Jendrik Seipp).

Downward Lab
^^^^^^^^^^^^
Expand Down
21 changes: 7 additions & 14 deletions downward/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
DOWNWARD_SCRIPTS_DIR = os.path.join(DIR, "scripts")


def _get_solver_resource_name(cached_rev):
return "fast_downward_" + cached_rev.name


class FastDownwardRun(Run):
def __init__(self, exp, algo, task):
Run.__init__(self, exp)
Expand All @@ -42,10 +38,14 @@ def __init__(self, exp, algo, task):
)
input_files = ["{domain}", "{problem}"]

driver = os.path.join(
exp.path,
algo.cached_revision.get_relative_exp_path("fast-downward.py"),
)
self.add_command(
"planner",
[tools.get_python_executable()]
+ ["{" + _get_solver_resource_name(algo.cached_revision) + "}"]
+ [driver]
+ self.driver_options
+ input_files
+ algo.component_options,
Expand Down Expand Up @@ -352,15 +352,8 @@ def _cache_revisions(self):
def _add_code(self):
"""Add the compiled code to the experiment."""
for cached_rev in self._get_unique_cached_revisions():
cache_path = os.path.join(self.revision_cache, cached_rev.name)
dest_path = "code-" + cached_rev.name
self.add_resource("", cache_path, dest_path)
# Overwrite the script to set an environment variable.
self.add_resource(
_get_solver_resource_name(cached_rev),
os.path.join(cache_path, "fast-downward.py"),
os.path.join(dest_path, "fast-downward.py"),
)
dest_path = cached_rev.get_relative_exp_path()
self.add_resource("", cached_rev.path, dest_path)

def _add_runs(self):
tasks = self._get_tasks()
Expand Down
15 changes: 2 additions & 13 deletions examples/downward/2020-09-11-B-bounded-cost.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@

from downward import suites
from downward.cached_revision import CachedFastDownwardRevision
from downward.experiment import (
_DownwardAlgorithm,
_get_solver_resource_name,
FastDownwardRun,
)
from downward.experiment import _DownwardAlgorithm, FastDownwardRun
from lab.experiment import Experiment, get_default_data_dir

import project
Expand Down Expand Up @@ -68,14 +64,7 @@
for rev, rev_nick in REVS:
cached_rev = CachedFastDownwardRevision(REVISION_CACHE, REPO, rev, BUILD_OPTIONS)
cached_rev.cache()
dest_path = Path(f"code-{cached_rev.name}")
exp.add_resource("", cached_rev.path, dest_path)
# Overwrite the script to set an environment variable.
exp.add_resource(
_get_solver_resource_name(cached_rev),
cached_rev.path / "fast-downward.py",
dest_path / "fast-downward.py",
)
exp.add_resource("", cached_rev.path, cached_rev.get_relative_exp_path())
for config_nick, config in CONFIGS:
algo_name = f"{rev_nick}-{config_nick}" if rev_nick else config_nick

Expand Down
3 changes: 3 additions & 0 deletions lab/cached_revision.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,6 @@ def _get_sentinel_file(self):

def _cleanup(self):
pass

def get_relative_exp_path(self, relpath=""):
return os.path.join(f"code-{self.name}", relpath)

0 comments on commit 6650a2d

Please sign in to comment.