-
Notifications
You must be signed in to change notification settings - Fork 10
Open
Labels
bugSomething isn't workingSomething isn't workingenhancementNew feature or requestNew feature or request
Description
The procedure _build_python_path leads to some unexpected behavior (IMO) in two cases.
- If I start an experiment with
python3 main.py config.yml -s
while conda environment A is activated andconfig.yml
contains a venv variable pointing to conda environment B, the PYTHONPATH (or more precisely the value of sys.path) of environment A is copied and used in thesbatch.sh
file (Line 25). I would expect the PYTHONPATH to be exported with the PYTHONPATH (or sys.path) of the environment specified in the venv config variable. As it is now, the PYTHONPATH specified in and activated with environment B in Line 21 will be overwritten with the sbatch script in Line 25.
Lines 18 to 32 in da87c58
# ------------------------------- | |
# Activate the virtualenv / conda environment | |
%%venv%% | |
# Export Pythonpath | |
%%pythonpath%% | |
# Additional Instructions from CONFIG.yml | |
%%sh_lines%% | |
python3 %%python_script%% %%path_to_yaml_config%% -j $SLURM_ARRAY_TASK_ID %%cw_args%% | |
# THIS WAS BUILT FROM THE DEFAULLT SBATCH TEMPLATE |
- When setting
experiment_copy_dst
orexperiment_copy_auto_dst
the generated PYTHONPATH still contains references to the original working directory (and not the copy) in some cases. As defined in https://docs.python.org/3/library/sys.html#sys.path, the first entry ofsys.path
is the directory "containing the script that was used to invoke the Python interpreter". As the script is invoked in the "uncopied" src directory, the PYTHONPATH will contain this entry if the script (the main.py file) is in a subfolder ofexperiment_copy_src
.
This happens because the code below only checks for exact copies ofsc["experiment_copy_src"]
and not paths containingsc["experiment_copy_src"]
. I think this also happens when the PYTHONPATH contains some manually added entries to subfolders ofsc["experiment_copy_src"]
. Changing the procedure to replace instances ofsc["experiment_copy_src"]
withdst
would solve this issue.
Lines 272 to 288 in 47d5eff
def _build_python_path(sc: attrdict.AttrDict) -> str: | |
"""clean the python path for the new experiment copy | |
Args: | |
sc (attrdict.AttrDict): slurm configuration | |
Returns: | |
str: python path bash command for slurm script | |
""" | |
pypath = sys.path.copy() | |
src = sc["experiment_copy_src"] | |
dst = sc["experiment_copy_dst"] | |
new_path = [x for x in pypath if x != src] | |
new_path.append(dst) | |
return "export PYTHONPATH=" + ":".join(new_path) |
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingenhancementNew feature or requestNew feature or request