Example #1
0
def install(benchmark, solver_names, dataset_names, force=False,
            recreate=False, env_name='False', confirm=False):

    # Check that the dataset/solver patterns match actual dataset
    benchmark = Benchmark(benchmark)
    print(f"Installing '{benchmark.name}' requirements")
    benchmark.validate_dataset_patterns(dataset_names)
    benchmark.validate_solver_patterns(solver_names)

    # Get a list of all conda envs
    default_conda_env, conda_envs = list_conda_envs()

    # If env_name is False (default), installation in the current environement.
    if env_name == 'False':
        env_name = None
        # incompatible with the 'recreate' flag to avoid messing with the
        # user environement
        if recreate:
            msg = "Cannot recreate conda env without using options " + \
                "'-e/--env' or '--env-name'."
            raise RuntimeError(msg)

        # check if any current conda environment
        if default_conda_env is not None:
            # ask for user confirmation to install in current conda env
            if not confirm:
                click.confirm(
                    f"Install in the current env '{default_conda_env}'?",
                    abort=True
                )
        else:
            raise RuntimeError("No conda environment is activated.")
    else:
        # If env_name is True, the flag `--env` has been used. Create a conda
        # env specific to the benchmark. Else, use the <env_name> value.
        if env_name == 'True':
            env_name = f"benchopt_{benchmark.name}"
        else:
            # check provided <env_name>
            # (to avoid empty name like `--env-name ""`)
            if len(env_name) == 0:
                raise RuntimeError("Empty environment name.")
            # avoid recreating 'base' conda env`
            if env_name == 'base' and recreate:
                raise RuntimeError(
                    "Impossible to recreate 'base' conda environment."
                )

        # create environment if necessary
        create_conda_env(env_name, recreate=recreate)

    # If force is True (default is False), it forces the reinstallation of
    # selected solvers (all solvers from the benchmark by default)
    forced_solvers = ()
    if force:
        if len(solver_names) > 0:
            forced_solvers = solver_names
        else:
            forced_solvers = benchmark.list_benchmark_solver_names()
    # same for datasets
    forced_datasets = ()
    if force:
        if len(dataset_names) > 0:
            forced_datasets = dataset_names
        else:
            forced_datasets = benchmark.list_benchmark_dataset_names()

    # install required datasets
    print("# Datasets", flush=True)
    benchmark.install_required_datasets(
        dataset_names, forced_datasets=forced_datasets, env_name=env_name
    )

    # install required solvers
    print("# Solvers", flush=True)
    benchmark.install_required_solvers(
        solver_names, forced_solvers=forced_solvers, env_name=env_name
    )
Example #2
0
def get_datasets(ctx, args, incomplete):
    skip_import()
    benchmark = Benchmark(args[1])
    datasets = benchmark.list_benchmark_dataset_names()
    datasets = [d.lower() for d in datasets]
    return [d for d in datasets if incomplete.lower() in d]