Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update household heat pump awareness over time #149

Merged
merged 10 commits into from
Nov 21, 2024
19 changes: 19 additions & 0 deletions simulation/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,18 @@ def check_string_is_isoformat_datetime(string) -> str:
parser.add_argument("--price-gbp-per-kwh-electricity", type=float, default=0.245)
parser.add_argument("--price-gbp-per-kwh-oil", type=float, default=0.068)

parser.add_argument(
"--heat-pump-awareness-campaign-date",
default=datetime.datetime(2028, 1, 1),
type=convert_to_datetime,
)

parser.add_argument(
"--campaign-target-heat-pump-awareness",
default=0.8,
type=float_between_0_and_1,
)

return parser.parse_args(args)


Expand All @@ -187,6 +199,11 @@ def validate_args(args):
f"Boiler ban announcement date must be on or before ban date, got gas_oil_boiler_ban_date:{args.gas_oil_boiler_ban_date}, gas_oil_boiler_ban_announce_date:{args.gas_oil_boiler_ban_announce_date}"
)

if args.campaign_target_heat_pump_awareness < args.heat_pump_awareness:
raise ValueError(
f"Campaign target awareness must be greater than or equal to the population heat pump awareness, got campaign_target_heat_pump_awareness:{args.campaign_target_heat_pump_awareness}, heat_pump_awareness:{args.heat_pump_awareness}"
)


if __name__ == "__main__":

Expand Down Expand Up @@ -226,6 +243,8 @@ def validate_args(args):
args.heat_pump_installer_count,
args.heat_pump_installer_annual_growth_rate,
ENGLAND_WALES_ANNUAL_NEW_BUILDS if args.include_new_builds else None,
args.campaign_target_heat_pump_awareness,
args.heat_pump_awareness_campaign_date,
)

with smart_open.open(args.history_file, "w") as file:
Expand Down
27 changes: 27 additions & 0 deletions simulation/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,11 +611,38 @@ def compute_heat_pump_capacity_kw(self, heat_pump_type: HeatingSystem) -> int:
)
)

def proba_of_becoming_heat_pump_aware_required_to_reach_campaign_target(
self, model
) -> float:
return (
model.campaign_target_heat_pump_awareness - model.heat_pump_awareness
) / (1 - model.heat_pump_awareness)

def update_heat_pump_awareness(self, model) -> None:

if InterventionType.HEAT_PUMP_CAMPAIGN in model.interventions:
if (
model.current_datetime == model.heat_pump_awareness_campaign_date
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this hard == safe? If user input is say '2028-01-31' will this work?

Maybe a safer one would be model.current_datetime >= model.heat_pump_awareness_campaign_date..

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to change the logging to implement this. See latest commit.

In summary: we want to say "if the target HP awareness has not been met in the previous timestep (t-1), give a suitable probability of converting agents to becoming HP aware to meet the target at timestep t", however, before the HP awareness was recalculated every timestep (every timestep, HP awareness set to value of zero, then using the line of code in agents.py: model.households_heat_pump_aware_at_current_step += 1 we count the HP awareness in that timstep). Remember, the simulation loops over each agent every timestep. So if you are on agent num. 3 in the loop, the HP awareness is calculated by looking at how many of the 3 agents are heat pump aware so far, and on timestep 5, we see the HP awareness by looking at how many of the 5 agents are heat pump aware so far etc. So we need to store the HP awareness at t-1, to access it at t, so we can convert a suitable number of households to become HP aware to meet the target.

and model.heat_pump_awareness_at_timestep
< model.campaign_target_heat_pump_awareness
and not self.is_heat_pump_aware
):
proba_to_become_heat_pump_aware = self.proba_of_becoming_heat_pump_aware_required_to_reach_campaign_target(
model
)
self.is_heat_pump_aware = true_with_probability(
proba_to_become_heat_pump_aware
)

def make_decisions(self, model):

self.update_heat_pump_awareness(model)
self.update_heating_status(model)
self.evaluate_renovation(model)

if self.is_heat_pump_aware:
model.households_heat_pump_aware_at_current_step += 1

