Skip to content

Commit

Permalink
ecal_gaps: enable caching for simulation/reconstruction
Browse files Browse the repository at this point in the history
  • Loading branch information
veprbl committed Nov 20, 2024
1 parent 417e954 commit 1d76774
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 30 deletions.
31 changes: 31 additions & 0 deletions Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,37 @@ exit 1
"""


import ctypes.util
import functools
import json
import os
import warnings
from snakemake.logging import logger


@functools.cache
def get_spack_package_hash(package_name):
try:
ver_info = json.loads(subprocess.check_output(["spack", "find", "--json", package_name]))
return ver_info[0]["package_hash"]
except FileNotFoundError as e:
logger.warning("Spack is not installed")
return ""
except subprocess.CalledProcessError as e:
print(e)
return ""


@functools.cache
def find_epic_libraries():
# if library is not found (not avaliable) we return an empty list to let DAG still evaluate
libs = []
lib = ctypes.util.find_library("epic")
if lib is not None:
libs.append(os.environ["DETECTOR_PATH"] + "/../../lib/" + lib)
return libs


rule warmup_run:
output:
"warmup/{DETECTOR_CONFIG}.edm4hep.root",
Expand Down
27 changes: 0 additions & 27 deletions benchmarks/backwards_ecal/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,6 @@ def get_n_events(wildcards):
n_events = int(n_events // (energy ** 0.5))
return n_events

import functools
import json
import ctypes.util
import warnings
from snakemake.logging import logger

@functools.cache
def get_spack_package_hash(package_name):
try:
ver_info = json.loads(subprocess.check_output(["spack", "find", "--json", package_name]))
return ver_info[0]["package_hash"]
except FileNotFoundError as e:
logger.warning("Spack is not installed")
return ""
except subprocess.CalledProcessError as e:
print(e)
return ""

@functools.cache
def find_epic_libraries():
# if library is not found (not avaliable) we return an empty list to let DAG still evaluate
libs = []
lib = ctypes.util.find_library("epic")
if lib is not None:
libs.append(os.environ["DETECTOR_PATH"] + "/../../lib/" + lib)
return libs


rule backwards_ecal_sim:
input:
Expand Down
17 changes: 14 additions & 3 deletions benchmarks/ecal_gaps/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ rule ecal_gaps_sim:
input:
steering_file=ancient("EPIC/EVGEN/SINGLE/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.steer"),
warmup="warmup/{DETECTOR_CONFIG}.edm4hep.root",
geometry_lib=find_epic_libraries(),
output:
"sim_output/ecal_gaps/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.edm4hep.root",
log:
Expand All @@ -16,18 +17,24 @@ rule ecal_gaps_sim:
INDEX="\d{4}",
params:
N_EVENTS=1000
SEED=lambda wildcards: "1" + wildcards.INDEX,
DETECTOR_PATH=os.environ["DETECTOR_PATH"],
DETECTOR_CONFIG=lambda wildcards: wildcards.DETECTOR_CONFIG,
DD4HEP_HASH=get_spack_package_hash("dd4hep"),
NPSIM_HASH=get_spack_package_hash("npsim"),
cache: True
shell:
"""
set -m # monitor mode to prevent lingering processes
exec ddsim \
--runType batch \
--enableGun \
--steeringFile "{input.steering_file}" \
--random.seed 1{wildcards.INDEX} \
--random.seed {wildcards.SEED} \
--filter.tracker edep0 \
-v WARNING \
--numberOfEvents {params.N_EVENTS} \
--compactFile $DETECTOR_PATH/{wildcards.DETECTOR_CONFIG}.xml \
--compactFile {wildcards.DETECTOR_PATH}/{wildcards.DETECTOR_CONFIG}.xml \
--outputFile {output}
"""

Expand All @@ -41,9 +48,13 @@ rule ecal_gaps_recon:
"sim_output/ecal_gaps/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.eicrecon.tree.edm4eic.root.log",
wildcard_constraints:
INDEX="\d{4}",
params:
DETECTOR_CONFIG=lambda wildcards: wildcards.DETECTOR_CONFIG,
EICRECON_HASH=get_spack_package_hash("eicrecon"),
cache: True
shell: """
set -m # monitor mode to prevent lingering processes
exec env DETECTOR_CONFIG={wildcards.DETECTOR_CONFIG} \
exec env DETECTOR_CONFIG={params.DETECTOR_CONFIG} \
eicrecon {input} -Ppodio:output_file={output} \
-Ppodio:output_collections=EcalEndcapNRecHits,EcalBarrelScFiRecHits,EcalBarrelImagingRecHits,EcalEndcapPRecHits,MCParticles
"""
Expand Down

0 comments on commit 1d76774

Please sign in to comment.