Skip to content

Commit be565f6

Browse files
committed
[PEx] Add support to serialize and deserialize search tasks in/from file
1 parent c17051d commit be565f6

File tree

12 files changed

+135
-57
lines changed

12 files changed

+135
-57
lines changed

Src/PRuntimes/PExplicitRuntime/src/main/java/pexplicit/runtime/ForeignFunctionInterface.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@
55
import java.util.function.Function;
66

77
public class ForeignFunctionInterface {
8-
/**
9-
* Invoke a foreign function with a void return type
10-
*
11-
* @param fn function to invoke
12-
* @param args arguments
13-
*/
14-
public static void accept(Consumer<List<Object>> fn, Object... args) {
15-
fn.accept(List.of(args));
16-
}
8+
/**
9+
* Invoke a foreign function with a void return type
10+
*
11+
* @param fn function to invoke
12+
* @param args arguments
13+
*/
14+
public static void accept(Consumer<List<Object>> fn, Object... args) {
15+
fn.accept(List.of(args));
16+
}
1717

18-
/**
19-
* Invoke a foreign function with a non-void return type
20-
*
21-
* @param fn function to invoke
22-
* @param args arguments
23-
* @return the return value of the function
24-
*/
25-
public static Object apply(Function<List<Object>, Object> fn, Object... args) {
26-
return fn.apply(List.of(args));
27-
}
18+
/**
19+
* Invoke a foreign function with a non-void return type
20+
*
21+
* @param fn function to invoke
22+
* @param args arguments
23+
* @return the return value of the function
24+
*/
25+
public static Object apply(Function<List<Object>, Object> fn, Object... args) {
26+
return fn.apply(List.of(args));
27+
}
2828
}

