Skip to content

Commit

Permalink
Merge pull request #37 from RWTH-EBC/36_validation_error
Browse files Browse the repository at this point in the history
fix: Validation bug. Rm unwanted tests as well (not a valid unittest)
  • Loading branch information
FWuellhorst authored Apr 20, 2022
2 parents 1d87f1e + 5ce57d8 commit 13e54aa
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 327 deletions.
24 changes: 21 additions & 3 deletions aixcalibuha/calibration/calibrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import json
import time
import logging
from typing import List
from typing import Dict
from copy import copy
import numpy as np
from ebcpy import data_types, Optimizer
from ebcpy.simulationapi import SimulationAPI
Expand Down Expand Up @@ -483,10 +484,15 @@ def save_results(self, parameter_values: dict, filename: str):
with open(s_path, 'w') as json_file:
json.dump(parameter_values, json_file, indent=4)

def validate(self, validation_class: CalibrationClass, tuner_parameter_values: List):
def validate(self, validation_class: CalibrationClass, calibration_result: Dict):
"""
Validate the given calibration class based on the given
values for tuner_parameters.
:param CalibrationClass validation_class:
The class to validate on
:param dict calibration_result:
The calibration result to apply to the validation class on.
"""
# Start Validation:
self.at_calibration = False
Expand All @@ -497,21 +503,33 @@ def validate(self, validation_class: CalibrationClass, tuner_parameter_values: L
start_time=self.calibration_class.start_time
)
self.calibration_class = validation_class
old_tuner_paras = copy(self.calibration_class.tuner_paras)
tuner_values = list(calibration_result.values())
self.calibration_class.tuner_paras = TunerParas(
names=list(calibration_result.keys()),
initial_values=tuner_values,
# Dummy bounds as they are scaled anyway
bounds=[(val - 1, val + 1) for val in tuner_values]
)

# Set the start-time for the simulation
self.sim_api.sim_setup.start_time = start_time

self.logger.calibrate_new_class(self.calibration_class,
cd=self.cd_of_class,
for_validation=True)

# Use the results parameter vector to simulate again.
self._counter = 0 # Reset to one
# Scale the tuner parameters
xk = self.tuner_paras.scale(tuner_parameter_values)
xk = self.tuner_paras.scale(tuner_values)
# Evaluate objective
obj = self.obj(xk=xk)
self.logger.validation_callback_func(
obj=obj
)
# Reset tuner_parameters to avoid unwanted behaviour
self.calibration_class.tuner_paras = old_tuner_paras
return obj

def _handle_error(self, error):
Expand Down
2 changes: 1 addition & 1 deletion examples/docs/e4_calibration_example.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ result = modelica_calibrator.calibrate(
```python
modelica_calibrator.validate(
validation_class=validation_class,
tuner_parameter_values=list(result.values())
calibration_result=result
)
```
Don't forget to close the simulation api:
Expand Down
2 changes: 1 addition & 1 deletion examples/e4_calibration_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def run_calibration(
# Start the validation process
modelica_calibrator.validate(
validation_class=validation_class,
tuner_parameter_values=list(result.values())
calibration_result=result
)
# Don't forget to close the simulation api:
sim_api.close()
Expand Down
2 changes: 1 addition & 1 deletion examples/jupyter_notebooks/e4_calibration_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": "modelica_calibrator.validate(\n validation_class=validation_class,\n tuner_parameter_values=list(result.values())\n)\n"
"source": "modelica_calibrator.validate(\n validation_class=validation_class,\n calibration_result=result\n)\n"
},
{
"cell_type": "markdown",
Expand Down
45 changes: 0 additions & 45 deletions tests/test_parallelisation.py

This file was deleted.

133 changes: 0 additions & 133 deletions tests/test_parallelisation_config.py

This file was deleted.

Loading

0 comments on commit 13e54aa

Please sign in to comment.