ATLAS Offline Software
Loading...
Searching...
No Matches
muonEdgeSegmentInference.py
Go to the documentation of this file.
1#!/usr/bin/env python
2# Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3# Test only the segment-edge inference decoration.
4
5def main(args):
6 from MuonGeoModelTestR4.testGeoModel import setupGeoR4TestCfg
7 from MuonConfig.MuonConfigUtils import executeTest
8 from AthenaConfiguration.AllConfigFlags import initConfigFlags
9 flags = initConfigFlags()
10
11 if args.athenaDebug:
12 flags.Exec.DebugMessageComponents = [
13 "SegmentEdgeInferenceAlg",
14 "SegmentEdgeInferenceAlg.SegmentEdgeClassifierTool",
15 "SegmentEdgeInferenceAlg.SegmentTrackCandidateBuilderTool",
16 "SegmentEdgeInferenceAlg.SegmentEdgeClassifierTool.OnnxRuntimeSessionToolCPU",
17 "SegmentEdgeInferenceAlg.SegmentEdgeClassifierTool.OnnxRuntimeSessionToolCUDA",
18 ]
19 print("INFO: Exec.DebugMessageComponents configured:", flags.Exec.DebugMessageComponents)
20
21 from AthOnnxComps.OnnxRuntimeFlags import OnnxRuntimeType
22 use_gpu_requested = args.use_gpu if args.use_gpu is not None else True
23 gpu_available = False
24 try:
25 import onnxruntime as ort
26 gpu_available = "CUDAExecutionProvider" in ort.get_available_providers()
27 except Exception:
28 try:
29 import torch
30 gpu_available = torch.cuda.is_available()
31 except Exception:
32 gpu_available = False
33 if use_gpu_requested and gpu_available:
34 flags.AthOnnx.ExecutionProvider = OnnxRuntimeType.CUDA
35 else:
36 flags.AthOnnx.ExecutionProvider = OnnxRuntimeType.CPU
37
38 flags, cfg = setupGeoR4TestCfg(args, flags)
39
40 from MuonConfig.MuonDataPrepConfig import xAODUncalibMeasPrepCfg
41 cfg.merge(xAODUncalibMeasPrepCfg(flags))
42
43 from MuonSpacePointFormation.SpacePointFormationConfig import MuonSpacePointFormationCfg
44 cfg.merge(MuonSpacePointFormationCfg(flags))
45
46 from MuonPatternRecognitionAlgs.MuonPatternRecognitionConfig import MuonPatternRecognitionCfg
47 cfg.merge(MuonPatternRecognitionCfg(flags))
48
49 output_level = 1 if args.athenaDebug else 3
50 from MuonInference.InferenceConfig import SegmentEdgeInferenceAlgCfg
51 cfg.merge(SegmentEdgeInferenceAlgCfg(flags, EdgeModelPath=args.edgeModel,
52 OutputLevel=output_level))
53
54 executeTest(cfg)
55
56if __name__ == "__main__":
57 from MuonGeoModelTestR4.testGeoModel import SetupArgParser, MuonPhaseIITestDefaults
58 parser = SetupArgParser()
59 parser.set_defaults(nEvents=-1)
60 parser.set_defaults(inputFile=MuonPhaseIITestDefaults.HITS_PG_R3)
61 parser.add_argument("--edgeModel", required=True, help="ONNX segment edge classifier")
62 parser.add_argument("--athenaDebug", action="store_true", help="Enable Athena DEBUG verbosity for MessageSvc and key algorithms")
63 parser.add_argument("--use-gpu", action="store_true", dest="use_gpu", default=True,
64 help="Use GPU for ONNX inference (default: True)")
65 parser.add_argument("--use-cpu", dest="use_gpu", action="store_false",
66 help="Force CPU for ONNX inference")
67 main(parser.parse_args())
void print(char *figname, TCanvas *c1)
int main()
Definition hello.cxx:18