Src/PRuntimes/PExplicitRuntime/src/main/java/pexplicit/runtime/logger/PExplicitLogger.java

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
import pexplicit.runtime.machine.PMonitor;
1414
import pexplicit.runtime.machine.State;
1515
import pexplicit.runtime.machine.events.PContinuation;
16-
import pexplicit.runtime.scheduler.choice.Choice;
17-
import pexplicit.runtime.scheduler.choice.ScheduleChoice;
1816
import pexplicit.runtime.scheduler.choice.ScheduleSearchUnit;
1917
import pexplicit.runtime.scheduler.choice.SearchUnit;
2018
import pexplicit.runtime.scheduler.explicit.ExplicitSearchScheduler;
@@ -155,7 +153,7 @@ public static void logEndTask(SearchTask task, int numSchedules) {
155153
* @param task Next search task
156154
*/
157155
public static void logNextTask(SearchTask task) {
158-
if (verbosity > 1) {
156+
if (verbosity > 0) {
159157
log.info(String.format(" Next task: %s", task.toStringDetailed()));
160158
}
161159
}
@@ -171,6 +169,29 @@ public static void logNewTasks(List<SearchTask> tasks) {
171169
}
172170
}
173171

172+
/**
173+
* Log when serializing a task
174+
*
175+
* @param task Task to serialize
176+
* @param szBytes Bytes written
177+
*/
178+
public static void logSerializeTask(SearchTask task, long szBytes) {
179+
if (verbosity > 1) {
180+
log.info(String.format(" %,.1f MB written in %s", (szBytes / 1024.0 / 1024.0), task.getSerializeFile()));
181+
}
182+
}
183+
184+
/**
185+
* Log when deserializing a task
186+
*
187+
* @param task Task that is deserialized
188+
*/
189+
public static void logDeserializeTask(SearchTask task) {
190+
if (verbosity > 1) {
191+
log.info(String.format(" Reading %s from %s", task, task.getSerializeFile()));
192+
}
193+
}
194+
174195
/**
175196
* Log at the start of an iteration
176197
*
@@ -209,9 +230,9 @@ public static void logFinishedIteration(int step) {
209230
/**
210231
* Log when backtracking to a search unit
211232
*
212-
* @param stepNum Step number
233+
* @param stepNum Step number
213234
* @param choiceNum Choice number
214-
* @param unit Search unit to which backtracking to
235+
* @param unit Search unit to which backtracking to
215236
*/
216237
public static void logBacktrack(int stepNum, int choiceNum, SearchUnit unit) {
217238
if (verbosity > 1) {

Src/PRuntimes/PExplicitRuntime/src/main/java/pexplicit/runtime/machine/PMachineId.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
import lombok.Getter;
44
import lombok.Setter;
55

6+
import java.io.Serializable;
7+
68
@Getter
7-
public class PMachineId {
9+
public class PMachineId implements Serializable {
810
Class<? extends PMachine> type;
911
int typeId;
1012
@Setter

Src/PRuntimes/PExplicitRuntime/src/main/java/pexplicit/runtime/machine/buffer/MessageQueue.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import lombok.Getter;
44
import pexplicit.runtime.machine.PMachine;
55
import pexplicit.utils.exceptions.PExplicitRuntimeException;
6-
import pexplicit.utils.misc.Assert;
76
import pexplicit.values.PMessage;
87

98
import java.io.Serializable;

Src/PRuntimes/PExplicitRuntime/src/main/java/pexplicit/runtime/scheduler/Schedule.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ public void removeChoicesAfter(int choiceNum) {
6363
/**
6464
* Set the schedule choice at a choice depth.
6565
*
66-
* @param stepNum Step number
67-
* @param choiceNum Choice number
68-
* @param current Machine to set as current schedule choice
66+
* @param stepNum Step number
67+
* @param choiceNum Choice number
68+
* @param current Machine to set as current schedule choice
6969
*/
7070
public void setScheduleChoice(int stepNum, int choiceNum, PMachineId current) {
7171
if (choiceNum == choices.size()) {
@@ -84,9 +84,9 @@ public void setScheduleChoice(int stepNum, int choiceNum, PMachineId current) {
8484
/**
8585
* Set the data choice at a choice depth.
8686
*
87-
* @param stepNum Step number
88-
* @param choiceNum Choice number
89-
* @param current PValue to set as current schedule choice
87+
* @param stepNum Step number
88+
* @param choiceNum Choice number
89+
* @param current PValue to set as current schedule choice
9090
*/
9191
public void setDataChoice(int stepNum, int choiceNum, PValue<?> current) {
9292
if (choiceNum == choices.size()) {

Src/PRuntimes/PExplicitRuntime/src/main/java/pexplicit/runtime/scheduler/SchedulerInterface.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import pexplicit.values.*;
44

5+
import java.io.IOException;
56
import java.io.Serializable;
67
import java.util.concurrent.TimeoutException;
78

@@ -13,7 +14,7 @@ public interface SchedulerInterface extends Serializable {
1314
/**
1415
* Perform the search
1516
*/
16-
void run() throws TimeoutException, InterruptedException;
17+
void run() throws TimeoutException, InterruptedException, IOException;
1718

1819
/**
1920
* Return a random PBool based on the search and strategy.

Src/PRuntimes/PExplicitRuntime/src/main/java/pexplicit/runtime/scheduler/choice/DataSearchUnit.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import java.util.ArrayList;
66
import java.util.List;
77

8-
public class DataSearchUnit extends SearchUnit<PValue<?>>{
8+
public class DataSearchUnit extends SearchUnit<PValue<?>> {
99
/**
1010
* Constructor
1111
*/

Src/PRuntimes/PExplicitRuntime/src/main/java/pexplicit/runtime/scheduler/choice/ScheduleChoice.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import lombok.Getter;
44
import lombok.Setter;
5-
import pexplicit.commandline.PExplicitConfig;
65
import pexplicit.runtime.machine.PMachineId;
76
import pexplicit.runtime.scheduler.explicit.StepState;
87

Src/PRuntimes/PExplicitRuntime/src/main/java/pexplicit/runtime/scheduler/choice/ScheduleSearchUnit.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package pexplicit.runtime.scheduler.choice;
22

33
import pexplicit.runtime.machine.PMachineId;
4-
import pexplicit.runtime.scheduler.explicit.StepState;
54

65
import java.util.ArrayList;
76
import java.util.List;

Src/PRuntimes/PExplicitRuntime/src/main/java/pexplicit/runtime/scheduler/explicit/ExplicitSearchScheduler.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import pexplicit.runtime.machine.PMachine;
1313
import pexplicit.runtime.machine.PMachineId;
1414
import pexplicit.runtime.scheduler.Scheduler;
15-
import pexplicit.runtime.scheduler.choice.Choice;
1615
import pexplicit.runtime.scheduler.choice.ScheduleChoice;
1716
import pexplicit.runtime.scheduler.choice.SearchUnit;
1817
import pexplicit.runtime.scheduler.explicit.strategy.*;
@@ -112,9 +111,9 @@ public void run() throws TimeoutException {
112111
runIteration();
113112
postProcessIteration();
114113
}
114+
PExplicitLogger.logEndTask(searchStrategy.getCurrTask(), searchStrategy.getNumSchedulesInCurrTask());
115115
addRemainingChoicesAsChildrenTasks();
116116
endCurrTask();
117-
PExplicitLogger.logEndTask(searchStrategy.getCurrTask(), searchStrategy.getNumSchedulesInCurrTask());
118117

119118
if (searchStrategy.getPendingTasks().isEmpty() || PExplicitGlobal.getStatus() == STATUS.SCHEDULEOUT) {
120119
// all tasks completed or schedule limit reached
@@ -431,7 +430,7 @@ private void postProcessIteration() {
431430
private void addRemainingChoicesAsChildrenTasks() {
432431
SearchTask parentTask = searchStrategy.getCurrTask();
433432
int numChildrenAdded = 0;
434-
for (int i: parentTask.getSearchUnitKeys(false)) {
433+
for (int i : parentTask.getSearchUnitKeys(false)) {
435434
SearchUnit unit = parentTask.getSearchUnit(i);
436435
// if search unit at this depth is non-empty
437436
if (!unit.getUnexplored().isEmpty()) {
@@ -462,7 +461,7 @@ private void setChildTask(SearchUnit unit, int choiceNum, SearchTask parentTask,
462461
newTask.addSuffixSearchUnit(choiceNum, unit);
463462

464463
if (!isExact) {
465-
for (int i: parentTask.getSearchUnitKeys(false)) {
464+
for (int i : parentTask.getSearchUnitKeys(false)) {
466465
if (i > choiceNum) {
467466
if (i > maxChoiceNum) {
468467
maxChoiceNum = i;
@@ -476,6 +475,7 @@ private void setChildTask(SearchUnit unit, int choiceNum, SearchTask parentTask,
476475
newTask.addPrefixChoice(schedule.getChoice(i));
477476
}
478477

478+
newTask.serializeTask();
479479
parentTask.addChild(newTask);
480480
searchStrategy.addNewTask(newTask);
481481
}
@@ -494,11 +494,11 @@ public SearchTask setNextTask() {
494494
}
495495

496496
public int getNumUnexploredChoices() {
497-
return searchStrategy.getCurrTask().getNumUnexploredChoices() + searchStrategy.getNumPendingChoices();
497+
return searchStrategy.getCurrTask().getCurrentNumUnexploredChoices() + searchStrategy.getNumPendingChoices();
498498
}
499499

500500
public int getNumUnexploredDataChoices() {
501-
return searchStrategy.getCurrTask().getNumUnexploredDataChoices() + searchStrategy.getNumPendingDataChoices();
501+
return searchStrategy.getCurrTask().getCurrentNumUnexploredDataChoices() + searchStrategy.getNumPendingDataChoices();
502502
}
503503

504504
/**
@@ -518,7 +518,7 @@ public double getUnexploredDataChoicesPercent() {
518518

519519
private void postIterationCleanup() {
520520
SearchTask task = searchStrategy.getCurrTask();
521-
for (int cIdx: task.getSearchUnitKeys(true)) {
521+
for (int cIdx : task.getSearchUnitKeys(true)) {
522522
SearchUnit unit = task.getSearchUnit(cIdx);
523523
if (unit.getUnexplored().isEmpty()) {
524524
task.clearSearchUnit(cIdx);

0 commit comments

Comments
 (0)