|
| 1 | +# JLearch architecture |
| 2 | + |
| 3 | +# Global Class Diagram |
| 4 | + |
| 5 | +```mermaid |
| 6 | +classDiagram |
| 7 | + class FeatureProcessor{ |
| 8 | + dumpFeatures() |
| 9 | + } |
| 10 | + <<interface>> FeatureProcessor |
| 11 | + class TraverseGraphStatistics{ |
| 12 | + onVisit(ExecutionState) |
| 13 | + onTraversed(ExecutionState) |
| 14 | + } |
| 15 | + class InterproceduralUnitGraph |
| 16 | + class FeatureExtractorFactory |
| 17 | + <<interface>> FeatureExtractorFactory |
| 18 | + class FeatureProcessorFactory |
| 19 | + <<interface>> FeatureProcessorFactory |
| 20 | + class EngineAnalyticsContext |
| 21 | + class UtBotSymbolicEngine |
| 22 | + class NNRewardGuidedSelectorFactory |
| 23 | + <<interface>> NNRewardGuidedSelectorFactory |
| 24 | + class FeatureExtractor{ |
| 25 | + extractFeatures(ExecutionState) |
| 26 | + } |
| 27 | + <<interface>> FeatureExtractor |
| 28 | + |
| 29 | + UtBotSymbolicEngine ..> EngineAnalyticsContext |
| 30 | + EngineAnalyticsContext o-- FeatureProcessorFactory |
| 31 | + EngineAnalyticsContext o-- FeatureExtractorFactory |
| 32 | + EngineAnalyticsContext o-- NNRewardGuidedSelectorFactory |
| 33 | +
|
| 34 | + FeatureProcessor --|> TraverseGraphStatistics |
| 35 | + InterproceduralUnitGraph o-- TraverseGraphStatistics |
| 36 | + UtBotSymbolicEngine *-- FeatureProcessor |
| 37 | + UtBotSymbolicEngine *-- InterproceduralUnitGraph |
| 38 | +
|
| 39 | + class Predictors |
| 40 | + class NNStateRewardPredictor |
| 41 | + class NNRewardGuidedSelector |
| 42 | +
|
| 43 | + |
| 44 | + class GreedySearch |
| 45 | +
|
| 46 | + class BasePathSelector |
| 47 | +
|
| 48 | + GreedySearch --|> BasePathSelector |
| 49 | + NNRewardGuidedSelector --|> GreedySearch |
| 50 | +
|
| 51 | + UtBotSymbolicEngine *-- BasePathSelector |
| 52 | + |
| 53 | + Predictors o-- NNStateRewardPredictor |
| 54 | + NNRewardGuidedSelector ..> Predictors |
| 55 | + NNRewardGuidedSelector *-- FeatureExtractor |
| 56 | + |
| 57 | + NNStateRewardPredictorSmile --|> NNStateRewardPredictor |
| 58 | + NNStateRewardPredictorTorch --|> NNStateRewardPredictor |
| 59 | + |
| 60 | + NNStateRewardGuidedSelectorWithRecalculationWeight --|> NNRewardGuidedSelector |
| 61 | + NNStateRewardGuidedSelectorWithoutRecalculationWeight --|> NNRewardGuidedSelector |
| 62 | +``` |
| 63 | + |
| 64 | +This diagram doesn't illustrate some details, so read them below. |
| 65 | + |
| 66 | +# FeatureProcessor |
| 67 | + |
| 68 | +It is interface in framework-module, that allows to use implementation from analytics module. |
| 69 | + |
| 70 | +* `dumpFeatures(state: ExecutionState)` - dump features and rewards in some format on disk. Called at the end of traverse in `UtBotSymbolicEngine` |
| 71 | + |
| 72 | +## Implementation class diagram |
| 73 | + |
| 74 | +```mermaid |
| 75 | +classDiagram |
| 76 | + class FeatureProcessorWithStatesRepetition{ |
| 77 | + -Map~Int, FeatureList~ dumpedStates |
| 78 | + -Set~Stmt~ visitedStmts |
| 79 | + -List~TestCase~ testCases |
| 80 | + -int generatedTestCases |
| 81 | + dumpFeatures() |
| 82 | + } |
| 83 | + |
| 84 | + class FeatureExtractor{ |
| 85 | + extractFeatures(ExecutionState) |
| 86 | + } |
| 87 | + |
| 88 | + class TraverseGraphStatistics{ |
| 89 | + onVisit(ExecutionState) |
| 90 | + onTraversed(ExecutionState) |
| 91 | + } |
| 92 | + |
| 93 | + class RewardEstimator{ |
| 94 | + calculateRewards(List~TestCase~) |
| 95 | + } |
| 96 | + |
| 97 | + class TestCase{ |
| 98 | + +List<State> states |
| 99 | + +int newCoverage |
| 100 | + +int testIndex |
| 101 | + } |
| 102 | + |
| 103 | + FeatureProcessorWithStatesRepetition --|> TraverseGraphStatistics |
| 104 | + FeatureProcessorWithStatesRepetition o-- FeatureExtractor |
| 105 | + FeatureProcessorWithStatesRepetition o-- RewardEstimator |
| 106 | + FeatureProcessorWithStatesRepetition ..> EngineAnalyticsContext |
| 107 | + |
| 108 | +``` |
| 109 | + |
| 110 | +`State = Pair<Int, Long>` |
| 111 | + |
| 112 | +`FeatureList = List<Double` |
| 113 | + |
| 114 | +## RewardEstimator |
| 115 | + |
| 116 | +Maintains calculation of reward. |
| 117 | + |
| 118 | +* `calculateRewards(List<TestCase>): Map<Int, Double>` - calculates `coverage` for each state and `time` for each state. `Coverage` - sum of `newCoverage` by `TestCase` that contains its state. `Time` - sum of `state.executingTime` by all states, that has this state on its path. Then calculates `reward(coverage, time)`. |
| 119 | + |
| 120 | +## FeatureProcessorWithStatesRepetition |
| 121 | + |
| 122 | +* `onVisit(state: ExecutionState)` - extractFeatures for state |
| 123 | +* `onTraversed(state: ExecutionState)` - create `TestCase`, so we go from `state` to `state.parent` while it is not root, for each `state` on path add its features to `dumpedStates`, calculate coverage of its `TestCase`, increment `generatedTestCases` on 1 and add new `TestCase` in `testCases`. |
| 124 | +* `dumpFeatures()` - call `RewardEstimator.calculateRewards()` and write `csv` file for each `TestCase` in format: `newCov,features,reward` for each `state` in it. `newCov` - flag that indicates whether this `TestCase` cover something new or not. So in this approach, each `state` will be written as many times as the number of `TestCase` that has it. |
| 125 | +For creating `FeatureExtractor`, it uses `FeatureExtractorFactory` from `EngineAnalyticsContext`. |
| 126 | + |
| 127 | +# FeatureExtractor |
| 128 | + |
| 129 | +It is interface in framework-module, that allows to use implementation from analytics module. |
| 130 | +* `extractFeatures(state: ExecutionState)` - create features list for state and store it in `state.features`. Now we extract all features, which were described in [paper](https://files.sri.inf.ethz.ch/website/papers/ccs21-learch.pdf). In feature, we can extend the feature list by other features, for example, NeuroSMT. |
| 131 | + |
| 132 | +# NNStateRewardPredictor |
| 133 | + |
| 134 | +Interface for reward predictors. Now it has two implementations in `analytics` module: |
| 135 | + |
| 136 | +* `NNStateRewardPredictorSmile`: it uses our own format to store feedforward neural network, and it uses `Smile` library to do multiplication of matrix. |
| 137 | +* `NNStateRewardPredictorTorch`: it assumed that a model is any type of model in `pt` format. It uses the `Deep Java library` to use such models. |
| 138 | + |
| 139 | +It should be created at the beginning of work and stored at `Predictors` class to be used in `NNRewardGuidedSelector` from the `framework` module. |
| 140 | + |
| 141 | + |
| 142 | +# NNStateRewardGuidedSelector |
| 143 | + |
| 144 | +It uses an `EngineAnalyticsContext` to create `FeatureExtractor`. |
| 145 | +We override `ExecutionState.weight` as `NNStateRewardPredictor.predict(this.features)`. |
| 146 | +We have two different implementantions: |
| 147 | +* `NNStateRewardGuidedSelectorWithRecalculation`: we recalculate reward every time, so in `ExecutionState.weight` we extract features and call predict. |
| 148 | +* `NNStateRewardGuidedSlectorWithoutRecalculation`: we extract features in `offerImpl`, calculate `reward` and store it in `ExecutionState.reward` without recalculation it every time. |
| 149 | + |
| 150 | +# EngineAnalyticsContext |
| 151 | + |
| 152 | +It is an object that should be filled by factories in the beginning of work to allow objects from the `framework` module using objects from `analytics` module. |
0 commit comments