From 2d58b4f9620034787bfe45b2253b64aef10c9725 Mon Sep 17 00:00:00 2001 From: simonge Date: Tue, 7 May 2024 23:16:45 +0100 Subject: [PATCH] Works locally and has settings to test on github --- benchmarks/LOWQ2/config.yml | 9 +- benchmarks/LOWQ2/training/Snakefile | 94 +++---------- .../LOWQ2/training/TaggerRegressionEICrecon.C | 6 +- benchmarks/LOWQ2/training/epic_edit.xml | 133 ++++++++++++++++++ benchmarks/LOWQ2/training/local_config.yml | 3 + 5 files changed, 167 insertions(+), 78 deletions(-) create mode 100644 benchmarks/LOWQ2/training/epic_edit.xml create mode 100644 benchmarks/LOWQ2/training/local_config.yml diff --git a/benchmarks/LOWQ2/config.yml b/benchmarks/LOWQ2/config.yml index 3382ffa0..fde59721 100644 --- a/benchmarks/LOWQ2/config.yml +++ b/benchmarks/LOWQ2/config.yml @@ -1,5 +1,12 @@ # Run Snakemake for the training -training: +train:LOWQ2: + extends: .det_benchmark + stage: benchmarks + script: + - snakemake --snakefile training/Snakefile --configfile config.yml +SIM_DIRECTORY: "LowQ2_G4out/" +RECO_DIRECTORY: "LowQ2_ReconOut/" +MODEL_DIRECTORY: "LowQ2_Model/" diff --git a/benchmarks/LOWQ2/training/Snakefile b/benchmarks/LOWQ2/training/Snakefile index 13e7a3ca..df9b9545 100644 --- a/benchmarks/LOWQ2/training/Snakefile +++ b/benchmarks/LOWQ2/training/Snakefile @@ -3,58 +3,32 @@ from itertools import product import os import shutil -from snakemake.remote.S3 import RemoteProvider as S3RemoteProvider -S3 = S3RemoteProvider( - endpoint_url="https://eics3.sdcc.bnl.gov:9000", - access_key_id=os.environ["S3_ACCESS_KEY"], - secret_access_key=os.environ["S3_SECRET_KEY"], -) +configfile: "local_config.yml" -EVENTS_DIRECTORY = "/scratch/EIC/Events/S3in/" -SIM_DIRECTORY = "/scratch/EIC/G4out/S3processed/" -RECO_DIRECTORY = "/scratch/EIC/ReconOut/S3in/" -RECO_DIRECTORY_P = "/scratch/EIC/ReconOut/S3processed/" -MODEL_DIRECTORY = "/scratch/EIC/LowQ2Model/" - -REMOTE_EVENTS_DIRECTORY = "EPIC/EVGEN/SIDIS/pythia6-eic/1.0.0/10x100/q2_0to1/" -REMOTE_RECO_DIRECTORY = "EPIC/RECO/24.02.1/epic_craterlake/SIDIS/pythia6-eic/1.0.0/10x100/q2_0to1/" -S3_DIR = "eictest/" -XROOTD_SERVER = "root://dtn-eic.jlab.org/" -XROOTD_DIR = "/work/eic2/" - -EVENT_EXTENSION = ".ab.hepmc3.tree.root" -SIM_EXTENSION = ".edm4hep.root" -RECO_EXTENSION = ".eicrecon.tree.edm4eic.root" +EVENT_EXTENSION = ".ab.hepmc3.tree.root" +SIM_EXTENSION = ".edm4hep.root" +RECO_EXTENSION = ".eicrecon.tree.edm4eic.root" -FILE_BASE = "pythia_ep_noradcor_10x100_q2_0.000000001_1.0_run" -XML_FILE = "/home/simong/EIC/epic/install/share/epic/epic_craterlake_10x100.xml" -XML_FILE_TAGGER = "/home/simong/EIC/epic/install/share/epic/epic_ip6.xml" -XML_FILE_EDIT = "/home/simong/EIC/epic/epic_edit.xml" -BEAM_ENERGY = "10" - -rule download_event_input: - input: - S3.remote(REMOTE_EVENTS_DIRECTORY+FILE_BASE+"{index}"+EVENT_EXTENSION), - output: - EVENTS_DIRECTORY+FILE_BASE+"{index}"+EVENT_EXTENSION, - run: - shutil.move(input[0], output[0]) +REMOTE_EVENTS_DIRECTORY = "root://dtn-eic.jlab.org//work/eic2/EPIC/EVGEN/SIDIS/pythia6-eic/1.0.0/10x100/q2_0to1/" +FILE_BASE = "pythia_ep_noradcor_10x100_q2_0.000000001_1.0_run" +XML_FILE = "epic_edit.xml" +BEAM_ENERGY = "10" def remote_file_exists(server,url): try: subprocess.check_output(['xrdfs', server, 'stat', url]) - return True + return url except subprocess.CalledProcessError: - return False - + return None +''' rule run_simulation_tagger: params: - XML=XML_FILE_EDIT, - input=lambda wildcards: XROOTD_SERVER+XROOTD_DIR+REMOTE_EVENTS_DIRECTORY+FILE_BASE+wildcards.index+EVENT_EXTENSION if remote_file_exists(XROOTD_SERVER,XROOTD_DIR+REMOTE_EVENTS_DIRECTORY+FILE_BASE+wildcards.index+EVENT_EXTENSION) else None, + XML=XML_FILE, + input=remote_file_exists(REMOTE_EVENTS_DIRECTORY+FILE_BASE+wildcards.index+EVENT_EXTENSION), output: - SIM_DIRECTORY+FILE_BASE+"{index}_tagger"+SIM_EXTENSION, + config["SIM_DIRECTORY"]+FILE_BASE+"{index}_tagger"+SIM_EXTENSION, shell: """ npsim \ --inputFiles {params.input} \ @@ -67,15 +41,7 @@ npsim \ --field.eps_max 1e-04 \ --physics.rangecut 50 \ """ - -rule download_recon: - input: - S3.remote(S3_DIR+REMOTE_RECO_DIRECTORY+FILE_BASE+"{runindex}"+".ab."+"{subindex}"+RECO_EXTENSION), - output: - RECO_DIRECTORY+FILE_BASE+"{runindex}"+".ab."+"{subindex}"+RECO_EXTENSION, - run: - shutil.move(input[0], output[0]) - +''' rule run_reconstruction: params: XML=XML_FILE, @@ -83,31 +49,13 @@ rule run_reconstruction: collections="TaggerTrackerProjectedTracks,MCScatteredElectrons,MCParticles,EventHeader", input: expand( - SIM_DIRECTORY+FILE_BASE+"{index}_tagger"+SIM_EXTENSION, - index=range(1,10), - ), - output: - RECO_DIRECTORY_P+FILE_BASE+".fab"+RECO_EXTENSION, - shell: """ -/home/simong/EIC/EICrecon/bin/eicrecon {input} -Pdd4hep:xml_files={params.XML} -Ppodio:output_include_collections={params.collections} -Ppodio:output_file={output[0]} -PLOWQ2:LowQ2Trajectories:electron_beamE={params.beam_energy} -""" - -rule run_reconstruction_remote: - params: - XML=XML_FILE, - beam_energy=BEAM_ENERGY, - collections="TaggerTrackerProjectedTracks,MCScatteredElectrons,MCParticles,EventHeader", - stringValue=RECO_DIRECTORY+FILE_BASE+"*.ab.*"+RECO_EXTENSION, - input: - expand( - RECO_DIRECTORY+FILE_BASE+"{runindex}"+".ab."+"{subindex:04d}"+RECO_EXTENSION, - subindex=range(1,4), - runindex=1 + config["SIM_DIRECTORY"]+FILE_BASE+"{index}_tagger"+SIM_EXTENSION, + index=range(1,4), ), output: - RECO_DIRECTORY_P+FILE_BASE+".ab"+RECO_EXTENSION, + config["RECO_DIRECTORY"]+FILE_BASE+".tagger_recon"+RECO_EXTENSION, shell: """ -/home/simong/EIC/EICrecon/bin/eicrecon {input} -Pdd4hep:xml_files={params.XML} -Ppodio:output_include_collections={params.collections} -Ppodio:output_file={output[0]} -PLOWQ2:LowQ2Trajectories:electron_beamE={params.beam_energy} +/home/simong/EIC/EICrecon/bin/eicrecon {input} -Pdd4hep:xml_files={params.XML} -Ppodio:output_include_collections={params.collections} -Ppodio:output_file={output} -PLOWQ2:LowQ2Trajectories:electron_beamE={params.beam_energy} """ rule low_q2_train_network: @@ -117,9 +65,9 @@ rule low_q2_train_network: method_name="DNN", model_dir="LowQ2Model" input: - train_data=RECO_DIRECTORY_P+FILE_BASE+".fab"+RECO_EXTENSION, + train_data=config["RECO_DIRECTORY"]+FILE_BASE+".tagger_recon"+RECO_EXTENSION, output: - root_output=MODEL_DIRECTORY+"trainedData.root", + root_output=config["MODEL_DIRECTORY"]+"trainedData.root", shell: """ root -l -b -q 'TaggerRegressionEICrecon.C++("{input.train_data}", "{output.root_output}", "{params.model_dir}", "{params.beam_energy}", "{params.type_name}", "{params.method_name}")' diff --git a/benchmarks/LOWQ2/training/TaggerRegressionEICrecon.C b/benchmarks/LOWQ2/training/TaggerRegressionEICrecon.C index fc2226f2..0e333dc6 100644 --- a/benchmarks/LOWQ2/training/TaggerRegressionEICrecon.C +++ b/benchmarks/LOWQ2/training/TaggerRegressionEICrecon.C @@ -97,14 +97,12 @@ void TaggerRegressionEICrecon( TString layoutString("Layout=TANH|1024,TANH|128,TANH|64,TANH|32,LINEAR"); TString trainingStrategyString("TrainingStrategy="); - //trainingStrategyString +="LearningRate=1e-4,Momentum=0,MaxEpochs=2000,ConvergenceSteps=200,BatchSize=64,TestRepetitions=1,Regularization=None,Optimizer=ADAM"; - trainingStrategyString +="LearningRate=1e-4,Momentum=0,MaxEpochs=2000,ConvergenceSteps=200,BatchSize=10,TestRepetitions=1,Regularization=None,Optimizer=ADAM"; + trainingStrategyString +="LearningRate=1e-4,Momentum=0,MaxEpochs=2000,ConvergenceSteps=200,BatchSize=64,TestRepetitions=1,Regularization=None,Optimizer=ADAM"; TString nnOptions("!H:V:ErrorStrategy=SUMOFSQUARES:WeightInitialization=XAVIERUNIFORM:RandomSeed=1234"); // Use GPU if possible on the machine - //TString architectureString("Architecture=GPU"); - TString architectureString("Architecture=CPU"); + TString architectureString("Architecture=GPU"); // Transformation of data prior to training layers - decorrelate and normalise whole dataset TString transformString("VarTransform=D,N"); diff --git a/benchmarks/LOWQ2/training/epic_edit.xml b/benchmarks/LOWQ2/training/epic_edit.xml new file mode 100644 index 00000000..79cfb1e3 --- /dev/null +++ b/benchmarks/LOWQ2/training/epic_edit.xml @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + # EPIC Detector + - https://github.com/eic/epic + - https://github.com/eic/ip6 + + + + + EPIC + + + + + + + + ## Main Constant Definitions + + The ip6 (or other ip) defines should be included first. + These files have only a define tags. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ## World Volume + + The world is a simple box, but could be a union of multiple regions. + + + + + + + + + ## Detector Subsystems + + ### IP Subsystems + + The interaction point subsystems are included before the central detector subsystems. + This is becuase the IP subsystems, for example the beampipe, will define paramters + which are subsquently used in the central detector construction -- e.g. the vertex tracker + uses the beampipe OD to help define its placement. + + The IP subsystems include the Far forward and backward regions. The list of subsystem includes: + - Interaction region beampipe + - B0 tracker + - Off-momentum tracker + - Far forward roman pots + - Zero Degree Calorimeter + - Beam line magnets. + - and more... + + + + + ## Main magnet and its field + + + + + + ## Central tracking detectors + + + + + + ## Central beam pipe + + + + + ## Far backward detectors + + + diff --git a/benchmarks/LOWQ2/training/local_config.yml b/benchmarks/LOWQ2/training/local_config.yml new file mode 100644 index 00000000..781f2bbf --- /dev/null +++ b/benchmarks/LOWQ2/training/local_config.yml @@ -0,0 +1,3 @@ +SIM_DIRECTORY: "/scratch/EIC/G4out/S3processed/" +RECO_DIRECTORY: "/scratch/EIC/ReconOut/S3processed/" +MODEL_DIRECTORY: "/scratch/EIC/LowQ2Model/"