cmelab / planckton

Reproducible exploration of organic photovoltaic morphology self-assembly using molecular dynamics.
GNU General Public License v3.0
5 stars 6 forks source link

Isolate Container Python #18

Closed mikemhenry closed 3 years ago

mikemhenry commented 3 years ago

This will prevent user packages from being loaded (at least when using python and pip)

codecov[bot] commented 3 years ago

Codecov Report

Merging #18 (209b9a6) into master (743021b) will not change coverage. The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #18   +/-   ##
=======================================
  Coverage   98.76%   98.76%           
=======================================
  Files           6        6           
  Lines         162      162           
=======================================
  Hits          160      160           
  Misses          2        2           
jennyfothergill commented 3 years ago

@mikemhenry Looks good! So this will fix the issue of finding conda installations outside of the container, right? Is there a built container I can grab?

jennyfothergill commented 3 years ago

also what's the best way to handle PRs that change the container? I commented this https://github.com/cmelab/planckton/pull/11#issuecomment-716822437 is that right?

mikemhenry commented 3 years ago

I think the instructions you posted are correct. It is clunky to handle environment changes but I don't know of a better way to do it yet. I haven't built an image yet for this PR, one thing I was thinking about it is it will be easier if we install everything we need for planckton into the root env since that will save us an activation step (or is there a way to make plankcton the "default" or "root" virtual environment? I bring this up since this line:

RUN sed -i -e 's/ENABLE_USER_SITE = None/ENABLE_USER_SITE = False/g' `python3 -c 'import site; print(site.__file__)'`

Currently is running in the root env and I will need to toss an "conda activate plancktonto actually make it work, which will be annoying when using the container withplankcton-flow` and singularity images.

jennyfothergill commented 3 years ago

Yeah, it seems like the behavior in singularity and docker is fairly different. In docker, the container opens with the planckton env active, but not in singularity. I'm ok with installing everything into the base env, but in singularity you would still need to run conda init bash I think. This could be due to the differences in the ways singularity/docker handle files.

mikemhenry commented 3 years ago

That behavior difference is how the filesystem is mounted/mapped when using singularity. I don't see anything (at least on master) that would cause the behavior:

In docker, the container opens with the planckton env active, but not in singularity. I'm ok with installing everything into the base env, but in singularity you would still need to run conda init bash I think.

That you are describing. How does docker automatically have the planckton env active?

jennyfothergill commented 3 years ago

How does docker automatically have the planckton env active?

In the feat/unyt branch I have the environment activated fc575a1. Sorry I think I'm getting mixed up with all the PR's and branches going right now haha 😅

mikemhenry commented 3 years ago

I think its good to push, I think right now things are in flux so it might not work, but in a perfect world we would have the tag of the containers match the version of plankcton, and then have a latest tag that matches what is on the master branch. We can do something like cmelab/planckton-cpu:$TAG and cmelab/planckton-gpu:$TAG for the CPU and GPU versions, we can also add building the image (and then pushing it) to dockerhub so it is all automated.

jennyfothergill commented 3 years ago

OK pushing to cmelab/planckton_cpu:0.0.4 sorry the version numbers are just all over the place.

I have not tested this with singularity yet. -- OK testing with singularity on Fry: I still see my normal fry conda envs and the environment does not load upon entering the container. I can access the container python using /opt/conda/envs/planckton/bin/python. Is there a way we can make this easier with singularity?

mikemhenry commented 3 years ago

Probably, but did it work to use the --nv flag and then when you import hoomd and ask for a GPU, do you get one?

jennyfothergill commented 3 years ago

No, that didn't work, but we don't expect it to--this is the cpu image, right? On Fry:

(base) [jennyfothergill@fry ~]$ srun -p volta --pty bash
(base) [jennyfothergill@node16 ~]$ singularity shell --nv planckton_cpu_0.0.4.sif 
Singularity planckton_cpu_0.0.4.sif:~> which python
/opt/conda/bin/python
Singularity planckton_cpu_0.0.4.sif:~> python 
Python 3.8.5 (default, Sep  4 2020, 07:30:14) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import hoomd
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'hoomd'
>>> 
Singularity planckton_cpu_0.0.4.sif:~> /opt/conda/envs/planckton/bin/python
Python 3.7.8 | packaged by conda-forge | (default, Jul 31 2020, 02:25:08) 
[GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import hoomd
>>> hoomd.context.initialize("--mode=gpu")
HOOMD-blue 2.9.3 DOUBLE HPMC_MIXED TBB SSE SSE2 SSE3 
Compiled: 10/17/2020
Copyright (c) 2009-2019 The Regents of the University of Michigan.
-----
You are using HOOMD-blue. Please cite the following:
* J A Anderson, J Glaser, and S C Glotzer. "HOOMD-blue: A Python package for
  high-performance molecular dynamics and hard particle Monte Carlo
  simulations", Computational Materials Science 173 (2020) 109363
-----
**ERROR**: GPU execution requested, but this hoomd was built without CUDA support
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/conda/envs/planckton/lib/python3.7/site-packages/hoomd/context.py", line 249, in initialize
    exec_conf = _create_exec_conf(mpi_conf, msg, options);
  File "/opt/conda/envs/planckton/lib/python3.7/site-packages/hoomd/context.py", line 375, in _create_exec_conf
    exec_conf = _hoomd.ExecutionConfiguration(exec_mode, gpu_vec, options.min_cpu, options.ignore_display, mpi_conf, msg);
RuntimeError: Error initializing execution configuration

But I think I was wrong before, it seems when inside the container I'm not finding python from outside the container, so that's good. Maybe we just install into the base env.

mikemhenry commented 3 years ago

Sorry I had my wires crossed, I was working on the GPU image so that's what I had on my mind, this is the CPU image and we wouldn't expect it to get a GPU

jennyfothergill commented 3 years ago

@mikemhenry is this PR ready to merge?