Commit 34f79301 authored by Christian Meyer's avatar Christian Meyer
Browse files

LauncherArgs.java: added option dryRun

        updated Launcher
    improved some usage messages
DefaultSimulationLooper, SimulationLooper.java
    implemented dry-run workings
parent 6dc2262f
......@@ -240,7 +240,7 @@ public class Launcher {
protected void process(LauncherArgs args, ZmtSimState simState, Iterator<Path> pathIterator) {
// use output dir from args if set, otherwise via path iterator
simState.setOutputPath(args.getOutputDir() != null ? args.getOutputDir().toPath() : pathIterator.next());
context.simulationLooper.loop(simState, args.getSimTime(), args.getPrintStatusInterval());
context.simulationLooper.loop(simState, args.getSimTime(), args.isDryRun(), args.getPrintStatusInterval());
}
}
......@@ -323,7 +323,7 @@ public class Launcher {
// run a simulation for every parameter object
context.simulationLooper.loop(simState.getClass(), appliedCombinations, combinations.size(),
args.getMaxThreads(), autoParams.getSimTime(), args.getPrintStatusInterval(),
args.isCombinationInFolderNames(), pathIterator);
args.isCombinationInFolderNames(), args.isDryRun(), pathIterator);
}
}
......
......@@ -29,7 +29,7 @@ public class LauncherArgs {
private boolean help;
@Argument(index = 0, metaVar = "<NAME>", required = true, usage = "Specify simulation name. This name must correspond to the name of the simulation's SimState class.")
private String simName;
@Argument(index = 1, metaVar = "<MODE>", required = true, usage = "Set interface mode. Available options are gui, single and batch.")
@Argument(index = 1, metaVar = "<MODE>", required = true, usage = "Set launch mode. Available options are gui, single and batch.")
private Mode mode;
@Option(name = "-s", aliases = "--sim-params", metaVar = "SIM_PARAMS", usage = "Path to the simulation parameters XML file.")
private File simParamsPath = DEFAULT_SIM_PARAMS_PATH;
......@@ -37,15 +37,17 @@ public class LauncherArgs {
private File autoParamsPath = DEFAULT_AUTO_PARAMS_PATH;
@Option(name = "-u", aliases = "--until", usage = "Make simulation stop after given time has been reached or exceeded.\n(SINGLE mode only)")
private double simTime = DEFAULT_SIM_TIME;
@Option(name = "-p", aliases = "--parallel", usage = "Maximum number of threads that can run concurrently. Each simulation will run in its own thread. Use '0' to use the amount of CPU cores as value.\n(BATCH mode only)")
@Option(name = "-p", aliases = "--parallel", usage = "Maximum number of threads that can run concurrently. Each simulation will run in its own thread. Use '0' to use the number of available CPU cores.\n(BATCH mode only)")
private int maxThreads = 0;
@Option(name = "-t", aliases = "--print-status-interval", usage = "Prints a log message about simulation status in given step intervals. '0' to disable.\n(SINGLE and BATCH mode only)")
private int printStatusInterval = DEFAULT_PRINT_STATUS_INTERVAL;
@Option(name = "-id", aliases = "--identifier", usage = "Identifier which is added to output path names.")
private String identifier = "";
@Option(name = "-out", aliases = "--output-dir", forbids = {
"-id" }, usage = "Specify the output directory.\n(SINGLE mode only)")
@Option(name = "-o", aliases = "--output-dir", forbids = {
"-id" }, usage = "Specify the output directory. Cannot be used with an identifier.\n(SINGLE mode only)")
private File outputDir;
@Option(name = "-d", aliases = "--dry-run", usage="Launch without running any simulations.\n(BATCH and SINGLE mode only)")
private boolean dryRun = false;
@Option(name = "-es", aliases = "--export-sim-params", help = true, usage = "Exports default simulation parameters.")
private File exportSimParamsFile;
@Option(name = "-ea", aliases = "--export-auto-params", help = true, usage = "Exports automation parameters that include values from all automatable default parameters. Use this option as a starting point to create automation parameters for your BATCH runs.")
......@@ -105,6 +107,10 @@ public class LauncherArgs {
return outputDir;
}
public boolean isDryRun() {
return dryRun;
}
public Path getExportSimParamsPath() {
return exportSimParamsFile == null ? null : exportSimParamsFile.toPath();
}
......
......@@ -30,20 +30,25 @@ class DefaultSimulationLooper implements SimulationLooper {
private static final double NANO_FACTOR = 1e-09;
@Override
public void loop(ZmtSimState simState, double simTime, int printStatusInterval) {
public void loop(ZmtSimState simState, double simTime, boolean dryRun, int printStatusInterval) {
if (dryRun) {
return;
}
runSimulation(simState, simTime, 1, printStatusInterval);
}
/**
* Iterate combinations apply them to parameters and run a simulation with
* each of them.
* {@inheritDoc} Iterates combinations, apply them to parameters and run a
* simulation with each of them.
*/
// TODO report simulation exceptions
@Override
public void loop(Class<? extends ZmtSimState> simClass, Iterable<AppliedCombination> appliedCombinations,
int combinationsCount, int maxThreads, double simTime, int printStatusInterval,
boolean combinationInFolderNames, Iterator<Path> pathIterator) {
SimRunContext context = new SimRunContext(simClass, simTime, combinationsCount, printStatusInterval);
boolean combinationInFolderNames, boolean dryRun, Iterator<Path> pathIterator) {
logger.warning("No combinations given: Could not start any simulation runs.");
SimRunContext context = new SimRunContext(simClass, simTime, combinationsCount, printStatusInterval, dryRun);
int jobNum = 0;
int availableProcessors = Runtime.getRuntime().availableProcessors();
......@@ -67,6 +72,9 @@ class DefaultSimulationLooper implements SimulationLooper {
}
executor.execute(new SimRun(context, appliedCombination, jobNum++, outputPath));
}
if (jobNum <= 0) {
logger.warning("No combinations given: Could not start any simulation runs.");
}
executor.shutdown();
try {
// wait endlessly until all simulation runs are done
......@@ -75,12 +83,8 @@ class DefaultSimulationLooper implements SimulationLooper {
throw new RuntimeException("Interrupt while waiting for simulations to complete.", e);
}
if (jobNum > 0) {
logger.info("Finished " + jobNum + " simulation runs in "
+ Duration.ofMillis(System.currentTimeMillis() - startTime));
} else {
logger.warning("No combinations given: Could not start any simulation runs.");
}
logger.info("Finished " + jobNum + " simulation runs in "
+ Duration.ofMillis(System.currentTimeMillis() - startTime));
}
/**
......@@ -138,16 +142,17 @@ class DefaultSimulationLooper implements SimulationLooper {
public final double simTime;
public final int jobCount;
public final double printStatusInterval;
public final boolean dryRun;
public SimRunContext(Class<? extends ZmtSimState> simClass, double simTime, int jobCount,
double printStatusInterval) {
double printStatusInterval, boolean dryRun) {
super();
this.simClass = simClass;
this.simTime = simTime;
this.jobCount = jobCount;
this.printStatusInterval = printStatusInterval;
this.dryRun = dryRun;
}
}
/**
......@@ -196,7 +201,9 @@ class DefaultSimulationLooper implements SimulationLooper {
simState.setOutputPath(outputPath);
simState.setJob(jobNum);
runSimulation(simState, context.simTime, context.jobCount, context.printStatusInterval);
if (!context.dryRun) {
runSimulation(simState, context.simTime, context.jobCount, context.printStatusInterval);
}
}
/**
......
......@@ -14,11 +14,13 @@ public interface SimulationLooper extends LauncherStrategy {
* @param simTime
* simulation time that needs to pass after a simulation is
* stopped
* @param dryRun
* performs without running any simulations if <code>true</code>
* @param printStatusInterval
* the step interval in which status messages are printed (&lt;1
* to disable)
*/
void loop(ZmtSimState simState, double simTime, int printStatusInterval);
void loop(ZmtSimState simState, double simTime, boolean dryRun, int printStatusInterval);
/**
* Performs a simulation run for every parameter object.
......@@ -40,12 +42,14 @@ public interface SimulationLooper extends LauncherStrategy {
* to disable)
* @param combinationInFolderNames
* use combination to generate inner folder names
* @param dryRun
* performs without running any simulations if <code>true</code>
* @param pathIterator
* an {@link Iterator} of output paths that is used for every new
* simulation run
*/
void loop(Class<? extends ZmtSimState> simClass, Iterable<AppliedCombination> appliedCombinations,
int combinationsCount, int maxThreads, double simTime, int printStatusInterval,
boolean combinationInFolderNames, Iterator<Path> pathIterator);
boolean combinationInFolderNames, boolean dryRun, Iterator<Path> pathIterator);
}
......@@ -151,12 +151,12 @@ public class LauncherTest {
@Override
public void loop(Class<? extends ZmtSimState> simClass, Iterable<AppliedCombination> simParamsObjects,
int combinationsCount, int maxThreads, double simTime, int printStatusInterval,
boolean combinationInFolderNames, Iterator<Path> pathIterator) {
boolean combinationInFolderNames, boolean dryRun, Iterator<Path> pathIterator) {
fail("Wrong method called.");
}
@Override
public void loop(ZmtSimState simState, double simTime, int printStatusInterval) {
public void loop(ZmtSimState simState, double simTime, boolean dryRun, int printStatusInterval) {
assertEquals(new TestParams(), simState.getParams());
}
});
......@@ -345,7 +345,7 @@ public class LauncherTest {
private static class TestSimulationLooper implements SimulationLooper {
@Override
public void loop(ZmtSimState simState, double simTime, int printStatusInterval) {
public void loop(ZmtSimState simState, double simTime, boolean dryRun, int printStatusInterval) {
assertEquals(TestSimState.class, simState.getClass());
assertEquals(SIM_PARAMS, simState.getParams());
assertEquals(CMD_LINE_SIM_TIME, simTime, 0);
......@@ -354,7 +354,7 @@ public class LauncherTest {
@Override
public void loop(Class<? extends ZmtSimState> simClass, Iterable<AppliedCombination> appliedCombinations,
int combinationsCount, int maxThreads, double simTime, int printStatusInterval,
boolean combinationInFolderNames, Iterator<Path> pathIterator) {
boolean combinationInFolderNames, boolean dryRun, Iterator<Path> pathIterator) {
assertEquals(TestSimState.class, simClass);
assertEquals(APPLIED_COMBINATIONS, appliedCombinations);
assertEquals(CMD_LINE_MAX_THREADS, maxThreads);
......
......@@ -56,7 +56,7 @@ public class DefaultSimulationLooperTest {
public void loopOnSingle() {
TestSimState simState = new TestSimState();
simState.setParams(SIM_PARAMS);
SIMULATION_LOOPER.loop(simState, SIM_TIME, PRINT_STATUS_INTERVAL);
SIMULATION_LOOPER.loop(simState, SIM_TIME, false, PRINT_STATUS_INTERVAL);
}
@Test
......@@ -74,7 +74,7 @@ public class DefaultSimulationLooperTest {
CountDownTestSimState.doneSignal.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
CountDownTestSimState.doneSignal = new CountDownLatch(RUN_COUNT);
SIMULATION_LOOPER.loop(CountDownTestSimState.class, APPLIED_COMBINATIONS, APPLIED_COMBINATIONS.size(),
MAX_THREADS, SIM_TIME, PRINT_STATUS_INTERVAL, combinationInFolderNames, outputPaths.iterator());
MAX_THREADS, SIM_TIME, PRINT_STATUS_INTERVAL, combinationInFolderNames, false, outputPaths.iterator());
waitUntilSimsFinished();
Iterator<AppliedCombination> iterator = APPLIED_COMBINATIONS.iterator();
......@@ -96,7 +96,7 @@ public class DefaultSimulationLooperTest {
CountDownTestSimState.doneSignal = new CountDownLatch(RUN_COUNT);
SIMULATION_LOOPER.loop(ThreadLocalSingletonTestSimState.class, APPLIED_COMBINATIONS,
APPLIED_COMBINATIONS.size(), MAX_THREADS, SIM_TIME, PRINT_STATUS_INTERVAL, false,
outputPaths.iterator());
false, outputPaths.iterator());
waitUntilSimsFinished();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment