Skip to content

Instantly share code, notes, and snippets.

@TysonRayJones
Last active November 3, 2023 03:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TysonRayJones/5d31bfd5dbf6d8417e345f32225db712 to your computer and use it in GitHub Desktop.
Save TysonRayJones/5d31bfd5dbf6d8417e345f32225db712 to your computer and use it in GitHub Desktop.
Installing ProjectQ on ARCHER or ARCUS-B

Table of Contents

Installation

These are instructions for installing projectq and using its fast C++ backend on ARCHER or ARCUS-B, accessible by SLURM / PBS jobs.

load a C11 compiler and anaconda

module load gcc/5.3.0

# if you're on ARCHER:
module load anaconda-compute/python3
module unload xalt

# if you're on ARCUS-B:
module load binutils python/anaconda3/4.3.0

Notice on ARCHER we loaded anaconda-compute rater than anaconda, so that our running jobs can access python. Notice on ARCUS-B we loaded some additional compiler instructions through binutils.

To see what compiler and anaconda versions are available, call

module avail gcc
module avail anaconda

You can clear your loaded modules with module purge, and view available modules with module avail, and view modules currently loaded with module list.

on ARCHER, calling module purge will limit which modules you can subsequently load, requiring you restart your SSH session

The above modules will need to be loaded each time you SSH into either ARCHER or ARCUS-B.

prepare an anaconda environment

