Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support QE conda env in /opt/conda #784

Merged
merged 6 commits into from
Jul 23, 2024
Merged

Support QE conda env in /opt/conda #784

merged 6 commits into from
Jul 23, 2024

Conversation

danielhollas
Copy link
Contributor

Change setup_codes.py to support QE conda environment located in /opt/conda

Built on top of #783. Separated from #781.

When building the QEApp Docker container,
the Quantum Espresso installation into a conda environment
is a step that's completely independent from the others.
By putting it into a separate Docker build stage,
it can be build in parallel (when using buildkit), as:

    DOCKER_BUILDKIT=1  docker build .
@@ -134,7 +139,7 @@ def setup_codes():
try:
run(["python", "-c", python_code], capture_output=True, check=True)
except CalledProcessError as error:
raise RuntimeError(f"Failed to setup codes: {error}")
raise RuntimeError(f"Failed to setup codes: {error}") from None
Copy link
Contributor Author

@danielhollas danielhollas Jul 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just to make stack traces nicer. Here's the correspoding flake8-bugbear rule as explained by ruff

❯ ruff rule B904
# raise-without-from-inside-except (B904)

Derived from the **flake8-bugbear** linter.

## What it does
Checks for `raise` statements in exception handlers that lack a `from`
clause.

## Why is this bad?
In Python, `raise` can be used with or without an exception from which the
current exception is derived. This is known as exception chaining. When
printing the stack trace, chained exceptions are displayed in such a way
so as make it easier to trace the exception back to its root cause.

When raising an exception from within an `except` clause, always include a
`from` clause to facilitate exception chaining. If the exception is not
chained, it will be difficult to trace the exception back to its root cause.

Example

try:
    ...
except FileNotFoundError:
    if ...:
        raise RuntimeError("...")
    else:
        raise UserWarning("...")

Use instead:

try:
    ...
except FileNotFoundError as exc:
    if ...:
        raise RuntimeError("...") from None
    else:
        raise UserWarning("...") from exc

References

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, how you find these good thing? Is it from your LSP?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is from ruff, which I have setup as LSP in neovim.

While the pre-commit in this repo uses ruff, it doesn't have any ruff-specific configuration. I think we should copy over the configuration from AWB. I think we have a good experience with that set and it will make things consistent across the two repos.

Copy link

codecov bot commented Jul 22, 2024

Codecov Report

Attention: Patch coverage is 16.66667% with 10 lines in your changes missing coverage. Please review.

Project coverage is 68.21%. Comparing base (a3b40b0) to head (7afc5f7).
Report is 36 commits behind head on main.

Files with missing lines Patch % Lines
src/aiidalab_qe/common/setup_codes.py 16.66% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #784      +/-   ##
==========================================
- Coverage   68.28%   68.21%   -0.07%     
==========================================
  Files          45       45              
  Lines        4143     4147       +4     
==========================================
  Hits         2829     2829              
- Misses       1314     1318       +4     
Flag Coverage Δ
python-3.10 68.21% <16.66%> (-0.07%) ⬇️
python-3.9 68.25% <16.66%> (-0.07%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@unkcpz unkcpz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A small note from my side. All good, thanks @danielhollas

Comment on lines +24 to +30
def get_qe_env():
# QE is already pre-installed in the QE image
path = Path(f"/opt/conda/envs/quantum-espresso-{QE_VERSION}")
if path.exists():
return path
else:
return Path.home().joinpath(".conda", "envs", f"quantum-espresso-{QE_VERSION}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can cause an edge problem that when the container is started with qeapp image and then shifted to using full-stack image. The QE not able to be accessed.
We were trying to provide full-stack, qe-app, base-with-server images in demo server. But as suggested by @giovannipizzi, we agree on only keep qe-app image. This change then wont be a problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. But hopefully that will not happen in practice, and the solution is simply to re-install the app. By the way, in this case the current solution with the symlink would not work anyway since the symlink would be broken, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in this case the current solution with the symlink would not work anyway since the symlink would be broken, right?

I think it won't work.

Base automatically changed from qe-stage to main July 23, 2024 12:17
@danielhollas danielhollas merged commit 4d92c54 into main Jul 23, 2024
13 checks passed
@danielhollas danielhollas deleted the qe-env-dir branch July 23, 2024 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants