Using pyPetal from the Command Line
We’ve seen how to run pyPetal both from the command line and from a TOML file - but is there any way to make it easier?
There is a very specific workaround to running each part of pyPetal separately, using virtualenv.
pyPetal has a few utility functions to create a TOML file and a bash script to run all modules of pyPetal, given two virtualenv environments - one for pyPetal and one for pyPetal-jav.
Let’s say we’ve created two virtualenv environments:
For the first, call python3:
python -m venv pypetal_env1
cd pypetal_env1
source activate
pip install pypetal
For the second, call python2:
python -m virtualenv pypetal_env2
cd pypetal_env2
source activate
pip install numpy
pip install pypetal-jav
Let’s also say we have a TOML file called input.toml to use as input for pyPetal.
Now, we can use the following code to create the bash script:
[ ]:
from pypetal.fromfile.write_bash import write_bash
toml_fname = 'input.toml'
env1 = 'pypetal_env1/'
env2 = 'pypetal_env2/'
write_bash( toml_fname, env1, env2 )
This should create a bash script named run.sh in the current working directory. To use, run:
source run.sh
pyPetal also has functionality to make the bash script without a TOML file, given input arguments:
[ ]:
from pypetal.fromfile.write_bash import bash_from_python
toml_fname = 'input.toml'
env1 = 'pypetal_env1/'
env2 = 'pypetal_env2/'
main_dir = 'pypetal/examples/dat/javelin_'
line_names = ['continuum', 'yelm', 'zing']
filenames = [ main_dir + x + '.dat' for x in line_names ]
output_dir = 'bash_output/'
drw_rej_params = {
'use_for_javelin': True,
'reject_data': [True, False, True]
}
pyccf_params = {
'nsim': 2000
}
pyzdcf_params = {
'run_plike': True,
'plike_dir': 'pypetal/plike_v4/'
}
pyroa_params = {
'nchain': 20000,
'nburn': 15000,
'psi_types': 'InverseGauss'
}
javelin_params = {
'nchain': 200,
'nburn': 200,
'nwalker': 200
}
weighting_params = {
'k': 5
}
bash_from_python(output_dir, filenames, toml_fname,
env1, env2, line_names,
run_drw_rej=True, drw_rej_params=drw_rej_params,
run_pyccf=True, pyccf_params=pyccf_params,
run_pyzdcf=True, pyzdcf_params=pyzdcf_params,
run_pyroa=True, pyroa_params=pyroa_params,
run_javelin=True, javelin_params=javelin_params,
run_weighting=True, weighting_params=weighting_params,
plot=False, verbose=True, lc_unit='', file_fmt='ascii',
threads=25)
This will produce the TOML file input.toml and the bash script run.sh.