Solve network
Functions to add constraints and prepare the network for the solver.
Associated with the solve_networks rule in the Snakefile.
add_battery_constraints(n)
Add constraint ensuring that charger = discharger, i.e. 1 * charger_size - efficiency * discharger_size = 0
Source code in workflow/scripts/solve_network.py
add_chp_constraints(n)
Add constraints to couple the heat and electricity output of CHP plants. Simplified treatment of extraction plant with Cb/Cv coeffs as per DKEA catalogue. Ignore the minimum electric power for heat output (aggregate over all units).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
Network
|
the pypsa network object to which's model the constraints are added |
required |
Source code in workflow/scripts/solve_network.py
add_chp_constraints_new_attempt(n)
Add constraints to couple the heat and electricity output of CHP plants. Simplified treatment of extraction plant with max heat to power ratio. Ignore the minimum electric power for heat output (aggregate over all units).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
Network
|
the pypsa network object to which's model the constraints are added |
required |
Source code in workflow/scripts/solve_network.py
add_co2_constraints_prices(network, co2_control)
Add co2 constraints or prices
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network
|
Network
|
the network to which prices or constraints are to be added |
required |
co2_control
|
dict
|
the config |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
unrecognised co2 control option |
Source code in workflow/scripts/solve_network.py
add_emission_prices(n, emission_prices={'co2': 0.0}, exclude_co2=False)
From pypsa-eur: add GHG price to marginal costs of generators and storage units
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
Network
|
the pypsa network |
required |
emission_prices
|
dict
|
emission prices per GHG. Defaults to {"co2": 0.0}. |
{'co2': 0.0}
|
exclude_co2
|
bool
|
do not charge for CO2 emissions. Defaults to False. |
False
|
Source code in workflow/scripts/solve_network.py
add_fuel_subsidies(n, subsidy_config, planning_year=None)
Apply fuel subsidies to generators as a post-processing step.
Subsidies are applied to generators based on their carrier and location. The subsidy values (in EUR/MWh fuel) are divided by efficiency to convert to electricity basis (EUR/MWhel). Links are not modified as they get their fuel from generators.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
Network
|
The network object to modify. |
required |
subsidy_config
|
dict
|
Subsidy configuration dictionary with keys like "coal" or "gas", each containing either: - dict mapping provinces to subsidy values (year-independent) - dict mapping years to dicts of provinces to subsidy values (year-dependent) |
required |
planning_year
|
int
|
Planning year for year-dependent subsidies. Required if subsidies are year-dependent. |
None
|
Source code in workflow/scripts/solve_network.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
add_land_use_constraint(n, planning_horizons)
Add land use constraints for renewable energy potential. This ensures that the brownfield + greenfield vre installations for each generator tech do not exceed the technical potential.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
Network
|
the network object to add the constraints to |
required |
planning_horizons
|
str | int
|
the planning horizon year as string |
required |
Source code in workflow/scripts/solve_network.py
add_nuclear_expansion_constraints(n)
Add nuclear expansion limit constraint if configured.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
Network
|
the network object |
required |
Source code in workflow/scripts/solve_network.py
add_operational_reserve_margin(n, config)
Build operational reserve margin constraints based on the formulation given in https://genxproject.github.io/GenX.jl/stable/Model_Reference/core/#GenX.operational_reserves_core!-Tuple{JuMP.Model,%20Dict,%20Dict}
The constraint is network wide and not at each node!
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
Network
|
the network object to optimize |
required |
config
|
dict
|
the configuration dictionary |
required |
Example
config.yaml requires to specify operational_reserve: operational_reserve: activate: true epsilon_load: 0.02 # percentage of load at each snapshot epsilon_vres: 0.02 # percentage of VRES at each snapshot contingency: 400000 # MW
Source code in workflow/scripts/solve_network.py
809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 | |
add_remind_paid_off_constraints(n)
Paid-off components can be placed wherever PyPSA wants but have a total limit.
Add constraints to ensure that the paid off capacity from REMIND is not exceeded across the network & that it does not exceed the technical potential.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
Network
|
the network object to which's model the constraints are added |
required |
Source code in workflow/scripts/solve_network.py
711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 | |
add_transmission_constraints(n)
Add constraint ensuring that transmission lines p_nom are the same for both directions, i.e. p_nom positive = p_nom negative
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
Network
|
the network object to optimize |
required |
Source code in workflow/scripts/solve_network.py
add_water_tank_charger_constraints(n, config)
Add constraint ensuring that centra water tank charger = discharger & limit p_nom/e_nom ratio, i.e.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
Network
|
the network object to optimize |
required |
config
|
dict
|
the snakemake configuration dictionary |
required |
Source code in workflow/scripts/solve_network.py
calc_nuclear_expansion_limit(n, config, planning_year, network_path)
Calculate the nuclear expansion limit from the configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
Network
|
the network object |
required |
config
|
dict
|
full configuration dictionary |
required |
planning_year
|
int
|
target planning horizon year |
required |
network_path
|
str
|
path to the current network file |
required |
Returns:
| Type | Description |
|---|---|
float | None
|
float | None: maximum allowed nuclear capacity in MW, or None if not applicable |
Source code in workflow/scripts/solve_network.py
extra_functionality(n, _)
Add supplementary constraints to the network model. pypsa.linopf.network_lopf.
If you want to enforce additional custom constraints, this is a good location to add them.
The arguments opts and snakemake.config are expected to be attached to the network.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
Network
|
the network object to optimize |
required |
_
|
dummy for compatibility with pypsa solve |
required |
Source code in workflow/scripts/solve_network.py
freeze_components(n, config, exclude=['H2 turbine'])
Set p_nom_extendable=False for the components in the network. Applies to vre_techs and conventional technologies not in the exclude list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
Network
|
the network object |
required |
config
|
dict
|
the configuration dictionary |
required |
exclude
|
list
|
list of technologies to exclude from freezing. Defaults to ["OCGT"] |
['H2 turbine']
|
Source code in workflow/scripts/solve_network.py
prepare_network(n, solve_opts, config, plan_year, co2_pathway)
Prepare the network for the solver,
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
Network
|
the network object to optimize |
required |
solve_opts
|
dict
|
solving options |
required |
config
|
dict
|
the snakemake configuration dictionary |
required |
plan_year
|
int
|
planning horizon year for which network is solved |
required |
co2_pathway
|
str
|
the CO2 pathway name to use |
required |
Returns:
| Type | Description |
|---|---|
Network
|
pypsa.Network: network object with additional constraints |
Source code in workflow/scripts/solve_network.py
set_transmission_limit(n, kind, factor, n_years=1)
Set global transimission limit constraints - adapted from pypsa-eur
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
Network
|
the network object |
required |
kind
|
str
|
the kind of limit to set, either 'c' for cost or 'v' for volume or l for length |
required |
factor
|
float or str
|
the factor to apply to the base year quantity, per year |
required |
n_years
|
int
|
the number of years to consider for the limit. Defaults to 1. |
1
|
Source code in workflow/scripts/solve_network.py
solve_network(n, config, solving, opts='', **kwargs)
Perform the optimisation Args: n (pypsa.Network): the pypsa network object config (dict): the configuration dictionary solving (dict): the solving configuration dictionary opts (str): optional wildcards such as ll (not used in pypsa-china)
Returns:
| Type | Description |
|---|---|
Network
|
pypsa.Network: the optimized network |