Skip to content

Commit

Permalink
Merge pull request #697 from ibpsa/issue686_DefaultTimeStep
Browse files Browse the repository at this point in the history
Closes #686 and #692
  • Loading branch information
dhblum authored Oct 29, 2024
2 parents b1a417e + 9a7f498 commit 6ceeba2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
1 change: 1 addition & 0 deletions contributors.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Thank you to all who have provided guidance on the development of this software.
- Robert Lutes, Pacific Northwest National Laboratory
- Bart Merema, dnergy
- Kefei Mo, Pacific Northwest National Laboratory
- Jaap Neven, KU Leuven, VITO
- Erik Paulson, Independent
- Matt Robinson, University of Colorado - Boulder
- Jermy Thomas, National Renewable Energy Laboratory
Expand Down
24 changes: 12 additions & 12 deletions examples/python/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,6 @@ def control_test(control_module='', start_time=0, warmup_period=0, length=24*360
# Retrieve a list of measurements (outputs) for the model from REST API
measurements = check_response(requests.get('{0}/measurements'.format(url)))
print('Measurements:\t\t\t{0}'.format(measurements))
# Get the default simulation timestep for the model for simulation run
step_def = check_response(requests.get('{0}/step'.format(url)))
print('Default Control Step:\t{0}'.format(step_def))

# IF ANY CUSTOM KPI CALCULATION, DEFINE STRUCTURES
# ------------------------------------------------
Expand All @@ -142,13 +139,11 @@ def control_test(control_module='', start_time=0, warmup_period=0, length=24*360
if res == None:
# If no time_period was specified (only electricity_price), initialize test with a specified start time and warmup period
res = check_response(requests.put('{0}/initialize'.format(url), json={'start_time': start_time, 'warmup_period': warmup_period}))
print("RESULT: {}".format(res))
# Set final time and total time steps according to specified length (seconds)
final_time = start_time + length
total_time_steps = int(length / step) # calculate number of timesteps
else:
# If a time_period was specified, the initialization is complete
print("RESULT: {}".format(res))
# Record test simulation start time
start_time = int(res['time'])
# Set final time and total time steps to be very large since scenario defines length
Expand All @@ -157,20 +152,21 @@ def control_test(control_module='', start_time=0, warmup_period=0, length=24*360
else:
# Initialize test with a specified start time and warmup period
res = check_response(requests.put('{0}/initialize'.format(url), json={'start_time': start_time, 'warmup_period': warmup_period}))
print("RESULT: {}".format(res))
# Set final time and total time steps according to specified length (seconds)
final_time = start_time + length
total_time_steps = int(length / step) # calculate number of timesteps
if res:
print('Successfully initialized the simulation')
print('\nRunning test case...')
# Set simulation time step
res = check_response(requests.put('{0}/step'.format(url), json={'step': step}))
# Set and print simulation time step
control_step = check_response(requests.put('{0}/step'.format(url), json={'step': step}))
print('Current Control Step:\t{0}'.format(control_step['step']))
# Initialize input to simulation from controller
u = controller.initialize()
# Initialize forecast storage structure
forecasts = None
print(requests.get('{0}/scenario'.format(url)).json())
res = check_response(requests.get('{0}/scenario'.format(url)))
print('Current Scenario Setting:\t{0}'.format(res))
# Simulation Loop
for t in range(total_time_steps):
# Advance simulation with control input value(s)
Expand All @@ -183,7 +179,6 @@ def control_test(control_module='', start_time=0, warmup_period=0, length=24*360
kpi.processing_data(y) # Process data as needed for custom KPI
custom_kpi_value = kpi.calculation() # Calculate custom KPI value
custom_kpi_result[kpi.name].append(round(custom_kpi_value, 2)) # Track custom KPI value
print('KPI:\t{0}:\t{1}'.format(kpi.name, round(custom_kpi_value, 2))) # Print custom KPI value
custom_kpi_result['time'].append(y['time']) # Track custom KPI calculation time
# If controller needs a forecast, get the forecast data and provide the forecast to the controller
if controller.use_forecast:
Expand All @@ -201,9 +196,14 @@ def control_test(control_module='', start_time=0, warmup_period=0, length=24*360

# VIEW RESULTS
# -------------------------------------------------------------------------
# Report KPIs
# Report Custom KPIs
if customized_kpi_config is not None:
print('\nCustom KPI RESULTS \n------------------')
print(pd.DataFrame(custom_kpi_result))

# Report BOPTEST KPIs
kpi = check_response(requests.get('{0}/kpi'.format(url)))
print('\nKPI RESULTS \n-----------')
print('\nBOPTEST KPI RESULTS \n-------------------')
for key in kpi.keys():
if key == 'ener_tot':
unit = 'kWh/m$^2$'
Expand Down
1 change: 0 additions & 1 deletion examples/python/testcase2.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,3 @@ def run(plot=False):

if __name__ == "__main__":
kpi, df_res, custom_kpi_result = run()
print(kpi)
2 changes: 1 addition & 1 deletion releasenotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Released on xx/xx/xxxx.
- Add support to ``parsing/parser.py`` for test case compilation using [Modelon's OPTIMICA Compiler Toolkit (OCT)](https://help.modelon.com/latest/reference/oct/). The parser can take arguments ``'JModelica'`` or ``'OCT'``, with ``'JModelica'`` as default. A user still requires access to an OCT license and software on their set up. This is for [#675](https://github.com/ibpsa/project1-boptest/issues/675).
- Changed ``bestest_hydronic`` and ``bestest_hydronic_heat_pump`` Modelica implementations in this repository to utilize the Modelica IDEAS Library as a dependency for component models, instead of serving as extensions from the Modelica IDEAS Library. This is to simplify dependencies for maintaining the models, and is how other test cases are implemented. It required duplication of the model implementations from the Modelica IDEAS Library into this repository. This is for [#680](https://github.com/ibpsa/project1-boptest/issues/680).
- Add ``activate`` control inputs that were missing in ``bestest_hydronic`` and ``bestest_hydronic_heat_pump`` Modelica documentation. This is for [#625](https://github.com/ibpsa/project1-boptest/issues/625).

- Updated ``examples/python/interface.py`` to print correct simulation time step, this is for [#686](https://github.com/ibpsa/project1-boptest/issues/686). Also removed clutter by printed custom KPI results, which is for [#692](https://github.com/ibpsa/project1-boptest/issues/692).

**The following new test cases have been added:**

Expand Down

0 comments on commit 6ceeba2

Please sign in to comment.