1313# limitations under the License.
1414from __future__ import annotations
1515import logging
16- from typing import Iterator , Optional , Set , Tuple , TYPE_CHECKING
16+ from typing import (
17+ Iterator , Optional , Set , Tuple , TYPE_CHECKING , List , Any , Dict )
1718
1819from spinn_utilities .log import FormatAdapter
1920
2021from spinn_front_end_common .data import FecDataView
2122
2223from spynnaker import _version
24+ from spinn_utilities .config_holder import get_config_bool , get_report_path
2325
2426if TYPE_CHECKING :
2527 from spynnaker .pyNN .models .projection import Projection
@@ -51,7 +53,8 @@ class _SpynnakerDataModel(object):
5153 "_id_counter" ,
5254 "_min_delay" ,
5355 "_populations" ,
54- "_projections" )
56+ "_projections" ,
57+ "_pynn_report" )
5558
5659 def __new__ (cls ) -> '_SpynnakerDataModel' :
5760 if cls .__singleton is not None :
@@ -70,6 +73,7 @@ def _clear(self) -> None:
7073 # Using a dict to verify if later could be stored here only
7174 self ._populations : Set [Population ] = set ()
7275 self ._projections : Set [Projection ] = set ()
76+ self ._pynn_report = None
7377
7478 def _hard_reset (self ) -> None :
7579 """
@@ -233,3 +237,24 @@ def get_sim_name(cls) -> str:
233237 :returns: The name to be returned by `pyNN.spiNNaker.name`.
234238 """
235239 return _version .NAME
240+
241+ @classmethod
242+ def write_pynn_report (cls , text : str , * args : List [Any ],
243+ ** kwargs : Dict [str , Any ]) -> None :
244+ """
245+ Writes text to the PyNN report file, or does nothing if the report is
246+ disabled.
247+
248+ :param text: The text to write to the report file.
249+ :param args: Any additional arguments to format into the text using
250+ `str.format`.
251+ :param kwargs: Any additional keyword arguments to format into the text
252+ using `str.format`.
253+ """
254+ if not get_config_bool ("Reports" , "write_pynn_report" ):
255+ return
256+ if cls .__spy_data ._pynn_report is None :
257+ cls .__spy_data ._pynn_report = get_report_path ("path_pynn_report" )
258+ with open (cls .__spy_data ._pynn_report , "a" , encoding = "utf-8" ) as f :
259+ f .write (text .format (* args , ** kwargs ))
260+ f .write ("\n " )
0 commit comments