Warning, /detector_benchmarks/doc/cache-policy.md is written in an unsupported language. File is not indexed.
0001 Snakemake output cache policy
0002 =============================
0003
0004 This document specifies what the detector benchmarks store in Snakemake's
0005 between-workflow output cache, how a cache entry is named, and under which
0006 conditions the cache is not used. It describes the behaviour of the Snakemake
0007 version in the CI container (9.6.3) together with this repository's
0008 `Snakefile`, `.gitlab-ci.yml` and `garbage-collect.py`.
0009
0010 Update this document whenever a rule gains or loses `cache: True`, a cached
0011 rule changes its `params`/`input`, or the CI cache handling changes.
0012
0013
0014 1. Notation
0015 -----------
0016
0017 The grammar uses EBNF (ISO/IEC 14977):
0018
0019 | Notation | Meaning |
0020 |---|---|
0021 | `a = b ;` | `a` is defined as `b` |
0022 | `a , b` | `a` followed by `b` (concatenation) |
0023 | `a \| b` | `a` or `b` |
0024 | `{ a }` | zero or more `a`, in the order stated in the comment |
0025 | `[ a ]` | optional `a` |
0026 | `"x"` | the literal string `x` |
0027 | `? text ?` | a value defined in prose |
0028 | `(* text *)` | comment |
0029
0030 `sha256hex(x)` is the lowercase hex SHA-256 digest of the UTF-8 bytes of `x`.
0031
0032
0033 2. Cache entries
0034 ----------------
0035
0036 ```ebnf
0037 cache entry = cache directory , "/" , provenance hash , output suffix ;
0038
0039 cache directory = shared cache | pipeline cache ;
0040 shared cache = ? $SNAKEMAKE_OUTPUT_CACHE as set by the eicweb CI/CD variable,
0041 i.e. /scratch/snakemake-cache; shared with physics_benchmarks ? ;
0042 pipeline cache = ? $LOCAL_DATA_PATH ? , "/snakemake-cache" ;
0043 (* /scratch/detector_benchmarks_<CI_PIPELINE_ID>/snakemake-cache *)
0044
0045 output suffix = ? the last extension of the job's single output file
0046 (Python Path(output).suffix), e.g. ".root" for
0047 "x.edm4hep.rnt.root", ".hepmc" for "x.hepmc" ? ;
0048 ```
0049
0050 Every cached rule has exactly one output file, so a job has exactly one cache
0051 entry. The job's output path in the pipeline (`sim_output/...`, `EPIC/...`)
0052 becomes a symbolic link to the cache entry.
0053
0054
0055 3. Provenance hash (cache key)
0056 ------------------------------
0057
0058 ```ebnf
0059 provenance hash = sha256hex( job hash , "0.1" ) ;
0060 (* "0.1" is the version of Snakemake's hashing scheme *)
0061
0062 job hash = sha256hex( code ,
0063 { param } , (* sorted by param name *)
0064 { input content hash } , (* sorted by hash value *)
0065 software ,
0066 { upstream hash } ) ; (* sorted by hash value *)
0067
0068 code = shell template | script source | notebook source | wrapper source ;
0069 shell template = ? the rule's shell: string before formatting: placeholders such as
0070 {wildcards.X}, {params.X}, {input}, {output}, {threads} appear
0071 literally, never their values ? ;
0072
0073 param = [ param name ] , json value ;
0074 param name = ? name of a params: entry ? ; (* absent for positional params *)
0075 json value = ? json.dumps(value, sort_keys=True) of the param's value
0076 for this job, after lambdas are evaluated ? ;
0077
0078 input content hash = sha256hex( ? the bytes of an input file, read through
0079 symbolic links ? ) ;
0080 (* only for inputs that no job in the DAG produces *)
0081
0082 software = "" ;
0083 (* Snakemake adds container or conda identifiers only with
0084 --software-deployment-method apptainer/conda; CI runs without
0085 it, so the singularity: directives of the rules are ignored *)
0086
0087 upstream hash = job hash ;
0088 (* of each job that produces one of this job's inputs, cached or
0089 not, computed with this same definition, recursively *)
0090 ```
0091
0092 Consequences:
0093
0094 - Only `params` values and the contents of non-generated input files carry
0095 per-job information into the key. A wildcard that is used only in the
0096 `shell:` command or in the `input:`/`output:` paths does not change the
0097 key (see the README section on caching).
0098 - Software versions enter the key only through:
0099 - the content of `libepic.so` (`geometry_lib=find_epic_libraries()` input),
0100 - the `DD4HEP_HASH`, `NPSIM_HASH` and `EICRECON_HASH` params
0101 (`get_spack_package_hash()`: the Spack DAG hash of the first installation
0102 `spack find --json <package>` lists, which covers its version, commit,
0103 variants, compiler and dependencies),
0104 - upstream hashes of jobs whose key contains one of the above.
0105 - `libepic.so` embeds its Spack installation prefix in its RPATH. The prefix
0106 contains the Spack hash of the epic installation, which includes the epic
0107 commit (CI specs carry a `commit=<sha>` variant), e.g.
0108 `epic-git.<commit>_main-<hash>` or `epic-main-<hash>`. Its content, and
0109 therefore every key that includes it, changes with every epic commit.
0110 epic's compact XML files, field maps and calibration files are not hashed
0111 themselves.
0112 - Upgrading Snakemake can change every key (for example, newer versions hash
0113 inputs as `sha256:<hex>` instead of `<hex>`), which makes existing entries
0114 unreachable.
0115
0116
0117 4. Cached rules
0118 ---------------
0119
0120 ```ebnf
0121 cached rule = eligible rule - excluded rule ;
0122 eligible rule = ? a rule with "cache: True" (the 57 rules in the table below) ? ;
0123 excluded rule = ? an eligible rule whose params include a name listed in
0124 $BENCHMARKS_CACHE_EXCLUDE_PARAMS ? ;
0125 ```
0126
0127 CI does not set `BENCHMARKS_CACHE_EXCLUDE_PARAMS` (section 6), so in CI every
0128 eligible rule is cached.
0129
0130 The table lists every eligible rule in this repository.
0131
0132 - **epic in key**: the rule has the `libepic.so` content in its own key, gets
0133 it through the named upstream rule, or does not depend on the epic build
0134 (—).
0135 - **Spack hash params**: software identifiers among the rule's `params`.
0136
0137 `fetch_epic` downloads input files (`EPIC/...`) from XRootD or S3. Its key
0138 contains its shell template, which depends on `remote_provider` in
0139 `snakemake.yml`, and the `PATH` param.
0140
0141 | Rule | Snakefile | Kind | epic in key | Spack hash params |
0142 |---|---|---|---|---|
0143 | `backgrounds_sim` | [benchmarks/backgrounds/Snakefile](../benchmarks/backgrounds/Snakefile) | simulation | `libepic.so` content | `DD4HEP_HASH`, `NPSIM_HASH` |
0144 | `backwards_ecal_sim` | [benchmarks/backwards_ecal/Snakefile](../benchmarks/backwards_ecal/Snakefile) | simulation | `libepic.so` content | `DD4HEP_HASH`, `NPSIM_HASH` |
0145 | `backwards_ecal_recon` | [benchmarks/backwards_ecal/Snakefile](../benchmarks/backwards_ecal/Snakefile) | reconstruction | via `backwards_ecal_sim` | `EICRECON_HASH` |
0146 | `backwards_ecal_dis_recon` | [benchmarks/backwards_ecal/Snakefile](../benchmarks/backwards_ecal/Snakefile) | reconstruction | via `trk_dis_sim` | `EICRECON_HASH` |
0147 | `emcal_barrel_particles` | [benchmarks/barrel_ecal/Snakefile](../benchmarks/barrel_ecal/Snakefile) | simulation | `libepic.so` content | `DD4HEP_HASH`, `NPSIM_HASH` |
0148 | `beamline_steering_sim` | [benchmarks/beamline/Snakefile](../benchmarks/beamline/Snakefile) | simulation | `libepic.so` content | `DD4HEP_HASH`, `NPSIM_HASH` |
0149 | `beamline_acceptance_sim` | [benchmarks/beamline/Snakefile](../benchmarks/beamline/Snakefile) | simulation | `libepic.so` content | `DD4HEP_HASH`, `NPSIM_HASH` |
0150 | `calo_pid_sim` | [benchmarks/calo_pid/Snakefile](../benchmarks/calo_pid/Snakefile) | simulation | `libepic.so` content | `DD4HEP_HASH`, `NPSIM_HASH` |
0151 | `calo_pid_recon` | [benchmarks/calo_pid/Snakefile](../benchmarks/calo_pid/Snakefile) | reconstruction | via `calo_pid_sim` | `EICRECON_HASH` |
0152 | `ecal_gaps_sim` | [benchmarks/ecal_gaps/Snakefile](../benchmarks/ecal_gaps/Snakefile) | simulation | `libepic.so` content | `DD4HEP_HASH`, `NPSIM_HASH` |
0153 | `ecal_gaps_recon` | [benchmarks/ecal_gaps/Snakefile](../benchmarks/ecal_gaps/Snakefile) | reconstruction | via `ecal_gaps_sim` | `EICRECON_HASH` |
0154 | `far_forward_dvcs_sim` | [benchmarks/far_forward_dvcs/Snakefile](../benchmarks/far_forward_dvcs/Snakefile) | simulation | `libepic.so` content | `DD4HEP_HASH`, `NPSIM_HASH` |
0155 | `far_forward_dvcs_reco` | [benchmarks/far_forward_dvcs/Snakefile](../benchmarks/far_forward_dvcs/Snakefile) | reconstruction | via `far_forward_dvcs_sim` | `EICRECON_HASH` |
0156 | `lowq2_training_sim` | [benchmarks/lowq2_reconstruction/Snakefile](../benchmarks/lowq2_reconstruction/Snakefile) | simulation | `libepic.so` content | `DD4HEP_HASH`, `NPSIM_HASH` |
0157 | `lowq2_reconstruction_particles_eicrecon` | [benchmarks/lowq2_reconstruction/Snakefile](../benchmarks/lowq2_reconstruction/Snakefile) | reconstruction | via `lowq2_training_sim` | `EICRECON_HASH` |
0158 | `lowq2_reconstruction_tensors_eicrecon` | [benchmarks/lowq2_reconstruction/Snakefile](../benchmarks/lowq2_reconstruction/Snakefile) | reconstruction | via `lowq2_training_sim` | `EICRECON_HASH` |
0159 | `lowq2_steering_reconstruction_particles_trained_eicrecon` | [benchmarks/lowq2_reconstruction/Snakefile](../benchmarks/lowq2_reconstruction/Snakefile) | reconstruction | via `lowq2_training_sim` | `EICRECON_HASH` |
0160 | `tracking_performance_sim` | [benchmarks/tracking_performances/Snakefile](../benchmarks/tracking_performances/Snakefile) | simulation | `libepic.so` content | `DD4HEP_HASH`, `NPSIM_HASH` |
0161 | `tracking_performance_recon` | [benchmarks/tracking_performances/Snakefile](../benchmarks/tracking_performances/Snakefile) | reconstruction | via `tracking_performance_sim` | `EICRECON_HASH` |
0162 | `trk_dis_sim` | [benchmarks/tracking_performances_dis/Snakefile](../benchmarks/tracking_performances_dis/Snakefile) | simulation | `libepic.so` content | `DD4HEP_HASH`, `NPSIM_HASH` |
0163 | `trk_dis_reco` | [benchmarks/tracking_performances_dis/Snakefile](../benchmarks/tracking_performances_dis/Snakefile) | reconstruction | via `trk_dis_sim` | `EICRECON_HASH` |
0164 | `lfhcal_sim` | [benchmarks/lfhcal/Snakefile](../benchmarks/lfhcal/Snakefile) | simulation | `libepic.so` content | `DD4HEP_HASH`, `NPSIM_HASH` |
0165 | `lfhcal_recon` | [benchmarks/lfhcal/Snakefile](../benchmarks/lfhcal/Snakefile) | reconstruction | via `lfhcal_sim` | `EICRECON_HASH` |
0166 | `zdc_lyso_sim` | [benchmarks/zdc_lyso/Snakefile](../benchmarks/zdc_lyso/Snakefile) | simulation | `libepic.so` content | `DD4HEP_HASH`, `NPSIM_HASH` |
0167 | `zdc_lyso_reco` | [benchmarks/zdc_lyso/Snakefile](../benchmarks/zdc_lyso/Snakefile) | reconstruction | via `zdc_lyso_sim` | `EICRECON_HASH` |
0168 | `zdc_neutron_sim` | [benchmarks/zdc_neutron/Snakefile](../benchmarks/zdc_neutron/Snakefile) | simulation | `libepic.so` content | `DD4HEP_HASH`, `NPSIM_HASH` |
0169 | `zdc_neutron_reco` | [benchmarks/zdc_neutron/Snakefile](../benchmarks/zdc_neutron/Snakefile) | reconstruction | via `zdc_neutron_sim` | `EICRECON_HASH` |
0170 | `insert_muon_simulate` | [benchmarks/insert_muon/Snakefile](../benchmarks/insert_muon/Snakefile) | simulation | `libepic.so` content | `DD4HEP_HASH`, `NPSIM_HASH` |
0171 | `insert_muon_recon` | [benchmarks/insert_muon/Snakefile](../benchmarks/insert_muon/Snakefile) | reconstruction | via `insert_muon_simulate` | `EICRECON_HASH` |
0172 | `irt_sim` | [benchmarks/irt/Snakefile](../benchmarks/irt/Snakefile) | simulation | `libepic.so` content | `DD4HEP_HASH`, `NPSIM_HASH` |
0173 | `irt_recon` | [benchmarks/irt/Snakefile](../benchmarks/irt/Snakefile) | reconstruction | via `irt_sim` | `EICRECON_HASH` |
0174 | `zdc_lambda_simulate` | [benchmarks/zdc_lambda/Snakefile](../benchmarks/zdc_lambda/Snakefile) | simulation | `libepic.so` content | `DD4HEP_HASH`, `NPSIM_HASH` |
0175 | `zdc_lambda_recon` | [benchmarks/zdc_lambda/Snakefile](../benchmarks/zdc_lambda/Snakefile) | reconstruction | via `zdc_lambda_simulate` | `EICRECON_HASH` |
0176 | `zdc_photon_simulate` | [benchmarks/zdc_photon/Snakefile](../benchmarks/zdc_photon/Snakefile) | simulation | `libepic.so` content | `DD4HEP_HASH`, `NPSIM_HASH` |
0177 | `zdc_photon_recon` | [benchmarks/zdc_photon/Snakefile](../benchmarks/zdc_photon/Snakefile) | reconstruction | via `zdc_photon_simulate` | `EICRECON_HASH` |
0178 | `zdc_pi0_simulate` | [benchmarks/zdc_pi0/Snakefile](../benchmarks/zdc_pi0/Snakefile) | simulation | `libepic.so` content | `DD4HEP_HASH`, `NPSIM_HASH` |
0179 | `zdc_pi0_recon` | [benchmarks/zdc_pi0/Snakefile](../benchmarks/zdc_pi0/Snakefile) | reconstruction | via `zdc_pi0_simulate` | `EICRECON_HASH` |
0180 | `zdc_sigma_simulate` | [benchmarks/zdc_sigma/Snakefile](../benchmarks/zdc_sigma/Snakefile) | simulation | `libepic.so` content | `DD4HEP_HASH`, `NPSIM_HASH` |
0181 | `zdc_sigma_recon` | [benchmarks/zdc_sigma/Snakefile](../benchmarks/zdc_sigma/Snakefile) | reconstruction | via `zdc_sigma_simulate` | `EICRECON_HASH` |
0182 | `insert_neutron_simulate` | [benchmarks/insert_neutron/Snakefile](../benchmarks/insert_neutron/Snakefile) | simulation | `libepic.so` content | `DD4HEP_HASH`, `NPSIM_HASH` |
0183 | `insert_neutron_recon` | [benchmarks/insert_neutron/Snakefile](../benchmarks/insert_neutron/Snakefile) | reconstruction | via `insert_neutron_simulate` | `EICRECON_HASH` |
0184 | `insert_tau_simulate` | [benchmarks/insert_tau/Snakefile](../benchmarks/insert_tau/Snakefile) | simulation | `libepic.so` content | `DD4HEP_HASH`, `NPSIM_HASH` |
0185 | `insert_tau_recon` | [benchmarks/insert_tau/Snakefile](../benchmarks/insert_tau/Snakefile) | reconstruction | via `insert_tau_simulate` | `EICRECON_HASH` |
0186 | `femc_electron_simulate` | [benchmarks/femc_electron/Snakefile](../benchmarks/femc_electron/Snakefile) | simulation | `libepic.so` content | `DD4HEP_HASH`, `NPSIM_HASH` |
0187 | `femc_electron_recon` | [benchmarks/femc_electron/Snakefile](../benchmarks/femc_electron/Snakefile) | reconstruction | via `femc_electron_simulate` | `EICRECON_HASH` |
0188 | `femc_photon_simulate` | [benchmarks/femc_photon/Snakefile](../benchmarks/femc_photon/Snakefile) | simulation | `libepic.so` content | `DD4HEP_HASH`, `NPSIM_HASH` |
0189 | `femc_photon_recon` | [benchmarks/femc_photon/Snakefile](../benchmarks/femc_photon/Snakefile) | reconstruction | via `femc_photon_simulate` | `EICRECON_HASH` |
0190 | `femc_pi0_simulate` | [benchmarks/femc_pi0/Snakefile](../benchmarks/femc_pi0/Snakefile) | simulation | `libepic.so` content | `DD4HEP_HASH`, `NPSIM_HASH` |
0191 | `femc_pi0_recon` | [benchmarks/femc_pi0/Snakefile](../benchmarks/femc_pi0/Snakefile) | reconstruction | via `femc_pi0_simulate` | `EICRECON_HASH` |
0192 | `nhcal_acceptance_simulate` | [benchmarks/nhcal_acceptance/Snakefile](../benchmarks/nhcal_acceptance/Snakefile) | simulation | `libepic.so` content | `DD4HEP_HASH`, `NPSIM_HASH` |
0193 | `nhcal_basic_distribution_simulate` | [benchmarks/nhcal_basic_distribution/Snakefile](../benchmarks/nhcal_basic_distribution/Snakefile) | simulation | `libepic.so` content | `DD4HEP_HASH`, `NPSIM_HASH` |
0194 | `nhcal_sampling_fraction_simulate` | [benchmarks/nhcal_sampling_fraction/Snakefile](../benchmarks/nhcal_sampling_fraction/Snakefile) | simulation | `libepic.so` content | `DD4HEP_HASH`, `NPSIM_HASH` |
0195 | `nhcal_dimuon_photoproduction_simulate` | [benchmarks/nhcal_dimuon_photoproduction/Snakefile](../benchmarks/nhcal_dimuon_photoproduction/Snakefile) | simulation | `libepic.so` content | `DD4HEP_HASH`, `NPSIM_HASH` |
0196 | `nhcal_dimuon_photoproduction_recon` | [benchmarks/nhcal_dimuon_photoproduction/Snakefile](../benchmarks/nhcal_dimuon_photoproduction/Snakefile) | reconstruction | via `nhcal_dimuon_photoproduction_simulate` | `EICRECON_HASH` |
0197 | `nhcal_pion_rejection_simulate` | [benchmarks/nhcal_pion_rejection/Snakefile](../benchmarks/nhcal_pion_rejection/Snakefile) | simulation | `libepic.so` content | `DD4HEP_HASH`, `NPSIM_HASH` |
0198 | `nhcal_pion_rejection_recon` | [benchmarks/nhcal_pion_rejection/Snakefile](../benchmarks/nhcal_pion_rejection/Snakefile) | reconstruction | via `nhcal_pion_rejection_simulate` | `EICRECON_HASH` |
0199 | `fetch_epic` | [Snakefile](../Snakefile) | download | — | — |
0200
0201 Rules without `cache: True` (event generators, `warmup_run`, analyses,
0202 `compile_analysis`, `org2py`, `metadata`, …) are never cached. Their job hash
0203 still enters the key of cached jobs that consume their outputs.
0204
0205
0206 5. When the cache is consulted
0207 ------------------------------
0208
0209 Snakemake first decides which jobs have to run (output missing, older than an
0210 input, or forced). Only for those jobs, and only for cached rules:
0211
0212 ```ebnf
0213 cached job run = cache hit | cache miss ;
0214 cache hit = ? the entry exists: the output path becomes a symbolic link
0215 to the entry and the job is not executed ? ;
0216 cache miss = ? the job is executed, its output is moved into the cache
0217 directory and replaced by a symbolic link to the entry ? ;
0218 ```
0219
0220 Jobs whose output already exists and is up to date neither read nor write the
0221 cache. A job that must run because an input was regenerated (for example
0222 `warmup.edm4hep.root`, which each CI job recreates) does consult the cache, so
0223 it normally gets the entry stored by an earlier job instead of re-running.
0224
0225 Before running Snakemake, every CI job removes symbolic links under
0226 `sim_output/` and `EPIC/` whose cache entry was deleted, so that their outputs
0227 are fetched or regenerated.
0228
0229
0230 6. When the shared cache is skipped
0231 -----------------------------------
0232
0233 The cache directory is chosen in the `before_script` of `.det_benchmark`
0234 (inherited by every CI job that runs Snakemake), based on `GITHUB_REPOSITORY`
0235 and `GITHUB_PR`, which the eic/epic and eic/EICrecon GitHub workflows pass
0236 through eic/containers to the pipelines it triggers. `GITHUB_PR` is the pull
0237 request number for `pull_request` events and empty for all other events
0238 (merge queue, tags, branch pushes, manual runs):
0239
0240 ```ebnf
0241 policy = epic policy | default policy ;
0242
0243 epic policy = ( GITHUB_REPOSITORY = "eic/epic" ) , ( GITHUB_PR <> "" ) ,
0244 ( cache directory = pipeline cache ) ;
0245
0246 default policy = ? any other GITHUB_REPOSITORY (including empty), or GITHUB_PR = "" ? ,
0247 ( cache directory = shared cache ) ;
0248 ```
0249
0250 Rationale: a pipeline that tests an epic or EICrecon pull request builds the
0251 PR's head commit (`epic@git.<sha>=main`, `eicrecon@git.<sha>=main`), so its
0252 keys contain that commit's `libepic.so` or `EICRECON_HASH`. The head commit
0253 never becomes `main` as is (epic only allows squash merges through its merge
0254 queue, and GitHub never fast-forwards a pull request), so no later pipeline
0255 builds the same software and such entries could never be retrieved again.
0256
0257 - For an epic PR, every cached output depends on the epic build, so the whole
0258 cache moves into the pipeline. Jobs of the same pipeline still share
0259 entries, as described in section 5.
0260 - An EICrecon PR uses the shared cache, including for reconstruction, even
0261 though its reconstruction entries are never retrieved by later pipelines
0262 (section 8). Its simulations do not depend on EICrecon and are shared with
0263 other pipelines. Reconstruction stays cached because jobs of the same
0264 pipeline share outputs under `sim_output/`: when a job reruns a cached
0265 reconstruction it only replaces the output with a link to the cache entry,
0266 but when it reruns an uncached one it rewrites the shared output in place
0267 while another job may be reading it.
0268 - An epic merge-queue run tests the squash commit that `main` is then
0269 fast-forwarded to, which the next nightly container build also builds, so
0270 it uses the shared cache. Tag, branch and manual runs also use the shared
0271 cache: they are rare, and their entries are evicted by garbage collection.
0272
0273 Complete list of conditions under which an output is neither read from nor
0274 written to the shared cache:
0275
0276 | # | Condition | Effect |
0277 |---|---|---|
0278 | 1 | The rule has no `cache: True` | Never cached |
0279 | 2 | Snakemake runs without `--cache`: any run outside CI unless `--cache` is passed, and the `RUN_EXTENDED_BENCHMARK` steps in `benchmarks/barrel_ecal/config.yml`, which do not pass `$SNAKEMAKE_FLAGS` | Nothing cached; Snakemake warns that the rules are "eligible for caching" |
0280 | 3 | `--cache` is given but `SNAKEMAKE_OUTPUT_CACHE` is not set | Nothing cached; Snakemake warns that no cache location is set |
0281 | 4 | The job's output exists and is up to date | Cache not consulted (section 5) |
0282 | 5 | `GITHUB_REPOSITORY` is `eic/epic` and `GITHUB_PR` is not empty | All cached rules use the pipeline cache instead of the shared cache |
0283 | 6 | The rule has a param listed in `BENCHMARKS_CACHE_EXCLUDE_PARAMS` (never set in CI) | The rule is not cached at all |
0284
0285
0286 7. Removal of entries
0287 ---------------------
0288
0289 ```ebnf
0290 entry removal = pipeline scratch removal | stale scratch removal | garbage collection ;
0291
0292 pipeline scratch removal = ? the cleanup:scratch job of a successful pipeline removes
0293 /scratch/detector_benchmarks_<CI_PIPELINE_ID>, including
0294 its pipeline cache and its symbolic links ? ;
0295
0296 stale scratch removal = ? common:setup removes /scratch/detector_benchmarks_* and
0297 /scratch/physics_benchmarks_* directories modified more than
0298 72 hours ago, including their pipeline caches ? ;
0299
0300 garbage collection = ? common:setup runs garbage-collect.py on the shared cache
0301 with a 500G target size and a 200G minimum of free space;
0302 see below ? ;
0303 ```
0304
0305 Stale scratch removal and garbage collection run under
0306 `flock --nonblock /scratch/garbage-collect.lock`. They are skipped when another
0307 pipeline holds the lock.
0308
0309 `garbage-collect.py` lists the shared cache, then:
0310
0311 1. removes empty regular files (never valid entries) unconditionally,
0312 2. never removes entries modified less than 6 hours ago (grace period),
0313 3. never removes entries that a symbolic link anywhere under `/scratch`
0314 points to ("alive"),
0315 4. removes the remaining entries in decreasing order of
0316 `size × (now − access time)` until the total size of the cache is below
0317 the target,
0318 5. continues removing entries in the same order, with the same protections,
0319 until the filesystem holding the cache has at least the minimum free
0320 space (as reported by `statvfs`, measured after every removal). The cache
0321 shares `/scratch` (about 1T) with the pipeline scratch directories, so a
0322 cache below its target does not by itself leave space free.
0323
0324 If the minimum free space cannot be reached because all remaining entries are
0325 protected by 2. or 3., `garbage-collect.py` prints a warning with the free
0326 space, the minimum, the size and number of entries protected by each rule, and
0327 the space used outside the cache. The job does not fail. Entries in the grace
0328 period or alive are never removed to make space, because the pipelines that
0329 are using them would then fail.
0330
0331 The pipeline cache is not garbage collected; it lives exactly as long as the
0332 pipeline's scratch directory.
0333
0334
0335 8. Known gaps
0336 -------------
0337
0338 - A pipeline that tests an EICrecon PR stores its reconstruction outputs in
0339 the shared cache, where no later pipeline retrieves them, until garbage
0340 collection evicts them (section 6 explains why).
0341 - When two pipelines miss the cache for the same entry at the same time, the
0342 one that finishes last replaces the entry with its own, newer file. The
0343 other pipeline's outputs that depend on that entry then look outdated, so
0344 its later jobs rerun them, and through the regenerated
0345 `warmup.edm4hep.root` everything else that depends on `warmup_run`. For
0346 cached rules these reruns are cache hits.
0347 - If `ctypes.util.find_library("epic")` finds no library, `geometry_lib` is
0348 empty and keys silently lose the epic dependency.
0349 - If `spack` is missing or `spack find` fails, `get_spack_package_hash()`
0350 returns `""` (with a warning) and the key loses that package. If several
0351 installations of a package exist (e.g. the eic_xl container ships several
0352 epic versions), the first one listed is used, which need not be the one in
0353 `DETECTOR_PREFIX`.
0354 - physics_benchmarks writes to the same shared cache and does not apply the
0355 policy in section 6.