Running fits on HTCondor #1807
-
Dear pyhf users, $ source setup.sh
$ python Fit.py
The error file, makes sense to me, since I am not setting up Traceback (most recent call last):
File "condor_exec.exe", line 2, in <module>
import pyhf
ModuleNotFoundError: No module named 'pyhf' Is there a way to setup pyhf on condor and submit the jobs ? I am thinking if we have to write a shell script wrapper for it ? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 13 replies
-
There's nothing specific to For example, if you were on a CVMFS machine and had a Python virtual environment built from a create_cvmfs_venv.sh:#!/bin/bash
# load LCG view to get Python
. /cvmfs/sft.cern.ch/lcg/views/LCG_101/x86_64-centos7-gcc11-opt/setup.sh
# Create Python virtual environment
python -m venv venv
. venv/bin/activate
# Ensure that the Python virtual environment is at head of PYTHONPATH
# c.f. https://github.com/matthewfeickert/cvmfs-venv for more info and alternatives to deal with this
export PYTHONPATH="$(readlink -f $(find venv -type d -iname site-packages)):${PYTHONPATH}"
python -m pip install --upgrade --ignore-installed pip setuptools wheel
python -m pip install --upgrade --ignore-installed pip-tools
# Generate environment lock file
pip-compile \
--generate-hashes \
--output-file requirements.lock \
requirements.txt
# Use Brett Cannon's recommendations for pip-secure-install to ensure environment
# is reproducible and installed as securely as possible.
# c.f. https://www.python.org/dev/peps/pep-0665/#secure-by-design
# c.f. https://github.com/brettcannon/pip-secure-install
# c.f. https://twitter.com/brettsky/status/1486137764315688961
# As working in CVMFS LCG views also add --ignore-installed to avoid CVMFS packages
python -m pip install \
--ignore-installed \
--no-deps \
--require-hashes \
--only-binary :all: \
--requirement requirements.lock
python -m pip list --local then if you had your executable be something like example.sh:#!/bin/bash
# Load environment
. /cvmfs/sft.cern.ch/lcg/views/LCG_101/x86_64-centos7-gcc11-opt/setup.sh # load LCG view to get Python
. /afs/cern.ch/user/f/feickert/htcondor_example/venv/bin/activate # load Python virtual environment
# Ensure that the Python virtual environment is at head of PYTHONPATH
# c.f. https://github.com/matthewfeickert/cvmfs-venv for more info and alternatives to deal with this
# This should be the equivalent of: export PYTHONPATH="$(readlink -f $(find venv -type d -iname site-packages)):${PYTHONPATH}"
export PYTHONPATH="/afs/cern.ch/user/f/feickert/htcondor_example/venv/lib/python3.9/site-packages:${PYTHONPATH}"
# Run script
python example.py you should be able to submit it in your HTCondor submission script and have things run. Here's a GitHub Gist with a full example. (Note that I wrote this without running it and I'm more of a SLURM user, so I might have made a mistake.) |
Beta Was this translation helpful? Give feedback.
There's nothing specific to
pyhf
here. If you want to load a particular environment then you need to ensure that environment gets loaded in your HTCondor submit file'sExecutable
. So if you make yourExecutable
a shell script (e.g.example.sh
) you would already have generated your Python virtual environment in advance in a location that is accessible by HTCondor (so you're not creating it over and over each time you run) and then source that Python virtual environment before you do anything.For example, if you were on a CVMFS machine and had a Python virtual env…