Skip to content

Policy targets constraints - #42

Open
abhishek0208 wants to merge 9 commits into
mainfrom
policy-targets-constraints
Open

Policy targets constraints#42
abhishek0208 wants to merge 9 commits into
mainfrom
policy-targets-constraints

Conversation

@abhishek0208

Copy link
Copy Markdown
Collaborator

Policy targets are added as custom linopy constraints in a PyPSA model.
This was first done in the tza-apg repo and has now been brought into this repo and generalised.

The steps to add custom constraints are:

from tz_pypsa.model import Model
from tz_pypsa.constraints import (constr_bus_self_sufficiency, 
                                  constr_cumulative_p_nom, 
                                  constr_policy_targets, 
                                  constr_max_annual_utilisation)

# Load a stock model with user-defined configuration
network = (
    Model.load_model(
        'ASEAN', 
        frequency = '72h',
        select_nodes = ['MYSPE', 'MYSSH', 'MYSSK', 'SGPXX'], 
        years = [2023, 2050],
        backstop = False,
        set_global_constraints = False,
    )
)

# Instantiate the linopy model
lp_model = network.optimize.create_model()

# Add policy targets as custom linopy constraints
constr_policy_targets(network,
                      lp_model,
                      'ASEAN') # This requires that a CSV with the policy targets are provided within the stock model data

@Handriyanti

Copy link
Copy Markdown
Collaborator

All functions can be called smoothly. But, I tried to set max_utilisation_rate = 1 and compare it with max_utilisation_rate = 0.85 in constr_max_annual_utilisation The results of p_nom, p_nom_opt and p are the same. Did I check the wrong variable on this?
Others are okay. Once this function is good, we can merge this branch to main and go on with brownfield.py in CFE.

@Handriyanti

Copy link
Copy Markdown
Collaborator

Coming back to this... All constraints including policy targets are actually able to be called and applied nicely. Just don't forget to solve the model first before defining a constraint then resolve it after defining a constraint. Please correct me here.

from tz_pypsa.model import Model
from tz_pypsa.constraints import (constr_bus_self_sufficiency, 
                                  constr_cumulative_p_nom, 
                                  constr_policy_targets, 
                                  constr_max_annual_utilisation)

# Load a stock model with user-defined configuration
network = (
    Model.load_model(
        'ASEAN', 
        frequency = '72h',
        select_nodes = ['IDNSM','IDNJW','IDNKA'], 
        years = [2023, 2030, 2050],
        backstop = False,
        set_global_constraints = False,
    )
)

# solve the model
network.optimize()

# Instantiate the linopy model
lp_model = network.optimize.create_model()

# Add policy targets as custom linopy constraints
constr_policy_targets(network,
                      lp_model,
                      'ASEAN') # This requires that a CSV with the policy targets are provided within the stock model data

# Let's solve the model again
network.optimize.solve_model()

I tried to run three IDN nodes because coal are super intensively used so the results with and without constraints are easily distinguished. I documented the results comparison here. ONe thing to be remembered is: The model is infeasible if it's heavily constrained.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants