Skip to content

k4bench.cli

k4bench.cli

Command-line interface for k4bench.

Entry point registered as k4bench in pyproject.toml.

Usage examples

Single baseline run::

k4bench --xml ALLEGRO.xml \
         --ddsim-args="--enableGun --gun.particle e- --gun.distribution uniform"

Full sweep (baseline + one run per detector removed)::

k4bench --xml ALLEGRO.xml --sweep \
         --ddsim-args="--enableGun --gun.particle e- --gun.distribution uniform"

Partial sweep (baseline + one run per named detector removed)::

k4bench --xml ALLEGRO.xml --sweep-detectors ECalBarrel HCalBarrel \
         --ddsim-args="--enableGun --gun.particle e- --gun.distribution uniform"

Simulate with only specific detectors::

k4bench --xml ALLEGRO.xml \
         --include-only ECalBarrel HCalBarrel \
         --ddsim-args="--enableGun --gun.particle e- --gun.distribution uniform"

Simulate with all detectors except specific ones::

k4bench --xml ALLEGRO.xml \
         --exclude-only ECalBarrel HCalBarrel \
         --ddsim-args="--enableGun --gun.particle e- --gun.distribution uniform"

List the detectors available in a geometry (no simulation is run)::

k4bench --xml ALLEGRO.xml --list-detectors

Control output::

k4bench --xml ALLEGRO.xml \
         --output-dir logs/ \
         --pickle results.pkl \
         --ddsim-args="--enableGun --gun.particle e- --gun.distribution uniform"

Benchmark a k4run job instead (k4bench k4run --help), here CLD reconstruction run from a copy of its configuration directory, with a truth-tracking variant next to the baseline::

k4bench k4run CLDReconstruction.py \
         --stage-dir $CLDCONFIG/share/CLDConfig \
         --events 30 \
         --k4run-args="--inputFiles $PWD/sim.edm4hep.root --compactFile $K4GEO/FCCee/CLD/compact/CLD_o2_v09/CLD_o2_v09.xml" \
         --variant truth_tracking=--truthTracking

main

main(argv: list[str] | None = None) -> int

Parse arguments, run the benchmark, save results.

k4bench k4run ... benchmarks a k4run job; any other command line is a ddsim benchmark.

Returns the exit code (0 = success, 1 = error).

Source code in k4bench/cli.py
def main(argv: list[str] | None = None) -> int:
    """Parse arguments, run the benchmark, save results.

    ``k4bench k4run ...`` benchmarks a k4run job; any other command line is a
    ddsim benchmark.

    Returns the exit code (0 = success, 1 = error).
    """
    argv = sys.argv[1:] if argv is None else argv
    if argv[:1] == [K4RUN_COMMAND]:
        return _main_k4run(argv[1:])

    parser = _build_parser()
    args = parser.parse_args(argv)

    if args.list_detectors:
        return _list_detectors(args.xml)

    if args.output_dir is None:
        args.output_dir = DEFAULT_LOG_ROOT / args.xml.stem

    try:
        config = _build_config(args)
    except (ValueError, SystemExit) as exc:
        print(f"Error: {exc}", file=sys.stderr)
        return 1

    results = run_sweep(config)

    return _report(results, args)