def get_hpsearch_call(cmd_args, num_seeds, grid_config, hpsearch_dir=None):
    """Generate the command line for the hpsearch.

    Args:
        cmd_args: The command line arguments.
        num_seeds (int): Number of searches.
        grid_config (str): Location of search grid.
        hpsearch_dir (str, optional): Where the hpsearch should write its
            results to.

    Returns:
        (str): The command line to be executed.

    """
    cluster_cmd_prefix = ''
    cluster_cmd_suffix = ''
    non_cluster_cmd_suffix = ''
    if cmd_args.run_cluster and cmd_args.scheduler == 'lsf':
        cluster_cmd_prefix = 'bsub -n 1 -W %s:00 ' % cmd_args.hps_num_hours + \
            '-e random_seeds.err -o random_seeds.out -R "%s" ' % \
            cmd_args.hps_resources.strip('"')

        cluster_cmd_suffix = ' --run_cluster ' + \
            '--scheduler=%s ' % cmd_args.scheduler +\
            '--num_jobs=%s ' % cmd_args.num_jobs +\
            '--num_hours=%s ' % cmd_args.num_hours + \
            '--resources="\\"%s\\"" ' % cmd_args.resources.strip('"') + \
            '--num_searches=%d ' % num_seeds
    elif cmd_args.run_cluster:
        assert cmd_args.scheduler == 'slurm'
        cluster_cmd_suffix = ' --run_cluster ' + \
            '--scheduler=%s ' % cmd_args.scheduler + \
            '--num_jobs=%s ' % cmd_args.num_jobs + \
            '--num_hours=%s ' % cmd_args.num_hours + \
            '--slurm_mem=%s ' % cmd_args.slurm_mem + \
            '--slurm_gres=%s ' % cmd_args.slurm_gres + \
            '--slurm_partition=%s ' % cmd_args.slurm_partition + \
            '--slurm_qos=%s ' % cmd_args.slurm_qos + \
            '--slurm_constraint=%s ' % cmd_args.slurm_constraint + \
            '--num_searches=%d ' % num_seeds
    else:
        non_cluster_cmd_suffix = \
            '--visible_gpus=%s ' % cmd_args.visible_gpus + \
            '--allowed_load=%f ' % cmd_args.allowed_load + \
            '--allowed_memory=%f ' % cmd_args.allowed_memory + \
            '--sim_startup_time=%d ' % cmd_args.sim_startup_time + \
            '--max_num_jobs_per_gpu=%d ' % cmd_args.max_num_jobs_per_gpu
    #cmd_str = 'TMP_CUR_DIR="$(pwd -P)" && pushd ../../hpsearch && ' + \
    cmd_str = cluster_cmd_prefix + \
        'python3 hpsearch.py --grid_module=%s '% cmd_args.grid_module + \
        '--grid_config=%s ' % grid_config + \
        '--run_cwd=%s ' % cmd_args.run_cwd #'--run_cwd=$TMP_CUR_DIR '
    if cmd_args.deterministic_search:
        cmd_str += '--deterministic_search '
    if cmd_args.dont_generate_full_grid:
        cmd_str += '--dont_generate_full_grid '
    if hpsearch_dir is not None:
        cmd_str += '--out_dir=%s --force_out_dir '% hpsearch_dir + \
    '--dont_force_new_dir '
    cmd_str += cluster_cmd_suffix + non_cluster_cmd_suffix #+ ' && popd'

    return cmd_str