Skip to content

Commit 392dceb

Browse files
authored
Fixed some parts in renaming ML related stuff (#839)
* Fixed renaming * Fixed renaming * Fixed renaming * Comment dependency
1 parent 24fe475 commit 392dceb

File tree

23 files changed

+89
-86
lines changed

23 files changed

+89
-86
lines changed

gradle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ jsoup_version=1.7.2
4444
djl_api_version=0.17.0
4545
pytorch_native_version=1.9.1
4646
shadow_jar_version=7.1.2
47+
openblas_version=0.3.10-1.5.4
48+
arpack_ng_version=3.7.0-1.5.4
4749
# soot also depends on asm, so there could be two different versions
4850

4951
org.gradle.daemon=false

utbot-analytics-torch/build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ dependencies {
1616
testImplementation project(':utbot-sample')
1717
testImplementation group: 'junit', name: 'junit', version: junit4_version
1818

19-
implementation group: 'org.bytedeco', name: 'arpack-ng', version: "3.7.0-1.5.4", classifier: "$classifier"
20-
implementation group: 'org.bytedeco', name: 'openblas', version: "0.3.10-1.5.4", classifier: "$classifier"
2119
implementation group: 'org.bytedeco', name: 'javacpp', version: javacpp_version, classifier: "$classifier"
2220
implementation group: 'org.jsoup', name: 'jsoup', version: jsoup_version
2321

utbot-analytics-torch/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
To enable support of the `utbot-analytics-torch` models in `utbot-intellij` module the following steps should be made:
22

3-
- change the row `api project(':utbot-analytics-torch')` to the `api project(':utbot-analytics-torch')` in the `build.gradle` file in the `utbot-intellij` module
3+
- change the row `api project(':utbot-analytics')` to the `api project(':utbot-analytics-torch')` in the `build.gradle` file in the `utbot-intellij` module and uncomment it, if it's commented.
44
- change the `pathSelectorType` in the `UtSettings.kt` to the `PathSelectorType.TORCH_SELECTOR`
55
- don't forget the put the Torch model in the path ruled by the setting `modelPath` in the `UtSettings.kt`
66

utbot-analytics-torch/src/main/kotlin/org/utbot/AnalyticsTorchConfiguration.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package org.utbot
33
import org.utbot.analytics.EngineAnalyticsContext
44
import org.utbot.features.FeatureExtractorFactoryImpl
55
import org.utbot.features.FeatureProcessorWithStatesRepetitionFactory
6-
import org.utbot.predictors.StateRewardPredictorWithTorchModelsSupportFactoryImpl
6+
import org.utbot.predictors.TorchPredictorFactoryImpl
77

88
/**
99
* The basic configuration of the utbot-analytics-torch module used in utbot-intellij and (as planned) in utbot-cli
@@ -16,6 +16,6 @@ object AnalyticsTorchConfiguration {
1616
init {
1717
EngineAnalyticsContext.featureProcessorFactory = FeatureProcessorWithStatesRepetitionFactory()
1818
EngineAnalyticsContext.featureExtractorFactory = FeatureExtractorFactoryImpl()
19-
EngineAnalyticsContext.stateRewardPredictorFactory = StateRewardPredictorWithTorchModelsSupportFactoryImpl()
19+
EngineAnalyticsContext.mlPredictorFactory = TorchPredictorFactoryImpl()
2020
}
2121
}

utbot-analytics-torch/src/main/kotlin/org/utbot/predictors/StateRewardPredictorFactory.kt

Lines changed: 0 additions & 11 deletions
This file was deleted.

utbot-analytics-torch/src/main/kotlin/org/utbot/predictors/StateRewardPredictorTorch.kt renamed to utbot-analytics-torch/src/main/kotlin/org/utbot/predictors/TorchPredictor.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import ai.djl.ndarray.NDArray
66
import ai.djl.ndarray.NDList
77
import ai.djl.translate.Translator
88
import ai.djl.translate.TranslatorContext
9-
import org.utbot.analytics.StateRewardPredictor
9+
import org.utbot.analytics.MLPredictor
1010
import org.utbot.framework.UtSettings
1111
import java.io.Closeable
1212
import java.nio.file.Paths
1313

14-
class StateRewardPredictorTorch : StateRewardPredictor, Closeable {
14+
class TorchPredictor : MLPredictor, Closeable {
1515
val model: Model
1616

1717
init {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.utbot.predictors
2+
3+
import org.utbot.analytics.MLPredictorFactory
4+
import org.utbot.framework.UtSettings
5+
6+
/**
7+
* Creates [StateRewardPredictor], by checking the [UtSettings] configuration.
8+
*/
9+
class TorchPredictorFactoryImpl : MLPredictorFactory {
10+
override operator fun invoke() = TorchPredictor()
11+
}

utbot-analytics-torch/src/test/kotlin/org/utbot/predictors/NNStateRewardPredictorTest.kt renamed to utbot-analytics-torch/src/test/kotlin/org/utbot/predictors/TorchPredictorTest.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ package org.utbot.predictors
33
import org.junit.jupiter.api.Assertions.assertEquals
44
import org.junit.jupiter.api.Disabled
55
import org.junit.jupiter.api.Test
6-
import org.utbot.analytics.StateRewardPredictor
6+
import org.utbot.analytics.MLPredictor
77
import org.utbot.testcheckers.withModelPath
88
import kotlin.system.measureNanoTime
99

10-
class NNStateRewardPredictorTest {
10+
class TorchPredictorTest {
1111
@Test
1212
@Disabled("Just to see the performance of predictors")
1313
fun simpleTest() {
1414
withModelPath("src/test/resources") {
15-
val pred = StateRewardPredictorTorch()
15+
val pred = TorchPredictor()
1616

1717
val features = listOf(0.0, 0.0)
1818

@@ -25,13 +25,13 @@ class NNStateRewardPredictorTest {
2525
fun performanceTest() {
2626
val features = (1..13).map { 1.0 }.toList()
2727
withModelPath("models") {
28-
val averageTime = calcAverageTimeForModelPredict(::StateRewardPredictorTorch, 100, features)
28+
val averageTime = calcAverageTimeForModelPredict(::TorchPredictor, 100, features)
2929
println(averageTime)
3030
}
3131
}
3232

3333
private fun calcAverageTimeForModelPredict(
34-
model: () -> StateRewardPredictor,
34+
model: () -> MLPredictor,
3535
iterations: Int,
3636
features: List<Double>
3737
): Double {

utbot-analytics/build.gradle

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ evaluationDependsOn(':utbot-framework')
1212
compileTestJava.dependsOn tasks.getByPath(':utbot-framework:testClasses')
1313

1414
dependencies {
15-
api(project(":utbot-api"))
16-
api(project(":utbot-core"))
17-
api(project(":utbot-summary"))
18-
api(project(":utbot-framework-api"))
19-
api(project(":utbot-fuzzers"))
20-
api(project(":utbot-instrumentation"))
21-
api(project(":utbot-framework"))
15+
implementation(project(":utbot-api"))
16+
implementation(project(":utbot-core"))
17+
implementation(project(":utbot-summary"))
18+
implementation(project(":utbot-framework-api"))
19+
implementation(project(":utbot-fuzzers"))
20+
implementation(project(":utbot-instrumentation"))
21+
implementation(project(":utbot-framework"))
2222
testImplementation project(':utbot-sample')
2323
testImplementation group: 'junit', name: 'junit', version: junit4_version
2424

@@ -30,9 +30,8 @@ dependencies {
3030
implementation group: 'io.github.microutils', name: 'kotlin-logging', version: kotlin_logging_version
3131
implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
3232

33-
implementation group: 'org.bytedeco', name: 'arpack-ng', version: "3.7.0-1.5.4", classifier: "$classifier"
34-
implementation group: 'org.bytedeco', name: 'openblas', version: "0.3.10-1.5.4", classifier: "$classifier"
35-
implementation group: 'org.bytedeco', name: 'javacpp', version: javacpp_version, classifier: "$classifier"
33+
implementation group: 'org.bytedeco', name: 'arpack-ng', version: arpack_ng_version, classifier: "$classifier"
34+
implementation group: 'org.bytedeco', name: 'openblas', version: openblas_version, classifier: "$classifier"
3635

3736
implementation group: 'tech.tablesaw', name: 'tablesaw-core', version: '0.38.2'
3837
implementation group: 'tech.tablesaw', name: 'tablesaw-jsplot', version: '0.38.2'

utbot-analytics/src/main/kotlin/org/utbot/AnalyticsConfiguration.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package org.utbot
33
import org.utbot.analytics.EngineAnalyticsContext
44
import org.utbot.features.FeatureExtractorFactoryImpl
55
import org.utbot.features.FeatureProcessorWithStatesRepetitionFactory
6-
import org.utbot.predictors.StateRewardPredictorFactoryImpl
6+
import org.utbot.predictors.MLPredictorFactoryImpl
77

88
/**
99
* The basic configuration of the utbot-analytics module used in utbot-intellij and (as planned) in utbot-cli
@@ -16,6 +16,6 @@ object AnalyticsConfiguration {
1616
init {
1717
EngineAnalyticsContext.featureProcessorFactory = FeatureProcessorWithStatesRepetitionFactory()
1818
EngineAnalyticsContext.featureExtractorFactory = FeatureExtractorFactoryImpl()
19-
EngineAnalyticsContext.stateRewardPredictorFactory = StateRewardPredictorFactoryImpl()
19+
EngineAnalyticsContext.mlPredictorFactory = MLPredictorFactoryImpl()
2020
}
2121
}

utbot-analytics/src/main/kotlin/org/utbot/predictors/LinearStateRewardPredictor.kt renamed to utbot-analytics/src/main/kotlin/org/utbot/predictors/LinearRegressionPredictor.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.utbot.predictors
22

3-
import org.utbot.analytics.StateRewardPredictor
3+
import org.utbot.analytics.MLPredictor
44
import mu.KotlinLogging
55
import org.utbot.framework.PathSelectorType
66
import org.utbot.framework.UtSettings
@@ -35,8 +35,8 @@ private fun loadWeights(path: String): Matrix {
3535
return Matrix(weightsArray)
3636
}
3737

38-
class LinearStateRewardPredictor(weightsPath: String = DEFAULT_WEIGHT_PATH, scalerPath: String = DEFAULT_SCALER_PATH) :
39-
StateRewardPredictor {
38+
class LinearRegressionPredictor(weightsPath: String = DEFAULT_WEIGHT_PATH, scalerPath: String = DEFAULT_SCALER_PATH) :
39+
MLPredictor {
4040
private lateinit var weights: Matrix
4141
private lateinit var scaler: StandardScaler
4242

@@ -46,7 +46,7 @@ class LinearStateRewardPredictor(weightsPath: String = DEFAULT_WEIGHT_PATH, scal
4646
scaler = loadScaler(scalerPath)
4747
} catch (e: PredictorLoadingException) {
4848
logger.info(e) {
49-
"Error while initialization of LinearStateRewardPredictor. Changing pathSelectorType on INHERITORS_SELECTOR"
49+
"Error while initialization of LinearRegressionPredictor. Changing pathSelectorType on INHERITORS_SELECTOR"
5050
}
5151
UtSettings.pathSelectorType = PathSelectorType.INHERITORS_SELECTOR
5252
}

utbot-analytics/src/main/kotlin/org/utbot/predictors/NNStateRewardPredictorBase.kt renamed to utbot-analytics/src/main/kotlin/org/utbot/predictors/MultilayerPerceptronPredictor.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.utbot.predictors
22

33
import mu.KotlinLogging
4-
import org.utbot.analytics.StateRewardPredictor
4+
import org.utbot.analytics.MLPredictor
55
import org.utbot.framework.PathSelectorType
66
import org.utbot.framework.UtSettings
77
import org.utbot.predictors.util.PredictorLoadingException
@@ -13,8 +13,8 @@ private val logger = KotlinLogging.logger {}
1313

1414
private fun getModel(path: String) = buildModel(loadModel(path))
1515

16-
class NNStateRewardPredictorBase(modelPath: String = DEFAULT_MODEL_PATH, scalerPath: String = DEFAULT_SCALER_PATH) :
17-
StateRewardPredictor {
16+
class MultilayerPerceptronPredictor(modelPath: String = DEFAULT_MODEL_PATH, scalerPath: String = DEFAULT_SCALER_PATH) :
17+
MLPredictor {
1818
private lateinit var nn: FeedForwardNetwork
1919
private lateinit var scaler: StandardScaler
2020

@@ -24,7 +24,7 @@ class NNStateRewardPredictorBase(modelPath: String = DEFAULT_MODEL_PATH, scalerP
2424
scaler = loadScaler(scalerPath)
2525
} catch (e: PredictorLoadingException) {
2626
logger.info(e) {
27-
"Error while initialization of NNStateRewardPredictorBase. Changing pathSelectorType on INHERITORS_SELECTOR"
27+
"Error while initialization of MultilayerPerceptronPredictor. Changing pathSelectorType on INHERITORS_SELECTOR"
2828
}
2929
UtSettings.pathSelectorType = PathSelectorType.INHERITORS_SELECTOR
3030
}
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
package org.utbot.predictors
22

3-
import org.utbot.analytics.StateRewardPredictorFactory
4-
import org.utbot.framework.StateRewardPredictorType
3+
import org.utbot.analytics.MLPredictor
4+
import org.utbot.analytics.MLPredictorFactory
5+
import org.utbot.framework.MLPredictorType
56
import org.utbot.framework.UtSettings
67

78
/**
8-
* Creates [StateRewardPredictor], by checking the [UtSettings] configuration.
9+
* Creates [MLPredictor], by checking the [UtSettings] configuration.
910
*/
10-
class StateRewardPredictorFactoryImpl : StateRewardPredictorFactory {
11-
override operator fun invoke() = when (UtSettings.stateRewardPredictorType) {
12-
StateRewardPredictorType.BASE -> NNStateRewardPredictorBase()
13-
StateRewardPredictorType.LINEAR -> LinearStateRewardPredictor()
11+
class MLPredictorFactoryImpl : MLPredictorFactory {
12+
override operator fun invoke() = when (UtSettings.mlPredictorType) {
13+
MLPredictorType.MLP -> MultilayerPerceptronPredictor()
14+
MLPredictorType.LINREG -> LinearRegressionPredictor()
1415
}
1516
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
project=antlr
2+
selectors=random_120,cpi_120,fork_120,inheritors_120,random_120
3+
covStatistics=logs/covStatistics,logs/covStatistics

utbot-analytics/src/test/kotlin/org/utbot/predictors/LinearStateRewardPredictorTest.kt renamed to utbot-analytics/src/test/kotlin/org/utbot/predictors/LinearRegressionPredictorTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import org.utbot.framework.UtSettings
77
import org.utbot.testcheckers.withPathSelectorType
88
import org.utbot.testcheckers.withModelPath
99

10-
class LinearStateRewardPredictorTest {
10+
class LinearRegressionPredictorTest {
1111
@Test
1212
fun simpleTest() {
1313
withModelPath("src/test/resources") {
14-
val pred = LinearStateRewardPredictor()
14+
val pred = LinearRegressionPredictor()
1515

1616
val features = listOf(
1717
listOf(2.0, 3.0),
@@ -26,7 +26,7 @@ class LinearStateRewardPredictorTest {
2626
fun wrongFormatTest() {
2727
withModelPath("src/test/resources") {
2828
withPathSelectorType(PathSelectorType.ML_SELECTOR) {
29-
LinearStateRewardPredictor("wrong_format_linear.txt")
29+
LinearRegressionPredictor("wrong_format_linear.txt")
3030
assertEquals(PathSelectorType.INHERITORS_SELECTOR, UtSettings.pathSelectorType)
3131
}
3232
}
@@ -35,7 +35,7 @@ class LinearStateRewardPredictorTest {
3535
@Test
3636
fun simpleTestNotBatch() {
3737
withModelPath("src/test/resources") {
38-
val pred = LinearStateRewardPredictor()
38+
val pred = LinearRegressionPredictor()
3939

4040
val features = listOf(2.0, 3.0)
4141

utbot-analytics/src/test/kotlin/org/utbot/predictors/NNStateRewardPredictorTest.kt renamed to utbot-analytics/src/test/kotlin/org/utbot/predictors/MultilayerPerceptronPredictorTest.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ package org.utbot.predictors
33
import org.junit.jupiter.api.Assertions.assertEquals
44
import org.junit.jupiter.api.Disabled
55
import org.junit.jupiter.api.Test
6-
import org.utbot.analytics.StateRewardPredictor
6+
import org.utbot.analytics.MLPredictor
77
import org.utbot.framework.PathSelectorType
88
import org.utbot.framework.UtSettings
99
import org.utbot.testcheckers.withPathSelectorType
1010
import org.utbot.testcheckers.withModelPath
1111
import kotlin.system.measureNanoTime
1212

13-
class NNStateRewardPredictorTest {
13+
class MultilayerPerceptronPredictorTest {
1414
@Test
1515
fun simpleTest() {
1616
withModelPath("src/test/resources") {
17-
val pred = NNStateRewardPredictorBase()
17+
val pred = MultilayerPerceptronPredictor()
1818

1919
val features = listOf(0.0, 0.0)
2020

@@ -27,13 +27,13 @@ class NNStateRewardPredictorTest {
2727
fun performanceTest() {
2828
val features = (1..13).map { 1.0 }.toList()
2929
withModelPath("models\\test\\0") {
30-
val averageTime = calcAverageTimeForModelPredict(::NNStateRewardPredictorBase, 100, features)
30+
val averageTime = calcAverageTimeForModelPredict(::MultilayerPerceptronPredictor, 100, features)
3131
println(averageTime)
3232
}
3333
}
3434

3535
internal fun calcAverageTimeForModelPredict(
36-
model: () -> StateRewardPredictor,
36+
model: () -> MLPredictor,
3737
iterations: Int,
3838
features: List<Double>
3939
): Double {
@@ -52,7 +52,7 @@ class NNStateRewardPredictorTest {
5252
fun corruptedModelFileTest() {
5353
withModelPath("src/test/resources") {
5454
withPathSelectorType(PathSelectorType.ML_SELECTOR) {
55-
NNStateRewardPredictorBase(modelPath = "corrupted_nn.json")
55+
MultilayerPerceptronPredictor(modelPath = "corrupted_nn.json")
5656
assertEquals(PathSelectorType.INHERITORS_SELECTOR, UtSettings.pathSelectorType)
5757
}
5858
}
@@ -62,7 +62,7 @@ class NNStateRewardPredictorTest {
6262
fun emptyModelFileTest() {
6363
withModelPath("src/test/resources") {
6464
withPathSelectorType(PathSelectorType.ML_SELECTOR) {
65-
NNStateRewardPredictorBase(modelPath = "empty_nn.json")
65+
MultilayerPerceptronPredictor(modelPath = "empty_nn.json")
6666
assertEquals(PathSelectorType.INHERITORS_SELECTOR, UtSettings.pathSelectorType)
6767
}
6868
}
@@ -72,7 +72,7 @@ class NNStateRewardPredictorTest {
7272
fun corruptedScalerTest() {
7373
withModelPath("src/test/resources") {
7474
withPathSelectorType(PathSelectorType.ML_SELECTOR) {
75-
NNStateRewardPredictorBase(scalerPath = "corrupted_scaler.txt")
75+
MultilayerPerceptronPredictor(scalerPath = "corrupted_scaler.txt")
7676
assertEquals(PathSelectorType.INHERITORS_SELECTOR, UtSettings.pathSelectorType)
7777
}
7878
}

utbot-framework-api/src/main/kotlin/org/utbot/framework/UtSettings.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ object UtSettings : AbstractSettings(
9393
var mlSelectorRecalculationType: MLSelectorRecalculationType by getEnumProperty(MLSelectorRecalculationType.WITHOUT_RECALCULATION)
9494

9595
/**
96-
* Type of [StateRewardPredictor].
96+
* Type of [MLPredictor].
9797
*/
98-
var stateRewardPredictorType: StateRewardPredictorType by getEnumProperty(StateRewardPredictorType.BASE)
98+
var mlPredictorType: MLPredictorType by getEnumProperty(MLPredictorType.MLP)
9999

100100
/**
101101
* Steps limit for path selector.
@@ -451,16 +451,16 @@ enum class MLSelectorRecalculationType {
451451
}
452452

453453
/**
454-
* Enum to specify [StateRewardPredictor], see implementations for details
454+
* Enum to specify [MLPredictor], see implementations for details
455455
*/
456-
enum class StateRewardPredictorType {
456+
enum class MLPredictorType {
457457
/**
458-
* [MLStateRewardPredictorBase]
458+
* [MultilayerPerceptronPredictor]
459459
*/
460-
BASE,
460+
MLP,
461461

462462
/**
463-
* [LinearStateRewardPredictorBase]
463+
* [LinearRegressionPredictor]
464464
*/
465-
LINEAR
465+
LINREG
466466
}

0 commit comments

Comments
 (0)