-
Notifications
You must be signed in to change notification settings - Fork 6
[Fix] Set Pythonpath for TestClusterExecutor #907
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
Changes from all commits
65068e8
a2cfca0
7ab6d51
1e0645d
12bca1a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
|
|
||
| from pysqa import QueueAdapter | ||
|
|
||
| from executorlib.standalone.command import set_current_directory_in_environment | ||
| from executorlib.standalone.hdf import dump, get_queue_id | ||
| from executorlib.standalone.inputcheck import check_file_exists | ||
| from executorlib.standalone.scheduler import pysqa_execute_command, terminate_with_pysqa | ||
|
|
@@ -85,6 +86,7 @@ def execute_with_pysqa( | |
| os.path.dirname(os.path.abspath(cwd)) | ||
| ) | ||
| submit_kwargs.update(resource_dict) | ||
| set_current_directory_in_environment() | ||
| queue_id = qa.submit_job(**submit_kwargs) | ||
|
Comment on lines
+89
to
90
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, find the set_current_directory_in_environment function
fd -t f -e py | xargs grep -l "set_current_directory_in_environment" | head -5Repository: pyiron/executorlib Length of output: 210 🏁 Script executed: # Also check the spawner_pysqa.py file around lines 89-90
cat -n src/executorlib/task_scheduler/file/spawner_pysqa.py | sed -n '85,95p'Repository: pyiron/executorlib Length of output: 525 🏁 Script executed: # Check how set_current_directory_in_environment is implemented
rg -A10 "def set_current_directory_in_environment" --type pyRepository: pyiron/executorlib Length of output: 910 🏁 Script executed: # Check PySQA's QueueAdapter.submit_job to see if it uses os.environ
python3 <<'EOF'
try:
import inspect
import pysqa
sig = inspect.signature(pysqa.QueueAdapter.submit_job)
print("submit_job signature:", sig)
# Try to get source if available
try:
src = inspect.getsource(pysqa.QueueAdapter.submit_job)
print("\nSource (first 50 lines):")
print('\n'.join(src.split('\n')[:50]))
except:
print("Could not retrieve source")
except ImportError:
print("PySQA not installed, checking online docs...")
EOFRepository: pyiron/executorlib Length of output: 106 🏁 Script executed: # Check the broader context in spawner_pysqa.py to understand qa object
cat -n src/executorlib/task_scheduler/file/spawner_pysqa.py | sed -n '1,100p'Repository: pyiron/executorlib Length of output: 4675 🏁 Script executed: # Find pysqa_execute_command implementation
rg -A20 "def pysqa_execute_command" --type pyRepository: pyiron/executorlib Length of output: 1941 🏁 Script executed: # Compare with subprocess spawner to see how it handles environment
cat -n src/executorlib/task_scheduler/file/spawner_subprocess.py | sed -n '1,100p'Repository: pyiron/executorlib Length of output: 3731 🏁 Script executed: # Check if there's any environment handling in spawner_subprocess
rg -n "set_current_directory_in_environment\|environ" src/executorlib/task_scheduler/file/spawner_subprocess.pyRepository: pyiron/executorlib Length of output: 44 🏁 Script executed: # Check PySQA documentation or examples in repo for environment handling
rg -n "submit_job\|environment\|environ" src/executorlib --type py -C2 | grep -A2 -B2 "submit_job"Repository: pyiron/executorlib Length of output: 44 🏁 Script executed: # Get the full pysqa_execute_command function
rg -A40 "def pysqa_execute_command" src/executorlib/standalone/scheduler.pyRepository: pyiron/executorlib Length of output: 1488 🏁 Script executed: # Check if PySQA's QueueAdapter has any environment-related parameters
rg -n "environment\|env\|environ" src/executorlib --type py | grep -i pysqaRepository: pyiron/executorlib Length of output: 44 🏁 Script executed: # Search for any usage of environment variable passing with PySQA in the codebase
rg -B5 -A10 "submit_job" src/executorlib/task_scheduler/file/spawner_pysqa.pyRepository: pyiron/executorlib Length of output: 564 🏁 Script executed: # Check if there are any tests or examples showing environment handling
fd -e py -path "*test*" | xargs grep -l "execute_with_pysqa\|submit_job" 2>/dev/null | head -3Repository: pyiron/executorlib Length of output: 230 🏁 Script executed: # Check the actual command being submitted - does it include environment setup?
cat -n src/executorlib/task_scheduler/file/spawner_pysqa.py | sed -n '66,70p'Repository: pyiron/executorlib Length of output: 302 🏁 Script executed: # Look for how environment variables might be passed in the command string
rg -B5 -A5 "\"command\":" src/executorlib/task_scheduler/file/spawner_pysqa.pyRepository: pyiron/executorlib Length of output: 500 🏁 Script executed: # Check if pysqa documentation is in the repo or referenced
find . -name "*.md" -o -name "*.rst" | xargs grep -l "pysqa\|PySQA" 2>/dev/null | head -3Repository: pyiron/executorlib Length of output: 123 🏁 Script executed: # Get more context on how the command is prepared - especially check if it includes env setup
cat -n src/executorlib/standalone/scheduler.py | head -50Repository: pyiron/executorlib Length of output: 2239 🏁 Script executed: # Check if there's any documentation about how subprocess inherits environment in pysqa_execute_command
cat -n src/executorlib/standalone/scheduler.py | sed -n '1,80p'Repository: pyiron/executorlib Length of output: 2841 🏁 Script executed: # Check if there's any documentation about PySQA environment parameter
cat README.md | grep -A5 -B5 -i "environment\|pysqa" | head -30Repository: pyiron/executorlib Length of output: 2344 🏁 Script executed: # Look for any environment setup in the command being submitted
rg -n "export\|PYTHONPATH" src/executorlib --type py | head -20Repository: pyiron/executorlib Length of output: 44 🏁 Script executed: # Check if the command itself includes any environment setup
cat -n src/executorlib/standalone/command.pyRepository: pyiron/executorlib Length of output: 8077 🏁 Script executed: # Check how the command is constructed and if there's any environment export mechanism
cat -n src/executorlib/task_scheduler/file/spawner_pysqa.py | sed -n '40,70p'Repository: pyiron/executorlib Length of output: 1509 🏁 Script executed: # Look for how pysqa_execute_command is used - specifically if it runs sbatch or similar
rg -B3 -A3 "sbatch\|submit" src/executorlib/standalone/scheduler.pyRepository: pyiron/executorlib Length of output: 44 🏁 Script executed: # Check if QueueAdapter or pysqa_execute_command has any env parameter documentation
python3 << 'EOF'
import subprocess
import inspect
# Test if subprocess.check_output inherits parent env when env is not specified
help_text = """
When env is not specified in subprocess calls, the child process inherits
the parent process's os.environ. However, for HPC schedulers like SLURM,
the job submitted via sbatch runs in a separate compute environment and
does NOT automatically inherit the submitting shell's environment variables.
"""
print(help_text)
# Simulate what happens in pysqa_execute_command
print("\nIn pysqa_execute_command:")
print("- subprocess.check_output() is called WITHOUT an 'env' parameter")
print("- This means it inherits parent process's os.environ")
print("- So the modified PYTHONPATH is passed to the sbatch command")
print("\nBUT:")
print("- sbatch submits the job to SLURM")
print("- The job runs in SLURM's compute environment")
print("- SLURM does NOT inherit the submitting shell's environment by default")
print("- You need --export=ALL or explicit env setup in the job script")
EOFRepository: pyiron/executorlib Length of output: 786 The modified
To fix this, either explicitly export environment variables in the job submission (e.g., 🤖 Prompt for AI Agents |
||
| dump(file_name=file_name, data_dict={"queue_id": queue_id}) | ||
| return queue_id | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: substring match on PYTHONPATH can cause false positives/negatives.
current_path not in environment["PYTHONPATH"]performs a substring check on the entire string, not a path-component check. For example, ifPYTHONPATH="/home/user/projectX"andcwd="/home/user/project", the substring match succeeds and the directory is incorrectly skipped. Split by the separator to check membership correctly.Also, Line 174 calls
os.getcwd()again instead of reusingcurrent_path.Proposed fix
def set_current_directory_in_environment(): """ Add the current directory to the PYTHONPATH to be able to access local Python modules. """ environment = os.environ current_path = os.getcwd() - if "PYTHONPATH" in environment and current_path not in environment["PYTHONPATH"]: - environment["PYTHONPATH"] = os.getcwd() + ":" + environment["PYTHONPATH"] + if "PYTHONPATH" in environment and current_path not in environment["PYTHONPATH"].split(os.pathsep): + environment["PYTHONPATH"] = current_path + os.pathsep + environment["PYTHONPATH"] elif "PYTHONPATH" not in environment: - environment["PYTHONPATH"] = os.getcwd() + environment["PYTHONPATH"] = current_path📝 Committable suggestion
🤖 Prompt for AI Agents