initialize_evaluation#
- TwinModel.initialize_evaluation(parameters=None, inputs=None, field_inputs=None, json_config_filepath=None)#
Initialize evaluation of a twin model.
A twin model can be initialized with either a dictionary of parameters values and/or input (start) values or a JSON configuration file. For more information, see the examples.
Using a JSON configuration file overrides using a dictionary of parameter values and/or input (start) values.
If no inputs are given in the arguments or in the configuration file, calling this method resets inputs to their default values. The behavior is the same for parameters.
Default values are kept for parameters and inputs that are not found in the provided dictionaries or configuration file. For example, the start value of the twin model is kept.
After this method is called and the initialization time is updated, the evaluation time is reset to zero.
This method must be called:
Before evaluating the twin model.
If you want to update parameters values between multiple twin evaluations. In this case, the twin model is reset.
Note
if field inputs are supplied for a TBROM, they will override any input mode coefficient inputs for that ROM that are included in
inputs
.- Parameters:
- parameters
dict
,optional
Dictionary of parameter values ({“name”: value}) to use for the next evaluation.
- inputs
dict
,optional
Dictionary of input values ({“name”: value}) to use for twin model initialization.
- field_inputs
dict
,optional
Dictionary of input fields snapshots ({“tbromname”: {“inputfieldname”: snapshotpath}}) to use for twin model initialization.
- json_config_filepath
str
,optional
Filepath to a JSON configuration file to use to initialize the evaluation.
- parameters
Examples
>>> import json >>> from pytwin import TwinModel >>> >>> # Example 1 - Using a config file and scalar inputs >>> config = {"version": "0.1.0", "model": {"inputs": {"input-name-1": 1., "input-name-2": 2.}, >>> "parameters": {"param-name-1": 1.,"param-name-2": 2.}}} >>> with open('path_to_your_config.json', 'w') as f: >>> f.write(json.dumps(config)) >>> twin_model = TwinModel(model_filepath='path_to_your_twin_model.twin') >>> twin_model.initialize_evaluation(json_config_filepath='path_to_your_config.json') >>> outputs = twin_model.outputs >>> >>> # Example 2 - Using a dictionary and field inputs from disk >>> twin_model = TwinModel(model_filepath='path_to_your_twin_model.twin') >>> twin_model.initialize_evaluation() >>> romname = twin_model.tbrom_names[0] >>> fieldname = twin_model.get_field_input_names(romname)[0] >>> twin_model.initialize_evaluation(field_inputs={romname: {fieldname:'path_to_the_snapshot.bin'}}) >>> results = {'Time': twin_model.evaluation_time, 'Outputs': twin_model.outputs} >>> >>> # Example 3 - Using a dictionary and field inputs from memory >>> twin_model = TwinModel(model_filepath='path_to_your_twin_model.twin') >>> twin_model.initialize_evaluation() >>> romname = twin_model.tbrom_names[0] >>> fieldname = twin_model.get_field_input_names(romname)[0] >>> snapshot = np.array([3.14, 2.71, 9.81, 6.02]) >>> twin_model.initialize_evaluation(field_inputs={romname: {fieldname:snapshot}}) >>> results = {'Time': twin_model.evaluation_time, 'Outputs': twin_model.outputs}