-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
M3SA - Multi-Meta-Model Simulation Analyzer #251
Changes from 7 commits
52f3738
be9011f
1122bb4
42ff227
cf91362
f26cce2
8b7de0b
0932a99
918cc5c
3dd068a
3ba2843
c93cf01
70f4952
33ab751
864c1c4
2b67e2e
904faea
36fbcc7
1e401a9
b9107b1
8909923
2ef3776
5be1008
f129706
59fbd93
f73c1db
9da4144
bcf7d12
da6c2f4
82ca406
64ec4ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,3 +115,6 @@ gradle-app.setting | |
|
||
# Cache of project | ||
.gradletasknamecache | ||
|
||
# Demo files | ||
demo/* |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, Experiment.kt should not be used by m3sa, and thus not changed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's see if we have a better alternative -- how would you suggest to make this change? what code to add in which file? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [TOTALK#1] |
Radu-Nicolae marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,8 +35,8 @@ private val experimentWriter = ExperimentWriter() | |
* @param filePath The path to the file containing the scenario specifications. | ||
* @return A list of Scenarios. | ||
*/ | ||
public fun getExperiment(filePath: String): List<Scenario> { | ||
return getExperiment(File(filePath)) | ||
public fun getExperiments(filePath: String): List<Scenario> { | ||
return getExperiments(File(filePath)) | ||
} | ||
|
||
/** | ||
|
@@ -45,8 +45,8 @@ public fun getExperiment(filePath: String): List<Scenario> { | |
* @param file The file containing the scenario specifications. | ||
* @return A list of Scenarios. | ||
*/ | ||
public fun getExperiment(file: File): List<Scenario> { | ||
return getExperiment(experimentReader.read(file)) | ||
public fun getExperiments(file: File): List<Scenario> { | ||
return getExperiments(experimentReader.read(file)) | ||
} | ||
|
||
/** | ||
|
@@ -56,7 +56,7 @@ public fun getExperiment(file: File): List<Scenario> { | |
* @param experimentSpec The ScenarioSpec containing the scenario specifications. | ||
* @return A list of Scenarios. | ||
*/ | ||
public fun getExperiment(experimentSpec: ExperimentSpec): List<Scenario> { | ||
public fun getExperiments(experimentSpec: ExperimentSpec): List<Scenario> { | ||
val outputFolder = experimentSpec.outputFolder + "/" + experimentSpec.name | ||
File(outputFolder).mkdirs() | ||
|
||
|
@@ -79,6 +79,7 @@ public fun getExperiment(experimentSpec: ExperimentSpec): List<Scenario> { | |
carbonTracePath = scenarioSpec.carbonTracePath, | ||
exportModelSpec = scenarioSpec.exportModel, | ||
outputFolder = outputFolder, | ||
m3saSetup = experimentSpec.m3saSetup, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is m3saSetup ever used when running a scenario? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, m3saSetup is used in scenario-post run. triggers and links the scenario with m3sa |
||
name = scenarioID.toString(), | ||
runs = experimentSpec.runs, | ||
initialSeed = experimentSpec.initialSeed, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. m3sa should not touch ExperimentSpec There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is also unclear what m3saSetup does, and why it is needed in ExperimentCli There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please suggest a better alternative, what files to change and with which code There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [TOTALK#2] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. m3saSetup in ExperimentSpec -- non mandatory to setup, but part of an experiment, used when parsing the JSON file. this is part of the JSON file parser. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,13 +42,15 @@ import java.util.UUID | |
* @property computeExportConfig configures which parquet columns are to | ||
* be included in the output files. | ||
*/ | ||
|
||
@Serializable | ||
public data class ExperimentSpec( | ||
var id: Int = -1, | ||
var name: String = "", | ||
val outputFolder: String = "output", | ||
val initialSeed: Int = 0, | ||
val runs: Int = 1, | ||
val m3saSetup: String = "", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this defined in the ExperimentSpec? |
||
val topologies: Set<ScenarioTopologySpec>, | ||
val workloads: Set<WorkloadSpec>, | ||
val allocationPolicies: Set<AllocationPolicySpec> = setOf(AllocationPolicySpec()), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright (c) 2020 AtLarge Research | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
description = "Multi-Meta-Model Simulation Analysis (M3SA) used across OpenDC modules" | ||
|
||
// Build configuration | ||
plugins { | ||
`kotlin-library-conventions` | ||
} | ||
|
||
dependencies { | ||
api(libs.kotlinx.coroutines) | ||
|
||
testImplementation(projects.opendcSimulator.opendcSimulatorCore) | ||
} | ||
|
||
sourceSets { | ||
main { | ||
kotlin.srcDirs("src/main/kotlin", "src/main/python") | ||
resources.srcDir("src/main/resources") | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (c) 2024 AtLarge Research | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
import kotlin.io.path.Path | ||
|
||
/** | ||
* This constant variable should be changed depending on the root folder that is being run. | ||
* PATH_TO_PYTHON_MAIN should point to the main python file, ran when the analysis starts. | ||
*/ | ||
|
||
public val ANALYSIS_SCRIPTS_DIRECTORY: String = "./opendc-experiments/opendc-m3sa/src/main/python" | ||
public val ABSOLUTE_SCRIPT_PATH: String = | ||
Path("$ANALYSIS_SCRIPTS_DIRECTORY/main.py").toAbsolutePath().normalize().toString() | ||
public val SCRIPT_LANGUAGE: String = "python3" | ||
|
||
public fun m3saRun( | ||
outputFolderPath: String, | ||
m3saSetupPath: String, | ||
) { | ||
val process = | ||
ProcessBuilder( | ||
SCRIPT_LANGUAGE, | ||
ABSOLUTE_SCRIPT_PATH, | ||
outputFolderPath, | ||
m3saSetupPath, | ||
).directory(Path(ANALYSIS_SCRIPTS_DIRECTORY).toFile()) | ||
.start() | ||
|
||
val exitCode = process.waitFor() | ||
if (exitCode == 0) { | ||
println("[M3SA says] M3SA operation(s) completed successfully.") | ||
} else { | ||
val errors = process.errorStream.bufferedReader().readText() | ||
println("[M3SA says] Exit code $exitCode; Error(s): $errors") | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import numpy as np | ||
|
||
from models.MetaModel import MetaModel | ||
|
||
|
||
def accuracy_evaluator( | ||
real_data, | ||
multi_model, | ||
compute_mape=True, | ||
compute_nad=True, | ||
compute_rmsle=True, | ||
rmsle_hyperparameter=0.5, | ||
only_metamodel=False | ||
): | ||
""" | ||
:param real_data: the real-world data of the simulation | ||
:param multi_model: the Multi-Model, containing individual models (possibly also a Meta-Model, with id=101) | ||
:param MAPE: whether to calculate Mean Absolute Percentage Error (MAPE) | ||
:param NAD: whether to calculate Normalized Absolute Differences (NAD) | ||
:param RMSLE: whether to calculate Root Mean Square Logarithmic Error (RMSLE) | ||
:param rmsle_hyperparameter: the hyperparameter that balances the ration underestimations:overestimations | ||
- default is 0.5 (balanced penalty) | ||
- < 0.5: more penalty for overestimations | ||
- > 0.5: more penalty for underestimations | ||
e.g., RMSLE_hyperparameter=0.3 -> 30% penalty for overestimations, 70% penalty for underestimations (3:7 ratio) | ||
:return: None, but prints the accuracy metrics | ||
""" | ||
|
||
meta_model = MetaModel(multimodel=multi_model) | ||
multi_model.models.append(meta_model.meta_model) # metamodel | ||
# multi_model.models.append(Model(raw_host_data=real_data, id=-1, path=None)) # real-world data | ||
|
||
with open(multi_model.output_folder_path + "/accuracy_report.txt", "a") as f: | ||
f.write("====================================\n") | ||
f.write("Accuracy Report, against ground truth\n") | ||
|
||
for model in multi_model.models: | ||
if only_metamodel and model.id != 101: | ||
continue | ||
|
||
if model.id == -1: | ||
f.write("Real-World data") | ||
elif model.id == 101: | ||
f.write( | ||
f"Meta-Model, meta-function: {multi_model.user_input['meta_function']}, window_size: {meta_model.multi_model.window_size}") | ||
else: | ||
f.write(f"Model {model.id}") | ||
|
||
simulation_data = model.raw_sim_data | ||
min_len = min(len(real_data), len(simulation_data)) | ||
real_data = real_data[:min_len] | ||
simulation_data = simulation_data[:min_len] | ||
if compute_mape: | ||
accuracy_mape = mape( | ||
real_data=real_data, | ||
simulation_data=simulation_data | ||
) | ||
f.write(f"\nMean Absolute Percentage Error (MAPE): {accuracy_mape}%") | ||
|
||
if compute_nad: | ||
accuracy_nad = nad( | ||
real_data=real_data, | ||
simulation_data=simulation_data | ||
) | ||
f.write(f"\nNormalized Absolute Differences (NAD): {accuracy_nad}%") | ||
|
||
if compute_rmsle: | ||
accuracy_rmsle = rmsle( | ||
real_data=real_data, | ||
simulation_data=simulation_data, | ||
alpha=rmsle_hyperparameter | ||
) | ||
f.write( | ||
f"\nRoot Mean Square Logarithmic Error (RMSLE), alpha={rmsle_hyperparameter}:{accuracy_rmsle}\n\n") | ||
|
||
f.write("====================================\n") | ||
|
||
|
||
def mape(real_data, simulation_data): | ||
""" | ||
Calculate Mean Absolute Percentage Error (MAPE) | ||
:param real_data: Array of real values | ||
:param simulation_data: Array of simulated values | ||
:return: MAPE value | ||
""" | ||
real_data = np.array(real_data) | ||
simulation_data = np.array(simulation_data) | ||
return round(np.mean(np.abs((real_data - simulation_data) / real_data)) * 100, 3) | ||
|
||
|
||
def nad(real_data, simulation_data): | ||
""" | ||
Calculate Normalized Absolute Differences (NAD) | ||
:param real_data: Array of real values | ||
:param simulation_data: Array of simulated values | ||
:return: NAD value | ||
""" | ||
real_data = np.array(real_data) | ||
simulation_data = np.array(simulation_data) | ||
return round(np.sum(np.abs(real_data - simulation_data)) / np.sum(real_data) * 100, 3) | ||
|
||
|
||
def rmsle(real_data, simulation_data, alpha=0.5): | ||
""" | ||
Calculate Root Mean Square Logarithmic Error (RMSLE) with an adjustable alpha parameter | ||
:param real_data: Array of real values | ||
:param simulation_data: Array of simulated values | ||
:param alpha: Hyperparameter that balances the penalty between underestimations and overestimations | ||
:return: RMSLE value | ||
""" | ||
real_data = np.array(real_data) | ||
simulation_data = np.array(simulation_data) | ||
log_diff = alpha * np.log(real_data) - (1 - alpha) * np.log(simulation_data) | ||
return round(np.sqrt(np.mean(log_diff ** 2)) * 100, 3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does experiment-base implement m3sa?
As far as I understand, m3sa uses base, not the other way around.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
both m3sa and experiment-base use, in one way or another, each other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In which way does experiment-base use m3sa?
Also this would be circular importing, which is not possible.