Skip to content

Commit 58d0602

Browse files
authored
Autosix python2 update (#61)
Fixes #62 * Added python2 input parameter * bugfix with duplicated column names * limit pandas version <1.2 because of pandas-dev/pandas#39872 * updated changelog
1 parent cdf9e8e commit 58d0602

File tree

9 files changed

+82
-21
lines changed

9 files changed

+82
-21
lines changed

.zenodo.json

+24
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,30 @@
33
{
44
"name": "OMC-Team",
55
"affiliation": "CERN"
6+
},
7+
{
8+
"name": "Michael Hofer",
9+
"affiliation": "CERN",
10+
"orcid": "0000-0001-6173-0232"
11+
},
12+
{
13+
"name": "Joschua Dilly",
14+
"affiliation": "CERN",
15+
"orcid": "0000-0001-7864-5448"
16+
},
17+
{
18+
"name": "Felix Soubelet",
19+
"affiliation": "University of Liverpool & CERN",
20+
"orcid": "0000-0001-8012-1440"
21+
},
22+
{
23+
"name": "Rogelio Tomas Garcia",
24+
"affiliation": "CERN",
25+
"orcid": "0000-0002-9857-1703"
26+
},
27+
{
28+
"name": "Tobias Persson",
29+
"affiliation": "CERN"
630
}
731
],
832
"title": "PyLHC",

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# pylhc Changelog
22

3+
## Version 0.1.1
4+
5+
- Added:
6+
- `python2` parameter for autosix.
7+
8+
- Changed:
9+
- Bugfix for non-unique column names when indexing (`forced_da_analysis`)
10+
311
## Version 0.1.0
412

513
- Added:

pylhc/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
__title__ = "pylhc"
1111
__description__ = "An accelerator physics script collection for the OMC team at CERN."
1212
__url__ = "https://github.com/pylhc/pylhc"
13-
__version__ = "0.1.0"
13+
__version__ = "0.1.1"
1414
__author__ = "pylhc"
1515
__author_email__ = "[email protected]"
1616
__license__ = "MIT"

pylhc/autosix.py

+28-9
Original file line numberDiff line numberDiff line change
@@ -204,14 +204,23 @@
204204
Mask to name jobs from replace_dict
205205
206206
207-
- **python** *(PathOrStr)*:
207+
- **python3** *(PathOrStr)*:
208208
209209
Path to python to use with sixdb (python3 with requirements
210210
installed).
211211
212212
default: ``python3``
213213
214214
215+
- **python2** *(PathOrStr)*:
216+
217+
Path to python to use with run_six.sh (python2 with requirements installed).
218+
ONLY THE PATH TO THE DIRECTORY OF THE python BINARY IS NEEDED!
219+
And it can't be an Anaconda Distribution.
220+
221+
default: None (uses the first `python` in path)
222+
223+
215224
- **resubmit**:
216225
217226
Resubmits if needed.
@@ -321,8 +330,16 @@ def get_params():
321330
help="Path to executable.",
322331
)
323332
params.add_parameter(
324-
name="python",
325-
default=DEFAULTS["python"],
333+
name="python2",
334+
default=DEFAULTS["python2"],
335+
type=PathOrStr,
336+
help=("Path to python to use with run_six.sh (python2 with requirements installed)."
337+
" ONLY THE PATH TO THE DIRECTORY OF THE python BINARY IS NEEDED!"
338+
" And it can't be an Anaconda Distribution."),
339+
)
340+
params.add_parameter(
341+
name="python3",
342+
default=DEFAULTS["python3"],
326343
type=PathOrStr,
327344
help="Path to python to use with sixdb (python3 with requirements installed).",
328345
)
@@ -388,7 +405,8 @@ def main(opt):
388405
basedir=opt.working_directory,
389406
# kwargs:
390407
ssh=opt.ssh,
391-
python=opt.python,
408+
python2=opt.python2,
409+
python3=opt.python3,
392410
unlock=opt.unlock,
393411
resubmit=opt.resubmit,
394412
da_turnstep=opt.da_turnstep,
@@ -426,7 +444,8 @@ def setup_and_run(jobname: str, basedir: Path, **kwargs):
426444
LOG.info(f"vv---------------- Job {jobname} -------------------vv")
427445
unlock: bool = kwargs.pop("unlock", False)
428446
ssh: str = kwargs.pop("ssh", None)
429-
python: Union[Path, str] = kwargs.pop("python", DEFAULTS["python"])
447+
python2: Union[Path, str] = kwargs.pop("python2", DEFAULTS["python2"])
448+
python3: Union[Path, str] = kwargs.pop("python3", DEFAULTS["python3"])
430449
resubmit: bool = kwargs.pop("resubmit", False)
431450
da_turnstep: int = kwargs.pop("da_turnstep", DEFAULTS["da_turnstep"])
432451
ignore_twissfail_check: bool = kwargs.pop("ignore_twissfail_check", False)
@@ -499,7 +518,7 @@ def setup_and_run(jobname: str, basedir: Path, **kwargs):
499518
> /afs/cern.ch/project/sixtrack/SixDesk_utilities/pro/utilities/bash/run_six.sh -a
500519
"""
501520
if check_ok:
502-
submit_sixtrack(jobname, basedir, ssh=ssh)
521+
submit_sixtrack(jobname, basedir, python=python2, ssh=ssh)
503522
return # takes even longer
504523

505524
with check_stage(STAGES.check_sixtrack_output, jobname, basedir) as check_ok:
@@ -515,7 +534,7 @@ def setup_and_run(jobname: str, basedir: Path, **kwargs):
515534
> /afs/cern.ch/project/sixtrack/SixDesk_utilities/pro/utilities/bash/run_six.sh -i
516535
"""
517536
if check_ok:
518-
check_sixtrack_output(jobname, basedir, ssh=ssh, resubmit=resubmit)
537+
check_sixtrack_output(jobname, basedir, python=python2, ssh=ssh, resubmit=resubmit)
519538

