<jupyter_start><jupyter_text>Model Verification This notebook is used to verify that the model is encoded correctly according to the model conceptualisation. The verification procedures used in this notebook are taken from the [Agent based modelling for Socio-technical systems](https://www.ieeexplore.ieee.org/abstract/document/5874914/?casa_token=<KEY>)  1. Tracing the agent behaviour Tracing the agent behavior was integrated into the encoding stage of the modeling. While model implementation, the agent behavior of each agent group was traced and verified with the conceptualization. The implementation is done in python using tracking variables and text prompts for agent interaction.Example:* Printing 'agent created' while agent initialisation* Printing 'asset initialised' for asset initialisation* Printing 'demand updated' when ToD is implemented and demand is revisedThese tracing flags and call-outs were used at the initial stage and were eventually removed after successful implementation of the model.  2.Single agent testing The single-agent testing consists of sanity checks to ensure all agent methods are functional and behave as per conceptualization.<jupyter_code>import datetime
import matplotlib.pyplot as plt
from model.model_code import *
model = EnergyCommunity()
agent = Residential(unique_id=model.next_id(),
                    member_name='hh1_consumption [kWh]',
                    member_type=MemberType.CONSUMER,
                    demand_flexibility=None,
                    asset_list=None,
                    model=model)
fig, ax = plt.subplots(figsize=(10, 5))
for i in np.arange(3):
    demand = agent.get_demand_schedule()
    date = datetime.datetime.strptime(agent.date, '%Y-%m-%d')
    date += datetime.timedelta(days=1)
    agent.date = date.strftime('%Y-%m-%d')
    ax.plot(demand.to_list(), label=agent.date)
    plt.xlabel('Time blocks of 15 minutes')
    plt.ylabel('Electricity Demand kWh')
    plt.title('Energy demand of a residential agent')
    leg = ax.legend()
    plt.tight_layout()
    plt.savefig('figures_verification/single_agent_testing1.png', dpi=300)<jupyter_output><empty_output><jupyter_text>As it can be seen above, the residential agent is successfully initialised. The above plot shows electricity demand of a Residential agent for 3 days. A similar verification is carried out for the non-residential agent.<jupyter_code># Creating the agent
agent = NonResidential(unique_id=model.next_id(),
                       member_name='school_mbo',
                       member_type=MemberType.CONSUMER,
                       demand_flexibility=None,
                       asset_list=None,
                       model=model)
fig, ax = plt.subplots(figsize=(10, 5))
for i in np.arange(3):
    demand = agent.get_demand_schedule()
    date = datetime.datetime.strptime(agent.date, '%Y-%m-%d')
    date += datetime.timedelta(days=2)
    agent.date = date.strftime('%Y-%m-%d')
    ax.plot(demand.to_list(), label=agent.date)
    plt.xlabel('Time blocks of 15 minutes')
    plt.ylabel('Energy demand of a non-residential agent (School)')
    plt.title('Electricity Demand kWh')
    leg = ax.legend()
    plt.tight_layout()
    plt.savefig('figures_verification/single_agent_testing2.png', dpi=300)<jupyter_output><empty_output><jupyter_text>As it can be seen above, the non-residential agent i.e. school is successfully initialised. The above plot shows electricity demand of the agent for 3 days which represents the input demand in the model.  3. Interaction testing in a minimal model The interaction testing is done by checking interaction between community members and assets<jupyter_code># Create an agent with asset
asset = [{'agent_type': Asset,
          'asset_type': Solar,
          'capacity': 10,
          'efficiency': 0.20,
          'price': 0.15}]
agent = NonResidential(unique_id=model.next_id(),
                       member_name='school_mbo',
                       member_type=MemberType.PROSUMER,
                       demand_flexibility=None,
                       asset_list=asset,
                       model=model)
asset = agent.assets[0]
fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(10, 5), sharex=True)
for i in np.arange(3):
    date = datetime.datetime.strptime(agent.date, '%Y-%m-%d')
    date += datetime.timedelta(days=1)
    agent.date = date.strftime('%Y-%m-%d')
    asset.date = agent.date
    demand = agent.get_demand_schedule()
    generation = asset.generate_supply_schedule()
    fig.suptitle('Generation and Supply curve for agent')
    ax1.plot(demand.to_list(), label=agent.date)
    ax2.plot(generation.to_list(), label=agent.date)

    ax1.set_ylabel('Electricity Demand kWh')
    ax2.set_ylabel('Electricity Generation kWh')

    ax2.set_xlabel('Time blocks of 15 minutes')
    leg = ax1.legend()

    plt.tight_layout()
    plt.savefig('figures_verification/interaction_testing.png', dpi=300)<jupyter_output><empty_output><jupyter_text>As shown in the plots above, member agent initialised an asset agent. Plots above show the demand and generation for an agent for three different days.  4. Multi-agent testing In the multi-agent testing, a minimalistic model is initialised to varify the agent interaction.<jupyter_code># initialise model
model = EnergyCommunity()
# model.all_agents[NonResidential] = model.all_agents[NonResidential][1:]
agent1 = model.all_agents[NonResidential][0]
agent2 = model.all_agents[NonResidential][1]
agent3 = model.all_agents[NonResidential][2]
model.step()
fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(10, 10), sharex=True, sharey=False)
for i in np.arange(1):
    plt.title('Multi-agent testing')
    ax1.plot(agent2.demand_schedule.to_list(), label='scheduled demand')
    ax1.plot(agent2.demand_realized.to_list(), label='realised demand')
    ax1.legend()
    ax1.set_title('agent 1')

    ax2.plot(agent3.demand_schedule.to_list(), label='scheduled demand')
    ax2.plot(agent3.demand_realized.to_list(), label='realised demand')
    ax2.legend()
    ax2.set_title('agent 2')
    ax2.set_xlabel('Time blocks of 15 minutes')
    plt.savefig('figures_verification/multi_agent_testing.png', dpi=300)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.101875808538163, 'fraction_numerical': 0.01633247089262613, 'mean_word_length': 3.850980392156863, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '493219', 'license': 'Apache-2.0', 'n_tokens_mistral': 1920, 'n_tokens_neox': 1796, 'n_words': 514, 'path': 'evidence_files/model_verification.ipynb', 'repo_name': 'SoniAnmol/Modelling-Dutch-Energy-Communities', 'size': '6271'}