IBM / rl-testbed-for-energyplus

Reinforcement Learning Testbed for Power Consumption Optimization using EnergyPlus
MIT License
189 stars 77 forks source link

Optimizing carbon emission instead of power consumption #107

Open WynnCJF opened 2 years ago

WynnCJF commented 2 years ago

Hi! I'm currently adopting this testbed to optimize the carbon emission of the data center. I've been trying to modify 2ZoneDataCenterHVAC_wEconomizer_Temp_Fan.idf so that the observation sent by @ExtCtrlObs includes the carbon emission sensor data.

I added three sensors as follows:

EnergyManagementSystem:Sensor,
    CARBON_EQUIVALENT,    !- Name
    Site,          !- Output:Variable or Output:Meter Index Key Name
    Environmental Impact Total CO2 Emissions Carbon Equivalent Mass;  !- Output:Variable or Output:Meter Name

EnergyManagementSystem:Sensor,
    CO2_EMISSION,          !- Name
    Site,          !- Output:Variable or Output:Meter Index Key Name
    Environmental Impact Electricity CO2 Emissions Mass;  !- Output:Variable or Output:Meter Name

EnergyManagementSystem:Sensor,
    CO_EMISSION,        !- Name
    Site,          !- Output:Variable or Output:Meter Index Key Name
    Environmental Impact Electricity CO Emissions Mass;  !- Output:Variable or Output:Meter Name

with the corresponding output variables:

Output:Variable,
  *,                       !- Key Value
  Environmental Impact Total CO2 Emissions Carbon Equivalent Mass,  !- Variable Name
  timestep;

Output:Variable,
  *,                       !- Key Value
  Environmental Impact Electricity CO2 Emissions Mass,  !- Variable Name
  timestep;                 !- Reporting Frequency

Output:Variable,
  *,                       !- Key Value
  Environmental Impact Electricity CO Emissions Mass,  !- Variable Name
  timestep;

The EMS program for sending the observation is basically the same as the original code, with the power consumption EMS variables substituted with the carbon emission ones:

EnergyManagementSystem:ProgramCallingManager,
    ExtCtrl-Based Observation Collector,  !- Name
    EndOfZoneTimestepAfterZoneReporting,  !- EnergyPlus Model Calling Point
    ExtCtrlBasedObservationCollector;  !- Program Name 1

  EnergyManagementSystem:Program,
    ExtCtrlBasedObservationCollector,  !- Name
    IF WarmupFlag == 0.0,    !- Program Line 1
    SET tmp_val1 = @ExtCtrlObs 1 OutdoorTemp,  !- Program Line 2
    SET tmp_val1 = @ExtCtrlObs 2 WestZoneTemp,  !- <none>
    SET tmp_val1 = @ExtCtrlObs 3 EastZoneTemp,  !- <none>
    SET tmp_val1 = @ExtCtrlObs 4 PUE_Value,  !- <none>
    SET tmp_val1 = @ExtCtrlObs 5 CARBON_EQUIVALENT,  !- <none>
    SET tmp_val1 = @ExtCtrlObs 6 CO_EMISSION,  !- <none>
    SET tmp_val1 = @ExtCtrlObs 7 CO2_EMISSION,  !- <none>
    ELSE,                    !- <none>
    ENDIF;                   !- <none>

(The variable PUE_Value here is just a placeholder as this value is neither involved in the reward calculation process nor included in the observation space.)

I modified the weight in the reward function. The training went on well and the observed carbon emission values decreased significantly during the inference process. Yet I just found that these carbon emission values sent as observation are different from the generated output in eplusout.csv.

For example, here's a snippet of the logged values of CARBON_EQUIVALENT from the first few observations:

Carbon Equivalent
--
0.0
0.133487
0.337323
0.307257
0.2369
0.282264
0.391187
0.225665
0.235469
0.157378
0.238455

And here's a snippet of the same timesteps in eplusout.csv:

Site:Environmental Impact Total CO2 Emissions Carbon Equivalent Mass [kg](TimeStep)
--
2.00229877741957
5.05984938339263
3.37983056774111
3.31660334495416
3.10490202242562
2.73830923089479
3.38498004573822
3.53203668198742
2.36067179328403
3.57682565240907
5.63639703991733
3.47494246773142

As a result, though the observed values got significantly reduced during the model's inference, it just doesn't seem to reduce carbon emission judging from the EnergyPlus output. The same inconsistency doesn't exists in the original case where electricity demand values are sent as observations.

I saw some issues discussing the inconsistency between EMS and output variables (https://github.com/NREL/EnergyPlus/issues/7563, https://github.com/NREL/EnergyPlus/issues/8915), and the problem seems to be the calling program manager. Yet I've tried a bunch of different calling points including EndOfSystemTimestepBeforeHVACReporting and AfterPredictorBeforeHVACManagers but they didn't fix the inconsistency.

Is there any suggestion on how solve this issue? Anything about applying this testbed to optimize carbon emission would be very helpful. Thanks!

antoine-galataud commented 2 years ago

Hi @WynnCJF. A discrepancy is possible if you don't use the right calling point, but it usually expresses as a lag, not a completely different value. There's also a possible problem when using EnergyManagementSystem:OutputVariable with an incorrect update frequency or aggregation (averaged -> summed).

What you could try:

I also recommend running your tests outside of this testbed since it's seems to be an EnergyPlus-related issue

Here is a test example (not tested):

EnergyManagementSystem:Sensor,
  CARBON_EQUIVALENT,                                                !- Name
  Site,                                                             !- Output:Variable or Output:Meter Index Key Name
  Environmental Impact Total CO2 Emissions Carbon Equivalent Mass;  !- Output:Variable or Output:Meter Name

EnergyManagementSystem:ProgramCallingManager,
  Test Prgm,                              !- Name
  EndOfZoneTimestepBeforeZoneReporting,   !- EnergyPlus Model Calling Point
  Test_Prgm;                              !- Program Name 1

EnergyManagementSystem:Program,
  Test_Prgm,                              !- Name
  SET carbon = CARBON_EQUIVALENT;         !- Program Line 1

EnergyManagementSystem:OutputVariable,
  EMS Carbon,                             !- Name
  carbon,                                 !- EMS Variable Name
  Summed,                                 !- Type of Data in Variable
  SystemTimestep,                         !- Update Frequency
  Test_Prgm,                              !- EMS Program or Subroutine Name
  J;                                      !- Units

!- Case 1: EMS output variable
Output:Variable,
  EMS,                                    !- Key Value
  EMS Carbon,                             !- Variable Name
  timestep;                               !- Reporting Frequency

!- Case 2: Output Variable
Output:Variable,
  *,                                                                !- Key Value
  Environmental Impact Total CO2 Emissions Carbon Equivalent Mass,  !- Variable Name
  timestep;                                                         !- Reporting Frequency

!- Case 3: Output Meter
Output:Meter,
  ElectricEmissions:CO2 ,  !- Key Name
  timestep;                !- Reporting Frequency

You may want to tweak the EnergyPlus Model Calling Point too, to check the impact.

See also EnergyPlus Input/Output Reference for other ways to express CO2 emissions as output variables and meters.