520539
with check_stage(STAGES.sixdb_load, jobname, basedir) as check_ok:
521540
"""
@@ -524,7 +543,7 @@ def setup_and_run(jobname: str, basedir: Path, **kwargs):
524543
> python3 /afs/cern.ch/project/sixtrack/SixDesk_utilities/pro/utilities/externals/SixDeskDB/sixdb . load_dir
525544
"""
526545
if check_ok:
527-
sixdb_load(jobname, basedir, python=python, ssh=ssh)
546+
sixdb_load(jobname, basedir, python=python3, ssh=ssh)
528547

529548
with check_stage(STAGES.sixdb_cmd, jobname, basedir) as check_ok:
530549
"""
@@ -537,7 +556,7 @@ def setup_and_run(jobname: str, basedir: Path, **kwargs):
537556
> python3 /afs/cern.ch/project/sixtrack/SixDesk_utilities/pro/utilities/externals/SixDeskDB/sixdb $jobname plot_da_vs_turns
538557
"""
539558
if check_ok:
540-
sixdb_cmd(jobname, basedir, cmd=["da"], python=python, ssh=ssh)
559+
sixdb_cmd(jobname, basedir, cmd=["da"], python=python3, ssh=ssh)
541560

542561
# da_vs_turns is broken at the moment (jdilly, 19.10.2020)
543562
# sixdb_cmd(jobname, basedir, cmd=['da_vs_turns', '-turnstep', str(da_turnstep), '-outfile'],

pylhc/constants/autosix.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
HEADER_BASEDIR = "BASEDIR"
2929

3030
DEFAULTS = dict(
31-
python="python3",
31+
python2=None,
32+
python3="python3",
3233
da_turnstep=100,
3334
executable=MADX_BIN,
3435
)

