GitHub

romtools.workflows.models

Protocol for interfacing with external applications

 1'''
 2Protocol for interfacing with external applications
 3'''
 4
 5from typing import Protocol
 6import numpy as np
 7
 8
 9class Model(Protocol):
10    '''
11    Baseline model protocol
12    '''
13    def __init__(self) -> None:
14        '''
15        Initialize coupler
16        '''
17        pass
18
19    def populate_run_directory(self, run_directory: str, parameter_sample: dict) -> None:
20        '''
21        This function is called from the base directory and is
22        responsible for populating the run directory located at run_directory.
23
24        Examples would be setting up input files, linking mesh files.
25
26        Args:
27          run_directory (str): Absolute path to run_directory.
28          parameter_sample: Dictionary contatining parameter names and sample values
29
30        '''
31        pass
32
33    def run_model(self, run_directory: str, parameter_sample: dict) -> int:
34        '''
35        This function is called from the base directory. It needs to execute our
36        model. If the model runs successfully, return 0. If fails, return 1.
37
38        Args:
39          run_directory (str): Absolute path to run_directory.
40          parameter_sample: Dictionary contatining parameter names and sample values
41
42        '''
43        pass
44
45
46class QoiModel(Model, Protocol):
47    '''
48    Protocol for a model that has a return_qoi implementation
49    '''
50
51    def compute_qoi(self, run_directory: str, parameter_sample: dict) -> np.ndarray:
52        '''
53        This function is called from a run directory
54        AFTER run_model has been run
55        '''
56        pass
57
58
59class QoiModelWithErrorEstimate(QoiModel, Protocol):
60    '''
61    Protocol for a model that has a return_qoi and compute_error_estimate
62    '''
63
64    def compute_error_estimate(self, run_directory: str, parameter_sample: dict) -> float:
65        '''
66        This function is called from a run directory
67        AFTER run_model has been run
68        '''
69        pass
class Model(typing.Protocol):
10class Model(Protocol):
11    '''
12    Baseline model protocol
13    '''
14    def __init__(self) -> None:
15        '''
16        Initialize coupler
17        '''
18        pass
19
20    def populate_run_directory(self, run_directory: str, parameter_sample: dict) -> None:
21        '''
22        This function is called from the base directory and is
23        responsible for populating the run directory located at run_directory.
24
25        Examples would be setting up input files, linking mesh files.
26
27        Args:
28          run_directory (str): Absolute path to run_directory.
29          parameter_sample: Dictionary contatining parameter names and sample values
30
31        '''
32        pass
33
34    def run_model(self, run_directory: str, parameter_sample: dict) -> int:
35        '''
36        This function is called from the base directory. It needs to execute our
37        model. If the model runs successfully, return 0. If fails, return 1.
38
39        Args:
40          run_directory (str): Absolute path to run_directory.
41          parameter_sample: Dictionary contatining parameter names and sample values
42
43        '''
44        pass

Baseline model protocol

Model()
14    def __init__(self) -> None:
15        '''
16        Initialize coupler
17        '''
18        pass

Initialize coupler

def populate_run_directory(self, run_directory: str, parameter_sample: dict) -> None:
20    def populate_run_directory(self, run_directory: str, parameter_sample: dict) -> None:
21        '''
22        This function is called from the base directory and is
23        responsible for populating the run directory located at run_directory.
24
25        Examples would be setting up input files, linking mesh files.
26
27        Args:
28          run_directory (str): Absolute path to run_directory.
29          parameter_sample: Dictionary contatining parameter names and sample values
30
31        '''
32        pass

This function is called from the base directory and is responsible for populating the run directory located at run_directory.

Examples would be setting up input files, linking mesh files.

Arguments:
  • run_directory (str): Absolute path to run_directory.
  • parameter_sample: Dictionary contatining parameter names and sample values
def run_model(self, run_directory: str, parameter_sample: dict) -> int:
34    def run_model(self, run_directory: str, parameter_sample: dict) -> int:
35        '''
36        This function is called from the base directory. It needs to execute our
37        model. If the model runs successfully, return 0. If fails, return 1.
38
39        Args:
40          run_directory (str): Absolute path to run_directory.
41          parameter_sample: Dictionary contatining parameter names and sample values
42
43        '''
44        pass

This function is called from the base directory. It needs to execute our model. If the model runs successfully, return 0. If fails, return 1.

Arguments:
  • run_directory (str): Absolute path to run_directory.
  • parameter_sample: Dictionary contatining parameter names and sample values
class QoiModel(Model, typing.Protocol):
47class QoiModel(Model, Protocol):
48    '''
49    Protocol for a model that has a return_qoi implementation
50    '''
51
52    def compute_qoi(self, run_directory: str, parameter_sample: dict) -> np.ndarray:
53        '''
54        This function is called from a run directory
55        AFTER run_model has been run
56        '''
57        pass

Protocol for a model that has a return_qoi implementation

def compute_qoi(self, run_directory: str, parameter_sample: dict) -> numpy.ndarray:
52    def compute_qoi(self, run_directory: str, parameter_sample: dict) -> np.ndarray:
53        '''
54        This function is called from a run directory
55        AFTER run_model has been run
56        '''
57        pass

This function is called from a run directory AFTER run_model has been run

class QoiModelWithErrorEstimate(QoiModel, typing.Protocol):
60class QoiModelWithErrorEstimate(QoiModel, Protocol):
61    '''
62    Protocol for a model that has a return_qoi and compute_error_estimate
63    '''
64
65    def compute_error_estimate(self, run_directory: str, parameter_sample: dict) -> float:
66        '''
67        This function is called from a run directory
68        AFTER run_model has been run
69        '''
70        pass

Protocol for a model that has a return_qoi and compute_error_estimate

def compute_error_estimate(self, run_directory: str, parameter_sample: dict) -> float:
65    def compute_error_estimate(self, run_directory: str, parameter_sample: dict) -> float:
66        '''
67        This function is called from a run directory
68        AFTER run_model has been run
69        '''
70        pass

This function is called from a run directory AFTER run_model has been run