Warning, /AID2E-framework/examples/epic/bic/workflow.yml is written in an unsupported language. File is not indexed.
0001 # ============================================================================
0002 # ePIC BIC Single-Objective Optimization
0003 # ============================================================================
0004 # This example shows how to configure and run an entire
0005 # ePIC workflow in YAML.
0006 #
0007 # Usage:
0008 # aid2e optimize epic_imaging_optimization.yml
0009 # ============================================================================
0010
0011 # SECTION 0: PROBLEM DEFINITION
0012 # What to optimize (objectives) and design space
0013 # ============================================================================
0014 problem:
0015 name: "BIC Single-Objective Optimization"
0016 problem_type: "EPIC_BIC"
0017 description: "Single-objective optimization of the BIC for angular resolution"
0018 output_location: "./output"
0019 work_location: "./work"
0020
0021 # ePIC Environment Configuration
0022 # ==============================
0023 # Configure paths to the ePIC software stack. Either eic_shell OR
0024 # singularity_image must be provided. If both are provided,
0025 # singularity_image takes precedence.
0026 epic_environment:
0027
0028 # Option A: Use eic-shell script
0029 eic_shell: "/path/to/my/eic-shell"
0030
0031 # Option B: Or use singularity image
0032 # singularity_image: "/path/to/my/eic_xl-nightly.sif"
0033
0034 # Path to ePIC installation directory. This
0035 # will be copied and modified during execution.
0036 epic_install: "./epic"
0037
0038 # Geometry configuration file to use (e.g. epic, epic_full)
0039 epic_config: "epic"
0040
0041 # Turn on/off recompilation of geometry after modifying it
0042 # in a trial. Options:
0043 # "build" -
0044 geometry_mode: "build"
0045
0046 # ===========================================================================
0047 # PARAMETERS: Define what we're optimizing
0048 # ===========================================================================
0049 # Here, we want to find the optimal combination of AstroPix
0050 # staves in the BIC. Staves can be enabled (1) or disabled
0051 # (0) in their xml files.
0052 #
0053 # NOTE: the inline_design keyword indicates that parameters will
0054 # be defined directly in this file. Parameters can also be defined
0055 # in a separate file, such as
0056 #
0057 # examples/dtlz2/dtlz2_design.params
0058 inline_design:
0059 epic_design_space:
0060 epic_design_parameters:
0061 bic:
0062 #file_path: "$DETECTOR_PATH/compact/ecal/bic_default.xml"
0063 file_path: "compact/ecal/bic_default.xml"
0064 parameters:
0065
0066 enable_staves_2:
0067 value: 0
0068 choices: [0, 1]
0069 xml_path: ".//constant[@name='EcalBarrel_enable_staves_2']"
0070 attribute: "value"
0071 unit: ""
0072
0073 enable_staves_3:
0074 value: 1
0075 choices: [0, 1]
0076 xml_path: ".//constant[@name='EcalBarrel_enable_staves_3']"
0077 attribute: "value"
0078 unit: ""
0079
0080 enable_staves_4:
0081 value: 1
0082 choices: [0, 1]
0083 xml_path: ".//constant[@name='EcalBarrel_enable_staves_4']"
0084 attribute: "value"
0085 unit: ""
0086
0087 enable_staves_5:
0088 value: 0
0089 choices: [0, 1]
0090 xml_path: ".//constant[@name='EcalBarrel_enable_staves_5']"
0091 attribute: "value"
0092 unit: ""
0093
0094 enable_staves_6:
0095 value: 1
0096 choices: [0, 1]
0097 xml_path: ".//constant[@name='EcalBarrel_enable_staves_6']"
0098 attribute: "value"
0099 unit: ""
0100
0101 optimization_groups:
0102 default:
0103 - "bic.EcalBarrel_enable_staves_2"
0104 - "bic.EcalBarrel_enable_staves_3"
0105 - "bic.EcalBarrel_enable_staves_4"
0106 - "bic.EcalBarrel_enable_staves_5"
0107 - "bic.EcalBarrel_enable_staves_6"
0108
0109 # ========================================================================
0110 # OBJECTIVES: Define what we're optimizing for
0111 # ========================================================================
0112 # This a SINGLE objective: one run of the workflow
0113 # will output the calculated eta resolution, which
0114 # we want to minimize
0115 objectives:
0116 - name: "phi_resolution"
0117 direction: "minimize"
0118
0119 # SECTION 1: OPTIMIZER DEFINITION
0120 # How to optimize the defined problem
0121 # =============================================================================
0122 optimizer:
0123 name: "ax" # supported optimizers: "ax", "pymoo"
0124 type: "bayesian" # supported types: "bayesian" (Ax), "generative" (PyMoo)
0125
0126 # ===========================================================================
0127 # PARAMETERS: Opimitizer-specific strategy and options
0128 # ===========================================================================
0129 # Here, we define (1) our generation strategy -- how to propose new design
0130 # points -- and (2) all optimizer-specific options.
0131 # In this case, we will
0132 # 1. Run n_initial_samples trials with design points generated quasi-
0133 # randomly (via a "Sobol sequence")
0134 # 2. And then run n_iterations - n_initial_samples trials with design
0135 # points generated by a "Modular BoTorch" model
0136 # For more details on generation strategies in Ax and BoTorch, see
0137 #
0138 # https://ax.dev/docs/generation_strategy
0139 # https://botorch.org/docs/introduction
0140 #
0141 parameters:
0142 initialization_strategy: "sobol"
0143 generator: "BOTORCH_MODULAR"
0144 warm_start_path: null # Optionally, can initialize Ax from a snapshot of a previous run
0145 save_snapshot: true # Save an Ax Client JSON snapshot after each completed optimization batch
0146
0147 # Options for Modular BoTorch generator
0148 generator_kwargs:
0149 botorch_acqf_class: "qLogNoisyExpectedImprovement"
0150 acquisition_options:
0151 prune_baseline: true
0152
0153 # General generation strategy options
0154 generator_gen_kwargs:
0155 model_gen_options:
0156 optimizer_kwargs:
0157 #sequential: false
0158 num_restarts: 10
0159
0160 # Minimum (or maximum) value of computed objectives to consider design
0161 # point as a viable candidate. Anything trial ABOVE (or BELOW if
0162 # maximizing) this will not be considered.
0163 objective_thresholds:
0164 phi_resolution: 1.0
0165
0166 n_initial_samples: 2 # number of initialization trials
0167 n_iterations: 5 # total number of trials to run
0168 batch_size: 1 # (optional) max number of trials to run in parallel
0169 seed: 999 # (optional) seed to use for random number generation
0170
0171 # SECTION 2: SCHEDULER CONFIGURATION
0172 # Global scheduler defaults (can be overridden at workflow/branch/stage level)
0173 # =============================================================================
0174 scheduler:
0175 runner_type: "JobLibRunner"
0176 parameters:
0177 n_jobs: 4 # Use 4 parallel jobs by default
0178 backend: "loky" # Use process-based parallelism (default)
0179
0180 # If you were to use Slurm, the configuration
0181 # would look like:
0182 #runner_type: "SlurmRunner"
0183 #parameters:
0184 # account: "<account>"
0185 # partition: "<partition>"
0186 # nodes: 1
0187 # ntasks: 1
0188 # cpus_per_task: 1
0189 # mem: 4G
0190 # time: "04:00:00"
0191 # poll_interval: 10
0192 # capture_stdout: true
0193 # capture_stderr: true
0194 # runtime_working_dir: "/path/to/this/directory"
0195
0196 # SECTION 3: WORKFLOW EXECUTION
0197 # How to execute the optimization (stages, parallelism, etc.)
0198 # =============================================================================
0199 # Here, we have only one workflow: optimize the number of Astropix layers
0200 # in the BIC. Multiple optimizations can be run in parallel, where each
0201 # one would have a corresponding workflow.
0202 #
0203 # Notice the 'stack_type' keyword: this indicates which software stack we're
0204 # going to use. For this example, we'll use the ePIC stack.
0205 #
0206 # NOTE: When objectives are simple (single script call), workflows are optional
0207 workflows:
0208 workflows:
0209 - name: "imaging_optimization"
0210 description: "Optimize the number of AstroPix layers in the BIC"
0211 stack_type: "epic"
0212
0213 # =========================================================================
0214 # BRANCHES: Parallel execution paths
0215 # =========================================================================
0216 # One optimization can have multiple branches which run in
0217 # parallel. These should correspond to independent pipelines.
0218 # For example, suppose we had 2 objectives,
0219 # 1. one for single particle simulations and
0220 # 2. another for an event generator.
0221 # These could be run in parallel as separate branches.
0222 branches:
0223 - name: "photon_phi_resolution"
0224 description: "Calculate phi resolution for single photons"
0225
0226 # =====================================================================
0227 # STAGES: Groups of sequential computation steps
0228 # =====================================================================
0229 # The workflow below has 3 stages:
0230 # 1. Run overlap checks on modified geometry
0231 # 2. Run Geant4 simulation via npsim for 3 kinematic points in parallel
0232 # 3. Merge npsim output, run eicrecon on merged output, and finally
0233 # run analysis on eicrecon output
0234 stages:
0235
0236 # Stage 1: run overlap checks
0237 # ==================================================================
0238 - name: "geo"
0239 description: "Check for overlaps in modified geomtry"
0240 jobs:
0241
0242 # JOBS: Individual steps in a stage of a workflow
0243 # ==============================================================
0244 # A stage can be composed of any number of jobs, which are
0245 # individual actions to be run. Details of how the job is
0246 # run are set in the "payload" block
0247 - name: "geo_job"
0248 payload:
0249 evaluator_type: "stack" # FIXME this should be default
0250 stack_type: "epic" # FIXME this should be default
0251 job_id: "geo"
0252
0253
0254 # LAYERS: Components of a software stack
0255 # ============================================================
0256 # A software stack is composed of one or more components,
0257 # such as npsim or EICrecon, referred to as a "layer" in
0258 # For a stack worklow, one or more layers can be run per job.
0259 #
0260 # The "name" keyowrd indicates which layer to run. For the
0261 # ePIC stack, we support:
0262 # -- geo: check for overlaps in geometry
0263 # -- sim: run npsim (Geant4)
0264 # -- rec: run EICrecon
0265 # -- ana: run user code or other commands (e.g. running
0266 # an analysis, compiling a plugin, etc.)
0267 layers:
0268 - name: "geo" # NOTE this should be a unique identifier for THIS instance of a layer
0269 layer: "geo"
0270 inputs:
0271 - "{{geometry_dir}}/install/share/epic/epic.xml"
0272 outputs:
0273 - "{{output_dir}}/geo.overlaps.txt"
0274
0275 # Stage 2: run Geant4 simulations
0276 # =================================================================
0277 - name: "sim"
0278 description: "Simulate single photons"
0279 jobs:
0280
0281 # NOTE: anything in {{ }} will be substituted during execution
0282 - name: "sim_job"
0283 payload:
0284 evaluator_type: "stack" # FIXME this should be default
0285 stack_type: "epic" # FIXME this should be default
0286 job_id: "sim"
0287 layers:
0288 - name: "sim"
0289 layer: "sim"
0290 inputs:
0291 - "inputs/central_photons_bin{{job_index}}.py"
0292 outputs:
0293 - "{{output_dir}}/central_photons_bin{{job_index}}.edm4hep.root"
0294
0295 # Now we're going to create 3 copies of the job with job IDs
0296 # 0, 1, 2. These correspond to the 3 kinematic points to run,
0297 # each of which is defined by a DD4hep steering file:
0298 # - central_electrons_bin0.py
0299 # - central_electrons_bin1.py
0300 # - central_electrons_bin2.py
0301 job_factory:
0302 type: "range"
0303 params:
0304 n: 3
0305
0306 # And here we specify how many copies we can run in parallel
0307 parallelism:
0308 max_concurrent: 3
0309 retry_max: 2
0310 timeout_sec: 3600 # should take no more than 30 min. per kinematic point to run
0311
0312 # Stage 3: Merge, run eicrecon, and do analysis
0313 # =================================================================
0314 - name: "merge_rec_ana"
0315 description: "Merge simulation output, run reconstruction and analysis"
0316 jobs:
0317 - name: "merge_rec_ana_job"
0318 payload:
0319 evaluator_type: "stack" # FIXME this should be default
0320 stack_type: "epic" # FIXME this should be default
0321 job_id: "merge_rec_ana"
0322
0323 # in this stage, we'll have 1 job where we run 3 layers:
0324 # 1. ana -- where we merge the 3 sim jobs
0325 # 2. rec -- where we run EICrecon on the merged sim output
0326 # 3. ana -- where we run an analysis script on the
0327 # EICrecon output
0328 layers:
0329
0330 # For 'ana' layers, you'll need to specify:
0331 # -- 'command', which sets which command (or executable)
0332 # to run; and
0333 # -- 'rule', which defines how arguments and the command
0334 # are put together on the command line
0335 # The keywords {{command}}, {{inputs}}, {{outputs}}, and
0336 # {{arguments}} will be appropriately subsituted during
0337 # execution.
0338 - name: "ana_merge"
0339 layer: "ana"
0340 inputs:
0341 - "{{outputs[sim:sim_job_0:sim](0)}}"
0342 - "{{outputs[sim:sim_job_1:sim](0)}}"
0343 - "{{outputs[sim:sim_job_2:sim](0)}}"
0344 outputs:
0345 - "{{output_dir}}/central_photons.edm4hep.root"
0346 command: "hadd"
0347 rule: "{{command}} -f {{outputs}} {{inputs}}"
0348
0349 # For the other layers, 'command' and 'rule' are already
0350 # defined. The defaults can be overwritten if needed.
0351 - name: "rec"
0352 layer: "rec"
0353 inputs:
0354 - "{{outputs[merge_rec_ana:merge_rec_ana_job:ana_merge](0)}}"
0355 outputs:
0356 - "{{output_dir}}/central_photons.edm4eic.root"
0357 arguments:
0358 - "-Pnthreads=8"
0359 - "-Peicrecon:LogLevel=debug"
0360
0361 - name: "ana_reso"
0362 layer: "ana"
0363 inputs:
0364 - "{{outputs[merge_rec_ana:merge_rec_ana_job:rec](0)}}"
0365 outputs:
0366 - "{{output_dir}}/central_photons.hist.root"
0367 arguments:
0368 - "-c phi"
0369 - "-s 22"
0370 command: "{{workflow[config_dir]}}/scripts/bic_angular_reso.py"
0371 rule: "python {{command}} -i {{inputs}} -o {{outputs}} {{arguments}}"
0372
0373 # Stage 4: Extract objective from output of merge_rec_ana stage
0374 # ==================================================================
0375 - name: "extract_objectives"
0376 description: "Extract objectives from output"
0377 objective_plan:
0378 steps:
0379 stages:
0380 - name: "extract"
0381 inline:
0382 entrypoint: "scripts.extract_objective:ExtractObjective"
0383 extra_args:
0384 key: "phi_resolution"
0385 file: "{{outputs[merge_rec_ana:merge_rec_ana_job:ana_reso](0)}}" # FIXME use artifacts instead
0386 produces_objective: true