pylhc/data_extract/timber.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def find_exact_time_for_beamprocess(acc_time: AccDatetime) -> AccDatetime:
1818
KnobExtractor, the timing event for SQUEEZE or RAMP.
1919
I don't think this is correct (jdilly).
2020
"""
21-
db = pytimber.LoggingDB()
21+
db = pytimber.LoggingDB(source="nxcals")
2222
t1, t2 = acc_time.sub(days=1).local_string(), acc_time.local_string()
2323

2424
event_ts, event_val = db.get("HX:SRMP-POW", t1, t2)["HX:SRMP-POW"]

pylhc/forced_da_analysis.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ def _get_old_kick_file(kick_dir, plane):
753753
df = df.set_index(TIME_COLUMN)
754754
df.index = _convert_time_index(df.index, path)
755755
rename_dict = {}
756-
for p in plane:
756+
for p in plane: # can be XY
757757
rename_dict.update(
758758
{
759759
f"2J{p}RES": column_action(p),
@@ -763,7 +763,8 @@ def _get_old_kick_file(kick_dir, plane):
763763
}
764764
)
765765
df = df.rename(rename_dict, axis="columns")
766-
df.loc[:, rename_dict.values()] = df.loc[:, rename_dict.values()] * 1e-6
766+
renamed_cols = list(set(rename_dict.values()))
767+
df.loc[:, renamed_cols] = df.loc[:, renamed_cols] * 1e-6
767768
return df
768769

769770

pylhc/sixdesk_tools/submit.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,17 @@ def check_sixtrack_input(jobname: str, basedir: Path, ssh: str = None, resubmit:
4949
LOG.info("Check for input files was successful.")
5050

5151

52-
def submit_sixtrack(jobname: str, basedir: Path, ssh: str = None, resubmit: bool = False):
52+
def submit_sixtrack(jobname: str, basedir: Path, python: Path = None, ssh: str = None, resubmit: bool = False):
5353
""" Generate simulation files and check if runnable and submit. """
5454
re_str = "Re-" if resubmit else ""
5555
LOG.info(f"{re_str}Submitting to sixtrack.")
5656
sixjobs_path = get_sixjobs_path(jobname, basedir)
57+
args = ["-i"] if resubmit else ["-a"]
58+
if python is not None:
59+
if not python.is_dir():
60+
python = python.parent
61+
args += ["-P", str(python)]
5762
try:
58-
args = ["-i"] if resubmit else ["-a"]
5963
start_subprocess([RUNSIX_SH] + args, cwd=sixjobs_path, ssh=ssh) # throws OSError if failed
6064
except OSError as e:
6165
raise StageSkip(
@@ -66,20 +70,24 @@ def submit_sixtrack(jobname: str, basedir: Path, ssh: str = None, resubmit: bool
6670
LOG.info(f"{re_str}Submitted jobs to Sixtrack")
6771

6872

69-
def check_sixtrack_output(jobname: str, basedir: Path, ssh: str = None, resubmit: bool = False):
73+
def check_sixtrack_output(jobname: str, basedir: Path, python: Union[Path, str], ssh: str = None, resubmit: bool = False):
7074
""" Checks if the sixtrack output is all there. """
7175
LOG.info("Checking if sixtrack has finished.")
7276
sixjobs_path = get_sixjobs_path(jobname, basedir)
7377
try:
7478
start_subprocess([RUNSTATUS_SH], cwd=sixjobs_path, ssh=ssh)
7579
except OSError as e:
7680
if resubmit:
77-
submit_sixtrack(jobname, basedir, ssh, resubmit=True)
78-
raise StageSkip("Resubmitted incomplete sixtrack jobs.")
81+
submit_sixtrack(jobname, basedir, python=python, ssh=ssh, resubmit=True)
82+
raise StageSkip(
83+
f"Sixtrack for {jobname} seems to be incomplete."
84+
" Resubmitted incomplete sixtrack jobs."
85+
" Wait until they have finished and run again."
86+
)
7987
else:
8088
raise StageSkip(
8189
f"Sixtrack for {jobname} seems to be incomplete."
82-
f"Run possibly not finished. Check (debug-) log or your Scheduler."
90+
f" Run possibly not finished. Check (debug-) log or your Scheduler."
8391
) from e
8492
else:
8593
LOG.info("Sixtrack results are all present.")

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def about_package(init_posixpath: pathlib.Path) -> dict:
3131
DEPENDENCIES = [
3232
"numpy>=1.19",
3333
"scipy>=1.4.0",
34-
"pandas>=1.0",
34+
"pandas>=1.0,<1.2", # limit because of https://github.com/pandas-dev/pandas/issues/39872
3535
"matplotlib>=3.2.0",
3636
"pjlsa>=0.0.14",
3737
"pytimber>=2.8.0",

0 commit comments

Comments
 (0)