if self.is_renovating:
if self.renovate_insulation:
chosen_elements = self.get_chosen_insulation_costs(
Expand Down
7 changes: 6 additions & 1 deletion simulation/collectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@ def model_heat_pump_installations_at_current_step(model) -> int:
return model.heat_pump_installations_at_current_step


def model_heat_pump_awareness_at_timestep(model) -> float:
return model.heat_pump_awareness_at_timestep


def is_first_timestep(model: "DomesticHeatingABM") -> bool:
return model.current_datetime == model.start_datetime + model.step_interval

Expand All @@ -303,7 +307,6 @@ def get_agent_collectors(
collect_when(model, is_first_timestep)(household_discount_rate),
collect_when(model, is_first_timestep)(household_renovation_budget),
collect_when(model, is_first_timestep)(household_is_heat_pump_suitable),
collect_when(model, is_first_timestep)(household_is_heat_pump_aware),
household_heating_system,
household_heating_system_previous,
household_heating_functioning,
Expand Down Expand Up @@ -340,6 +343,7 @@ def get_agent_collectors(
household_heating_system_costs_insulation_heat_pump_air_source,
household_heating_system_costs_insulation_heat_pump_ground_source,
household_boiler_upgrade_grant_used,
household_is_heat_pump_aware,
]


Expand All @@ -355,4 +359,5 @@ def get_model_collectors(
collect_when(model, is_first_timestep)(model_price_gbp_per_kwh_gas),
collect_when(model, is_first_timestep)(model_price_gbp_per_kwh_electricity),
collect_when(model, is_first_timestep)(model_price_gbp_per_kwh_oil),
model_heat_pump_awareness_at_timestep,
]
1 change: 1 addition & 0 deletions simulation/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ class InterventionType(enum.Enum):
BOILER_UPGRADE_SCHEME = 1
GAS_OIL_BOILER_BAN = 2
EXTENDED_BOILER_UPGRADE_SCHEME = 3
HEAT_PUMP_CAMPAIGN = 4


# Source: https://www.ons.gov.uk/peoplepopulationandcommunity/birthsdeathsandmarriages/families/datasets/householdsbytypeofhouseholdandfamilyregionsofenglandandukconstituentcountries
Expand Down
17 changes: 17 additions & 0 deletions simulation/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ def __init__(
heat_pump_installer_count: int,
heat_pump_installer_annual_growth_rate: float,
annual_new_builds: Optional[Dict[int, int]],
heat_pump_awareness: float,
campaign_target_heat_pump_awareness: float,
heat_pump_awareness_campaign_date: datetime.datetime,
):
self.start_datetime = start_datetime
self.step_interval = step_interval
Expand Down Expand Up @@ -74,6 +77,10 @@ def __init__(
)
self.heat_pump_installations_at_current_step = 0
self.annual_new_builds = annual_new_builds
self.heat_pump_awareness = heat_pump_awareness
self.campaign_target_heat_pump_awareness = campaign_target_heat_pump_awareness
self.heat_pump_awareness_campaign_date = heat_pump_awareness_campaign_date
self.households_heat_pump_aware_at_current_step = 0

super().__init__(UnorderedSpace())

Expand Down Expand Up @@ -193,12 +200,17 @@ def boiler_upgrade_scheme_spend_gbp(self) -> int:
]
)

@property
def heat_pump_awareness_at_timestep(self) -> float:
return self.households_heat_pump_aware_at_current_step / self.household_count

def increment_timestep(self):
self.current_datetime += self.step_interval
self.boiler_upgrade_scheme_cumulative_spend_gbp += (
self.boiler_upgrade_scheme_spend_gbp
)
self.heat_pump_installations_at_current_step = 0
self.households_heat_pump_aware_at_current_step = 0


def create_household_agents(
Expand Down Expand Up @@ -263,6 +275,8 @@ def create_and_run_simulation(
heat_pump_installer_count: int,
heat_pump_installer_annual_growth_rate: float,
annual_new_builds: Dict[int, int],
campaign_target_heat_pump_awareness: float,
heat_pump_awareness_campaign_date: datetime.datetime,
):

model = DomesticHeatingABM(
Expand All @@ -282,6 +296,9 @@ def create_and_run_simulation(
heat_pump_installer_count=heat_pump_installer_count,
heat_pump_installer_annual_growth_rate=heat_pump_installer_annual_growth_rate,
annual_new_builds=annual_new_builds,
heat_pump_awareness=heat_pump_awareness,
campaign_target_heat_pump_awareness=campaign_target_heat_pump_awareness,
heat_pump_awareness_campaign_date=heat_pump_awareness_campaign_date,
)

households = create_household_agents(
Expand Down
3 changes: 3 additions & 0 deletions simulation/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ def model_factory(**model_attributes):
"heat_pump_installer_count": 2_800,
"heat_pump_installer_annual_growth_rate": 0,
"annual_new_builds": None,
"heat_pump_awareness": 0.5,
"campaign_target_heat_pump_awareness": 0.8,
"heat_pump_awareness_campaign_date": datetime.datetime(2028, 1, 1),
}

return DomesticHeatingABM(**{**default_values, **model_attributes})
18 changes: 18 additions & 0 deletions simulation/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,16 @@ def test_intervention_argument(self, mandatory_local_args):
"boiler_upgrade_scheme",
"--intervention",
"extended_boiler_upgrade_scheme",
"--intervention",
"heat_pump_campaign",
]
)

assert args.intervention == [
InterventionType.RHI,
InterventionType.BOILER_UPGRADE_SCHEME,
InterventionType.EXTENDED_BOILER_UPGRADE_SCHEME,
InterventionType.HEAT_PUMP_CAMPAIGN,
]

def test_gas_oil_boiler_ban_date_returns_datetime(self, mandatory_local_args):
Expand Down Expand Up @@ -289,3 +292,18 @@ def test_ban_date_before_announcement_date_raises_value_error(
)
with pytest.raises(ValueError):
validate_args(args)

def test_campaign_target_less_than_heat_pump_awareness_raises_value_error(
self, mandatory_local_args
):
args = parse_args(
[
*mandatory_local_args,
"--campaign-target-heat-pump-awareness",
"0.1",
"--heat-pump-awareness",
"0.5",
]
)
with pytest.raises(ValueError):
validate_args(args)
Loading