Here we create and activate an environment (and if on ARCHER, get some C++ symbols we'll need later).

On ARCUS-B

conda create --name projqenv python=3.5 anaconda

source activate projqenv

This environment will need to be activated (source activate projqenv) each time after SSH'ing in to ARCUS-B.

Enter conda info --env to see a list of your conda environments, source deactivate to leave an environment and delete the environment with

conda remove --name projqenv --all

On ARCHER

Care must be taken to put your conda environment in the work (accessible by the compute nodes) and not the default home directory. Replace PROJNAME and USERNAME below with your project code and username (which you SSH in with) respectively.

cd /work/PROJNAME/PROJNAME/USERNAME/

rm -rf .condarc .conda .local .cache
mkdir -p .conda .local .cache

export CONDARC=$PWD/.condarc
export PYTHONUSERBASE=$PWD/.local

conda config --add envs_dirs $PWD/.conda/envs
conda create --copy --name projqenv python=3.5 anaconda
source activate projqenv

conda install --copy libgcc

This environment will need to be activated (source activate projqenv) each time after SSH'ing in to ARCHER.

check pip

Anaconda has a habit of giving you an old pip version, or a handle to the global pip (rather than your projqenv environment's pip).

Check that

which pip

features

~/.conda/envs/projqenv/bin/pip

and if not, call

conda install pip

Also ensure pip is up-to-date:

pip install --upgrade pip

clear any previous attempts to build projectq

pip uninstall pybind11
pip uninstall projectq
rm -r ~/.cache/pip

This clears any built wheels, so we can force pip to (re)build projectq correctly

install pybind11

Even the latest version of pip can goof up installing projectq's dependencies in the correct order. Give it a hand by installing pybind11 yourself first, though not the notoriously bugged 2.0.0 version!

# on ARCUS-B
python -m pip install pybind11!=2.2.0

# on ARCHER
pip install --cache-dir $PWD/.cache pybind11!=2.2.0

On ARCHER, we were careful to install pybind in our cache in the /work directory.

build ProjectQ

Let's now (force pip to) build projectq.

# ARCUS-B:
env LANG=en_GB.UTF-8 CC=gcc CXX=g++ python -m pip install --user --force-reinstall --ignore-installed projectq

# ARCHER:
env LANG=en_GB.UTF-8 CC=gcc CXX=g++ pip install --cache-dir $PWD/.cache --user --force-reinstall --ignore-installed projectq

Here, we've

  • warned pip that projectq's README file contains non-ASCII characters (through LANG)
  • pointed pip to our C and C++ compilers (gcc and g++)
  • forced projectq to build, regardless of any previous builds (e.g. ones which failed to build the C++ backend)
  • on ARCHER, forced projq to install on the /work directory

check installation was successful

All done (hopefully)! Open python, and call

from projectq import MainEngine
MainEngine()

If the following notice doesn't appear: (Note: This is the (slow) Python simulator.) then installation of projectq (with the C++ backend) was successful, at least on the front-end.

On ARCHER, further check that

import projectq
projectq.__file__

import pybind11
pybind11.__file__

are located inside the /work dir, and not /home, so as to be accessible by the compute nodes.

possible errors

  • Assembler Error: no such instruction ...:
    you're missing some assembler instructions. On ARCUS-B, load these with module load binutils

  • (some generic compilation error):
    your C/C++ compilers mightn't support C11! Get a compatible one using (for example) module load gcc/5.3.0; view available compilers using module avail gcc

  • PermissionError: [Errno 13] Permission denied: '.../site-packages/projectq':
    you mightn't be using your conda environment's pip, but the global one instead. Check this which which pip (the direc should feature your environment name), and correct it with conda install pip then pip install --upgrade pip

  • FileNotFoundError: [Errno 2] No such file or directory: '.../.conda/envs/.pkgs/qt-5.6.2-4/info/index.json':
    You might be using an incompatible compiler version. Try a newer/older compiler using (for example) module load gcc/5.3.0; view available compilers using module avail gcc

  • ImportError: No module named 'pybind11' --- Failed building wheel for projectq:
    pip didn't build projectq's dependencies in the correct order; this can still happen with the latest pip! Install pybind11 yourself first before retrying (python -m pip install pybind11!=2.2.0)

  • Successful installation, but MainEngine() gives (Note: This is the (slow) Python simulator.):
    Check building projectq was successful by checking .../site-packages/projectq/backends/_sim/_cppsim...so exists. If not, force rebuilding as above. If so, you might need extra C symbols which you can get with conda install libgcc. To better diagnose, edit site-packages/projectq/backends/_sim/_simulator.py. You can find site packages with python -m site --user-site. In _simulator.py, add from ._cppsim import Simulator as SimulatorBackend above the try/except. Then open python and call from projectq import MainEngine and you may see a more descriptive error message.

  • Successful installation, MainEngine() gives no warning, but ARCHER PBS jobs give error No module named projectq. Check projectq and pybind11 are in the /work dir, by in python: import projectq; projectq.__file__. If so, ensure you CONDARC and PYTHONUSERBASE in your submission script and pass -b to aprun (see below).

Usage

In the frontend

Now that you've set projectq up, the next time you SSH into ARCHER or ARCUS-B, in order to access projectq on the submit machine, you'll need to call...

on ARCHER:

module load gcc/5.3.0 anaconda-compute/python3
module unload xalt
source activate projqenv

on ARCUS-B:

module load gcc/5.3.0 python/anaconda3/4.3.0
source activate projqenv

You can put the above code into a script...

nano myscript.sh
< paste above code >
chmod +x myscript.sh

which you can then call via source myscript.sh after SSH'ing in, or inside your SLURM or PBS submission scripts.

Recall you can enter conda info --env to see a list of your conda environments, and source deactivate to leave an environment.

In a job

ARCUS-B:

In your SLURM submit script, simply include

module load gcc/5.3.0 python/anaconda3/4.3.0
source activate projqenv

export OMP_NUM_THREADS=16
export OMP_PROC_BIND=spread

python my_projq_script.py

ARCHER:

Your PBS submit script should include (replacing PROJECTNAME and USERNAME)

mydir=/work/PROJECTNAME/PROJECTNAME/USERNAME

module load anaconda-compute/python3
module load gcc/5.3.0
module unload xalt

export CONDARC=${mydir}/.condarc
export PYTHONUSERBASE=${mydir}/.local
source activate projqenv

export OMP_NUM_THREADS=24
export OMP_PROC_BIND=spread

cd "$PBS_O_WORKDIR"

aprun -b -n 1 -d 24 python my_projq_script.py

Take note of the -b argument to aprun.

We recommend creating a script /work/PROJECTNAME/PROJECTNAME/USERNAME/prepq.sh with contents

mydir=/work/PROJECTNAME/PROJECTNAME/USERNAME

module load anaconda-compute/python3
module load gcc/5.3.0
module unload xalt

export CONDARC=${mydir}/.condarc
export PYTHONUSERBASE=${mydir}/.local
source activate projqenv

export OMP_NUM_THREADS=24
export OMP_PROC_BIND=spread

and giving it permission to run (chmod +x prepq.sh) and replacing the above code in your PBS submission script with

cd "$PBS_O_WORKDIR"
source .../path/to/prepq.sh

aprun -b -n 1 -d 24 python my_projq_script.py

An enormous thankyou to the ARCHER CSE team, Andrew Gittings of ARCUS and Thomas Haener of ProjectQ for their considerable help and patience!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment