Skip to content
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

feat: Use seeding performance in score for Optuna and Orion automatic tuning #2662

Merged
merged 10 commits into from
Feb 5, 2024
41 changes: 29 additions & 12 deletions Examples/Scripts/Optimization/Optuna_tuning.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def __init__(self, k_dup, k_time):
self.k_dup = k_dup
self.k_time = k_time

def __call__(self, trial):
def __call__(self, trial, ckf_perf=True):
LuisFelipeCoelho marked this conversation as resolved.
Show resolved Hide resolved
LuisFelipeCoelho marked this conversation as resolved.
Show resolved Hide resolved
params = []

maxSeedsPerSpM = trial.suggest_int("maxSeedsPerSpM", 0, 10)
Expand Down Expand Up @@ -110,24 +110,41 @@ def __call__(self, trial):
"deltaRMax",
]

outputDir = Path(srcDir / "Output_CKF")
outputfile = srcDir / "Output_CKF/performance_ckf.root"
if ckf_perf:
outDirName = "Output_CKF"
outputfile = srcDir / outDirName / "performance_ckf.root"
effContName = "particles"
contName = "tracks"
else:
outDirName = "Output_Seeding"
outputfile = srcDir / outDirName / "performance_seeding.root"
effContName = "seeds"
contName = "seeds"

outputDir = Path(srcDir / outDirName)
outputDir.mkdir(exist_ok=True)
run_ckf(params, keys, outputDir)
rootFile = uproot.open(outputfile)
self.res["eff"].append(rootFile["eff_particles"].member("fElements")[0])
self.res["fakerate"].append(rootFile["fakerate_tracks"].member("fElements")[0])
self.res["eff"].append(rootFile["eff_" + effContName].member("fElements")[0])
self.res["fakerate"].append(
rootFile["fakerate_" + contName].member("fElements")[0]
)
LuisFelipeCoelho marked this conversation as resolved.
Show resolved Hide resolved
self.res["duplicaterate"].append(
rootFile["duplicaterate_tracks"].member("fElements")[0]
rootFile["duplicaterate_" + contName].member("fElements")[0]
)

timingfile = srcDir / "Output_CKF/timing.tsv"
timingfile = srcDir / outDirName / "timing.tsv"
timing = pd.read_csv(timingfile, sep="\t")
time_ckf = float(
timing[timing["identifier"].str.match("Algorithm:TrackFindingAlgorithm")][
"time_perevent_s"
]
)

if ckf_perf:
time_ckf = float(
timing[
timing["identifier"].str.match("Algorithm:TrackFindingAlgorithm")
]["time_perevent_s"]
)
else:
time_ckf = 0
LuisFelipeCoelho marked this conversation as resolved.
Show resolved Hide resolved

time_seeding = float(
timing[timing["identifier"].str.match("Algorithm:SeedingAlgorithm")][
"time_perevent_s"
Expand Down
40 changes: 29 additions & 11 deletions Examples/Scripts/Optimization/Orion_tuning.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def __call__(
maxPtScattering,
deltaRMin,
deltaRMax,
ckf_perf=True,
):

params = [
Expand All @@ -106,24 +107,41 @@ def __call__(
"deltaRMax",
]

outputDir = Path(srcDir / "Output_CKF")
outputfile = srcDir / "Output_CKF/performance_ckf.root"
if ckf_perf:
outDirName = "Output_CKF"
outputfile = srcDir / outDirName / "performance_ckf.root"
effContName = "particles"
contName = "tracks"
else:
outDirName = "Output_Seeding"
outputfile = srcDir / outDirName / "performance_seeding.root"
effContName = "seeds"
contName = "seeds"

outputDir = Path(srcDir / outDirName)
outputDir.mkdir(exist_ok=True)
run_ckf(params, keys, outputDir)
rootFile = uproot.open(outputfile)
self.res["eff"].append(rootFile["eff_particles"].member("fElements")[0])
self.res["fakerate"].append(rootFile["fakerate_tracks"].member("fElements")[0])
self.res["eff"].append(rootFile["eff_" + effContName].member("fElements")[0])
self.res["fakerate"].append(
rootFile["fakerate_" + contName].member("fElements")[0]
)
self.res["duplicaterate"].append(
rootFile["duplicaterate_tracks"].member("fElements")[0]
rootFile["duplicaterate_" + contName].member("fElements")[0]
)

timingfile = srcDir / "Output_CKF/timing.tsv"
timingfile = srcDir / outDirName / "timing.tsv"
timing = pd.read_csv(timingfile, sep="\t")
time_ckf = float(
timing[timing["identifier"].str.match("Algorithm:TrackFindingAlgorithm")][
"time_perevent_s"
]
)

if ckf_perf:
time_ckf = float(
timing[
timing["identifier"].str.match("Algorithm:TrackFindingAlgorithm")
]["time_perevent_s"]
)
else:
time_ckf = 0

time_seeding = float(
timing[timing["identifier"].str.match("Algorithm:SeedingAlgorithm")][
"time_perevent_s"
Expand Down
Loading