Skip to content

Commit

Permalink
ruff and more
Browse files Browse the repository at this point in the history
  • Loading branch information
rkansal47 committed Mar 5, 2024
1 parent 182abfd commit c748c79
Show file tree
Hide file tree
Showing 55 changed files with 1,100 additions and 3,357 deletions.
14 changes: 7 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ repos:
hooks:
- id: shellcheck

- repo: local
hooks:
- id: disallow-caps
name: Disallow improper capitalization
language: pygrep
entry: PyBind|Numpy|Cmake|CCache|Github|PyTest
exclude: .pre-commit-config.yaml
# - repo: local
# hooks:
# - id: disallow-caps
# name: Disallow improper capitalization
# language: pygrep
# entry: PyBind|Numpy|Cmake|CCache|Github|PyTest
# exclude: .pre-commit-config.yaml

- repo: https://github.com/abravalheri/validate-pyproject
rev: "v0.16"
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ line-length = 100

[tool.ruff]
src = ["src"]
exclude = ["src/HHbbVV/postprocessing/pickle_scripts", "src/HHbbVV/postprocessing/AK15", "src/HHbbVV/triton/ParticleTransformer*", "src/runCoffeaCasa.py"]

[tool.ruff.lint]
extend-select = [
Expand Down Expand Up @@ -139,13 +140,16 @@ ignore = [
"EM102",
"G002", # Logging statement format
"G004",
"PLE1205", # logging format string
"E722", # bare except
"E741", # ambiguous variable name
"RUF005", # iterable unpacking
"RUF013", # implicit 'Optional' type
"PGH001", # eval
"RET503",
"RET504", # unnecessary assignment before return
"RET505", # unnecessary else after return statement
"NPY002", # np.random.rand -> np.random.Generator
]

isort.required-imports = ["from __future__ import annotations"]
Expand Down
31 changes: 16 additions & 15 deletions src/HHbbVV/combine/submit/submit_bias.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,26 @@
Author(s): Raghav Kansal
"""
from __future__ import annotations

import argparse
import os
from math import ceil
from string import Template
import json
from pathlib import Path

import sys
from utils import parse_common_args, setup

from utils import add_bool_arg, write_template, setup, parse_common_args
from HHbbVV import run_utils


def main(args):
t2_local_prefix, t2_prefix, proxy, username, submitdir = setup(args)

prefix = f"bias_{args.bias}_seed_{args.seed}"
local_dir = f"condor/bias/{args.tag}/{prefix}"
local_dir = Path(f"condor/bias/{args.tag}/{prefix}")

# make local directory
logdir = local_dir + "/logs"
os.system(f"mkdir -p {logdir}")
logdir = local_dir / "logs"
logdir.mkdir(parents=True, exist_ok=True)

jdl_templ = f"{submitdir}/submit_bias.templ.jdl"
sh_templ = f"{submitdir}/submit_bias.templ.sh"
Expand All @@ -35,7 +34,9 @@ def main(args):
print("Submitting jobs")

for j in range(args.num_jobs):
localcondor = f"{local_dir}/{prefix}_{j}.jdl"
local_jdl = Path(f"{local_dir}/{prefix}_{j}.jdl")
local_log = Path(f"{local_dir}/{prefix}_{j}.log")

seed = args.seed + j * args.toys_per_job
jdl_args = {
"dir": local_dir,
Expand All @@ -45,7 +46,7 @@ def main(args):
"bias": args.bias,
"seed": seed,
}
write_template(jdl_templ, localcondor, jdl_args)
run_utils.write_template(jdl_templ, local_jdl, jdl_args)

localsh = f"{local_dir}/{prefix}_{j}.sh"
sh_args = {
Expand All @@ -55,16 +56,16 @@ def main(args):
"bias": args.bias,
"mintol": args.mintol,
}
write_template(sh_templ, localsh, sh_args)
run_utils.write_template(sh_templ, localsh, sh_args)
os.system(f"chmod u+x {localsh}")

if os.path.exists(f"{localcondor}.log"):
os.system(f"rm {localcondor}.log")
if local_log.exists():
local_log.unlink()

if args.submit:
os.system("condor_submit %s" % localcondor)
os.system(f"condor_submit {local_jdl}")
else:
print("To submit ", localcondor)
print("To submit ", local_jdl)


if __name__ == "__main__":
Expand Down
63 changes: 19 additions & 44 deletions src/HHbbVV/combine/submit/submit_cards.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,18 @@
Author(s): Raghav Kansal
"""
from __future__ import annotations

import argparse
import itertools
import os
from math import ceil
from string import Template
import json
import itertools
import sys

from utils import add_bool_arg, write_template, setup, parse_common_args


def add_bool_arg(parser, name, help, default=False, no_name=None):
"""Add a boolean command line argument for argparse"""
varname = "_".join(name.split("-")) # change hyphens to underscores
group = parser.add_mutually_exclusive_group(required=False)
group.add_argument("--" + name, dest=varname, action="store_true", help=help)
if no_name is None:
no_name = "no-" + name
no_help = "don't " + help
else:
no_help = help
group.add_argument("--" + no_name, dest=varname, action="store_false", help=no_help)
parser.set_defaults(**{varname: default})
from pathlib import Path

from utils import setup

def write_template(templ_file: str, out_file: str, templ_args: dict):
"""Write to ``out_file`` based on template from ``templ_file`` using ``templ_args``"""

with open(templ_file, "r") as f:
templ = Template(f.read())

with open(out_file, "w") as f:
f.write(
templ.safe_substitute(
templ_args,
)
)

from HHbbVV import run_utils
from HHbbVV.run_utils import add_bool_arg

res_mps = [
(1000, 100),
Expand Down Expand Up @@ -193,18 +166,18 @@ def write_template(templ_file: str, out_file: str, templ_args: dict):


def main(args):
global scan_txbb_wps, scan_thww_wps, scan_leadingpt_wps, scan_subleadingpt_wps
global scan_txbb_wps, scan_thww_wps, scan_leadingpt_wps, scan_subleadingpt_wps # noqa: PLW0602, PLW0603

t2_local_prefix, t2_prefix, proxy, username, submitdir = setup(args)

local_dir = f"condor/cards/{args.tag}"
local_dir = Path(f"condor/cards/{args.tag}")

templates_dir = f"/store/user/{username}/bbVV/templates/{args.templates_dir}/"
cards_dir = f"/store/user/{username}/bbVV/cards/{args.tag}/"

# make local directory
logdir = local_dir + "/logs"
os.system(f"mkdir -p {logdir}")
logdir = local_dir / "logs"
logdir.mkdir(parents=True, exist_ok=True)

# and eos directory
os.system(f"mkdir -p {t2_local_prefix}/{cards_dir}")
Expand Down Expand Up @@ -259,9 +232,10 @@ def main(args):
run_cards_dir = cards_dir

prefix = "cards" f"{'Scan' if args.scan else ''}"
localcondor = f"{local_dir}/{prefix}_{j}.jdl"
local_jdl = Path(f"{local_dir}/{prefix}_{j}.jdl")
local_log = Path(f"{local_dir}/{prefix}_{j}.log")
jdl_args = {"dir": local_dir, "prefix": prefix, "jobid": j, "proxy": proxy}
write_template(jdl_templ, localcondor, jdl_args)
run_utils.write_template(jdl_templ, local_jdl, jdl_args)

localsh = f"{local_dir}/{prefix}_{j}.sh"
sh_args = {
Expand All @@ -270,15 +244,16 @@ def main(args):
"in_cards_dir": run_cards_dir,
"datacard_args": datacard_args,
}
write_template(sh_templ, localsh, sh_args)
run_utils.write_template(sh_templ, localsh, sh_args)
os.system(f"chmod u+x {localsh}")

if os.path.exists(f"{localcondor}.log"):
os.system(f"rm {localcondor}.log")
if local_log.exists():
local_log.unlink()

print("To submit ", localcondor)
if args.submit:
os.system("condor_submit %s" % localcondor)
os.system(f"condor_submit {local_jdl}")
else:
print("To submit ", local_jdl)

nsubmit = nsubmit + 1

Expand Down
65 changes: 19 additions & 46 deletions src/HHbbVV/combine/submit/submit_ftest.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,54 +5,25 @@
Author(s): Raghav Kansal
"""
from __future__ import annotations

import argparse
import os
from math import ceil
from string import Template
import json
import sys

from utils import add_bool_arg, write_template, setup, parse_common_args


def add_bool_arg(parser, name, help, default=False, no_name=None):
"""Add a boolean command line argument for argparse"""
varname = "_".join(name.split("-")) # change hyphens to underscores
group = parser.add_mutually_exclusive_group(required=False)
group.add_argument("--" + name, dest=varname, action="store_true", help=help)
if no_name is None:
no_name = "no-" + name
no_help = "don't " + help
else:
no_help = help
group.add_argument("--" + no_name, dest=varname, action="store_false", help=no_help)
parser.set_defaults(**{varname: default})


def write_template(templ_file: str, out_file: str, templ_args: dict):
"""Write to ``out_file`` based on template from ``templ_file`` using ``templ_args``"""

with open(templ_file, "r") as f:
templ = Template(f.read())

with open(out_file, "w") as f:
f.write(
templ.safe_substitute(
templ_args,
)
)
from pathlib import Path

from utils import setup

from HHbbVV import run_utils
from HHbbVV.run_utils import add_bool_arg


def main(args):
t2_local_prefix, t2_prefix, proxy, username, submitdir = setup(args)

username = os.environ["USER"]
local_dir = f"condor/f_tests/{args.tag}_{args.low1}{args.low2}"
local_dir = Path(f"condor/f_tests/{args.tag}_{args.low1}{args.low2}")

# make local directory
logdir = local_dir + "/logs"
os.system(f"mkdir -p {logdir}")
logdir = local_dir / "logs"
logdir.mkdir(parents=True, exist_ok=True)

# and eos directories
for i, j in [(0, 0), (0, 1), (1, 0)]:
Expand All @@ -70,15 +41,17 @@ def main(args):

for j in range(args.num_jobs):
prefix = f"ftests_{args.low1}{args.low2}"
localcondor = f"{local_dir}/{prefix}_{j}.jdl"
local_jdl = Path(f"{local_dir}/{prefix}_{j}.jdl")
local_log = Path(f"{local_dir}/{prefix}_{j}.log")

jdl_args = {
"dir": local_dir,
"prefix": prefix,
"tag": args.cards_tag,
"jobid": j,
"proxy": proxy,
}
write_template(jdl_templ, localcondor, jdl_args)
run_utils.write_template(jdl_templ, local_jdl, jdl_args)

localsh = f"{local_dir}/{prefix}_{j}.sh"
sh_args = {
Expand All @@ -88,16 +61,16 @@ def main(args):
"in_seed": args.seed + j * args.toys_per_job,
"in_num_toys": args.toys_per_job,
}
write_template(sh_templ, localsh, sh_args)
run_utils.write_template(sh_templ, localsh, sh_args)
os.system(f"chmod u+x {localsh}")

if os.path.exists(f"{localcondor}.log"):
os.system(f"rm {localcondor}.log")
if local_log.exists():
local_log.unlink()

if args.submit:
os.system("condor_submit %s" % localcondor)
os.system(f"condor_submit {local_jdl}")
else:
print("To submit ", localcondor)
print("To submit ", local_jdl)


if __name__ == "__main__":
Expand Down
Loading

0 comments on commit c748c79

Please sign in to comment.