NREL / boptest-service

Other
3 stars 3 forks source link

ValueError: No JSON object could be decoded #27

Closed dhblum closed 8 months ago

dhblum commented 1 year ago

Problem

When using boptest-service to run the test cases multizone_office_simple_air or multizone_residential_hydronic with scenario peak_heat_day and control step size equal to one month (2592000 seconds), the service eventually returns the error when using the /advance call:

Traceback (most recent call last):
  File "demo_service_error.py", line 43, in <module>
    y = requests.post("{0}/advance/{1}".format(url, testid), data=u).json()["payload"]
  File "/home/dhbubu18/.local/lib/python2.7/site-packages/requests/models.py", line 897, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/lib/python2.7/json/__init__.py", line 339, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python2.7/json/decoder.py", line 364, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

After the error ends the process, if I make a get /kpi request to the test case, it returns the expected KPI values for the given scenario.

Other Notes

When setting the control step to one day (86400 seconds, note that this is less than the length of the scenario, which is two weeks), the error does NOT occur, and the test runs to completion OK. Note also that when deploying BOPTEST v0.3.0 core locally and running the same experiment with multizone_residential_hydronic, the test runs to completion OK as well. This problem also wasn't seen when running single-zone test cases from BOPTEST.

Expected KPIs for multizone_residential_hydronic:

"cost_tot": 0.7932061254859891,
"emis_tot": 1.425504109372381,
"ener_tot": 8.141192268442058,
"idis_tot": 9114.594708949711,
"pdih_tot": null,
"pele_tot": 0.0017390231869758264,
"pgas_tot": 0.09592720495532536,
"tdis_tot": 22.003316309231238,
"time_rat": NaN

Python Code to Reproduce

# GENERAL PACKAGE IMPORT
import requests
#------------------------------------------------------------------------------

# SET PARAMETERS
# Set URL for service
url = "http://api.boptest.net"
# Set test case name to run
test_case = 'multizone_residential_hydronic'
# Set testing scenario
scenario = {"time_period":"peak_heat_day",
            "electricity_price":"dynamic"}
# Set control step
step = 3600*24*30
#------------------------------------------------------------------------------

# RUN TEST
# Select test case on service
testid = requests.post("{0}/testcases/{1}/select".format(url, test_case)).json()["testid"]
print('Selected test case {0} with test id: {1}'.format(test_case, testid))
# Set control step
requests.put("{0}/step/{1}".format(url, testid), data={"step":step})
print('Set control step.')
# Set test case scenario
print('Initializing test scenario...')
y = requests.put("{0}/scenario/{1}".format(url, testid), data=scenario).json()["payload"]["time_period"]
print('Done initializing test scenario.')
# Record test start time
start_time = y["time"]
# Simulation Loop
print('Running test...')
while y:
    u={}
    # Advance simulation with control signal
    y = requests.post("{0}/advance/{1}".format(url, testid), data=u).json()["payload"]
print('Done running test.')
#------------------------------------------------------------------------------
dhblum commented 9 months ago

@kbenne I just re-ran this test and it is still an issue, as described. I ran with multizone_office_simple_air.

dhblum commented 8 months ago

This seems to have been fixed with deployment of https://github.com/NREL/boptest-service/releases/tag/v0.3.0. I've confirmed through tests with the script that previously produced the error. I will close this issue for now.