Source code for panpython.sdk.parser.htc_condition_parser


"""
"Parser: HTC Condition Parser" Module
=====================================
A parser of HTC arguments
"""

import json
from typing import Dict, Union, TextIO, List, Any
from panpython._libs.parser import HtcInputJSONParser


[docs]class JsonParser: """A JSON parser of HTC arguments Parameters ---------- json_file: str full path of JSON file Examples -------- >>> from panpython.sdk.parser.htc_condition_parser import JsonParser >>> parser: JsonParser = JsonParser('htc_condition.JSON') >>> task_map: dict = parser.task_map """ def __init__(self, json_file): """ Initialize JSON Parser of HTC Mesh Parameters ---------- json_file: str full path of JSON file Returns ------- """ self._task_map: Dict[str, Dict[str, Union[int, float]]] = {} self._units: Dict[str, str] = {} self._PanHTC_interface: str = "" m_parser = HtcInputJSONParser(json_file=json_file) self._task_map = m_parser.task_map self._units = m_parser.units self._PanHTC_interface = m_parser.PanHTC_interface self._scan_log = m_parser.scan_log self._task_type = m_parser.task_type self._thermal_history = m_parser.thermal_history self._opt_condition = m_parser.opt_condition self._opt_protocol = m_parser.opt_protocol self._opt_bounds = m_parser.opt_bounds @property def opt_condition(self): """Dict: the map storing conditions of the optimization""" return self._opt_condition @opt_condition.setter def opt_condition(self, var): raise ValueError('Assigning \'opt_condition\' is not allowed') @property def opt_protocol(self): """Dict[int, string]: the map for easily updating batch file inside objective function""" return self._opt_protocol @opt_protocol.setter def opt_protocol(self, var): raise ValueError('Assigning \'opt_protocol\' is not allowed') @property def opt_bounds(self): """Dict[int, string]: the list of bounds for objective function, following protocol""" return self._opt_bounds @opt_bounds.setter def opt_bounds(self, var): raise ValueError('Assigning \'opt_bounds\' is not allowed') @property def task_map(self): """Dict[str, Dict[str, Union[int, float]]]: the map storing all conditions of the simulation, with task_id as the key""" return self._task_map @task_map.setter def task_map(self, var): raise ValueError('Assigning \'test_pool\' is not allowed') @property def units(self): """Dict[str, str]: the units of variables in the HTC condition""" return self._units @units.setter def units(self, var): raise ValueError('Assigning \'units\' is not allowed') @property def task_type(self): """str: The type of HTC calculation, for example, point, line, precipitation, pan_solidification, solidification ...""" return self._task_type @task_type.setter def task_type(self, var): raise ValueError('Assigning \'task_type\' is not allowed')
[docs] def write_thermal_history(self, th_file): """ Write thermal history file on disk Parameters ---------- th_file: str full path of output file Returns ------- """ fp: TextIO with open(th_file, 'w', encoding='utf-8') as fp: json.dump(self._thermal_history, fp, indent=4)
[docs] def write_task_map(self, map_file): """ Write task map (task_id->task_condition) file on disk Parameters ---------- map_file: str full path of output file Returns ------- """ fp: TextIO with open(map_file, 'w', encoding='utf-8') as fp: json.dump(self._task_map, fp, indent=4)
[docs] def write_PanHTC_interface(self, htc_file): """ Write an conf. file which can be used by HTC in Pandat GUI Parameters ---------- htc_file: str full path of the PanHTC file Returns ------- """ fp: TextIO with open(htc_file, 'w', encoding='utf-8') as fp: fp.write(self._PanHTC_interface)
[docs] def write_statistics_log(self, stat_file): """ Write an log file of statistics of this HTC Parameters ---------- stat_file: str full path of the statistics log file Returns ------- """ fp: TextIO with open(stat_file, 'w', encoding='utf-8') as fp: json.dump(self._scan_log, fp, indent=4)