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

Cuquantum appliance: Can´t install and run own python package package in Cuquantum appliance when using apptainer #164

Open
TomasBezdek-Research opened this issue Nov 5, 2024 · 1 comment
Assignees

Comments

@TomasBezdek-Research
Copy link

Cuquantum appliance: Can´t install and run own python package package in Cuquantum appliance when using apptainer

I am a user of Cuquantum appliance 24.08 with apptainer container on HPC cluster, and I need to install my own local package VHA which has dependency on Qiskit and Qiskit Aer. After installation of this package by pip install --no-deps ./VHA, if I use pip show, the package is successfully found, but after running python script or interactive python console when trying to import VHA, I get module not found error, see below for more details.

Setting up the container

To ensure the container works properly with apptainer, and that correct conda environment is activated on every use, i build a container from following .def file.

Bootstrap: docker
From: nvcr.io/nvidia/cuquantum-appliance:24.08-x86_64

%post
    # Ensure conda is initialized
    conda init
    # Ensure environment activation on every start
    echo ". /opt/conda/etc/profile.d/conda.sh" >> ~/.bashrc
    echo "conda activate cuquantum-24.08" >> ~/.bashrc

%environment
    source /opt/conda/etc/profile.d/conda.sh
    conda activate cuquantum-24.08

And after that, I run

apptainer shell cuquantum-appliance.sif

and in the interactive shell, i use

pip install --no-deps ./vha
pip install --no-deps pyscf>=2.6 qiskit_algorithms>=0.3 qiskit_nature>=0.7.2 qiskit_ibm_runtime>=0.24.1 nlopt~=2.7 cma~=3.3.0 IPython traitlets stack_data executing asttokens pure_eval pygments decorator prompt_toolkit wcwidth click h5py

I also tried to install the local package directly to .sif image, but get the same result, i build this image from following .def file.

Bootstrap: docker
From: nvcr.io/nvidia/cuquantum-appliance:24.08-x86_64

%files
    /home/tom/vha

%post
    # Activate the conda environment and install the local package
    # Ensure conda is initialized
    conda init
    # Ensure environment activation on every start
    echo ". /opt/conda/etc/profile.d/conda.sh" >> ~/.bashrc
    echo "conda activate cuquantum-24.08" >> ~/.bashrc

    /bin/bash -c "
    source /opt/conda/etc/profile.d/conda.sh
    conda activate cuquantum-24.08
    pip install --no-deps /vha
    pip install --no-deps pyscf>=2.6 qiskit_algorithms>=0.3 qiskit_nature>=0.7.2 qiskit_ibm_runtime>=0.24.1 nlopt~=2.7 cma~=3.3.0 IPython traitlets stack_data executing asttokens pure_eval pygments decorator prompt_toolkit wcwidth click h5py
    "


%environment
    source /opt/conda/etc/profile.d/conda.sh
    conda activate cuquantum-24.08

Trying to use package

After setting the container, in both cases I get a same result.
I tried just to import the VHA package with following steps.

  1. Activate container
apptainer shell ./cuquantum-appliance.sif
  1. Use pip show to ensure VHA is installed, and get positive result.
    This for installing the vha during building container.
(cuquantum-24.08) pip show vha
Name: vha
Version: 0.1.dev21+g451e767.d20241102
Summary: 
Home-page: 
Author: 
Author-email: 
License: 
Location: /opt/conda/envs/cuquantum-24.08/lib/python3.11/site-packages
Requires: cma, nlopt, pyscf, qiskit, qiskit-aer, qiskit-algorithms, qiskit-ibm-runtime, qiskit-nature
Required-by: 

This for installing the VHA after build

cuquantum-24.08) pip show vha
Name: vha
Version: 0.1.dev21+g451e767
Summary: 
Home-page: 
Author: 
Author-email: 
License: 
Location: /home/tom/.local/lib/python3.11/site-packages
Requires: cma, nlopt, numpy, pyscf, qiskit, qiskit-aer, qiskit-algorithms, qiskit-ibm-runtime, qiskit-nature
Required-by: 

  1. Trying to import VHA
cuquantum-24.08) python3 
Python 3.11.9 | packaged by conda-forge | (main, Apr 19 2024, 18:36:13) [GCC 12.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
import vha
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'vha'

I also get the same error when trying to run a python script that import vha.

@ssarikurt
Copy link

There is a mistake in /home/cuquantum/entrypoint.sh, that prevents the proper Conda environment from being loaded. Please try to fix it as below and try again. It worked for me when I added some extra pip packages to the relevant conda environment. I hope it works for your case.

add below line to the /home/cuquantum/entrypoint.sh

CONDA_ENV_NAME=cuquantum-24.08

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

No branches or pull requests

3 participants