I'm trying to use some particle physics software and run it in a loop with slightly changed variables each time. It has specific functionality to take a txt file and scan it for relevant commands for this, so naturally I am trying to make use of this. I have written a python script (this was originally written in python3 to run on my laptop, but I need to move over to the university's cluster. I've converted to python2 as the particle physics software itself is python 2 and trying to run both versions of python on the cluster simultaneously is not something I know how to do. Specifically the cluster has python2.6.9 installed, I do not have any ability to change this, I also cannot update it or install new modules. The problematic part of my code is:
def run_madgraph():
# starts madgraph and tells it to run mg5_aMC using mg_run_iridis.txt as a file for it.
print('starting....')
subprocess.check_call(['python', './madgraph/bin/mg5_aMC mg_run_iridis.txt'])
mg5_aMC starts up the physics software, mg_run_iridis.txt is the text file with the information about variables. I don't understand why this doesn't work as the following command works just fine in the bash terminal (on the cluster):
python ./madgraph/bin/mg5_aMC mg_run_iridis.txt
As far as I can tell the issue is on the python-bash side rather than it being anything in the physics software. The error I get is:
(MGenv) [cb27g11@green0155 Development]$ python MainIridis_script.py
about to run madgraph 1.0 0.9
starting....
python: can't open file '/home/cb27g11/Development/./madgraph/bin/mg5_aMC mg_run_iridis.txt': [Errno 2] No such file or directory
Traceback (most recent call last):
File "/home/cb27g11/Development/MainIridis_script.py", line 41, in <module>
the_main_event()
File "/home/cb27g11/Development/MainIridis_script.py", line 21, in the_main_event
run_madgraph()
File "/home/cb27g11/Development/MainIridis_script.py", line 38, in run_madgraph
subprocess.check_call(['python', './madgraph/bin/mg5_aMC mg_run_iridis.txt'])
File "/home/cb27g11/.conda/envs/MGenv/lib/python3.9/subprocess.py", line 373, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['python', './madgraph/bin/mg5_aMC mg_run_iridis.txt']' returned non-zero exit status 2.
Just to be clear, /home/cb27g11/Development
, definitely exists:
(MGenv) [cb27g11@green0155 Development]$ pwd
/home/cb27g11/Development
As do the various files involved:
(MGenv) [cb27g11@green0155 Development]$ ls
AD_noCharge_021020.tar.gz NoChar_Allh_1.0_0.9 mg_run_basic.txt
MainIridis_script.py NoChar_Allh_1_0.9 mg_run_iridis.txt
NoCh_h1Only.tar.gz iridis_script.pbs py.py
NoCh_h2Only.tar.gz madgraph
Including mg5_aMC:
(MGenv) [cb27g11@green0155 Development]$ cd madgraph/
(MGenv) [cb27g11@green0155 madgraph]$ cd bin
(MGenv) [cb27g11@green0155 bin]$ ls
mg5 mg5_aMC py.py
I don't know how else to go about this, and ultimately however I do it, I still need to call this script file inside another script (bash this time) in order to submit it to the cluster.
I'm unsure if it's possible to just avoid the python script all together and switch to bash, I suspect at least some of it needs to remain in python but I'm a physicist not a programmer so I could easily be wrong! Here's the full script in anycase:
from __future__ import absolute_import, division, print_function
import numpy as np
import subprocess
import fileinput
tan_beta = np.arange(1, 21.2, 0.2) #Array of tan(beta) values
sin_bma = np.arange(0.9, 1.001, 0.001)#Array of sin(beta-alpha) values
hcm = 1.500000e+05 # Mass of charged Higgses in GeV
textfilepath = 'mg_run_iridis.txt' #path to txt file madgraph will use
Process = 'NoChar_Allh'
def the_main_event():
with open('mg_run_basic.txt','r') as old_card:
text =old_card.read() #stores string of old_card ready for editing
for i in range(0, len(tan_beta)):
tb = tan_beta[i] # loops over tan(beta) values
for j in range(0, len(sin_bma)):
sbma = sin_bma[j] # loops over sin(beta-alpha) values
make_input(tb, sbma, hcm, text)
print('about to run madgraph ' + str(tb) + ' ' + str(sbma))
run_madgraph()
def make_input(Tb, Sbma, Hcm, Text):
# inputs are the value of tan_beta, the value of sin(beta-alpha) values, the desired mass for the charged higgses and a string of text
with open(textfilepath, 'w') as new_card:
#simulation card, the .txt file that gets fed to madgraph
sim_card = Text.replace('TBV', str(Tb))
sim_card = sim_card.replace('SBMAV', str(Sbma))
sim_card = sim_card.replace('HCMV', str(Hcm))
sim_card = sim_card.replace('NAME', str(Process)+'_' + str(Tb) +'_' + str(Sbma))
new_card.write(sim_card) # saves new txt file for madgraph
def run_madgraph():
# starts madgraph and tells it to run mg5_aMC using mg_run_iridis.txt as a file for it.
print('starting....')
subprocess.check_call(['python', './madgraph/bin/mg5_aMC mg_run_iridis.txt'])
the_main_event()
It seems like from the errors it's treating the madgraph executable (I'm not sure if thats correct terminology, I mean the file that starts up the propgram) as a module?
Any help would be really appreciated!