-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(optimizer): improved configuration output
- Loading branch information
1 parent
251ad58
commit d040f04
Showing
6 changed files
with
120 additions
and
10 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
discopop_library/ParallelConfiguration/ParallelConfiguration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# This file is part of the DiscoPoP software (http://www.discopop.tu-darmstadt.de) | ||
# | ||
# Copyright (c) 2020, Technische Universitaet Darmstadt, Germany | ||
# | ||
# This software may be modified and distributed under the terms of | ||
# the 3-Clause BSD License. See the LICENSE file in the package base | ||
# directory for details. | ||
|
||
import json | ||
from typing import List, Tuple, Any, Dict | ||
import warnings | ||
|
||
from discopop_library.discopop_optimizer.classes.context.Update import Update, construct_update_from_dict | ||
from discopop_library.discopop_optimizer.classes.types.Aliases import DeviceID | ||
|
||
SuggestionId = int | ||
|
||
|
||
class ParallelConfiguration(object): | ||
"""Object to store, save and reconstruct configurations and suggestions to be applied by the patch applicator.""" | ||
|
||
__applied_patterns: List[Dict[str, Any]] | ||
__data_movement: List[Update] | ||
|
||
def __init__(self): | ||
self.__applied_patterns = [] | ||
self.__data_movement = [] | ||
|
||
def reconstruct_from_file(self, file_path: str): | ||
with open(file_path, "r") as f: | ||
loaded_data = json.load(f) | ||
self.__applied_patterns = loaded_data["applied_patterns"] | ||
|
||
for values in loaded_data["data_movement"]: | ||
self.__data_movement.append(construct_update_from_dict(values)) | ||
|
||
def dump_to_file(self, file_path: str): | ||
dumpable_dict = dict() | ||
dumpable_dict["applied_patterns"] = self.__applied_patterns | ||
dumpable_dict["data_movement"] = [update.toDict() for update in self.__data_movement] | ||
|
||
with open(file_path, "w") as f: | ||
json.dump(dumpable_dict, f) | ||
|
||
test = ParallelConfiguration() | ||
test.reconstruct_from_file(file_path) | ||
|
||
def add_pattern(self, pattern_id: SuggestionId, target_device_id: DeviceID): | ||
tmp_dict = {"pattern_id": pattern_id, "device_id": target_device_id} | ||
self.__applied_patterns.append(tmp_dict) | ||
|
||
def add_data_movement(self, update: Update): | ||
self.__data_movement.append(update) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters