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

installation and docker guide #261

Draft
wants to merge 77 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
59d122e
add docker, fix windows problems, add installation guide
alexey-pronkin Nov 3, 2021
56891f7
litle fixes, not done yet
alexey-pronkin Nov 22, 2021
2c7d41f
start making dokerfile
alexey-pronkin Jun 13, 2022
4ec42f2
add script convert2ipynb and light docker
alexey-pronkin Jun 15, 2022
91f9e20
change gitignore and next stage of dockerfile
alexey-pronkin Jun 16, 2022
a98aa91
working docker
alexey-pronkin Jun 16, 2022
8485671
Merge branch 'master' into feature/docker2
alexey-pronkin Jun 18, 2022
bd136bc
style change
alexey-pronkin Jun 18, 2022
8b9e629
style 2
alexey-pronkin Jun 18, 2022
77f632e
style 2
alexey-pronkin Jun 18, 2022
893218d
fix convert2ipynb.py; add .dockerignore; add toml2requirements.py
Jun 22, 2022
d519fc8
refactor scripts, remove bugs
alexey-pronkin Jun 24, 2022
e306988
manually change requirements file
alexey-pronkin Jun 25, 2022
f6bf0d8
Merge branch 'master' into feature/docker2
alexey-pronkin Jun 25, 2022
69e1fc6
working with listner docker stage
alexey-pronkin Jun 26, 2022
a9677ce
not working bash in listener stage
alexey-pronkin Jun 27, 2022
a75192c
Update comment
alexey-pronkin Jun 27, 2022
efcd23d
Merge branch 'master' into feature/docker2
alexey-pronkin Jun 27, 2022
cb3ee79
add entry point
alexey-pronkin Jun 28, 2022
170dcd0
add tex libs
Jul 3, 2022
607e2dd
refactor docker, remove buildings to interactive regime
alexey-pronkin Jul 7, 2022
5da04d1
clean
alexey-pronkin Jul 8, 2022
1bdefba
merge master
alexey-pronkin Jul 8, 2022
c9916f4
add test to convert2ipynb.py
alexey-pronkin Jul 8, 2022
f51727f
Merge branch 'feature/docker' into feature/docker2
alexey-pronkin Jul 8, 2022
ab11b58
Merge pull request #409 from quantum-ods/feature/docker2
alexey-pronkin Jul 8, 2022
9859ef1
fix merge
alexey-pronkin Jul 8, 2022
fc33b41
starting working on docker lecture
alexey-pronkin Jul 8, 2022
2cc4136
Merge branch 'master' into feature/docker
vvssttkk Jul 8, 2022
1a3f891
start working on install lecture test
alexey-pronkin Jul 10, 2022
0047393
Merge branch 'feature/docker' of https://github.com/SemyonSinchenko/q…
alexey-pronkin Jul 10, 2022
a2c6657
Merge branch 'master' into feature/docker
alexey-pronkin Jul 10, 2022
0830fbb
fix test-installation and lecture
alexey-pronkin Jul 10, 2022
b8c24d2
Merge branch 'feature/docker' of https://github.com/SemyonSinchenko/q…
alexey-pronkin Jul 10, 2022
abfc0ae
staged version
alexey-pronkin Jul 11, 2022
dfd9354
Merge branch 'master' into feature/docker
vvssttkk Jul 15, 2022
a015f45
style: apply
vvssttkk Jul 15, 2022
494779b
pre-commit autoupdate & add args for mypy
vvssttkk Jul 15, 2022
bf7f9c2
style: bump flake8
vvssttkk Jul 15, 2022
8a05e8b
style: apply
vvssttkk Jul 15, 2022
92ec179
refactor: rename `scripts/` to `tools/`
vvssttkk Jul 16, 2022
6aaddc6
refactor: transfer from tools/ to tests/ 1 test file
vvssttkk Jul 16, 2022
da9292e
refactor: remove comment lines from makefile
vvssttkk Jul 16, 2022
6edf150
refactor tests
vvssttkk Jul 16, 2022
d126c03
refactor: rename `convert2ipynb` to `convert`
vvssttkk Jul 16, 2022
ded0cba
refactorL naming
vvssttkk Jul 16, 2022
314fa67
refactor: update how to run convert file
vvssttkk Jul 16, 2022
298d822
refactor: add version for some reqs & add fire
vvssttkk Jul 16, 2022
a3e1b65
refactor
vvssttkk Jul 16, 2022
099e1a4
ci: rename `name` pre-commit
vvssttkk Jul 16, 2022
b99537e
add todo about toml2reqs
vvssttkk Jul 16, 2022
c88a8cc
tests: replave some test files by conftest
vvssttkk Jul 16, 2022
016d6a6
test: update tests little bit
vvssttkk Jul 16, 2022
cc1e80a
style: apply for conftest
vvssttkk Jul 16, 2022
a979664
ci: add jupytext to runt tests
vvssttkk Jul 16, 2022
3a37698
add __init__
vvssttkk Jul 16, 2022
922d8d9
add tools/__init__
vvssttkk Jul 16, 2022
515a382
fixL typing for toc file
vvssttkk Jul 16, 2022
fb7008f
test: add data/
vvssttkk Jul 16, 2022
f61efa7
test: update
vvssttkk Jul 16, 2022
96f1078
refactor tools
vvssttkk Jul 16, 2022
28f7e61
style
vvssttkk Jul 16, 2022
0ebcb6d
ci: add deps
vvssttkk Jul 16, 2022
22dbabb
ci: add pytests
vvssttkk Jul 16, 2022
66e7e07
add loguru to reqs
vvssttkk Jul 16, 2022
5c0eef4
refactor
vvssttkk Jul 16, 2022
771fb5c
style
vvssttkk Jul 16, 2022
c719ca5
remove caplog
vvssttkk Jul 16, 2022
c8ce44e
refactor
vvssttkk Jul 16, 2022
a4cc27a
test: remove finally
vvssttkk Jul 16, 2022
e760dfd
add to gitignore some tests data
vvssttkk Jul 16, 2022
3cd5836
ci: refactor test-installation
vvssttkk Jul 16, 2022
0a327f3
Merge branch 'master' into feature/docker
vvssttkk Jul 17, 2022
2b3ad8e
change order of dockerfile for old docker engines. Change order in le…
alexey-pronkin Jul 18, 2022
99ec43c
resolve conflict
vvssttkk Aug 19, 2022
2da977b
Merge branch 'master' into feature/docker
vvssttkk Aug 19, 2022
7deea99
ci: add instaling deps & tests
vvssttkk Aug 19, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.git/*
.github/*
2 changes: 2 additions & 0 deletions .github/workflows/test-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Test docker for student and contributor + autoupdate requirements.txt file
# TODO
1 change: 1 addition & 0 deletions .github/workflows/windows-requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#TODO: test that requirements.txt works for windows and tools/
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -513,3 +513,7 @@ _build*

# VSCode settings dir
.vscode
# Docker errors
docker_errors
# Docker volume
docker_volume
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM continuumio/miniconda3:latest
COPY . .
RUN conda create -n qmlcourse.ai python=3.8 --yes
# Make RUN commands use the new environment:
RUN conda run -n qmlcourse.ai conda install poetry --yes
RUN conda run -n qmlcourse.ai poetry install
RUN conda run -n qmlcourse.ai conda install psi4 python=3.8 -c psi4 --yes
# RUN conda run -n qmlcourse.ai conda list -e > requirements.txt - we could use this to make requirements.txt exactly as poetry, however this works only on Ubuntu :(
RUN conda run -n qmlcourse.ai conda install -c conda-forge jupyterlab
225 changes: 225 additions & 0 deletions INSTALLATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
# Installation

There are several ways to install this course: with your system installed anaconda3/miniconda3 or with docker. If you don't need to contribute or change the course, you could follow only Listener instructions. The contributor environment additionally contains pre-commit hooks and the patched jupyter book package. Additionally, you could install GPU versions of the packages and use your modern Nvidia GPUs.

## Before we start

Clone this repository using git or manualy:

```shell
git clone https://github.com/SemyonSinchenko/qmlcourse.git
```

## Conda

First of all, install miniconda for your operating system https://docs.conda.io/en/latest/miniconda.html
Then you need to create an empty environment for the course, let's name it `qmlcourse.ai`. For this course we use some features of python 3.8, so you need at least this version.

```shell
conda create -n qmlcourse.ai python=3.8 --yes
```

after that, you need to activate this env by the following command

```shell
conda activate qmlcourse.ai
```

---

**NOTE**

You could also install all packages from Intel optimized repositories, but for now, we don't test this approach. This could make sense in four cases:

- if you are using a very old Intel/AMD processor (that does not have AVX2 instructions, for example). Then with high probability, you'll need to compile some packages by yourself. Intel® Distribution for Python contains many compilers and tools to help you with this non-trivial task.
- if you are using an extra modern Intel CPU with avx-512 or new AMX instructions. Or your CPU has more than eight cores.
- if you are using cluster and don't want to install OpenMP and other libraries manually.
In the mean case scenario with 8 cores CPU, you probably get about a 10% increase in the speed of calculations that, in my opinion, do not cost additional efforts and space on your SSD/HDD. Some users reviews that this actually works with an AMD processor, so if you have an AMD CPU you could message @avpronkin in ODS.ai Slack about a successful installation or ask for help.

### Intel® Distribution for Python

First of all, update your conda:

```shell
conda update conda
```

Secondly, add Intel channel for packages:

```shell
conda config --add channels intel
```

Finally, create intel based python environment and activate it:

```shell
conda create -n qmlcourse.ai intelpython3_core python=3.8 --yes
conda activate qmlcourse.ai
```

After you could activate your environment and continue to install all other packages, conda automatically search all repositories with the preference of the intel repo.

If you stack with problems, you could remove the Intel channel

```shell
conda config --remove channels intel
```

And remove `qmlcourse.ai` environment:
**WARNING**
_This cannot be undone, so you remove all packages that you install in `qmlcourse.ai` environment_

```shell
conda deactivate
conda env remove -n qmlcourse.ai
```

## so then you could proceed with another type of installation

### Check the installation

The following command prints your path to the `alias python` in the activated environment:

```shell
python -c "import sys; print(sys.executable)"
```

The printed path should look like `/home/user/miniconda3/envs/qmlcourse.ai/python` on Unix system and `C:\Users\USER\miniconda3\envs\qmlcourse.ai\python.exe` on Windows.

### Installing packages

#### Listener

When you activate conda env

```shell
conda activate qmlcourse.ai
```

On linux and OSX you could install stable version of psi4:

```shell
conda install psi4 python=3.8 -c psi4 --yes
```

On Windows, you need to install nightly build:

```shell
conda install psi4 python=3.8 -c psi4/label/dev -c conda-forge --yes
```

Before installation the main packages, you could install GPU version of tensorflow/jax.
See instructions here [_tensorflow-gpu_](https://www.tensorflow.org/install/gpu), [_Jax GPU_](https://github.com/google/jax#pip-installation-gpu-cuda):

And, finally, you need to install the majority of packages by:

```
python -m pip install -r requirements-listner.txt
```

Additionally, you could install jupyter or jupyter lab. In this guide, we install `jupyter-lab`

```
conda activate qmlcourse.ai
conda install -c conda-forge jupyterlab
```

### Working with course

I recommend you always use an explicit command like `python -m some_module` and work only inside the virtual environment. For example:

```shell
conda activate qmlcourse.ai
python - m pip install pandas
python - m jupyter notebook
```

In other cases (python3, py3, pip3, poetry run, etc.) you need to know what you do, where you do, and why you do that.
You could always use aliases and macros for shortcuts like

```bash
alias qml='conda activate qmlcourse.ai && python -m jupyter notebook'
```

or for Windows:

```bat
doskey qml=conda activate qmlcourse.ai $T python -m jupyter notebook
```

And then printing `qml` in your terminal gives you proper jupyter notebook kernel (do not forget back up your ".dotfiles" somewhere. You could search on the Internet which file you need to back up to save all your aliases).

```shell
qml
```

#### Contributor

\*\*
**WINDOWS NOTE**
There is no way to easily install the contributor packages due to changes in some async packages from python 3.8 on Windows. We use in our course some tricks from python3.8 like f-string debugging, so you need Docker Desktop or WSL2
\*\*

```shell
conda create -n qmlcourse.ai-dev python=3.9 --yes
```

```shell
conda activate qmlcourse.ai-dev
```

On linux and OSX you could install stable version of psi4:

```shell
conda install psi4 python=3.8 -c psi4 --yes
```

On Windows, you need to install nightly build:

```shell
conda install psi4 python=3.8 -c psi4/label/dev -c conda-forge --yes
```

And finally, install all other packages:

```
python -m pip install -r requirements.txt
```

Or in Linux, you could use poetry:

```shell
conda activate qmlcourse.ai-dev
conda install psi4 python=3.8 -c psi4 --yes
python -m pip install poetry
python -m poetry install
```

#### Troubleshooting

##### Known problems

[_Jupyter book does not work with python 3.8+ on Windows_](https://github.com/jupyter/nbclient/issues/85), so for contributing use docker/WSL2 instead.

If packagin conflicts, then update conda:
Copy link
Collaborator Author

@alexey-pronkin alexey-pronkin Nov 3, 2021

Choose a reason for hiding this comment

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

Packages


```shell
conda deactivate
conda update conda
```

## Docker

For installing a docker environment on your operating system, please read [_this official guide_](https://docs.docker.com/get-docker/). After the installation, if you are on a Linux system, please make post-installation steps: [_Linux post-installation steps_](https://docs.docker.com/engine/install/linux-postinstall/). After that, you probably should restart your OS. You could test your installation with the following command:

### Test that docker is working

### Contributor

### Listener

`TODO`

### Starting jupyter:

#### jupyter-lab
12 changes: 12 additions & 0 deletions requirements-listner.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
PennyLane>=0.18.0
cirq>=0.11.0
dwave-system>=1.10.0
dwavebinarycsp>=0.1.3
matplotlib>=3.3.4
networkx>=2.6.3
numpy>=1.19.2
penaltymodel-maxgap>=0.5.5
pyppeteer>=0.2.6
qiskit>=0.31.0
scikit-learn>=0.24.1
sympy==1.5
18 changes: 18 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
PennyLane>=0.18.0
cirq>=0.11.0
dwave-system>=1.10.0
dwavebinarycsp>=0.1.3
jupyter-book>=0.10.1
matplotlib>=3.3.4
networkx>=2.6.3
numpy>=1.19.2
paramiko>=2.8.0
penaltymodel-maxgap>=0.5.5
pre-commit>=2.13.0
pylatexenc==2.10
pyppeteer>=0.2.6
pyyaml>=5.4.1
qiskit>=0.31.0
Copy link
Collaborator

Choose a reason for hiding this comment

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

давай лучше использовать схему строгую (==), а не compat или gt

scikit-learn>=0.24.1
scp>=0.14.1
sympy==1.5
49 changes: 49 additions & 0 deletions tools/toml2requirements.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

prohibited_packages_listner = set([
"python",
"pre-commit",
"jupyter-book",
"pyyaml",
"pylatexenc",
"paramiko",
"scp",
"",
])
prohibited_packages_dev = set(["python", ""])


def get_packages(prohibited_packages):
packages = []
packages_flag = False
with open("pyproject.toml", 'r') as toml_file:
for line in toml_file:
line = line.strip()
if line == "[tool.poetry.dependencies]":
packages_flag=True
continue
elif line == "[build-system]":
packages_flag=False
elif line == "":
continue
if packages_flag:
package, version = line.split(" = ")
package = package.strip()
version = version.strip()[1:-1] # remove brakets \"^version\"
if package not in prohibited_packages:
if version.startswith("^"):
if len(version.split("."))==3:
packages.append(package+">="+version[1:]) # choose major version, needed for security bugfixes
else:
packages.append(package+"=="+version[1:])
else:
packages.append(package+"=="+version)
return sorted(packages)

#Sorting just for penaltymodel be upper
# GPU
# Intel
if __name__=="__main__":
with open("requirements.txt", 'w') as req_file:
req_file.writelines("\n".join(get_packages(prohibited_packages=prohibited_packages_dev)))
with open("requirements-listner.txt", 'w') as req_file:
req_file.writelines("\n".join(get_packages(prohibited_packages=prohibited_packages_listner)))