Skip to content

Commit 68f95fc

Browse files
authored
Merge pull request #1080 from stephenswat/extras/cut_optimiser
Add black-box cut optimisation tool to extras
2 parents 7b8f5d3 + f4ee829 commit 68f95fc

File tree

7 files changed

+1035
-4
lines changed

7 files changed

+1035
-4
lines changed

extras/benchmark/pyproject.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# SPDX-License-Identifier: MPL-2.0
44

55
[project]
6-
name = ""
6+
name = "traccc-bench-tools"
77
version = "0.0.1"
88
requires-python = "~=3.9"
99
dependencies = [
@@ -15,9 +15,6 @@ dependencies = [
1515
[dependency-groups]
1616
dev = ["black>=25.1.0,<26"]
1717

18-
[tool.uv]
19-
package = false
20-
2118
[build-system]
2219
requires = ["hatchling"]
2320
build-backend = "hatchling.build"

extras/cut_optimiser/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*.csv
2+
*.csv.bak
3+
*.json
4+
.venv/
5+
!example.json

extras/cut_optimiser/example.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"input": {
3+
"event_dir": "/data/Acts/odd-simulations-20240506/geant4_ttbar_mu200",
4+
"digitization_file": "geometries/odd/odd-digi-geometric-config.json",
5+
"detector_file": "geometries/odd/odd-detray_geometry_detray.json",
6+
"grid_file": "geometries/odd/odd-detray_surface_grids_detray.json",
7+
"material_file": "geometries/odd/odd-detray_material_detray.json"
8+
},
9+
"config": {
10+
"truth-finding-min-track-candidates": 7,
11+
"track-candidates-range": "7:100"
12+
},
13+
"parameters": {
14+
"max-num-branches-per-surface": [1, 2, 3],
15+
"max-num-skipping-per-cand": [2, 3],
16+
"chi2-max": [2.5, 5.0, 7.5, 10.0, 15.0, 20.0]
17+
}
18+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import argparse
2+
import csv
3+
import logging
4+
import pathlib
5+
6+
7+
log = logging.getLogger("find_pareto_set")
8+
9+
10+
def main():
11+
parser = argparse.ArgumentParser()
12+
13+
parser.add_argument(
14+
"db",
15+
type=pathlib.Path,
16+
help="the CSV database file",
17+
)
18+
19+
parser.add_argument(
20+
"-v",
21+
"--verbose",
22+
help="enable verbose output",
23+
action="store_true",
24+
)
25+
26+
args = parser.parse_args()
27+
28+
logging.basicConfig(
29+
level=logging.DEBUG if (args.verbose or False) else logging.INFO,
30+
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
31+
)
32+
33+
results = []
34+
35+
total_results = 0
36+
37+
with open(args.db, "r") as f:
38+
reader = csv.DictReader(f)
39+
for i in reader:
40+
total_results += 1
41+
if i["success"] != "0":
42+
results.append({k: float(v) for k, v in i.items()})
43+
44+
log.info(
45+
"Database contained %d results of which %d are valid",
46+
total_results,
47+
len(results),
48+
)
49+
50+
pareto_set = []
51+
52+
for i, m in enumerate(results):
53+
for j, n in enumerate(results):
54+
if i == j:
55+
continue
56+
57+
if (
58+
n["rec_throughput"] <= m["rec_throughput"]
59+
and n["efficiency"] >= m["efficiency"]
60+
and n["fake_rate"] <= m["fake_rate"]
61+
and n["duplicate_rate"] <= m["duplicate_rate"]
62+
):
63+
log.debug(
64+
"Removing %s from the Pareto set because %s is superior",
65+
str(n),
66+
str(m),
67+
)
68+
break
69+
else:
70+
pareto_set.append(m)
71+
72+
log.info("Pareto set contains %d elements:", len(pareto_set))
73+
74+
for i in sorted(pareto_set, key=lambda x: x["rec_throughput"], reverse=True):
75+
log.info(
76+
" Eff. %.2f, fake rate %.2f, duplicate rate %.2f with reciprocal througput %.1fms is achieved by setup {%s}",
77+
100.0 * i["efficiency"],
78+
i["fake_rate"],
79+
i["duplicate_rate"],
80+
i["rec_throughput"] * 1000.0,
81+
", ".join(
82+
"%s: %s" % (k, str(v))
83+
for k, v in i.items()
84+
if k
85+
not in [
86+
"efficiency",
87+
"fake_rate",
88+
"duplicate_rate",
89+
"rec_throughput",
90+
"success",
91+
]
92+
),
93+
)
94+
95+
96+
if __name__ == "__main__":
97+
main()

0 commit comments

Comments
 (0)