Skip to content

Commit

Permalink
Merge 79debeb into 028a98c
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian-B committed Aug 23, 2019
2 parents 028a98c + 79debeb commit 31684dd
Show file tree
Hide file tree
Showing 12 changed files with 915 additions and 44 deletions.
4 changes: 2 additions & 2 deletions pacman/model/graphs/common/edge_traffic_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from enum import Enum
from enum import IntEnum


class EdgeTrafficType(Enum):
class EdgeTrafficType(IntEnum):
""" Indicates the traffic type of an Edge in a graph
"""

Expand Down
6 changes: 6 additions & 0 deletions pacman/model/graphs/impl/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ def add_outgoing_edge_partition(self, outgoing_edge_partition):
def vertices(self):
return self._vertices

# TEMP method until another PR does this better
def vertex_by_label(self, label):
for vertex in self._vertices:
if vertex.label == label:
return vertex

@property
@overrides(AbstractGraph.n_vertices)
def n_vertices(self):
Expand Down
10 changes: 10 additions & 0 deletions pacman/model/resources/iptag_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,13 @@ def __repr__(self):
"traffic_identifier={})".format(
self._ip_address, self._port, self._strip_sdp, self._tag,
self._traffic_identifier))

def __eq__(self, other):
"""
For unit tests ONLY so __hash__ and __eq__ pairing not done!
"""
return (self._ip_address == other._ip_address and
self._port == other._port and
self._strip_sdp == other._strip_sdp and
self._tag == other._tag and
self._traffic_identifier == other._traffic_identifier)
16 changes: 16 additions & 0 deletions pacman/model/resources/resource_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,19 @@ def extend(self, other):

# add reverse IPtags
self._reverse_iptags.extend(other.reverse_iptags)

def __eq__(self, other):
"""
For unit tests ONLY so __hash__ and __eq__ pairing not done!
"""
if self._dtcm_usage.get_value() != other.dtcm.get_value():
return False
if self._sdram_usage.fixed != other._sdram_usage.fixed:
return False
if self._sdram_usage.per_timestep != other._sdram_usage.per_timestep:
return False
if self._cpu_cycles.get_value() != other.cpu_cycles.get_value():
return False
if self._iptags != other._iptags:
return False
return self._reverse_iptags == other._reverse_iptags
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
21 changes: 21 additions & 0 deletions pacman/operations/algorithm_reports/reports_metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -417,4 +417,25 @@
<param_type>JsonRoutingTablesPath</param_type>
</outputs>
</algorithm>
<algorithm name="ConvertToJsonMachineGraph">
<python_module>pacman.operations.algorithm_reports.convert_to_json_machine_graph</python_module>
<python_class>ConvertToJsonMachineGraph</python_class>
<input_definitions>
<parameter>
<param_name>machine_graph</param_name>
<param_type>MemoryMachineGraph</param_type>
</parameter>
<parameter>
<param_name>report_folder</param_name>
<param_type>ReportFolder</param_type>
</parameter>
</input_definitions>
<required_inputs>
<param_name>machine_graph</param_name>
<param_name>report_folder</param_name>
</required_inputs>
<outputs>
<param_type>JsonMachineGraphPath</param_type>
</outputs>
</algorithm>
</algorithms>
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def __call__(self, machine_graph, plan_n_timesteps, file_path):
json.dump(json_graph, f)
progress.update()

file_format_schemas.validate(json_graph, "machine_graph.json")
file_format_schemas.validate(json_graph, "rig_machine_graph.json")

progress.end()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __call__(self, machine_graph, plan_n_timesteps, file_path):
json.dump(json_graph, file_to_write)
progress.update()

file_format_schemas.validate(json_graph, "machine_graph.json")
file_format_schemas.validate(json_graph, "rig_machine_graph.json")

progress.end()

Expand Down
Loading

0 comments on commit 31684dd

Please sign in to comment.