Update YZ sim to address large memory usage#905
Conversation
…is broken into four "daq" modules, one per TPC. These files make that definition, for standard YZ sim and also for overlay
…yz sim uses 4 modules (daq0-daq3) while the standard sim continues to use only one (daq) so stage 0 will need to recognize this
… inherit from the standard one
There was a problem hiding this comment.
Pull request overview
This PR updates the ICARUS WireCell-based YZ simulation configuration to reduce peak memory usage by splitting the YZ TPC simulation into four per-TPC producer modules, while also refactoring the Jsonnet graph generation to avoid expensive g.uses() expansion/dedup behavior.
Changes:
- Add a new per-TPC YZ Jsonnet graph (
wcls-per-tpc-...) driven bytpc_idx, designed to be run by four separateWireCellToolkitmodules. - Refactor the existing multi-TPC YZ Jsonnet to use shared
YZMapnodes and a memoized DFS-basedusesresolver; updatesim.jsonnetto derive YZ pipeline counts fromtools.anodes. - Update detsim and stage0 FHiCL wiring for the per-TPC YZ module labels (
daq0..daq3) and adjust YZ SimChannel merge inputs accordingly.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
| icaruscode/TPC/ICARUSWireCell/icarus/wcls-per-tpc-sim-drift-simchannel-yzsim.jsonnet | New per-TPC YZ simulation graph parameterized by tpc_idx to enable 4-module execution. |
| icaruscode/TPC/ICARUSWireCell/icarus/wcls-multitpc-sim-drift-simchannel-yzsim-refactored.jsonnet | Refactors YZ graph pieces (YZMap, sink, uses traversal) and speeds up configuration emission. |
| icaruscode/TPC/ICARUSWireCell/icarus/wcls-multitpc-sim-drift-simchannel-refactored.jsonnet | Replaces g.uses() emission with the same memoized DFS resolver (non-YZ path). |
| icaruscode/TPC/ICARUSWireCell/icarus/sim.jsonnet | Makes YZ transform/reframer/analog pipeline counts depend on nanodes for per-TPC slicing. |
| icaruscode/TPC/ICARUSWireCell/detsimmodules_wirecell_per_TPC_ICARUS.fcl | New detsim module definitions for running YZ as four modules (daq0..daq3) plus overlay variants. |
| icaruscode/TPC/ICARUSWireCell/detsimmodules_wirecell_ICARUS.fcl | Switches the base icarus_simwire_wirecell config to the YZ-sim Jsonnet. |
| fcl/standard/standard_mc_all_stage0_icarus.fcl | Changes the standard stage0 include to the YZ-specific stage0 config. |
| fcl/reco/Stage0/mc/stage0_run2_wcdnn_icarus_mc.fcl | Changes the stage0+DNN entry point to include the YZ-specific stage0 config. |
| fcl/reco/Stage0/mc/stage0_run2_wc_yz_icarus_mc.fcl | New stage0 config variant that overrides decoder fragment labels for per-TPC (daq0..daq3) inputs. |
| fcl/reco/Stage0/mc/stage0_run2_wc_raw_icarus_mc.fcl | Switches the “keep raw digits” stage0 config to include the YZ-specific stage0 config. |
| fcl/reco/Stage0/mc/stage0_run2_wc_icarus_mc_notriggersim.fcl | Switches the “no trigger sim” stage0 config to include the YZ-specific stage0 config. |
| fcl/g4/mergesimsources_icarus.fcl | Updates YZ SimChannel merge input labels to use daq0..daq3:simpleSC*. |
| fcl/detsim/detsim_2d_icarus_refactored.fcl | Includes the new per-TPC WireCell detsim module definitions (non-YZ still uses single daq). |
| fcl/detsim/detsim_2d_icarus_refactored_yzsim.fcl | Rewires YZ detsim to run daq0..daq3 instead of a single daq producer. |
| fcl/detsim/detsim_2d_icarus_refactored_yzsim_overlay.fcl | Updates overlay YZ detsim overrides to target daq0..daq3 producers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| local g = import 'pgraph.jsonnet'; | ||
| local f = import 'pgrapher/common/funcs.jsonnet'; | ||
| local wc = import 'wirecell.jsonnet'; | ||
|
|
||
| local io = import 'pgrapher/common/fileio.jsonnet'; | ||
| local tools_maker = import 'pgrapher/experiment/icarus/icarus_tools.jsonnet'; | ||
| local base = import 'pgrapher/experiment/icarus/simparams.jsonnet'; | ||
|
|
| local tpc_idx = std.parseInt(std.extVar('tpc_idx')); | ||
| local apa_lo = tpc_idx * 2; // 2 anodes per TPC | ||
| local local_iota = std.range(0, 89); // 90 per-anode-plane-response branches | ||
| local volname = ["EE", "EW", "WE", "WW"]; | ||
|
|
| // product instances match the single-module reference run. | ||
| // --------------------------------------------------------------------------- | ||
| local overlay_drifter = std.extVar("overlay_drifter"); | ||
| local localeLiftime = [std.extVar('lifetime') * wc.us,std.extVar('lifetime') * wc.us,std.extVar('lifetime') * wc.us,std.extVar('lifetime') * wc.us,std.extVar('lifetime') * wc.us,std.extVar('lifetime') * wc.us,std.extVar('lifetime') * wc.us,std.extVar('lifetime') * wc.us]; |
| structs: { | ||
| DL: 4e-9 | ||
| DT: 8.8e-9 | ||
| coh_noise_scale: 1 | ||
| gain0: 1.705212e1 |
| structs: { | ||
| DL: 4e-9 | ||
| DT: 8.8e-9 | ||
| coh_noise_scale: 1 | ||
| gain0: 1.705212e1 |
| @@ -1 +1 @@ | |||
| #include "stage0_run2_icarus_mc.fcl" | |||
| #include "stage0_run2_wc_yz_icarus_mc.fcl" | |||
| @@ -1,3 +1,3 @@ | |||
| #include "stage0_run2_wc_icarus_mc.fcl" | |||
| #include "stage0_run2_wc_yz_icarus_mc.fcl" | |||
| ## This fhicl file takes the standard stage 0 wc mc file and keeps the raw digits | ||
| ## | ||
| #include "stage0_run2_wc_icarus_mc.fcl" | ||
| #include "stage0_run2_wc_yz_icarus_mc.fcl" |
| @@ -1,4 +1,4 @@ | |||
| #include "stage0_run2_wc_icarus_mc.fcl" | |||
| #include "stage0_run2_wc_yz_icarus_mc.fcl" | |||
There was a problem hiding this comment.
here (and in other places), I think Copilot is pointing out that effectively you are changing the behavior of the fcl file to be "non-YZ" to become "YZ". Is this correct?
| plugins: ["WireCellPgraph", "WireCellGen","WireCellSio","WireCellRoot","WireCellLarsoft", "WireCellHio"] | ||
| // needs to be found via your WIRECELL_PATH | ||
| configs: ["pgrapher/experiment/icarus/wcls-multitpc-sim-drift-simchannel-refactored.jsonnet"] | ||
| configs: ["pgrapher/experiment/icarus/wcls-multitpc-sim-drift-simchannel-yzsim-refactored.jsonnet"] |
|
The above PR is compatible with larsoft v10_20_09 and later. It also requires icarus_data v10_20_03. |
cerati
left a comment
There was a problem hiding this comment.
I do not fully understand the details of the jsonnet options, but this generally does what expected, i.e. splitting the detsim per tpc and updating the configuration to reflect wire cell changes. I approve pending some minor comments i left.
| @@ -1,4 +1,4 @@ | |||
| #include "stage0_run2_wc_icarus_mc.fcl" | |||
| #include "stage0_run2_wc_yz_icarus_mc.fcl" | |||
There was a problem hiding this comment.
here (and in other places), I think Copilot is pointing out that effectively you are changing the behavior of the fcl file to be "non-YZ" to become "YZ". Is this correct?
| // tools.anodes so that callers that narrow tools.anodes to a per-TPC | ||
| // subset (e.g. the per-module wcls-per-tpc...jsonnet) only build the | ||
| // relevant slice instead of indexing past the end. With the full 8 | ||
| // anodes this evaluates to std.range(0, 359), matching the legacy form. |
There was a problem hiding this comment.
what about defining a local variable as nanodes*45-1 and the using it below?
| // g4_ref_time: -1500 * wc.us, // G4RefTime from detectorclocks_icarus.fcl | ||
| // use_energy: true, | ||
| // }, | ||
| // },nin=1, nout=1, uses=tools.anodes); |
There was a problem hiding this comment.
should this block be deleted or is there a reason to keep it around commented out?
| local resolve_uses_unique(roots) = | ||
| std.foldl(function(s, n) visit(n, s), roots, { seen: {}, result: [] }).result; | ||
|
|
||
| resolve_uses_unique(graph.uses) + [app] No newline at end of file |
There was a problem hiding this comment.
not clear to me what this code does, maybe add some documentation? (copilot please help...)
There was a problem hiding this comment.
this is referring to lines 369-404
| name: 'setdrifters%d' %n, | ||
| data: { | ||
| drifter: wc.tn(drifters[n]) | ||
| #drifter: "Drifter" |
| // g4_ref_time: -1500 * wc.us, // G4RefTime from detectorclocks_icarus.fcl | ||
| // use_energy: true, | ||
| // }, | ||
| // },nin=1, nout=1, uses=tools.anodes); |
There was a problem hiding this comment.
same as above, shall this be removed?
| // Pnodes (g.pipeline/g.pnode/g.intern wrappers) are scaffolding whose names | ||
| // can collide (fandrifter creates fanout/fanin/intern all named 'fandrifter'), | ||
| // so we always traverse them and never dedup them. The pgraph is acyclic | ||
| // by design, so unconditional traversal terminates. |
There was a problem hiding this comment.
maybe the above documentation is what needs to be added to the other jsonnet as well?
This PR provides the necessary updates to utilize improvements in the wirecell toolkit to address the ICARUS YZ simulation's large memory usage. While the main changes are in the toolkit itself we have modified the detector simulation at the ICARUS level to break the TPC simulation into four separate producer modules. At the same time we are maintaining the non-YZ simulation to a single producer module. This requires updates at the stage 0 processing level as well for the two cases.
At this point the comparison of non-YZ (top) to YZ (bottom) cpu and memory usage is:

Generally, we are now running the YZ sim with more than a 2x reduction in memory usage