From d2d4d9e97944009dfeb839b377f45ee416de2e8c Mon Sep 17 00:00:00 2001 From: Jakob Rehmann Date: Mon, 29 Apr 2024 07:49:50 +0200 Subject: [PATCH] added boiler plate batch classes for episim workshop --- .../matsim/run/CreateBatteryForCluster.java | 4 +- .../matsim/run/batch/StarterBatchBerlin.java | 120 ++++++++++++++++ .../matsim/run/batch/StarterBatchCologne.java | 136 ++++++++++++++++++ 3 files changed, 258 insertions(+), 2 deletions(-) create mode 100644 src/main/java/org/matsim/run/batch/StarterBatchBerlin.java create mode 100644 src/main/java/org/matsim/run/batch/StarterBatchCologne.java diff --git a/src/main/java/org/matsim/run/CreateBatteryForCluster.java b/src/main/java/org/matsim/run/CreateBatteryForCluster.java index 03f459a9c..0a9adc16c 100644 --- a/src/main/java/org/matsim/run/CreateBatteryForCluster.java +++ b/src/main/java/org/matsim/run/CreateBatteryForCluster.java @@ -84,10 +84,10 @@ public class CreateBatteryForCluster implements Callable { @CommandLine.Option(names = "--jvm-opts", description = "Additional options for JVM", defaultValue = "-Xms82G -Xmx82G -XX:+UseParallelGC") private String jvmOpts; - @CommandLine.Option(names = "--setup", defaultValue = "org.matsim.run.batch.CologneBMBF202310XX_soup") + @CommandLine.Option(names = "--setup", defaultValue = "org.matsim.run.batch.StarterBatchCologne") private Class> setup; - @CommandLine.Option(names = "--params", defaultValue = "org.matsim.run.batch.CologneBMBF202310XX_soup$Params") + @CommandLine.Option(names = "--params", defaultValue = "org.matsim.run.batch.StarterBatchCologne$Params") private Class params; @SuppressWarnings("rawtypes") diff --git a/src/main/java/org/matsim/run/batch/StarterBatchBerlin.java b/src/main/java/org/matsim/run/batch/StarterBatchBerlin.java new file mode 100644 index 000000000..0dbcc9778 --- /dev/null +++ b/src/main/java/org/matsim/run/batch/StarterBatchBerlin.java @@ -0,0 +1,120 @@ +package org.matsim.run.batch; + +import com.google.inject.Module; +import org.matsim.core.config.Config; +import org.matsim.core.config.ConfigUtils; +import org.matsim.episim.BatchRun; +import org.matsim.episim.EpisimConfigGroup; +import org.matsim.episim.VirusStrainConfigGroup; +import org.matsim.episim.analysis.OutputAnalysis; +import org.matsim.episim.model.InfectionModelWithAntibodies; +import org.matsim.run.RunParallel; +import org.matsim.run.modules.SnzBerlinProductionScenario; +import org.matsim.run.modules.SnzCologneProductionScenario; + +import javax.annotation.Nullable; +import java.util.Collection; +import java.util.List; + + +/** + * boilerplate batch for berlin + */ +public class StarterBatchBerlin implements BatchRun { + + /* + * here you can swap out vaccination model, antibody model, etc. + * See CologneBMBF202310XX_soup.java for an example + */ + @Nullable + @Override + public Module getBindings(int id, @Nullable Params params) { + return getBindings(params); + } + + + /* + * here you select & modify models specified in the SnzCologneProductionScenario & SnzProductionScenario. + */ + private SnzBerlinProductionScenario getBindings(Params params) { + return new SnzBerlinProductionScenario.Builder() + .setActivityHandling(EpisimConfigGroup.ActivityHandling.startOfDay) + .setInfectionModel(InfectionModelWithAntibodies.class) + .setEasterModel(SnzBerlinProductionScenario.EasterModel.no) + .setChristmasModel(SnzBerlinProductionScenario.ChristmasModel.no) + .setSample(1) + .build(); + } + + /* + * Metadata is needed for covid-sim. + */ + @Override + public Metadata getMetadata() { + return Metadata.of("berlin", "calibration"); + } + + + /* + * Here you can add post-processing classes, that will be executed after the simulation. + */ + @Override + public Collection postProcessing() { + return List.of(); + } + + /* + * Here you can specify configuration options + */ + @Override + public Config prepareConfig(int id, Params params) { + + // Level 1: General (matsim) config. Here you can specify number of iterations and the seed. + Config config = getBindings(params).config(); + + config.global().setRandomSeed(params.seed); + + // Level 2: Episim specific configs: + // 2a: general episim config + EpisimConfigGroup episimConfig = ConfigUtils.addOrGetModule(config, EpisimConfigGroup.class); + + episimConfig.setCalibrationParameter(episimConfig.getCalibrationParameter() * 1.2 * 1.7 * params.thetaFactor); + + // 2b: specific config groups, e.g. virusStrainConfigGroup + VirusStrainConfigGroup virusStrainConfigGroup = ConfigUtils.addOrGetModule(config, VirusStrainConfigGroup.class); + + return config; + } + + + /* + * Specify parameter combinations that will be run. + */ + public static final class Params { + // general + @GenerateSeeds(1) + public long seed; + + @Parameter({1.0, 2.0}) + public double thetaFactor; + } + + + + /* + * top-level parameters for a run on your local machine. + */ + public static void main(String[] args) { + String[] args2 = { + RunParallel.OPTION_SETUP, StarterBatchBerlin.class.getName(), + RunParallel.OPTION_PARAMS, Params.class.getName(), + RunParallel.OPTION_TASKS, Integer.toString(8), + RunParallel.OPTION_ITERATIONS, Integer.toString(50), + RunParallel.OPTION_METADATA + }; + + RunParallel.main(args2); + } + +} + diff --git a/src/main/java/org/matsim/run/batch/StarterBatchCologne.java b/src/main/java/org/matsim/run/batch/StarterBatchCologne.java new file mode 100644 index 000000000..173c6d563 --- /dev/null +++ b/src/main/java/org/matsim/run/batch/StarterBatchCologne.java @@ -0,0 +1,136 @@ +package org.matsim.run.batch; + +import com.google.inject.AbstractModule; +import com.google.inject.Module; +import com.google.inject.Singleton; +import com.google.inject.multibindings.Multibinder; +import com.google.inject.util.Modules; +import it.unimi.dsi.fastutil.ints.Int2DoubleAVLTreeMap; +import it.unimi.dsi.fastutil.ints.Int2DoubleMap; +import org.matsim.core.config.Config; +import org.matsim.core.config.ConfigUtils; +import org.matsim.episim.*; +import org.matsim.episim.analysis.HospitalNumbersFromEvents; +import org.matsim.episim.analysis.OutputAnalysis; +import org.matsim.episim.model.*; +import org.matsim.episim.model.listener.HouseholdSusceptibility; +import org.matsim.episim.model.vaccination.VaccinationModel; +import org.matsim.episim.model.vaccination.VaccinationStrategyBMBF202310XX; +import org.matsim.episim.policy.FixedPolicy; +import org.matsim.episim.policy.Restriction; +import org.matsim.run.RunParallel; +import org.matsim.run.modules.SnzCologneProductionScenario; + +import javax.annotation.Nullable; +import java.io.IOException; +import java.io.UncheckedIOException; +import java.time.LocalDate; +import java.time.temporal.ChronoUnit; +import java.util.*; +import java.util.Map.Entry; + + +/** + * boilerplate batch for cologne + */ +public class StarterBatchCologne implements BatchRun { + + /* + * here you can swap out vaccination model, antibody model, etc. + * See CologneBMBF202310XX_soup.java for an example + */ + @Nullable + @Override + public Module getBindings(int id, @Nullable Params params) { + return getBindings(params); + } + + + /* + * here you select & modify models specified in the SnzCologneProductionScenario & SnzProductionScenario. + */ + private SnzCologneProductionScenario getBindings(Params params) { + return new SnzCologneProductionScenario.Builder() + .setCarnivalModel(SnzCologneProductionScenario.CarnivalModel.yes) + .setFutureVacations(SnzCologneProductionScenario.FutureVacations.yes) + .setSebastianUpdate(true) + .setLeisureCorrection(1.3) //params == null ? 0.0 : params.actCorrection) + .setScaleForActivityLevels(1.3) + .setSuscHouseholds_pct(0.35) + .setActivityHandling(EpisimConfigGroup.ActivityHandling.startOfDay) + .setInfectionModel(InfectionModelWithAntibodies.class) + .build(); + } + + /* + * Metadata is needed for covid-sim. + */ + @Override + public Metadata getMetadata() { + return Metadata.of("cologne", "calibration"); + } + + + /* + * Here you can add post-processing classes, that will be executed after the simulation. + */ + @Override + public Collection postProcessing() { + return List.of(); + } + + /* + * Here you can specify configuration options + */ + @Override + public Config prepareConfig(int id, Params params) { + + // Level 1: General (matsim) config. Here you can specify number of iterations and the seed. + Config config = getBindings(params).config(); + + config.global().setRandomSeed(params.seed); + + // Level 2: Episim specific configs: + // 2a: general episim config + EpisimConfigGroup episimConfig = ConfigUtils.addOrGetModule(config, EpisimConfigGroup.class); + + episimConfig.setCalibrationParameter(episimConfig.getCalibrationParameter() * 1.2 * 1.7 * params.thetaFactor); + + // 2b: specific config groups, e.g. virusStrainConfigGroup + VirusStrainConfigGroup virusStrainConfigGroup = ConfigUtils.addOrGetModule(config, VirusStrainConfigGroup.class); + + return config; + } + + + /* + * Specify parameter combinations that will be run. + */ + public static final class Params { + // general + @GenerateSeeds(1) + public long seed; + + @Parameter({1.0, 2.0}) + public double thetaFactor; + } + + + + /* + * top-level parameters for a run on your local machine. + */ + public static void main(String[] args) { + String[] args2 = { + RunParallel.OPTION_SETUP, StarterBatchCologne.class.getName(), + RunParallel.OPTION_PARAMS, Params.class.getName(), + RunParallel.OPTION_TASKS, Integer.toString(8), + RunParallel.OPTION_ITERATIONS, Integer.toString(10), + RunParallel.OPTION_METADATA + }; + + RunParallel.main(args2); + } + +} +