managing random generator seeds with seedservice
play

Managing random generator seeds with SeedService Gianluca Petrillo - PowerPoint PPT Presentation

Managing random generator seeds with SeedService Gianluca Petrillo University of Rochester/Fermilab LArSoft Coordinators Meeting, February 24 th , 2015 February 24 th , 2015 G. Petrillo (Rochester/FNAL) Managing random generator seeds with


  1. Managing random generator seeds with SeedService Gianluca Petrillo University of Rochester/Fermilab LArSoft Coordinators Meeting, February 24 th , 2015 February 24 th , 2015 G. Petrillo (Rochester/FNAL) Managing random generator seeds with SeedService 1 / 16

  2. Outline Introduction 1 Code changes and setup 2 Settings and “policies” 3 February 24 th , 2015 G. Petrillo (Rochester/FNAL) Managing random generator seeds with SeedService 2 / 16

  3. Why to care about SeedService Currently, each module handles its random seed(s) independently ⇒ to set all the seeds, must act on all modules SeedService concentrates the seed control into a single place: decide the way (“policy”) to assign seeds once for all (modules) let the service take care of the individual seeds override single seeds, if you need to unique feature: per-event seeds SeedService was originally written by Mu2e experiment to make job reproducibility easier. it is now provided in artextensions UPS product I am the current maintainer of the SeedService part February 24 th , 2015 G. Petrillo (Rochester/FNAL) Managing random generator seeds with SeedService 3 / 16

  4. Two main ways to use SeedService How to use: traditional way, with module interface let SeedService tell you which seed to use ( getSeed() ) call module’s createEngine() with that seed How to use: direct way, with SeedService interface tell SeedService you want a new engine ( createEngine() ) This is the easiest way to enable the per-event seeds. Both ways end up talking to RandomNumberGenerator . The use of the random engines is unchanged: get them with RandomNumberGenerator ’s getEngine() . February 24 th , 2015 G. Petrillo (Rochester/FNAL) Managing random generator seeds with SeedService 4 / 16

  5. Outline Introduction 1 Code changes and setup 2 Settings and “policies” 3 February 24 th , 2015 G. Petrillo (Rochester/FNAL) Managing random generator seeds with SeedService 5 / 16

  6. How to use SeedService Three things must happen for SeedService to be operational: artextensions must be available and set up in your 1 environment ( LArSoft should take care of that) your job must configure SeedService 2 standard configurations are available; see later the module initializing the random number generators must 3 explicitly use SeedService February 24 th , 2015 G. Petrillo (Rochester/FNAL) Managing random generator seeds with SeedService 6 / 16

  7. Updating your LArSoft module to use SeedService Say you have a module that uses art ’s RandomNumberGenerator service to obtain a random generator (“engine”): // in SimWireMicroBooNE::SimWireMicroBooNE(): // get the random number seed, use a random default if not specified // in the configuration file. unsigned int seed = pset.get< unsigned int >("Seed", sim::GetRandomNumberSeed()); createEngine(seed); Listing 1: Example from uboonecode/uboone/DetSim/SimWireMicroBooNE_module.cc The easiest way to update your code to use the SeedService is: have artextensions configured in your CMakeLists.txt 1 create your engines with SeedService::createEngine() 2 include SeedService in module’s link list ( CMakeLists.txt ) 3 February 24 th , 2015 G. Petrillo (Rochester/FNAL) Managing random generator seeds with SeedService 7 / 16

  8. Updating your LArSoft module to use SeedService 1) have artextensions configured in your CMakeLists.txt ⇒ in the top-level CMakeLists.txt of your repository, add # ... find_ups_product( nutools v1_00_00 ) find_ups_product( art v1_09_00 ) find_ups_product( artextensions v1_00_01 ) find_ups_product( cetbuildtools v3_10_00 ) # ... Listing 2: Updated uboonecode/CMakeLists.txt In principle, you should also have a artextensions entry in your ups/product_deps file. Matter of fact, almost all of LArSoft depends on larsim , that already regulates that dependency. February 24 th , 2015 G. Petrillo (Rochester/FNAL) Managing random generator seeds with SeedService 8 / 16

  9. Updating your LArSoft module to use SeedService 2) create your engines with SeedService::createEngine() : #include "artextensions/SeedService/SeedService.hh" //... // in SimWireMicroBooNE::SimWireMicroBooNE(): // create a default random engine; obtain the random seed from // SeedService, unless overridden in configuration with key "Seed" art::ServiceHandle<artext::SeedService> Seeds; Seeds->createEngine(*this, pset, "Seed"); Listing 3: Updated uboonecode/uboone/DetSim/SimWireMicroBooNE_module.cc 3) include SeedService in module’s link list ( CMakeLists.txt ): art_make( BASENAME_ONLY MODULE_LIBRARIES Geometry # ... Database SignalShapingServiceMicroBooNE_service ${SEEDSERVICE_SERVICE} # artextensions ${ART_FRAMEWORK_CORE} # ... and all the rest Listing 4: Updated uboonecode/uboone/DetSim/CMakeLists.txt (or it may be in a simple_plugin macro instead) February 24 th , 2015 G. Petrillo (Rochester/FNAL) Managing random generator seeds with SeedService 9 / 16

  10. Outline Introduction 1 Code changes and setup 2 Settings and “policies” 3 Managing random generator seeds with SeedService February 24 th , 2015 G. Petrillo (Rochester/FNAL) 10 / 16

  11. Per-event random seed The perEvent policy of SeedService deterministically computes the seed from the event and execution context. The current algorithm ( EventTimestamp_v1 ) includes: event information: – run, subrun and event number – event time stamp execution context information: – process name – current module label – random engine instance name This means that every event is born with its set of seeds . Managing random generator seeds with SeedService February 24 th , 2015 G. Petrillo (Rochester/FNAL) 11 / 16

  12. Per-event random seed: quod ab emptore cavenda Seeds from event information data each event has unique run/subrun/event numbers → unique seed MC typically created by EmptyEvent , with R/S/E 1/0/1, 1/0/2 etc. and with an invalid timestamp ( 0 ); timestamp is created with the event by a timestamp plug-in , configured by FHiCL; use something like GeneratedEventTimestamp to generate unique seeds, or you’ll get the same events! source: { source_type: EmptyEvent timestampPlugin: { plugin_type: "GeneratedEventTimestamp" } } # source Per-event seeding does not work in GENIE GENIE does not allow access to its random engine a , that can’t be re- seeded event by event. A request to nusoft has been opened. a Some ugly hack could be arranged. Managing random generator seeds with SeedService February 24 th , 2015 G. Petrillo (Rochester/FNAL) 12 / 16

  13. Policies (I) ⇒ autoIncrement : sequential seed: services.user.SeedService: { policy: "autoIncrement" seedBase: 100 } The first seed fetched is baseSeed ( 100 ), the next 101 ... ⇒ linearMapping : for job submission: services.user.SeedService: { policy: "linearMapping" maxUniqueEngines: 20 nJob: 1 } we have at most maxUniqueEngines (e.g. 20 ) seeds, the first job ( nJob: 0 ), obtains 1, 2... , the second job ( nJob: 1 ) gets 21, 22... Managing random generator seeds with SeedService February 24 th , 2015 G. Petrillo (Rochester/FNAL) 13 / 16

  14. Policies (II) ⇒ preDefinedOffset : seed offsets are specified per module/engine on top of a baseSeed : services.user.SeedService: { policy: "preDefinedOffset" baseSeed: 50 cry: 1 larg4: 2 daq: 5 } cry module will get 51, larg4 52, daq 55. ⇒ preDefinedSeed : seeds are specified per module/engine: services.user.SeedService: { policy: "preDefinedSeed" cry: 121 larg4: 412 daq: 75 } cry module will get 121, larg4 412, daq 75. In both cases, if generator tries to get a seed it triggers an exception. Managing random generator seeds with SeedService February 24 th , 2015 G. Petrillo (Rochester/FNAL) 14 / 16

  15. Policies (III) ⇒ random : just random seeds, no reproducibility: services.user.SeedService.policy: "random" this is mostly useful to override a SeedService configuration for local tests. ⇒ perEvent : determined by event and context: services.user.SeedService: { policy: "perEvent" algorithm: "EventTimestamp_v1" # currently default and the only option } SeedService documentation Full documentation inline in Doxygen format, and in artextensions Redmine wiki: https://cdcvs.fnal.gov/redmine/projects/ artextensions/wiki/SeedService Managing random generator seeds with SeedService February 24 th , 2015 G. Petrillo (Rochester/FNAL) 15 / 16

  16. Summary SeedService allows a one-entry-point control for all the random seeds in a job it makes it easy to reproduce a job code enabling it in ≈ 22 modules is in feature/SeedService branch explicit configuration for all jobs is needed (standard configurations available at lardata/Utilities/seedservice.fcl ) I proprose and recommend this service to be used for MicroBooNE Monte Carlo Challenges Breaking change SeedService must be configured and running. The feature/SeedService branch version of the existing modules (e.g. LArG4 ) will fail to run if SeedService is missing. Managing random generator seeds with SeedService February 24 th , 2015 G. Petrillo (Rochester/FNAL) 16 / 16

Recommend


More recommend