Skip to content

Commit

Permalink
[PEx] Adds modes for stateful backtracking
Browse files Browse the repository at this point in the history
Adds CLI option --stateful-backtrack none|intra-task|all to limit stateful backtracking to OFF|within-a-task|ON
  • Loading branch information
aman-goel committed Jul 15, 2024
1 parent c150243 commit 9d7199f
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.Setter;
import pexplicit.runtime.machine.buffer.BufferSemantics;
import pexplicit.runtime.scheduler.explicit.StateCachingMode;
import pexplicit.runtime.scheduler.explicit.StatefulBacktrackingMode;
import pexplicit.runtime.scheduler.explicit.strategy.SearchStrategyMode;

/**
Expand Down Expand Up @@ -52,9 +53,9 @@ public class PExplicitConfig {
// state caching mode
@Setter
StateCachingMode stateCachingMode = StateCachingMode.Murmur3_128;
// use stateful backtracking
// stateful backtracking mode
@Setter
boolean statefulBacktrackEnabled = true;
StatefulBacktrackingMode statefulBacktrackingMode = StatefulBacktrackingMode.IntraTask;
// search strategy mode
@Setter
SearchStrategyMode searchStrategyMode = SearchStrategyMode.Random;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.apache.commons.cli.*;
import pexplicit.runtime.scheduler.explicit.StateCachingMode;
import pexplicit.runtime.scheduler.explicit.StatefulBacktrackingMode;
import pexplicit.runtime.scheduler.explicit.strategy.SearchStrategyMode;

import java.io.PrintWriter;
Expand Down Expand Up @@ -165,13 +166,15 @@ public class PExplicitOptions {
addHiddenOption(stateCachingMode);

// whether or not to disable stateful backtracking
Option backtrack =
Option backtrackMode =
Option.builder()
.longOpt("no-backtrack")
.desc("Disable stateful backtracking")
.numberOfArgs(0)
.longOpt("stateful-backtrack")
.desc("Stateful backtracking mode: none, intra-task, all (default: intra-task)")
.numberOfArgs(1)
.hasArg()
.argName("Backtrack Mode (string)")
.build();
addHiddenOption(backtrack);
addHiddenOption(backtrackMode);

// max number of schedules to explore per search task
Option maxSchedulesPerTask =
Expand Down Expand Up @@ -363,8 +366,22 @@ public static PExplicitConfig ParseCommandlineArgs(String[] args) {
String.format("Unrecognized state caching mode, got %s", option.getValue()));
}
break;
case "no-backtrack":
config.setStatefulBacktrackEnabled(false);
case "stateful-backtrack":
switch (option.getValue()) {
case "none":
config.setStatefulBacktrackingMode(StatefulBacktrackingMode.None);
break;
case "intra-task":
config.setStatefulBacktrackingMode(StatefulBacktrackingMode.IntraTask);
break;
case "all":
config.setStatefulBacktrackingMode(StatefulBacktrackingMode.All);
break;
default:
optionError(
option,
String.format("Unrecognized stateful backtrack mode, got %s", option.getValue()));
}
break;
case "schedules-per-task":
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pexplicit.runtime.scheduler.choice.Choice;
import pexplicit.runtime.scheduler.choice.DataChoice;
import pexplicit.runtime.scheduler.choice.ScheduleChoice;
import pexplicit.runtime.scheduler.explicit.StatefulBacktrackingMode;
import pexplicit.runtime.scheduler.explicit.StepState;
import pexplicit.values.PValue;

Expand Down Expand Up @@ -71,7 +72,7 @@ public void setScheduleChoice(int stepNum, int choiceNum, PMachineId current) {
choices.add(null);
}
assert (choiceNum < choices.size());
if (PExplicitGlobal.getConfig().isStatefulBacktrackEnabled()
if (PExplicitGlobal.getConfig().getStatefulBacktrackingMode() != StatefulBacktrackingMode.None
&& stepNum != 0) {
assert (stepBeginState != null);
choices.set(choiceNum, new ScheduleChoice(stepNum, choiceNum, current, stepBeginState));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void clearCurrent() {
*
* @return Choice object with the copied current choice
*/
abstract public Choice copyCurrent();
abstract public Choice copyCurrent(boolean copyState);

abstract public String toString();
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public DataChoice(PValue<?> c) {
super(c);
}

public Choice copyCurrent() {
public Choice copyCurrent(boolean copyState) {
return new DataChoice(this.current);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.Getter;
import lombok.Setter;
import pexplicit.commandline.PExplicitConfig;
import pexplicit.runtime.machine.PMachineId;
import pexplicit.runtime.scheduler.explicit.StepState;

Expand Down Expand Up @@ -32,8 +33,12 @@ public ScheduleChoice(int stepNum, int choiceNum, PMachineId c, StepState s) {
this.choiceState = s;
}

public Choice copyCurrent() {
return new ScheduleChoice(this.stepNumber, this.choiceNumber, this.current, this.choiceState);
public Choice copyCurrent(boolean copyState) {
if (copyState) {
return new ScheduleChoice(this.stepNumber, this.choiceNumber, this.current, this.choiceState);
} else {
return new ScheduleChoice(this.stepNumber, this.choiceNumber, this.current, null);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ protected void runStep() throws TimeoutException {
return;
}

if (PExplicitGlobal.getConfig().isStatefulBacktrackEnabled()
if (PExplicitGlobal.getConfig().getStatefulBacktrackingMode() != StatefulBacktrackingMode.None
&& stepNumber != 0) {
schedule.setStepBeginState(stepState.copyState());
}
Expand Down Expand Up @@ -528,7 +528,7 @@ private void postIterationCleanup() {
backtrackChoiceNumber = cIdx;
int newStepNumber = 0;
ScheduleChoice scheduleChoice = null;
if (PExplicitGlobal.getConfig().isStatefulBacktrackEnabled()) {
if (PExplicitGlobal.getConfig().getStatefulBacktrackingMode() != StatefulBacktrackingMode.None) {
scheduleChoice = schedule.getScheduleChoiceAt(cIdx);
if (scheduleChoice != null && scheduleChoice.getChoiceState() != null) {
newStepNumber = scheduleChoice.getStepNumber();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package pexplicit.runtime.scheduler.explicit;

public enum StatefulBacktrackingMode {
None,
IntraTask,
All
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package pexplicit.runtime.scheduler.explicit.strategy;

import lombok.Getter;
import pexplicit.runtime.PExplicitGlobal;
import pexplicit.runtime.machine.PMachineId;
import pexplicit.runtime.scheduler.choice.*;
import pexplicit.runtime.scheduler.explicit.StatefulBacktrackingMode;
import pexplicit.values.PValue;

import java.io.Serializable;
Expand Down Expand Up @@ -41,7 +43,8 @@ public void cleanup() {
}

public void addPrefixChoice(Choice choice) {
prefixChoices.add(choice.copyCurrent());
boolean copyState = (PExplicitGlobal.getConfig().getStatefulBacktrackingMode() == StatefulBacktrackingMode.All);
prefixChoices.add(choice.copyCurrent(copyState));
}

public void addSuffixSearchUnit(int choiceNum, SearchUnit unit) {
Expand Down

0 comments on commit 9d7199f

Please sign in to comment.