diff --git a/Dockerfile b/Dockerfile index 1c6d73981..c110f7fca 100644 --- a/Dockerfile +++ b/Dockerfile @@ -75,7 +75,7 @@ RUN --mount=from=qe_conda_env,source=${QE_DIR},target=${QE_DIR} \ bash /usr/local/bin/before-notebook.d/40_prepare-aiida.sh && \ bash /usr/local/bin/before-notebook.d/41_setup-hq-computer.sh && \ python -m aiidalab_qe install-qe --computer local-hq && \ - python -m aiidalab_qe install-pseudos --source ${PSEUDO_FOLDER} && \ + # python -m aiidalab_qe install-pseudos --source ${PSEUDO_FOLDER} && \ verdi daemon stop && \ mamba run -n aiida-core-services pg_ctl stop && \ cd /home/${NB_USER} && tar -cf /opt/conda/home.tar . diff --git a/src/aiidalab_qe/__main__.py b/src/aiidalab_qe/__main__.py index b5d83f965..9af82931a 100644 --- a/src/aiidalab_qe/__main__.py +++ b/src/aiidalab_qe/__main__.py @@ -27,12 +27,12 @@ def cli(): def install_qe(force, profile, computer): load_profile(profile) try: - for msg in install_and_setup_qe_codes(target_computer=computer, force=force): + for msg in install_and_setup_qe_codes(computer=computer, force=force): click.echo(msg) - assert codes_are_setup() + assert codes_are_setup(computer=computer) click.secho("Codes are setup!", fg="green") except Exception as error: - raise click.ClickException(f"Failed to set up QE failed: {error}") from error + raise click.ClickException(f"Failed to set up QE: {error}") from error @cli.command() diff --git a/src/aiidalab_qe/common/setup_codes.py b/src/aiidalab_qe/common/setup_codes.py index ddaa56f90..6934f1413 100644 --- a/src/aiidalab_qe/common/setup_codes.py +++ b/src/aiidalab_qe/common/setup_codes.py @@ -81,17 +81,17 @@ def install_qe(): ) -def _code_is_setup(name): +def _code_is_setup(name, computer): try: - load_code(f"{name}-{QE_VERSION}@localhost") + load_code(f"{name}-{QE_VERSION}@{computer}") except NotExistent: return False else: return True -def codes_are_setup(): - return all(_code_is_setup(code_name) for code_name in CODE_NAMES) +def codes_are_setup(computer): + return all(_code_is_setup(code_name, computer) for code_name in CODE_NAMES) def _generate_header_to_setup_code(): @@ -106,7 +106,7 @@ def _generate_header_to_setup_code(): return header_code -def _generate_string_to_setup_code(code_name, computer="localhost"): +def _generate_string_to_setup_code(code_name, computer): """Generate the Python string to setup an AiiDA code for a given computer. Tries to load an existing code and if not existent, @@ -118,7 +118,7 @@ def _generate_string_to_setup_code(code_name, computer="localhost"): description = f"{code_name}.x ({QE_VERSION}) setup by AiiDAlab." filepath_executable = get_qe_env().joinpath("bin", f"{code_name}.x") default_calc_job_plugin = f"quantumespresso.{code_name}" - prepend_text = f'eval "$(conda shell.posix hook)"\\nconda activate {get_qe_env()}\\nexport OMP_NUM_THREADS=1' + prepend_text = f'eval "$(conda shell.posix hook)"\\nconda acitvate {get_qe_env()}\\nexport OMP_NUM_THREADS=1' python_code = """ computer = load_computer('{}') code = InstalledCode(computer=computer, @@ -144,22 +144,22 @@ def _generate_string_to_setup_code(code_name, computer="localhost"): return "" -def setup_codes(): +def setup_codes(computer): python_code = _generate_header_to_setup_code() for code_name in CODE_NAMES: - python_code += _generate_string_to_setup_code(code_name) + python_code += _generate_string_to_setup_code(code_name, computer) try: subprocess.run(["python", "-c", python_code], capture_output=True, check=True) - except subprocess.CalledProcessError as error: - raise RuntimeError(f"Failed to setup codes: {error}") from None + except subprocess.CalledProcessError as err: + raise RuntimeError(f"Failed to setup codes, exit_code={err.returncode}, {err.stderr}") from None -def install_and_setup(target_computer, force=False): +def install_and_setup(computer="localhost", force=False): """Install Quantum ESPRESSO and the corresponding AiiDA codes. Args: force: Ignore previously failed attempts and install anyways. - target_computer: computer label in AiiDA where the code is setup for + computer: computer label in AiiDA where the code is setup for """ # Check for "do not install file" and skip actual check. The purpose of # this file is to not re-try this process on every app start in case that @@ -169,7 +169,7 @@ def install_and_setup(target_computer, force=False): raise RuntimeError("Installation failed in previous attempt.") yield from _install() - yield from _setup(target_computer) + yield from _setup(computer) def _install(): @@ -219,14 +219,14 @@ def _setup(computer): # present (`which conda`). If that is not the case then we assume # that this is a custom user environment in which case we also take # no further action. - if codes_are_setup(): + if codes_are_setup(computer=computer): return # Already setup # After installing QE, we install the corresponding # AiiDA codes: python_code = _generate_header_to_setup_code() for code_name in CODE_NAMES: - if not _code_is_setup(code_name): + if not _code_is_setup(code_name, computer=computer): yield f"Preparing setup script for ({code_name}) on ({computer})..." code_string = _generate_string_to_setup_code(code_name, computer) python_code += code_string @@ -235,14 +235,14 @@ def _setup(computer): subprocess.run( ["python", "-c", python_code], capture_output=True, check=True ) - except subprocess.CalledProcessError as error: - raise RuntimeError(f"Failed to setup codes: {error}") from None + except subprocess.CalledProcessError as err: + raise RuntimeError(f"Failed to setup codes, exit_code={err.returncode}, {err.stderr}") from None except Timeout: # Assume that the installation was triggered by a different process. yield "Installation was already started, waiting for it to finish..." with FileLock(FN_SETUP_LOCKFILE, timeout=120): - if not codes_are_setup(): + if not codes_are_setup(computer=computer): raise RuntimeError( "Installation process did not finish in the expected time." ) from None