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_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_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
628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 | |
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
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 | |
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. Args: n (pypsa.Network): the network object to optimize config (dict): the snakemake configuration dictionary
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 |