def __init__(self, path=None, environment=None): """ The experiment will be built at *path*. It defaults to ``<scriptdir>/data/<scriptname>/``. E.g., for the script ``experiments/myexp.py``, the default *path* will be ``experiments/data/myexp/``. *environment* must be an :ref:`Environment <environments>` instance. You can use :class:`~lab.environments.LocalEnvironment` to run your experiment on a single computer (default). If you have access to the computer grid in Basel you can use the predefined grid environment :class:`~lab.environments.BaselSlurmEnvironment`. Alternatively, you can derive your own class from :ref:`Environment <environments>`. """ tools.configure_logging() _Buildable.__init__(self) path = path or _get_default_experiment_dir() self.path = os.path.abspath(path) if any(char in self.path for char in (":", ",")): logging.critical(f"Path contains commas or colons: {self.path}") self.environment = environment or environments.LocalEnvironment() self.environment.exp = self self.steps = [] self.runs = [] self.set_property("experiment_file", self._script)
def run_steps(self): """Parse the commandline and run selected steps.""" ARGPARSER.epilog = get_steps_text(self.steps) args = ARGPARSER.parse_args() assert not args.steps or not args.run_all_steps if not args.steps and not args.run_all_steps: ARGPARSER.print_help() return # Run all steps if --all is passed. steps = [get_step(self.steps, name) for name in args.steps] or self.steps # Use LocalEnvironment if the main experiment step is inactive. if any(environments.is_run_step(step) for step in steps): env = self.environment else: env = environments.LocalEnvironment() env.run_steps(steps)