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

managing random generator seeds with seedservice
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Managing random generator seeds with SeedService

Gianluca Petrillo

University of Rochester/Fermilab

LArSoft Coordinators Meeting, February 24th , 2015

  • G. Petrillo (Rochester/FNAL)

Managing random generator seeds with SeedService February 24th , 2015 1 / 16

slide-2
SLIDE 2

Outline

1

Introduction

2

Code changes and setup

3

Settings and “policies”

  • G. Petrillo (Rochester/FNAL)

Managing random generator seeds with SeedService February 24th , 2015 2 / 16

slide-3
SLIDE 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

  • verride 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

  • G. Petrillo (Rochester/FNAL)

Managing random generator seeds with SeedService February 24th , 2015 3 / 16

slide-4
SLIDE 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().

  • G. Petrillo (Rochester/FNAL)

Managing random generator seeds with SeedService February 24th , 2015 4 / 16

slide-5
SLIDE 5

Outline

1

Introduction

2

Code changes and setup

3

Settings and “policies”

  • G. Petrillo (Rochester/FNAL)

Managing random generator seeds with SeedService February 24th , 2015 5 / 16

slide-6
SLIDE 6

How to use SeedService

Three things must happen for SeedService to be operational:

1

artextensions must be available and set up in your environment (LArSoft should take care of that)

2

your job must configure SeedService

standard configurations are available; see later

3

the module initializing the random number generators must explicitly use SeedService

  • G. Petrillo (Rochester/FNAL)

Managing random generator seeds with SeedService February 24th , 2015 6 / 16

slide-7
SLIDE 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:

1

have artextensions configured in your CMakeLists.txt

2

create your engines with SeedService::createEngine()

3

include SeedService in module’s link list (CMakeLists.txt)

  • G. Petrillo (Rochester/FNAL)

Managing random generator seeds with SeedService February 24th , 2015 7 / 16

slide-8
SLIDE 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.

  • G. Petrillo (Rochester/FNAL)

Managing random generator seeds with SeedService February 24th , 2015 8 / 16

slide-9
SLIDE 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)

  • G. Petrillo (Rochester/FNAL)

Managing random generator seeds with SeedService February 24th , 2015 9 / 16

slide-10
SLIDE 10

Outline

1

Introduction

2

Code changes and setup

3

Settings and “policies”

  • G. Petrillo (Rochester/FNAL)

Managing random generator seeds with SeedService February 24th , 2015 10 / 16

slide-11
SLIDE 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.

  • G. Petrillo (Rochester/FNAL)

Managing random generator seeds with SeedService February 24th , 2015 11 / 16

slide-12
SLIDE 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 enginea, that can’t be re- seeded event by event. A request to nusoft has been opened.

aSome ugly hack could be arranged.

  • G. Petrillo (Rochester/FNAL)

Managing random generator seeds with SeedService February 24th , 2015 12 / 16

slide-13
SLIDE 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...

  • G. Petrillo (Rochester/FNAL)

Managing random generator seeds with SeedService February 24th , 2015 13 / 16

slide-14
SLIDE 14

Policies (II)

⇒ preDefinedOffset: seed offsets are specified per module/engine

  • n 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.

  • G. Petrillo (Rochester/FNAL)

Managing random generator seeds with SeedService February 24th , 2015 14 / 16

slide-15
SLIDE 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

  • G. Petrillo (Rochester/FNAL)

Managing random generator seeds with SeedService February 24th , 2015 15 / 16

slide-16
SLIDE 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.

  • G. Petrillo (Rochester/FNAL)

Managing random generator seeds with SeedService February 24th , 2015 16 / 16