Tools for ML models of thermohydraulics#
The help provides tools for preparing additional descriptions of ML thermophysical models for use by the Approximation model (TL) block when loading the model.
- class repeat_onnx.ModelTH(nodes: list[NodeTH])#
The class is intended for additional description of machine learning models stored in the neutral ONNX format.
The class allows for a unique mapping of the input and output parameters of a machine learning model with the nodes of the Approximation model (TL) block of the Thermohydraulics library of the REPEAT platform.
The names of the input parameters for pressures and temperatures, and the output parameters for flow rates and enthalpy fluxes, are specified using the :py:class:
NodeTHclass of the model node.- Parameters:
- nodeslist[NodeTH]
A set of nodes with names of pressures, temperatures, flow rates, and enthalpy flows.
- Attributes:
flowsAn attribute that allows you to get the names of the streams of all model nodes
potentialsAn attribute that allows you to obtain the names of the potentials of all model nodes
Methods
to_onnx()The method returns a string representation of the JSON structure for subsequent saving to a neutral ONNX format file.
- Returns:
- None
Examples
>>> from pprint import pp >>> import repeat_onnx as rx >>> >>> >>> model_description = rx.ModelTH( >>> [ >>> rx.NodeTH( >>> "Input unit", "pressure_1", "temperature_1", >>> "flowrate_1", "enthalpy_flux_1" >>> ), >>> rx.NodeTH( >>> "Output unit", "pressure_2", "temperature_2", >>> "flowrate_2", "enthalpy_flux_2" >>> ), >>> ] >>> )
- property flows: list#
An attribute that allows you to get the names of the streams of all model nodes
- Returns:
- list
A set of stream names for all model nodes.
- property potentials: list#
An attribute that allows you to obtain the names of the potentials of all model nodes
- Returns:
- list
A set of potential names for all model nodes.
- to_onnx()#
The method returns a string representation of the JSON structure for subsequent saving to a neutral ONNX format file.
An additional description of the ML model should be located in the
metadata_propsstructure under the"repeat_contract"key.- Returns:
- str
JSON describing the model for the ONNX neutral format file.
Examples
>>> import onnx >>> import repeat_onnx as rx >>> >>> >>> model_description = rx.ModelTH( >>> [ >>> rx.NodeTH( >>> "Input unit", "pressure_1", "temperature_1", >>> "flowrate_1", "enthalpy_flux_1" >>> ), >>> ] >>> ) >>> properties = onnx.StringStringEntryProto() >>> properties.key = "repeat_contract" >>> properties.value = model_description.to_onnx() >>> model = onnx.load(path) >>> model.metadata_props.append(properties) >>> onnx.save(model, path)
- class repeat_onnx.NodeTH(name: str, pressure: str, temperature: str, flowrate: str, enthalpy_flux: str)#
This class is designed to describe a node in a thermal-hydraulic model. The node is a mandatory component of the thermal-hydraulic model, which is described using the :py:class:
ModelTHclass.The node class provides a one-to-one mapping in the model of pressure and temperature to the corresponding names of the input parameters of the user’s machine learning model, stored in the neutral ONNX format. The
NodeTHclass also provides an unambiguous comparison of the flow rate and enthalpy flux with the calculation results on the output parameters of the machine learning model.- Parameters:
- namestr
Model node name. The node name will be displayed in the properties of the Approximation Model (TL) block in the Thermohydraulics library of the REPEAT platform.
- pressurestr
The name of the pressure input parameter in the model node
- temperaturestr
Name of the temperature input parameter in the model node
- flowratestr
The name of the output parameter with the result of the mass flow calculation in the model node
- enthalpy_fluxstr
The name of the output parameter containing the result of calculating the enthalpy flow in the model node
- Attributes:
flowsAn attribute that allows you to get the names of the node’s threads
potentialsAn attribute that allows you to get the names of node potentials
- Returns:
- None
Examples
>>> from pprint import pp >>> import repeat_onnx as rx >>> >>> >>> node = rx.NodeTH( >>> "Input unit", "pressure_1", "temperature_1", >>> "flowrate_1", "enthalpy_flux_1" >>> ) >>> pp(node) >>> # NodeP( >>> # name='Input unit', >>> # pressure='pressure_1', >>> # temperature='temperature_1', >>> # flowrate='flowrate_1', >>> # enthalpy_flux='enthalpy_flux_1' >>> # )
- property flows: list#
An attribute that allows you to get the names of the node’s threads
- Returns:
- list
Node stream names.
- property potentials: list#
An attribute that allows you to get the names of node potentials
- Returns:
- list
Names of node potentials.