-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
915 additions
and
44 deletions.
There are no files selected for viewing
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
82 changes: 82 additions & 0 deletions
82
pacman/operations/algorithm_reports/convert_to_json_machine_graph.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,82 @@ | ||
# Copyright (c) 2017-2019 The University of Manchester | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import logging | ||
import json | ||
import os | ||
from spinn_utilities.log import FormatAdapter | ||
from spinn_utilities.progress_bar import ProgressBar | ||
from pacman.utilities import file_format_schemas | ||
from pacman.utilities.json_utils import graph_to_json | ||
|
||
_ROUTING_FILENAME = "machine_graph.json" | ||
logger = FormatAdapter(logging.getLogger(__name__)) | ||
|
||
|
||
class ConvertToJsonMachineGraph(object): | ||
""" Converter from MulticastRoutingTables to json | ||
""" | ||
|
||
def __call__(self, machine_graph, report_folder): | ||
""" Runs the code to write the machine in Java readable JSON. | ||
:param machine_graph: The machine_graph to place | ||
:type machine_graph:\ | ||
:py:class:`pacman.model.graphs.machine.MachineGraph` | ||
:param report_folder: the folder to which the reports are being written | ||
:type report_folder: str | ||
""" | ||
# Steps are tojson, validate and writefile | ||
progress = ProgressBar(3, "Converting to JSON MachineGraph") | ||
|
||
file_path = os.path.join(report_folder, _ROUTING_FILENAME) | ||
return ConvertToJsonMachineGraph.do_convert( | ||
machine_graph, file_path, progress) | ||
|
||
@staticmethod | ||
def do_convert(machine_graph, file_path, progress=None): | ||
""" Runs the code to write the machine in Java readable JSON. | ||
:param machine_graph: The machine_graph to place | ||
:type machine_graph:\ | ||
:py:class:`pacman.model.graphs.machine.MachineGraph` | ||
:param file_path: Location to write file to. Warning will overwrite! | ||
:type file_path: str | ||
""" | ||
|
||
json_obj = graph_to_json(machine_graph) | ||
|
||
if progress: | ||
progress.update() | ||
|
||
# validate the schema | ||
try: | ||
file_format_schemas.validate(json_obj, "machine_graph.json") | ||
except Exception as ex: | ||
logger.error("json valiation exception:\n {} \n {} \n".format( | ||
ex.message, ex.instance)) | ||
|
||
# update and complete progress bar | ||
if progress: | ||
progress.update() | ||
|
||
# dump to json file | ||
with open(file_path, "w") as f: | ||
json.dump(json_obj, f) | ||
|
||
if progress: | ||
progress.end() | ||
|
||
return file_path |
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
Oops, something went wrong.