Problem 9.3#

Integrated Energy Grids

Build the model described in Problem 3.2 in PyPSA (i.e. the problem 9.2 but not including the CCGT generator with exogenous capacity).

a) Solve the problem for different CO\(_2\) values ranging from 5 MtCO\(_2\)/year to zero. Plot the total system cost and the required CO\(_2\) prices as a function of the emissions allowance.

b) Show what would happen if a CO\(_2\) tax was used instead of a CO\(_2\) limit. You can do this by adding a carbon tax to the relevant generators, and then comparing your results (total system costs, emissions, and generation mix) with the previous section. Make sure to use your results from part (a) for the appropriate carbon taxes.

Note

If you have not yet set up Python on your computer, you can execute this tutorial in your browser via Google Colab. Click on the rocket in the top right corner and launch “Colab”. If that doesn’t work download the .ipynb file and import it in Google Colab.

Then install pandas and numpy by executing the following command in a Jupyter cell at the top of the notebook.

!pip install pandas pypsa

Note

See also https://model.energy.

In this exercise, we want to build a replica of model.energy. This tool calculates the cost of meeting a constant electricity demand from a combination of wind power, solar power and storage for different regions of the world. We deviate from model.energy by including electricity demand profiles rather than a constant electricity demand.

import matplotlib.pyplot as plt
import pandas as pd
import pypsa
Set parameter Username
Set parameter LicenseID to value 2767832
Academic license - for non-commercial use only - expires 2027-01-20

Prerequisites: handling technology data and costs#

We maintain a database (PyPSA/technology-data, v0.11.0) which collects assumptions and projections for energy system technologies (such as costs, efficiencies, lifetimes, etc.) for given years, which we can load into a pandas.DataFrame. This requires some pre-processing to load (e.g. converting units, setting defaults, re-arranging dimensions):

year = 2030
url = f"https://raw.githubusercontent.com/PyPSA/technology-data/v0.11.0/outputs/costs_{year}.csv"
costs = pd.read_csv(url, index_col=[0, 1])
costs.loc[costs.unit.str.contains("/kW"), "value"] *= 1e3
costs.unit = costs.unit.str.replace("/kW", "/MW")

defaults = {
    "FOM": 0,
    "VOM": 0,
    "efficiency": 1,
    "fuel": 0,
    "investment": 0,
    "lifetime": 25,
    "CO2 intensity": 0,
    "discount rate": 0.07,
}
costs = costs.value.unstack().fillna(defaults)

costs.at["OCGT", "fuel"] = costs.at["gas", "fuel"]
costs.at["OCGT", "CO2 intensity"] = costs.at["gas", "CO2 intensity"]

Let’s also write a small utility function that calculates the annuity to annualise investment costs. The formula is

\[ a(r, n) = \frac{r}{1-(1+r)^{-n}} \]

where \(r\) is the discount rate and \(n\) is the lifetime.

def annuity(r, n):
    return r / (1.0 - 1.0 / (1.0 + r) ** n)
annuity(0.07, 20)
0.09439292574325567

Based on this, we can calculate the marginal generation costs (€/MWh):

costs["marginal_cost"] = costs["VOM"] + costs["fuel"] / costs["efficiency"]

and the annualised investment costs (capital_cost in PyPSA terms, €/MW/a):

annuity = costs.apply(lambda x: annuity(x["discount rate"], x["lifetime"]), axis=1)
costs["capital_cost"] = (annuity + costs["FOM"] / 100) * costs["investment"]

Now we can for example read the capital and marginal cost of onshore wind and solar, or the emissions factors of the carrier gas used in and OCGT

costs.at["onwind", "capital_cost"] #EUR/MW/a
np.float64(101644.12332388277)
costs.at["solar", "capital_cost"] #EUR/MW/a
np.float64(51346.82981964593)
costs.at["OCGT", "CO2 intensity"] #tCO2/MWh_th
np.float64(0.198)

Retrieving time series data#

In this example, wind data from https://zenodo.org/record/3253876#.XSiVOEdS8l0 and solar PV data from https://zenodo.org/record/2613651#.X0kbhDVS-uV is used. The data is downloaded in csv format and saved in the ‘data’ folder. The Pandas package is used as a convenient way of managing the datasets.

For convenience, the column including date information is converted into Datetime and set as index

data_solar = pd.read_csv('data/pv_optimal.csv',sep=';')
data_solar.index = pd.DatetimeIndex(data_solar['utc_time'])

data_wind = pd.read_csv('data/onshore_wind_1979-2017.csv',sep=';')
data_wind.index = pd.DatetimeIndex(data_wind['utc_time'])

data_el = pd.read_csv('data/electricity_demand.csv',sep=';')
data_el.index = pd.DatetimeIndex(data_el['utc_time'])

The data format can now be analyzed using the .head() function to show the first lines of the data set

data_solar.head()
utc_time AUT BEL BGR BIH CHE CYP CZE DEU DNK ... MLT NLD NOR POL PRT ROU SRB SVK SVN SWE
utc_time
1979-01-01 00:00:00+00:00 1979-01-01T00:00:00Z 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
1979-01-01 01:00:00+00:00 1979-01-01T01:00:00Z 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
1979-01-01 02:00:00+00:00 1979-01-01T02:00:00Z 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
1979-01-01 03:00:00+00:00 1979-01-01T03:00:00Z 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
1979-01-01 04:00:00+00:00 1979-01-01T04:00:00Z 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0

5 rows × 33 columns

We will use timeseries for Portugal in this excercise

country = 'PRT'

Joint capacity and dispatch optimisation#

For building the model, we start again by initialising an empty network, adding the snapshots, and the electricity bus.

n = pypsa.Network()
hours_in_2015 = pd.date_range('2015-01-01 00:00Z',
                              '2015-12-31 23:00Z',
                              freq='h')

n.set_snapshots(hours_in_2015.values)

n.add("Bus",
      "electricity")

n.snapshots
DatetimeIndex(['2015-01-01 00:00:00', '2015-01-01 01:00:00',
               '2015-01-01 02:00:00', '2015-01-01 03:00:00',
               '2015-01-01 04:00:00', '2015-01-01 05:00:00',
               '2015-01-01 06:00:00', '2015-01-01 07:00:00',
               '2015-01-01 08:00:00', '2015-01-01 09:00:00',
               ...
               '2015-12-31 14:00:00', '2015-12-31 15:00:00',
               '2015-12-31 16:00:00', '2015-12-31 17:00:00',
               '2015-12-31 18:00:00', '2015-12-31 19:00:00',
               '2015-12-31 20:00:00', '2015-12-31 21:00:00',
               '2015-12-31 22:00:00', '2015-12-31 23:00:00'],
              dtype='datetime64[ns]', name='snapshot', length=8760, freq=None)

We add all the technologies we are going to include as carriers.

carriers = [
    "onwind",
    "solar",
    "OCGT",
    "battery storage",
]

n.add(
    "Carrier",
    carriers,
    color=["dodgerblue", "gold", "indianred", "brown"],
    co2_emissions=[costs.at[c, "CO2 intensity"] for c in carriers],
)

Next, we add the demand time series to the model.

# add load to the bus
n.add("Load",
      "demand",
      bus="electricity",
      p_set=data_el[country].values)

Let’s have a check whether the data was read-in correctly.

n.loads_t.p_set.plot(figsize=(6, 2), ylabel="MW")
<Axes: xlabel='snapshot', ylabel='MW'>
../_images/8a5f93d31c4a552f639e2b6277aa2ffc8b5e70ae75db3dd33685ff76cecea2fd.png

We add now the generators and set up their capacities to be extendable so that they can be optimized together with the dispatch time series. For the wind and solar generator, we need to indicate the capacity factor or maximum power per unit ‘p_max_pu’

n.add(
    "Generator",
    "OCGT",
    bus="electricity",
    carrier="OCGT",
    capital_cost=costs.at["OCGT", "capital_cost"],
    marginal_cost=costs.at["OCGT", "marginal_cost"],
    efficiency=costs.at["OCGT", "efficiency"],
    p_nom_extendable=True,
)

CF_wind = data_wind[country][[hour.strftime("%Y-%m-%dT%H:%M:%SZ") for hour in n.snapshots]]
n.add(
        "Generator",
        "onwind",
        bus="electricity",
        carrier="onwind",
        p_max_pu=CF_wind.values,
        capital_cost=costs.at["onwind", "capital_cost"],
        marginal_cost=costs.at["onwind", "marginal_cost"],
        efficiency=costs.at["onwind", "efficiency"],
        p_nom_extendable=True,
    )

CF_solar = data_solar[country][[hour.strftime("%Y-%m-%dT%H:%M:%SZ") for hour in n.snapshots]]
n.add(
        "Generator",
        "solar",
        bus="electricity",
        carrier="solar",
        p_max_pu= CF_solar.values,
        capital_cost=costs.at["solar", "capital_cost"],
        marginal_cost=costs.at["solar", "marginal_cost"],
        efficiency=costs.at["solar", "efficiency"],
        p_nom_extendable=True,
    )

So let’s make sure the capacity factors are read-in correctly.

n.generators_t.p_max_pu.loc["2015-01"].plot(figsize=(6, 2), ylabel="CF")
<Axes: xlabel='snapshot', ylabel='CF'>
../_images/109e0d0858e0341f538bf966514dd49939ce25648aa5ee7bed2a6a9df98d9054.png

We add the battery storage, assuming a fixed energy-to-power ratio of 2 hours, i.e. if fully charged, the battery can discharge at full capacity for 2 hours.

For the capital cost, we have to factor in both the capacity and energy cost of the storage.

We include the charging and discharging efficiencies we enforce a cyclic state-of-charge condition, i.e. the state of charge at the beginning of the optimisation period must equal the final state of charge.

n.add(
    "StorageUnit",
    "battery storage",
    bus="electricity",
    carrier="battery storage",
    max_hours=2,
    capital_cost=costs.at["battery inverter", "capital_cost"]
    + 2 * costs.at["battery storage", "capital_cost"],
    efficiency_store=costs.at["battery inverter", "efficiency"],
    efficiency_dispatch=costs.at["battery inverter", "efficiency"],
    p_nom_extendable=True,
    cyclic_state_of_charge=True,
)

Model Run#

Before solving the problem we add a CO\(_2\) emission limit as global constraint:

n.add(
    "GlobalConstraint",
    "CO2Limit",
    carrier_attribute="co2_emissions",
    sense="<=",
    constant=5000000, #5MtCO2
)

We can already solved the model using the open-solver “highs” or the commercial solver “gurobi” with the academic license

n.optimize(solver_name="gurobi")
WARNING:pypsa.consistency:The following buses have carriers which are not defined:
Index(['electricity'], dtype='object', name='name')
INFO:linopy.model: Solve problem using Gurobi solver
INFO:linopy.io:Writing objective.
Writing constraints.: 100%|██████████| 13/13 [00:00<00:00, 100.63it/s]
Writing continuous variables.: 100%|██████████| 6/6 [00:00<00:00, 660.73it/s]
INFO:linopy.io: Writing time: 0.17s
Set parameter Username
INFO:gurobipy:Set parameter Username
Set parameter LicenseID to value 2767832
INFO:gurobipy:Set parameter LicenseID to value 2767832
Academic license - for non-commercial use only - expires 2027-01-20
INFO:gurobipy:Academic license - for non-commercial use only - expires 2027-01-20
Read LP format model from file /private/var/folders/zg/by4_k0616s98pw41wld9475c0000gp/T/linopy-problem-_2t9h6_8.lp
INFO:gurobipy:Read LP format model from file /private/var/folders/zg/by4_k0616s98pw41wld9475c0000gp/T/linopy-problem-_2t9h6_8.lp
Reading time = 0.11 seconds
INFO:gurobipy:Reading time = 0.11 seconds
obj: 122645 rows, 52564 columns, 240922 nonzeros
INFO:gurobipy:obj: 122645 rows, 52564 columns, 240922 nonzeros
Gurobi Optimizer version 13.0.0 build v13.0.0rc1 (mac64[arm] - Darwin 25.3.0 25D2128)
INFO:gurobipy:Gurobi Optimizer version 13.0.0 build v13.0.0rc1 (mac64[arm] - Darwin 25.3.0 25D2128)

INFO:gurobipy:
CPU model: Apple M3
INFO:gurobipy:CPU model: Apple M3
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads
INFO:gurobipy:Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

INFO:gurobipy:
Optimize a model with 122645 rows, 52564 columns and 240922 nonzeros (Min)
INFO:gurobipy:Optimize a model with 122645 rows, 52564 columns and 240922 nonzeros (Min)
Model fingerprint: 0xa92146da
INFO:gurobipy:Model fingerprint: 0xa92146da
Model has 26284 linear objective coefficients
INFO:gurobipy:Model has 26284 linear objective coefficients
Coefficient statistics:
INFO:gurobipy:Coefficient statistics:
  Matrix range     [1e-03, 2e+00]
INFO:gurobipy:  Matrix range     [1e-03, 2e+00]
  Objective range  [1e-02, 1e+05]
INFO:gurobipy:  Objective range  [1e-02, 1e+05]
  Bounds range     [0e+00, 0e+00]
INFO:gurobipy:  Bounds range     [0e+00, 0e+00]
  RHS range        [3e+03, 5e+06]
INFO:gurobipy:  RHS range        [3e+03, 5e+06]
Presolve removed 56926 rows and 4362 columns
INFO:gurobipy:Presolve removed 56926 rows and 4362 columns
Presolve time: 0.07s
INFO:gurobipy:Presolve time: 0.07s
Presolved: 65719 rows, 48202 columns, 179634 nonzeros
INFO:gurobipy:Presolved: 65719 rows, 48202 columns, 179634 nonzeros

INFO:gurobipy:
Concurrent LP optimizer: primal simplex, dual simplex, and barrier
INFO:gurobipy:Concurrent LP optimizer: primal simplex, dual simplex, and barrier
Showing barrier log only...
INFO:gurobipy:Showing barrier log only...

INFO:gurobipy:
Ordering time: 0.01s
INFO:gurobipy:Ordering time: 0.01s

INFO:gurobipy:
Barrier statistics:
INFO:gurobipy:Barrier statistics:
 Dense cols : 4
INFO:gurobipy: Dense cols : 4
 AA' NZ     : 1.577e+05
INFO:gurobipy: AA' NZ     : 1.577e+05
 Factor NZ  : 7.408e+05 (roughly 50 MB of memory)
INFO:gurobipy: Factor NZ  : 7.408e+05 (roughly 50 MB of memory)
 Factor Ops : 8.664e+06 (less than 1 second per iteration)
INFO:gurobipy: Factor Ops : 8.664e+06 (less than 1 second per iteration)
 Threads    : 1
INFO:gurobipy: Threads    : 1

INFO:gurobipy:
                  Objective                Residual
INFO:gurobipy:                  Objective                Residual
Iter       Primal          Dual         Primal    Dual     Compl     Time
INFO:gurobipy:Iter       Primal          Dual         Primal    Dual     Compl     Time
   0   4.12585279e+11  0.00000000e+00  2.29e+09 0.00e+00  5.25e+08     0s
INFO:gurobipy:   0   4.12585279e+11  0.00000000e+00  2.29e+09 0.00e+00  5.25e+08     0s
   1   5.08782818e+11 -5.18438138e+10  4.20e+08 2.12e+02  1.20e+08     0s
INFO:gurobipy:   1   5.08782818e+11 -5.18438138e+10  4.20e+08 2.12e+02  1.20e+08     0s
   2   3.52589040e+11 -4.54745890e+10  2.65e+07 2.50e+01  1.61e+07     0s
INFO:gurobipy:   2   3.52589040e+11 -4.54745890e+10  2.65e+07 2.50e+01  1.61e+07     0s
   3   1.16464956e+11 -1.00836547e+10  6.98e+05 1.39e+00  1.88e+06     0s
INFO:gurobipy:   3   1.16464956e+11 -1.00836547e+10  6.98e+05 1.39e+00  1.88e+06     0s
   4   4.81024973e+10 -1.73999122e+09  1.66e+05 2.30e-01  5.87e+05     0s
INFO:gurobipy:   4   4.81024973e+10 -1.73999122e+09  1.66e+05 2.30e-01  5.87e+05     0s
   5   1.11924201e+10  5.74472137e+08  2.39e+04 2.33e-10  1.13e+05     0s
INFO:gurobipy:   5   1.11924201e+10  5.74472137e+08  2.39e+04 2.33e-10  1.13e+05     0s
   6   7.14587220e+09  1.10041428e+09  1.32e+04 4.07e-10  6.34e+04     0s
INFO:gurobipy:   6   7.14587220e+09  1.10041428e+09  1.32e+04 4.07e-10  6.34e+04     0s
   7   5.60797505e+09  1.38888003e+09  8.12e+03 0.00e+00  4.42e+04     0s
INFO:gurobipy:   7   5.60797505e+09  1.38888003e+09  8.12e+03 0.00e+00  4.42e+04     0s
   8   4.93461352e+09  1.89917124e+09  6.01e+03 3.49e-10  3.17e+04     0s
INFO:gurobipy:   8   4.93461352e+09  1.89917124e+09  6.01e+03 3.49e-10  3.17e+04     0s
   9   4.37948516e+09  2.10380201e+09  4.05e+03 3.78e-10  2.37e+04     0s
INFO:gurobipy:   9   4.37948516e+09  2.10380201e+09  4.05e+03 3.78e-10  2.37e+04     0s
  10   3.98394709e+09  2.48994304e+09  2.57e+03 8.15e-10  1.56e+04     0s
INFO:gurobipy:  10   3.98394709e+09  2.48994304e+09  2.57e+03 8.15e-10  1.56e+04     0s
  11   3.77822442e+09  2.70993873e+09  1.73e+03 4.37e-10  1.11e+04     0s
INFO:gurobipy:  11   3.77822442e+09  2.70993873e+09  1.73e+03 4.37e-10  1.11e+04     0s
  12   3.69126316e+09  2.94844144e+09  1.33e+03 0.00e+00  7.73e+03     0s
INFO:gurobipy:  12   3.69126316e+09  2.94844144e+09  1.33e+03 0.00e+00  7.73e+03     0s
  13   3.59129077e+09  3.21067288e+09  7.04e+02 1.96e-10  3.96e+03     0s
INFO:gurobipy:  13   3.59129077e+09  3.21067288e+09  7.04e+02 1.96e-10  3.96e+03     0s
  14   3.54465249e+09  3.34425004e+09  4.06e+02 1.02e-09  2.08e+03     0s
INFO:gurobipy:  14   3.54465249e+09  3.34425004e+09  4.06e+02 1.02e-09  2.08e+03     0s
  15   3.52348162e+09  3.38932394e+09  2.90e+02 3.78e-10  1.39e+03     0s
INFO:gurobipy:  15   3.52348162e+09  3.38932394e+09  2.90e+02 3.78e-10  1.39e+03     0s
  16   3.50323556e+09  3.41793427e+09  1.70e+02 1.13e-10  8.86e+02     0s
INFO:gurobipy:  16   3.50323556e+09  3.41793427e+09  1.70e+02 1.13e-10  8.86e+02     0s
  17   3.49227209e+09  3.44968604e+09  1.07e+02 2.04e-10  4.42e+02     0s
INFO:gurobipy:  17   3.49227209e+09  3.44968604e+09  1.07e+02 2.04e-10  4.42e+02     0s
  18   3.48149367e+09  3.45665085e+09  4.87e+01 6.11e-10  2.58e+02     0s
INFO:gurobipy:  18   3.48149367e+09  3.45665085e+09  4.87e+01 6.11e-10  2.58e+02     0s
  19   3.47678886e+09  3.46936238e+09  2.25e+01 5.53e-10  7.71e+01     0s
INFO:gurobipy:  19   3.47678886e+09  3.46936238e+09  2.25e+01 5.53e-10  7.71e+01     0s
  20   3.47360484e+09  3.47077013e+09  6.60e+00 2.84e-10  2.94e+01     0s
INFO:gurobipy:  20   3.47360484e+09  3.47077013e+09  6.60e+00 2.84e-10  2.94e+01     0s
  21   3.47271523e+09  3.47155068e+09  2.15e+00 3.20e-10  1.21e+01     0s
INFO:gurobipy:  21   3.47271523e+09  3.47155068e+09  2.15e+00 3.20e-10  1.21e+01     0s
  22   3.47237333e+09  3.47205311e+09  4.96e-01 7.28e-10  3.33e+00     0s
INFO:gurobipy:  22   3.47237333e+09  3.47205311e+09  4.96e-01 7.28e-10  3.33e+00     0s
  23   3.47227354e+09  3.47223746e+09  1.74e-02 9.82e-11  3.75e-01     0s
INFO:gurobipy:  23   3.47227354e+09  3.47223746e+09  1.74e-02 9.82e-11  3.75e-01     0s
  24   3.47226695e+09  3.47226143e+09  9.37e-04 0.00e+00  5.73e-02     0s
INFO:gurobipy:  24   3.47226695e+09  3.47226143e+09  9.37e-04 0.00e+00  5.73e-02     0s
  25   3.47226649e+09  3.47226614e+09  1.23e-04 6.37e-10  3.64e-03     1s
INFO:gurobipy:  25   3.47226649e+09  3.47226614e+09  1.23e-04 6.37e-10  3.64e-03     1s
  26   3.47226639e+09  3.47226638e+09  1.00e-06 2.18e-10  8.98e-06     1s
INFO:gurobipy:  26   3.47226639e+09  3.47226638e+09  1.00e-06 2.18e-10  8.98e-06     1s
  27   3.47226639e+09  3.47226639e+09  2.09e-07 6.99e-09  8.98e-09     1s
INFO:gurobipy:  27   3.47226639e+09  3.47226639e+09  2.09e-07 6.99e-09  8.98e-09     1s

INFO:gurobipy:
Barrier solved model in 27 iterations and 0.54 seconds (0.88 work units)
INFO:gurobipy:Barrier solved model in 27 iterations and 0.54 seconds (0.88 work units)
Optimal objective 3.47226639e+09
INFO:gurobipy:Optimal objective 3.47226639e+09

INFO:gurobipy:
Crossover log...
INFO:gurobipy:Crossover log...

INFO:gurobipy:
      90 DPushes remaining with DInf 0.0000000e+00                 1s
INFO:gurobipy:      90 DPushes remaining with DInf 0.0000000e+00                 1s
       0 DPushes remaining with DInf 0.0000000e+00                 1s
INFO:gurobipy:       0 DPushes remaining with DInf 0.0000000e+00                 1s
Warning: Markowitz tolerance tightened to 0.5
INFO:gurobipy:Warning: Markowitz tolerance tightened to 0.5

INFO:gurobipy:
    7252 PPushes remaining with PInf 0.0000000e+00                 1s
INFO:gurobipy:    7252 PPushes remaining with PInf 0.0000000e+00                 1s
       0 PPushes remaining with PInf 0.0000000e+00                 2s
INFO:gurobipy:       0 PPushes remaining with PInf 0.0000000e+00                 2s

INFO:gurobipy:
  Push phase complete: Pinf 0.0000000e+00, Dinf 1.2711992e-09      2s
INFO:gurobipy:  Push phase complete: Pinf 0.0000000e+00, Dinf 1.2711992e-09      2s

INFO:gurobipy:
Crossover time: 1.87 seconds (4.22 work units)
INFO:gurobipy:Crossover time: 1.87 seconds (4.22 work units)

INFO:gurobipy:
Solved with barrier
INFO:gurobipy:Solved with barrier
Iteration    Objective       Primal Inf.    Dual Inf.      Time
INFO:gurobipy:Iteration    Objective       Primal Inf.    Dual Inf.      Time
    7345    3.4722664e+09   0.000000e+00   0.000000e+00      2s
INFO:gurobipy:    7345    3.4722664e+09   0.000000e+00   0.000000e+00      2s

INFO:gurobipy:
Solved in 7345 iterations and 2.50 seconds (5.27 work units)
INFO:gurobipy:Solved in 7345 iterations and 2.50 seconds (5.27 work units)
Optimal objective  3.472266385e+09
INFO:gurobipy:Optimal objective  3.472266385e+09
INFO:linopy.constants: Optimization successful: 
Status: ok
Termination condition: optimal
Solution: 52564 primals, 122645 duals
Objective: 3.47e+09
Solver model: available
Solver message: 2

INFO:pypsa.optimization.optimize:The shadow-prices of the constraints Generator-ext-p-lower, Generator-ext-p-upper, StorageUnit-ext-p_dispatch-lower, StorageUnit-ext-p_dispatch-upper, StorageUnit-ext-p_store-lower, StorageUnit-ext-p_store-upper, StorageUnit-ext-state_of_charge-lower, StorageUnit-ext-state_of_charge-upper, StorageUnit-energy_balance were not assigned to the network.
('ok', 'optimal')

Now, we can look at the results and evaluate the total system cost (in billion Euros per year)

print(n.objective / 1e9)
n.global_constraints
3.4722663853160163
type investment_period bus carrier_attribute sense constant mu
name
CO2Limit primary_energy NaN co2_emissions <= 5000000.0 -106.265723

a) Solve the problem for different CO\(_2\) values ranging from 5 MtCO2/year to zero. Plot the total system cost and the required CO\(_2\) prices as a function of the emissions allowance.

sensitivity = {}
co2_price = pd.Series()
def system_cost(n):
    tsc = n.statistics.capex() + n.statistics.opex()
    return tsc.droplevel(0).div(1e6)  # million €/a
    
for co2 in [5, 4, 3, 2, 1, 0]:
    n.global_constraints.loc["CO2Limit", "constant"] = co2 * 1e6
    n.optimize(solver_name="gurobi")
    sensitivity[co2] = system_cost(n)
    co2_price[co2] = -n.global_constraints.mu['CO2Limit']
WARNING:pypsa.consistency:The following buses have carriers which are not defined:
Index(['electricity'], dtype='object', name='name')
WARNING:pypsa.consistency:The following sub_networks have carriers which are not defined:
Index(['0'], dtype='object', name='name')
INFO:linopy.model: Solve problem using Gurobi solver
INFO:linopy.io:Writing objective.
Writing constraints.: 100%|██████████| 13/13 [00:00<00:00, 90.19it/s]
Writing continuous variables.: 100%|██████████| 6/6 [00:00<00:00, 588.01it/s]
INFO:linopy.io: Writing time: 0.16s
Set parameter Username
INFO:gurobipy:Set parameter Username
Set parameter LicenseID to value 2767832
INFO:gurobipy:Set parameter LicenseID to value 2767832
Academic license - for non-commercial use only - expires 2027-01-20
INFO:gurobipy:Academic license - for non-commercial use only - expires 2027-01-20
Read LP format model from file /private/var/folders/zg/by4_k0616s98pw41wld9475c0000gp/T/linopy-problem-776c8g0d.lp
INFO:gurobipy:Read LP format model from file /private/var/folders/zg/by4_k0616s98pw41wld9475c0000gp/T/linopy-problem-776c8g0d.lp
Reading time = 0.12 seconds
INFO:gurobipy:Reading time = 0.12 seconds
obj: 122645 rows, 52564 columns, 240922 nonzeros
INFO:gurobipy:obj: 122645 rows, 52564 columns, 240922 nonzeros
Gurobi Optimizer version 13.0.0 build v13.0.0rc1 (mac64[arm] - Darwin 25.3.0 25D2128)
INFO:gurobipy:Gurobi Optimizer version 13.0.0 build v13.0.0rc1 (mac64[arm] - Darwin 25.3.0 25D2128)

INFO:gurobipy:
CPU model: Apple M3
INFO:gurobipy:CPU model: Apple M3
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads
INFO:gurobipy:Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

INFO:gurobipy:
Optimize a model with 122645 rows, 52564 columns and 240922 nonzeros (Min)
INFO:gurobipy:Optimize a model with 122645 rows, 52564 columns and 240922 nonzeros (Min)
Model fingerprint: 0xa92146da
INFO:gurobipy:Model fingerprint: 0xa92146da
Model has 26284 linear objective coefficients
INFO:gurobipy:Model has 26284 linear objective coefficients
Coefficient statistics:
INFO:gurobipy:Coefficient statistics:
  Matrix range     [1e-03, 2e+00]
INFO:gurobipy:  Matrix range     [1e-03, 2e+00]
  Objective range  [1e-02, 1e+05]
INFO:gurobipy:  Objective range  [1e-02, 1e+05]
  Bounds range     [0e+00, 0e+00]
INFO:gurobipy:  Bounds range     [0e+00, 0e+00]
  RHS range        [3e+03, 5e+06]
INFO:gurobipy:  RHS range        [3e+03, 5e+06]
Presolve removed 56926 rows and 4362 columns
INFO:gurobipy:Presolve removed 56926 rows and 4362 columns
Presolve time: 0.07s
INFO:gurobipy:Presolve time: 0.07s
Presolved: 65719 rows, 48202 columns, 179634 nonzeros
INFO:gurobipy:Presolved: 65719 rows, 48202 columns, 179634 nonzeros

INFO:gurobipy:
Concurrent LP optimizer: primal simplex, dual simplex, and barrier
INFO:gurobipy:Concurrent LP optimizer: primal simplex, dual simplex, and barrier
Showing barrier log only...
INFO:gurobipy:Showing barrier log only...

INFO:gurobipy:
Ordering time: 0.02s
INFO:gurobipy:Ordering time: 0.02s

INFO:gurobipy:
Barrier statistics:
INFO:gurobipy:Barrier statistics:
 Dense cols : 4
INFO:gurobipy: Dense cols : 4
 AA' NZ     : 1.577e+05
INFO:gurobipy: AA' NZ     : 1.577e+05
 Factor NZ  : 7.408e+05 (roughly 50 MB of memory)
INFO:gurobipy: Factor NZ  : 7.408e+05 (roughly 50 MB of memory)
 Factor Ops : 8.664e+06 (less than 1 second per iteration)
INFO:gurobipy: Factor Ops : 8.664e+06 (less than 1 second per iteration)
 Threads    : 1
INFO:gurobipy: Threads    : 1

INFO:gurobipy:
                  Objective                Residual
INFO:gurobipy:                  Objective                Residual
Iter       Primal          Dual         Primal    Dual     Compl     Time
INFO:gurobipy:Iter       Primal          Dual         Primal    Dual     Compl     Time
   0   4.12585279e+11  0.00000000e+00  2.29e+09 0.00e+00  5.25e+08     0s
INFO:gurobipy:   0   4.12585279e+11  0.00000000e+00  2.29e+09 0.00e+00  5.25e+08     0s
   1   5.08782818e+11 -5.18438138e+10  4.20e+08 2.12e+02  1.20e+08     0s
INFO:gurobipy:   1   5.08782818e+11 -5.18438138e+10  4.20e+08 2.12e+02  1.20e+08     0s
   2   3.52589040e+11 -4.54745890e+10  2.65e+07 2.50e+01  1.61e+07     0s
INFO:gurobipy:   2   3.52589040e+11 -4.54745890e+10  2.65e+07 2.50e+01  1.61e+07     0s
   3   1.16464956e+11 -1.00836547e+10  6.98e+05 1.39e+00  1.88e+06     0s
INFO:gurobipy:   3   1.16464956e+11 -1.00836547e+10  6.98e+05 1.39e+00  1.88e+06     0s
   4   4.81024973e+10 -1.73999122e+09  1.66e+05 2.30e-01  5.87e+05     0s
INFO:gurobipy:   4   4.81024973e+10 -1.73999122e+09  1.66e+05 2.30e-01  5.87e+05     0s
   5   1.11924201e+10  5.74472137e+08  2.39e+04 2.33e-10  1.13e+05     0s
INFO:gurobipy:   5   1.11924201e+10  5.74472137e+08  2.39e+04 2.33e-10  1.13e+05     0s
   6   7.14587220e+09  1.10041428e+09  1.32e+04 4.07e-10  6.34e+04     0s
INFO:gurobipy:   6   7.14587220e+09  1.10041428e+09  1.32e+04 4.07e-10  6.34e+04     0s
   7   5.60797505e+09  1.38888003e+09  8.12e+03 0.00e+00  4.42e+04     0s
INFO:gurobipy:   7   5.60797505e+09  1.38888003e+09  8.12e+03 0.00e+00  4.42e+04     0s
   8   4.93461352e+09  1.89917124e+09  6.01e+03 3.49e-10  3.17e+04     0s
INFO:gurobipy:   8   4.93461352e+09  1.89917124e+09  6.01e+03 3.49e-10  3.17e+04     0s
   9   4.37948516e+09  2.10380201e+09  4.05e+03 3.78e-10  2.37e+04     0s
INFO:gurobipy:   9   4.37948516e+09  2.10380201e+09  4.05e+03 3.78e-10  2.37e+04     0s
  10   3.98394709e+09  2.48994304e+09  2.57e+03 8.15e-10  1.56e+04     0s
INFO:gurobipy:  10   3.98394709e+09  2.48994304e+09  2.57e+03 8.15e-10  1.56e+04     0s
  11   3.77822442e+09  2.70993873e+09  1.73e+03 4.37e-10  1.11e+04     0s
INFO:gurobipy:  11   3.77822442e+09  2.70993873e+09  1.73e+03 4.37e-10  1.11e+04     0s
  12   3.69126316e+09  2.94844144e+09  1.33e+03 0.00e+00  7.73e+03     0s
INFO:gurobipy:  12   3.69126316e+09  2.94844144e+09  1.33e+03 0.00e+00  7.73e+03     0s
  13   3.59129077e+09  3.21067288e+09  7.04e+02 1.96e-10  3.96e+03     0s
INFO:gurobipy:  13   3.59129077e+09  3.21067288e+09  7.04e+02 1.96e-10  3.96e+03     0s
  14   3.54465249e+09  3.34425004e+09  4.06e+02 1.02e-09  2.08e+03     0s
INFO:gurobipy:  14   3.54465249e+09  3.34425004e+09  4.06e+02 1.02e-09  2.08e+03     0s
  15   3.52348162e+09  3.38932394e+09  2.90e+02 3.78e-10  1.39e+03     0s
INFO:gurobipy:  15   3.52348162e+09  3.38932394e+09  2.90e+02 3.78e-10  1.39e+03     0s
  16   3.50323556e+09  3.41793427e+09  1.70e+02 1.13e-10  8.86e+02     0s
INFO:gurobipy:  16   3.50323556e+09  3.41793427e+09  1.70e+02 1.13e-10  8.86e+02     0s
  17   3.49227209e+09  3.44968604e+09  1.07e+02 2.04e-10  4.42e+02     0s
INFO:gurobipy:  17   3.49227209e+09  3.44968604e+09  1.07e+02 2.04e-10  4.42e+02     0s
  18   3.48149367e+09  3.45665085e+09  4.87e+01 6.11e-10  2.58e+02     0s
INFO:gurobipy:  18   3.48149367e+09  3.45665085e+09  4.87e+01 6.11e-10  2.58e+02     0s
  19   3.47678886e+09  3.46936238e+09  2.25e+01 5.53e-10  7.71e+01     0s
INFO:gurobipy:  19   3.47678886e+09  3.46936238e+09  2.25e+01 5.53e-10  7.71e+01     0s
  20   3.47360484e+09  3.47077013e+09  6.60e+00 2.84e-10  2.94e+01     0s
INFO:gurobipy:  20   3.47360484e+09  3.47077013e+09  6.60e+00 2.84e-10  2.94e+01     0s
  21   3.47271523e+09  3.47155068e+09  2.15e+00 3.20e-10  1.21e+01     1s
INFO:gurobipy:  21   3.47271523e+09  3.47155068e+09  2.15e+00 3.20e-10  1.21e+01     1s
  22   3.47237333e+09  3.47205311e+09  4.96e-01 7.28e-10  3.33e+00     1s
INFO:gurobipy:  22   3.47237333e+09  3.47205311e+09  4.96e-01 7.28e-10  3.33e+00     1s
  23   3.47227354e+09  3.47223746e+09  1.74e-02 9.82e-11  3.75e-01     1s
INFO:gurobipy:  23   3.47227354e+09  3.47223746e+09  1.74e-02 9.82e-11  3.75e-01     1s
  24   3.47226695e+09  3.47226143e+09  9.37e-04 0.00e+00  5.73e-02     1s
INFO:gurobipy:  24   3.47226695e+09  3.47226143e+09  9.37e-04 0.00e+00  5.73e-02     1s
  25   3.47226649e+09  3.47226614e+09  1.23e-04 6.37e-10  3.64e-03     1s
INFO:gurobipy:  25   3.47226649e+09  3.47226614e+09  1.23e-04 6.37e-10  3.64e-03     1s
  26   3.47226639e+09  3.47226638e+09  1.00e-06 2.18e-10  8.98e-06     1s
INFO:gurobipy:  26   3.47226639e+09  3.47226638e+09  1.00e-06 2.18e-10  8.98e-06     1s
  27   3.47226639e+09  3.47226639e+09  2.09e-07 6.99e-09  8.98e-09     1s
INFO:gurobipy:  27   3.47226639e+09  3.47226639e+09  2.09e-07 6.99e-09  8.98e-09     1s

INFO:gurobipy:
Barrier solved model in 27 iterations and 0.63 seconds (0.88 work units)
INFO:gurobipy:Barrier solved model in 27 iterations and 0.63 seconds (0.88 work units)
Optimal objective 3.47226639e+09
INFO:gurobipy:Optimal objective 3.47226639e+09

INFO:gurobipy:
Crossover log...
INFO:gurobipy:Crossover log...

INFO:gurobipy:
      90 DPushes remaining with DInf 0.0000000e+00                 1s
INFO:gurobipy:      90 DPushes remaining with DInf 0.0000000e+00                 1s
       0 DPushes remaining with DInf 0.0000000e+00                 1s
INFO:gurobipy:       0 DPushes remaining with DInf 0.0000000e+00                 1s
Warning: Markowitz tolerance tightened to 0.5
INFO:gurobipy:Warning: Markowitz tolerance tightened to 0.5

INFO:gurobipy:
    7252 PPushes remaining with PInf 0.0000000e+00                 1s
INFO:gurobipy:    7252 PPushes remaining with PInf 0.0000000e+00                 1s
       0 PPushes remaining with PInf 0.0000000e+00                 2s
INFO:gurobipy:       0 PPushes remaining with PInf 0.0000000e+00                 2s

INFO:gurobipy:
  Push phase complete: Pinf 0.0000000e+00, Dinf 1.2711992e-09      2s
INFO:gurobipy:  Push phase complete: Pinf 0.0000000e+00, Dinf 1.2711992e-09      2s

INFO:gurobipy:
Crossover time: 1.43 seconds (4.22 work units)
INFO:gurobipy:Crossover time: 1.43 seconds (4.22 work units)

INFO:gurobipy:
Solved with barrier
INFO:gurobipy:Solved with barrier
Iteration    Objective       Primal Inf.    Dual Inf.      Time
INFO:gurobipy:Iteration    Objective       Primal Inf.    Dual Inf.      Time
    7345    3.4722664e+09   0.000000e+00   0.000000e+00      2s
INFO:gurobipy:    7345    3.4722664e+09   0.000000e+00   0.000000e+00      2s

INFO:gurobipy:
Solved in 7345 iterations and 2.11 seconds (5.27 work units)
INFO:gurobipy:Solved in 7345 iterations and 2.11 seconds (5.27 work units)
Optimal objective  3.472266385e+09
INFO:gurobipy:Optimal objective  3.472266385e+09
INFO:linopy.constants: Optimization successful: 
Status: ok
Termination condition: optimal
Solution: 52564 primals, 122645 duals
Objective: 3.47e+09
Solver model: available
Solver message: 2

INFO:pypsa.optimization.optimize:The shadow-prices of the constraints Generator-ext-p-lower, Generator-ext-p-upper, StorageUnit-ext-p_dispatch-lower, StorageUnit-ext-p_dispatch-upper, StorageUnit-ext-p_store-lower, StorageUnit-ext-p_store-upper, StorageUnit-ext-state_of_charge-lower, StorageUnit-ext-state_of_charge-upper, StorageUnit-energy_balance were not assigned to the network.
WARNING:pypsa.consistency:The following buses have carriers which are not defined:
Index(['electricity'], dtype='object', name='name')
WARNING:pypsa.consistency:The following sub_networks have carriers which are not defined:
Index(['0'], dtype='object', name='name')
INFO:linopy.model: Solve problem using Gurobi solver
INFO:linopy.io:Writing objective.
Writing constraints.: 100%|██████████| 13/13 [00:00<00:00, 77.90it/s]
Writing continuous variables.: 100%|██████████| 6/6 [00:00<00:00, 603.50it/s]
INFO:linopy.io: Writing time: 0.18s
Set parameter Username
INFO:gurobipy:Set parameter Username
Set parameter LicenseID to value 2767832
INFO:gurobipy:Set parameter LicenseID to value 2767832
Academic license - for non-commercial use only - expires 2027-01-20
INFO:gurobipy:Academic license - for non-commercial use only - expires 2027-01-20
Read LP format model from file /private/var/folders/zg/by4_k0616s98pw41wld9475c0000gp/T/linopy-problem-030wvbrh.lp
INFO:gurobipy:Read LP format model from file /private/var/folders/zg/by4_k0616s98pw41wld9475c0000gp/T/linopy-problem-030wvbrh.lp
Reading time = 0.11 seconds
INFO:gurobipy:Reading time = 0.11 seconds
obj: 122645 rows, 52564 columns, 240922 nonzeros
INFO:gurobipy:obj: 122645 rows, 52564 columns, 240922 nonzeros
Gurobi Optimizer version 13.0.0 build v13.0.0rc1 (mac64[arm] - Darwin 25.3.0 25D2128)
INFO:gurobipy:Gurobi Optimizer version 13.0.0 build v13.0.0rc1 (mac64[arm] - Darwin 25.3.0 25D2128)

INFO:gurobipy:
CPU model: Apple M3
INFO:gurobipy:CPU model: Apple M3
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads
INFO:gurobipy:Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

INFO:gurobipy:
Optimize a model with 122645 rows, 52564 columns and 240922 nonzeros (Min)
INFO:gurobipy:Optimize a model with 122645 rows, 52564 columns and 240922 nonzeros (Min)
Model fingerprint: 0x67f3398a
INFO:gurobipy:Model fingerprint: 0x67f3398a
Model has 26284 linear objective coefficients
INFO:gurobipy:Model has 26284 linear objective coefficients
Coefficient statistics:
INFO:gurobipy:Coefficient statistics:
  Matrix range     [1e-03, 2e+00]
INFO:gurobipy:  Matrix range     [1e-03, 2e+00]
  Objective range  [1e-02, 1e+05]
INFO:gurobipy:  Objective range  [1e-02, 1e+05]
  Bounds range     [0e+00, 0e+00]
INFO:gurobipy:  Bounds range     [0e+00, 0e+00]
  RHS range        [3e+03, 4e+06]
INFO:gurobipy:  RHS range        [3e+03, 4e+06]
Presolve removed 56926 rows and 4362 columns
INFO:gurobipy:Presolve removed 56926 rows and 4362 columns
Presolve time: 0.07s
INFO:gurobipy:Presolve time: 0.07s
Presolved: 65719 rows, 48202 columns, 179634 nonzeros
INFO:gurobipy:Presolved: 65719 rows, 48202 columns, 179634 nonzeros

INFO:gurobipy:
Concurrent LP optimizer: primal simplex, dual simplex, and barrier
INFO:gurobipy:Concurrent LP optimizer: primal simplex, dual simplex, and barrier
Showing barrier log only...
INFO:gurobipy:Showing barrier log only...

INFO:gurobipy:
Ordering time: 0.01s
INFO:gurobipy:Ordering time: 0.01s

INFO:gurobipy:
Barrier statistics:
INFO:gurobipy:Barrier statistics:
 Dense cols : 4
INFO:gurobipy: Dense cols : 4
 AA' NZ     : 1.577e+05
INFO:gurobipy: AA' NZ     : 1.577e+05
 Factor NZ  : 7.408e+05 (roughly 50 MB of memory)
INFO:gurobipy: Factor NZ  : 7.408e+05 (roughly 50 MB of memory)
 Factor Ops : 8.664e+06 (less than 1 second per iteration)
INFO:gurobipy: Factor Ops : 8.664e+06 (less than 1 second per iteration)
 Threads    : 1
INFO:gurobipy: Threads    : 1

INFO:gurobipy:
                  Objective                Residual
INFO:gurobipy:                  Objective                Residual
Iter       Primal          Dual         Primal    Dual     Compl     Time
INFO:gurobipy:Iter       Primal          Dual         Primal    Dual     Compl     Time
   0   3.69267059e+11  0.00000000e+00  2.05e+09 0.00e+00  3.97e+08     0s
INFO:gurobipy:   0   3.69267059e+11  0.00000000e+00  2.05e+09 0.00e+00  3.97e+08     0s
   1   4.50254865e+11 -4.61348819e+10  3.65e+08 1.94e+02  8.99e+07     0s
INFO:gurobipy:   1   4.50254865e+11 -4.61348819e+10  3.65e+08 1.94e+02  8.99e+07     0s
   2   2.98124505e+11 -3.83635392e+10  2.31e+07 2.26e+01  1.20e+07     0s
INFO:gurobipy:   2   2.98124505e+11 -3.83635392e+10  2.31e+07 2.26e+01  1.20e+07     0s
   3   9.98817646e+10 -7.70679161e+09  8.93e+05 1.14e+00  1.40e+06     0s
INFO:gurobipy:   3   9.98817646e+10 -7.70679161e+09  8.93e+05 1.14e+00  1.40e+06     0s
   4   4.22624564e+10 -1.44338531e+09  2.44e+05 2.27e-01  4.67e+05     0s
INFO:gurobipy:   4   4.22624564e+10 -1.44338531e+09  2.44e+05 2.27e-01  4.67e+05     0s
   5   1.11012872e+10  5.74145360e+08  4.05e+04 1.28e-02  1.03e+05     0s
INFO:gurobipy:   5   1.11012872e+10  5.74145360e+08  4.05e+04 1.28e-02  1.03e+05     0s
   6   7.06898395e+09  1.41533003e+09  2.10e+04 8.15e-10  5.43e+04     0s
INFO:gurobipy:   6   7.06898395e+09  1.41533003e+09  2.10e+04 8.15e-10  5.43e+04     0s
   7   5.23009621e+09  1.84890016e+09  1.18e+04 0.00e+00  3.24e+04     0s
INFO:gurobipy:   7   5.23009621e+09  1.84890016e+09  1.18e+04 0.00e+00  3.24e+04     0s
   8   4.69781646e+09  2.06962854e+09  8.41e+03 4.37e-10  2.51e+04     0s
INFO:gurobipy:   8   4.69781646e+09  2.06962854e+09  8.41e+03 4.37e-10  2.51e+04     0s
   9   4.14198847e+09  2.57256333e+09  4.39e+03 3.49e-10  1.50e+04     0s
INFO:gurobipy:   9   4.14198847e+09  2.57256333e+09  4.39e+03 3.49e-10  1.50e+04     0s
  10   3.87019792e+09  2.99185873e+09  2.61e+03 9.90e-10  8.37e+03     0s
INFO:gurobipy:  10   3.87019792e+09  2.99185873e+09  2.61e+03 9.90e-10  8.37e+03     0s
  11   3.78765194e+09  3.33237365e+09  2.00e+03 3.78e-10  4.34e+03     0s
INFO:gurobipy:  11   3.78765194e+09  3.33237365e+09  2.00e+03 3.78e-10  4.34e+03     0s
  12   3.69712548e+09  3.45112355e+09  1.21e+03 7.28e-12  2.34e+03     0s
INFO:gurobipy:  12   3.69712548e+09  3.45112355e+09  1.21e+03 7.28e-12  2.34e+03     0s
  13   3.65158495e+09  3.52158170e+09  7.26e+02 1.93e-10  1.24e+03     0s
INFO:gurobipy:  13   3.65158495e+09  3.52158170e+09  7.26e+02 1.93e-10  1.24e+03     0s
  14   3.61576986e+09  3.56136836e+09  3.35e+02 1.16e-09  5.18e+02     0s
INFO:gurobipy:  14   3.61576986e+09  3.56136836e+09  3.35e+02 1.16e-09  5.18e+02     0s
  15   3.59710655e+09  3.57890305e+09  9.63e+01 9.31e-10  1.73e+02     0s
INFO:gurobipy:  15   3.59710655e+09  3.57890305e+09  9.63e+01 9.31e-10  1.73e+02     0s
  16   3.59292482e+09  3.58566048e+09  4.53e+01 6.98e-10  6.92e+01     0s
INFO:gurobipy:  16   3.59292482e+09  3.58566048e+09  4.53e+01 6.98e-10  6.92e+01     0s
  17   3.59068796e+09  3.58759811e+09  1.92e+01 2.80e-10  2.94e+01     0s
INFO:gurobipy:  17   3.59068796e+09  3.58759811e+09  1.92e+01 2.80e-10  2.94e+01     0s
  18   3.58944332e+09  3.58847589e+09  4.78e+00 1.71e-10  9.21e+00     0s
INFO:gurobipy:  18   3.58944332e+09  3.58847589e+09  4.78e+00 1.71e-10  9.21e+00     0s
  19   3.58904012e+09  3.58887068e+09  2.97e-01 3.20e-10  1.61e+00     0s
INFO:gurobipy:  19   3.58904012e+09  3.58887068e+09  2.97e-01 3.20e-10  1.61e+00     0s
  20   3.58901395e+09  3.58897423e+09  3.89e-02 3.60e-10  3.78e-01     0s
INFO:gurobipy:  20   3.58901395e+09  3.58897423e+09  3.89e-02 3.60e-10  3.78e-01     0s
  21   3.58900858e+09  3.58899839e+09  6.40e-03 2.91e-10  9.70e-02     0s
INFO:gurobipy:  21   3.58900858e+09  3.58899839e+09  6.40e-03 2.91e-10  9.70e-02     0s
  22   3.58900752e+09  3.58900661e+09  3.85e-04 4.73e-09  8.70e-03     0s
INFO:gurobipy:  22   3.58900752e+09  3.58900661e+09  3.85e-04 4.73e-09  8.70e-03     0s
  23   3.58900734e+09  3.58900733e+09  3.42e-07 1.86e-10  1.12e-05     0s
INFO:gurobipy:  23   3.58900734e+09  3.58900733e+09  3.42e-07 1.86e-10  1.12e-05     0s
  24   3.58900734e+09  3.58900734e+09  4.84e-07 9.03e-09  1.12e-08     1s
INFO:gurobipy:  24   3.58900734e+09  3.58900734e+09  4.84e-07 9.03e-09  1.12e-08     1s
  25   3.58900734e+09  3.58900734e+09  3.74e-07 7.17e-09  1.20e-11     1s
INFO:gurobipy:  25   3.58900734e+09  3.58900734e+09  3.74e-07 7.17e-09  1.20e-11     1s

INFO:gurobipy:
Barrier solved model in 25 iterations and 0.52 seconds (0.83 work units)
INFO:gurobipy:Barrier solved model in 25 iterations and 0.52 seconds (0.83 work units)
Optimal objective 3.58900734e+09
INFO:gurobipy:Optimal objective 3.58900734e+09

INFO:gurobipy:
Crossover log...
INFO:gurobipy:Crossover log...

INFO:gurobipy:
      76 DPushes remaining with DInf 0.0000000e+00                 1s
INFO:gurobipy:      76 DPushes remaining with DInf 0.0000000e+00                 1s
       0 DPushes remaining with DInf 0.0000000e+00                 1s
INFO:gurobipy:       0 DPushes remaining with DInf 0.0000000e+00                 1s
Warning: Markowitz tolerance tightened to 0.25
INFO:gurobipy:Warning: Markowitz tolerance tightened to 0.25

INFO:gurobipy:
    6905 PPushes remaining with PInf 0.0000000e+00                 1s
INFO:gurobipy:    6905 PPushes remaining with PInf 0.0000000e+00                 1s
       0 PPushes remaining with PInf 0.0000000e+00                 2s
INFO:gurobipy:       0 PPushes remaining with PInf 0.0000000e+00                 2s

INFO:gurobipy:
  Push phase complete: Pinf 0.0000000e+00, Dinf 1.2586698e-09      2s
INFO:gurobipy:  Push phase complete: Pinf 0.0000000e+00, Dinf 1.2586698e-09      2s

INFO:gurobipy:
Crossover time: 1.74 seconds (3.26 work units)
INFO:gurobipy:Crossover time: 1.74 seconds (3.26 work units)

INFO:gurobipy:
Solved with barrier
INFO:gurobipy:Solved with barrier
Iteration    Objective       Primal Inf.    Dual Inf.      Time
INFO:gurobipy:Iteration    Objective       Primal Inf.    Dual Inf.      Time
    6984    3.5890073e+09   0.000000e+00   0.000000e+00      2s
INFO:gurobipy:    6984    3.5890073e+09   0.000000e+00   0.000000e+00      2s

INFO:gurobipy:
Solved in 6984 iterations and 2.31 seconds (4.21 work units)
INFO:gurobipy:Solved in 6984 iterations and 2.31 seconds (4.21 work units)
Optimal objective  3.589007336e+09
INFO:gurobipy:Optimal objective  3.589007336e+09
INFO:linopy.constants: Optimization successful: 
Status: ok
Termination condition: optimal
Solution: 52564 primals, 122645 duals
Objective: 3.59e+09
Solver model: available
Solver message: 2

INFO:pypsa.optimization.optimize:The shadow-prices of the constraints Generator-ext-p-lower, Generator-ext-p-upper, StorageUnit-ext-p_dispatch-lower, StorageUnit-ext-p_dispatch-upper, StorageUnit-ext-p_store-lower, StorageUnit-ext-p_store-upper, StorageUnit-ext-state_of_charge-lower, StorageUnit-ext-state_of_charge-upper, StorageUnit-energy_balance were not assigned to the network.
WARNING:pypsa.consistency:The following buses have carriers which are not defined:
Index(['electricity'], dtype='object', name='name')
WARNING:pypsa.consistency:The following sub_networks have carriers which are not defined:
Index(['0'], dtype='object', name='name')
INFO:linopy.model: Solve problem using Gurobi solver
INFO:linopy.io:Writing objective.
Writing constraints.: 100%|██████████| 13/13 [00:00<00:00, 48.11it/s]
Writing continuous variables.: 100%|██████████| 6/6 [00:00<00:00, 227.02it/s]
INFO:linopy.io: Writing time: 0.3s
Set parameter Username
INFO:gurobipy:Set parameter Username
Set parameter LicenseID to value 2767832
INFO:gurobipy:Set parameter LicenseID to value 2767832
Academic license - for non-commercial use only - expires 2027-01-20
INFO:gurobipy:Academic license - for non-commercial use only - expires 2027-01-20
Read LP format model from file /private/var/folders/zg/by4_k0616s98pw41wld9475c0000gp/T/linopy-problem-lzxb9t1j.lp
INFO:gurobipy:Read LP format model from file /private/var/folders/zg/by4_k0616s98pw41wld9475c0000gp/T/linopy-problem-lzxb9t1j.lp
Reading time = 0.12 seconds
INFO:gurobipy:Reading time = 0.12 seconds
obj: 122645 rows, 52564 columns, 240922 nonzeros
INFO:gurobipy:obj: 122645 rows, 52564 columns, 240922 nonzeros
Gurobi Optimizer version 13.0.0 build v13.0.0rc1 (mac64[arm] - Darwin 25.3.0 25D2128)
INFO:gurobipy:Gurobi Optimizer version 13.0.0 build v13.0.0rc1 (mac64[arm] - Darwin 25.3.0 25D2128)

INFO:gurobipy:
CPU model: Apple M3
INFO:gurobipy:CPU model: Apple M3
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads
INFO:gurobipy:Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

INFO:gurobipy:
Optimize a model with 122645 rows, 52564 columns and 240922 nonzeros (Min)
INFO:gurobipy:Optimize a model with 122645 rows, 52564 columns and 240922 nonzeros (Min)
Model fingerprint: 0x9542c46a
INFO:gurobipy:Model fingerprint: 0x9542c46a
Model has 26284 linear objective coefficients
INFO:gurobipy:Model has 26284 linear objective coefficients
Coefficient statistics:
INFO:gurobipy:Coefficient statistics:
  Matrix range     [1e-03, 2e+00]
INFO:gurobipy:  Matrix range     [1e-03, 2e+00]
  Objective range  [1e-02, 1e+05]
INFO:gurobipy:  Objective range  [1e-02, 1e+05]
  Bounds range     [0e+00, 0e+00]
INFO:gurobipy:  Bounds range     [0e+00, 0e+00]
  RHS range        [3e+03, 3e+06]
INFO:gurobipy:  RHS range        [3e+03, 3e+06]
Presolve removed 56926 rows and 4362 columns
INFO:gurobipy:Presolve removed 56926 rows and 4362 columns
Presolve time: 0.15s
INFO:gurobipy:Presolve time: 0.15s
Presolved: 65719 rows, 48202 columns, 179634 nonzeros
INFO:gurobipy:Presolved: 65719 rows, 48202 columns, 179634 nonzeros

INFO:gurobipy:
Concurrent LP optimizer: primal simplex, dual simplex, and barrier
INFO:gurobipy:Concurrent LP optimizer: primal simplex, dual simplex, and barrier
Showing barrier log only...
INFO:gurobipy:Showing barrier log only...

INFO:gurobipy:
Ordering time: 0.06s
INFO:gurobipy:Ordering time: 0.06s

INFO:gurobipy:
Barrier statistics:
INFO:gurobipy:Barrier statistics:
 Dense cols : 4
INFO:gurobipy: Dense cols : 4
 AA' NZ     : 1.577e+05
INFO:gurobipy: AA' NZ     : 1.577e+05
 Factor NZ  : 7.408e+05 (roughly 50 MB of memory)
INFO:gurobipy: Factor NZ  : 7.408e+05 (roughly 50 MB of memory)
 Factor Ops : 8.664e+06 (less than 1 second per iteration)
INFO:gurobipy: Factor Ops : 8.664e+06 (less than 1 second per iteration)
 Threads    : 1
INFO:gurobipy: Threads    : 1

INFO:gurobipy:
                  Objective                Residual
INFO:gurobipy:                  Objective                Residual
Iter       Primal          Dual         Primal    Dual     Compl     Time
INFO:gurobipy:Iter       Primal          Dual         Primal    Dual     Compl     Time
   0   3.20092970e+11  0.00000000e+00  1.77e+09 0.00e+00  3.44e+08     0s
INFO:gurobipy:   0   3.20092970e+11  0.00000000e+00  1.77e+09 0.00e+00  3.44e+08     0s
   1   3.90382018e+11 -4.48290374e+10  3.13e+08 1.94e+02  7.76e+07     0s
INFO:gurobipy:   1   3.90382018e+11 -4.48290374e+10  3.13e+08 1.94e+02  7.76e+07     0s
   2   2.58301613e+11 -3.55745905e+10  1.99e+07 2.22e+01  1.03e+07     0s
INFO:gurobipy:   2   2.58301613e+11 -3.55745905e+10  1.99e+07 2.22e+01  1.03e+07     0s
   3   8.75013295e+10 -6.65866075e+09  8.38e+05 1.26e+00  1.26e+06     0s
INFO:gurobipy:   3   8.75013295e+10 -6.65866075e+09  8.38e+05 1.26e+00  1.26e+06     0s
   4   3.92380744e+10 -1.47778576e+09  2.45e+05 3.31e-01  4.45e+05     0s
INFO:gurobipy:   4   3.92380744e+10 -1.47778576e+09  2.45e+05 3.31e-01  4.45e+05     0s
   5   1.15546261e+10  4.76736687e+08  4.57e+04 3.66e-02  1.09e+05     1s
INFO:gurobipy:   5   1.15546261e+10  4.76736687e+08  4.57e+04 3.66e-02  1.09e+05     1s
   6   6.81450399e+09  1.23306361e+09  2.06e+04 1.60e-09  5.42e+04     1s
INFO:gurobipy:   6   6.81450399e+09  1.23306361e+09  2.06e+04 1.60e-09  5.42e+04     1s
   7   5.37918303e+09  1.82403531e+09  1.29e+04 8.73e-10  3.42e+04     1s
INFO:gurobipy:   7   5.37918303e+09  1.82403531e+09  1.29e+04 8.73e-10  3.42e+04     1s
   8   4.72643171e+09  2.25039703e+09  9.03e+03 5.24e-10  2.38e+04     1s
INFO:gurobipy:   8   4.72643171e+09  2.25039703e+09  9.03e+03 5.24e-10  2.38e+04     1s
   9   4.11121371e+09  2.69374443e+09  4.38e+03 4.37e-10  1.36e+04     1s
INFO:gurobipy:   9   4.11121371e+09  2.69374443e+09  4.38e+03 4.37e-10  1.36e+04     1s
  10   3.94556428e+09  3.17232450e+09  2.92e+03 1.09e-11  7.40e+03     1s
INFO:gurobipy:  10   3.94556428e+09  3.17232450e+09  2.92e+03 1.09e-11  7.40e+03     1s
  11   3.90228950e+09  3.51599921e+09  2.35e+03 6.40e-10  3.69e+03     1s
INFO:gurobipy:  11   3.90228950e+09  3.51599921e+09  2.35e+03 6.40e-10  3.69e+03     1s
  12   3.80306256e+09  3.62668904e+09  9.94e+02 1.25e-09  1.68e+03     1s
INFO:gurobipy:  12   3.80306256e+09  3.62668904e+09  9.94e+02 1.25e-09  1.68e+03     1s
  13   3.78448708e+09  3.69055471e+09  6.75e+02 4.62e-10  8.97e+02     1s
INFO:gurobipy:  13   3.78448708e+09  3.69055471e+09  6.75e+02 4.62e-10  8.97e+02     1s
  14   3.76043830e+09  3.72281507e+09  2.60e+02 2.62e-10  3.59e+02     1s
INFO:gurobipy:  14   3.76043830e+09  3.72281507e+09  2.60e+02 2.62e-10  3.59e+02     1s
  15   3.74747222e+09  3.73746279e+09  4.33e+01 2.69e-10  9.55e+01     1s
INFO:gurobipy:  15   3.74747222e+09  3.73746279e+09  4.33e+01 2.69e-10  9.55e+01     1s
  16   3.74518596e+09  3.74288361e+09  1.01e+01 4.95e-10  2.20e+01     1s
INFO:gurobipy:  16   3.74518596e+09  3.74288361e+09  1.01e+01 4.95e-10  2.20e+01     1s
  17   3.74472102e+09  3.74364762e+09  4.03e+00 5.06e-10  1.02e+01     1s
INFO:gurobipy:  17   3.74472102e+09  3.74364762e+09  4.03e+00 5.06e-10  1.02e+01     1s
  18   3.74448650e+09  3.74420675e+09  1.03e+00 1.15e-09  2.67e+00     1s
INFO:gurobipy:  18   3.74448650e+09  3.74420675e+09  1.03e+00 1.15e-09  2.67e+00     1s
  19   3.74440292e+09  3.74437513e+09  8.25e-02 0.00e+00  2.65e-01     1s
INFO:gurobipy:  19   3.74440292e+09  3.74437513e+09  8.25e-02 0.00e+00  2.65e-01     1s
  20   3.74439476e+09  3.74439298e+09  3.95e-03 2.07e-09  1.70e-02     1s
INFO:gurobipy:  20   3.74439476e+09  3.74439298e+09  3.95e-03 2.07e-09  1.70e-02     1s
  21   3.74439423e+09  3.74439418e+09  9.02e-05 6.98e-10  4.80e-04     1s
INFO:gurobipy:  21   3.74439423e+09  3.74439418e+09  9.02e-05 6.98e-10  4.80e-04     1s
  22   3.74439422e+09  3.74439421e+09  1.06e-06 1.05e-09  3.44e-05     1s
INFO:gurobipy:  22   3.74439422e+09  3.74439421e+09  1.06e-06 1.05e-09  3.44e-05     1s
  23   3.74439422e+09  3.74439422e+09  2.52e-07 2.59e-09  3.94e-08     1s
INFO:gurobipy:  23   3.74439422e+09  3.74439422e+09  2.52e-07 2.59e-09  3.94e-08     1s
  24   3.74439422e+09  3.74439422e+09  1.97e-07 2.49e-09  3.69e-11     1s
INFO:gurobipy:  24   3.74439422e+09  3.74439422e+09  1.97e-07 2.49e-09  3.69e-11     1s

INFO:gurobipy:
Barrier solved model in 24 iterations and 0.87 seconds (0.80 work units)
INFO:gurobipy:Barrier solved model in 24 iterations and 0.87 seconds (0.80 work units)
Optimal objective 3.74439422e+09
INFO:gurobipy:Optimal objective 3.74439422e+09

INFO:gurobipy:
Crossover log...
INFO:gurobipy:Crossover log...

INFO:gurobipy:
      89 DPushes remaining with DInf 0.0000000e+00                 1s
INFO:gurobipy:      89 DPushes remaining with DInf 0.0000000e+00                 1s
       0 DPushes remaining with DInf 0.0000000e+00                 1s
INFO:gurobipy:       0 DPushes remaining with DInf 0.0000000e+00                 1s
Warning: Markowitz tolerance tightened to 0.5
INFO:gurobipy:Warning: Markowitz tolerance tightened to 0.5

INFO:gurobipy:
    6553 PPushes remaining with PInf 0.0000000e+00                 1s
INFO:gurobipy:    6553 PPushes remaining with PInf 0.0000000e+00                 1s
       0 PPushes remaining with PInf 0.0000000e+00                 1s
INFO:gurobipy:       0 PPushes remaining with PInf 0.0000000e+00                 1s

INFO:gurobipy:
  Push phase complete: Pinf 0.0000000e+00, Dinf 1.1525471e-09      1s
INFO:gurobipy:  Push phase complete: Pinf 0.0000000e+00, Dinf 1.1525471e-09      1s

INFO:gurobipy:
Crossover time: 0.32 seconds (1.08 work units)
INFO:gurobipy:Crossover time: 0.32 seconds (1.08 work units)

INFO:gurobipy:
Solved with barrier
INFO:gurobipy:Solved with barrier
Iteration    Objective       Primal Inf.    Dual Inf.      Time
INFO:gurobipy:Iteration    Objective       Primal Inf.    Dual Inf.      Time
    6645    3.7443942e+09   0.000000e+00   0.000000e+00      1s
INFO:gurobipy:    6645    3.7443942e+09   0.000000e+00   0.000000e+00      1s

INFO:gurobipy:
Solved in 6645 iterations and 1.22 seconds (1.93 work units)
INFO:gurobipy:Solved in 6645 iterations and 1.22 seconds (1.93 work units)
Optimal objective  3.744394217e+09
INFO:gurobipy:Optimal objective  3.744394217e+09
INFO:linopy.constants: Optimization successful: 
Status: ok
Termination condition: optimal
Solution: 52564 primals, 122645 duals
Objective: 3.74e+09
Solver model: available
Solver message: 2

INFO:pypsa.optimization.optimize:The shadow-prices of the constraints Generator-ext-p-lower, Generator-ext-p-upper, StorageUnit-ext-p_dispatch-lower, StorageUnit-ext-p_dispatch-upper, StorageUnit-ext-p_store-lower, StorageUnit-ext-p_store-upper, StorageUnit-ext-state_of_charge-lower, StorageUnit-ext-state_of_charge-upper, StorageUnit-energy_balance were not assigned to the network.
WARNING:pypsa.consistency:The following buses have carriers which are not defined:
Index(['electricity'], dtype='object', name='name')
WARNING:pypsa.consistency:The following sub_networks have carriers which are not defined:
Index(['0'], dtype='object', name='name')
INFO:linopy.model: Solve problem using Gurobi solver
INFO:linopy.io:Writing objective.
Writing constraints.: 100%|██████████| 13/13 [00:00<00:00, 74.71it/s]
Writing continuous variables.: 100%|██████████| 6/6 [00:00<00:00, 371.13it/s]
INFO:linopy.io: Writing time: 0.21s
Set parameter Username
INFO:gurobipy:Set parameter Username
Set parameter LicenseID to value 2767832
INFO:gurobipy:Set parameter LicenseID to value 2767832
Academic license - for non-commercial use only - expires 2027-01-20
INFO:gurobipy:Academic license - for non-commercial use only - expires 2027-01-20
Read LP format model from file /private/var/folders/zg/by4_k0616s98pw41wld9475c0000gp/T/linopy-problem-7xi59ezc.lp
INFO:gurobipy:Read LP format model from file /private/var/folders/zg/by4_k0616s98pw41wld9475c0000gp/T/linopy-problem-7xi59ezc.lp
Reading time = 0.13 seconds
INFO:gurobipy:Reading time = 0.13 seconds
obj: 122645 rows, 52564 columns, 240922 nonzeros
INFO:gurobipy:obj: 122645 rows, 52564 columns, 240922 nonzeros
Gurobi Optimizer version 13.0.0 build v13.0.0rc1 (mac64[arm] - Darwin 25.3.0 25D2128)
INFO:gurobipy:Gurobi Optimizer version 13.0.0 build v13.0.0rc1 (mac64[arm] - Darwin 25.3.0 25D2128)

INFO:gurobipy:
CPU model: Apple M3
INFO:gurobipy:CPU model: Apple M3
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads
INFO:gurobipy:Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

INFO:gurobipy:
Optimize a model with 122645 rows, 52564 columns and 240922 nonzeros (Min)
INFO:gurobipy:Optimize a model with 122645 rows, 52564 columns and 240922 nonzeros (Min)
Model fingerprint: 0x6eda6212
INFO:gurobipy:Model fingerprint: 0x6eda6212
Model has 26284 linear objective coefficients
INFO:gurobipy:Model has 26284 linear objective coefficients
Coefficient statistics:
INFO:gurobipy:Coefficient statistics:
  Matrix range     [1e-03, 2e+00]
INFO:gurobipy:  Matrix range     [1e-03, 2e+00]
  Objective range  [1e-02, 1e+05]
INFO:gurobipy:  Objective range  [1e-02, 1e+05]
  Bounds range     [0e+00, 0e+00]
INFO:gurobipy:  Bounds range     [0e+00, 0e+00]
  RHS range        [3e+03, 2e+06]
INFO:gurobipy:  RHS range        [3e+03, 2e+06]
Presolve removed 56926 rows and 4362 columns
INFO:gurobipy:Presolve removed 56926 rows and 4362 columns
Presolve time: 0.08s
INFO:gurobipy:Presolve time: 0.08s
Presolved: 65719 rows, 48202 columns, 179634 nonzeros
INFO:gurobipy:Presolved: 65719 rows, 48202 columns, 179634 nonzeros

INFO:gurobipy:
Concurrent LP optimizer: primal simplex, dual simplex, and barrier
INFO:gurobipy:Concurrent LP optimizer: primal simplex, dual simplex, and barrier
Showing barrier log only...
INFO:gurobipy:Showing barrier log only...

INFO:gurobipy:
Ordering time: 0.01s
INFO:gurobipy:Ordering time: 0.01s

INFO:gurobipy:
Barrier statistics:
INFO:gurobipy:Barrier statistics:
 Dense cols : 4
INFO:gurobipy: Dense cols : 4
 AA' NZ     : 1.577e+05
INFO:gurobipy: AA' NZ     : 1.577e+05
 Factor NZ  : 7.408e+05 (roughly 50 MB of memory)
INFO:gurobipy: Factor NZ  : 7.408e+05 (roughly 50 MB of memory)
 Factor Ops : 8.664e+06 (less than 1 second per iteration)
INFO:gurobipy: Factor Ops : 8.664e+06 (less than 1 second per iteration)
 Threads    : 1
INFO:gurobipy: Threads    : 1

INFO:gurobipy:
                  Objective                Residual
INFO:gurobipy:                  Objective                Residual
Iter       Primal          Dual         Primal    Dual     Compl     Time
INFO:gurobipy:Iter       Primal          Dual         Primal    Dual     Compl     Time
   0   2.61757993e+11  0.00000000e+00  1.45e+09 0.00e+00  2.80e+08     0s
INFO:gurobipy:   0   2.61757993e+11  0.00000000e+00  1.45e+09 0.00e+00  2.80e+08     0s
   1   3.19381524e+11 -4.33338009e+10  2.52e+08 1.93e+02  6.32e+07     0s
INFO:gurobipy:   1   3.19381524e+11 -4.33338009e+10  2.52e+08 1.93e+02  6.32e+07     0s
   2   2.11023798e+11 -3.22734815e+10  1.58e+07 2.17e+01  8.25e+06     0s
INFO:gurobipy:   2   2.11023798e+11 -3.22734815e+10  1.58e+07 2.17e+01  8.25e+06     0s
   3   7.25897480e+10 -5.30357857e+09  7.78e+05 1.38e+00  1.06e+06     0s
INFO:gurobipy:   3   7.25897480e+10 -5.30357857e+09  7.78e+05 1.38e+00  1.06e+06     0s
   4   3.70860696e+10 -1.55849161e+09  2.80e+05 4.46e-01  4.39e+05     0s
INFO:gurobipy:   4   3.70860696e+10 -1.55849161e+09  2.80e+05 4.46e-01  4.39e+05     0s
   5   1.83162922e+10  2.01591248e+08  1.14e+05 8.65e-02  1.84e+05     0s
INFO:gurobipy:   5   1.83162922e+10  2.01591248e+08  1.14e+05 8.65e-02  1.84e+05     0s
   6   8.53494976e+09  1.13358921e+09  4.20e+04 2.67e-04  7.24e+04     0s
INFO:gurobipy:   6   8.53494976e+09  1.13358921e+09  4.20e+04 2.67e-04  7.24e+04     0s
   7   7.19834727e+09  1.50214009e+09  3.23e+04 2.99e-02  5.53e+04     0s
INFO:gurobipy:   7   7.19834727e+09  1.50214009e+09  3.23e+04 2.99e-02  5.53e+04     0s
   8   5.66508940e+09  1.90454630e+09  2.02e+04 2.18e-11  3.63e+04     0s
INFO:gurobipy:   8   5.66508940e+09  1.90454630e+09  2.02e+04 2.18e-11  3.63e+04     0s
   9   4.83750516e+09  2.45797472e+09  1.25e+04 0.00e+00  2.28e+04     0s
INFO:gurobipy:   9   4.83750516e+09  2.45797472e+09  1.25e+04 0.00e+00  2.28e+04     0s
  10   4.36999329e+09  2.90429320e+09  6.35e+03 7.28e-11  1.40e+04     1s
INFO:gurobipy:  10   4.36999329e+09  2.90429320e+09  6.35e+03 7.28e-11  1.40e+04     1s
  11   4.19002426e+09  3.30671697e+09  4.19e+03 2.18e-11  8.45e+03     1s
INFO:gurobipy:  11   4.19002426e+09  3.30671697e+09  4.19e+03 2.18e-11  8.45e+03     1s
  12   4.11215571e+09  3.54708529e+09  3.03e+03 6.98e-10  5.40e+03     1s
INFO:gurobipy:  12   4.11215571e+09  3.54708529e+09  3.03e+03 6.98e-10  5.40e+03     1s
  13   4.06432365e+09  3.71170958e+09  2.04e+03 7.28e-10  3.37e+03     1s
INFO:gurobipy:  13   4.06432365e+09  3.71170958e+09  2.04e+03 7.28e-10  3.37e+03     1s
  14   4.02118032e+09  3.81713952e+09  1.28e+03 4.66e-10  1.95e+03     1s
INFO:gurobipy:  14   4.02118032e+09  3.81713952e+09  1.28e+03 4.66e-10  1.95e+03     1s
  15   3.99203239e+09  3.89236220e+09  6.59e+02 1.46e-11  9.53e+02     1s
INFO:gurobipy:  15   3.99203239e+09  3.89236220e+09  6.59e+02 1.46e-11  9.53e+02     1s
  16   3.98387560e+09  3.93603591e+09  4.83e+02 1.75e-10  4.57e+02     1s
INFO:gurobipy:  16   3.98387560e+09  3.93603591e+09  4.83e+02 1.75e-10  4.57e+02     1s
  17   3.97029208e+09  3.94691516e+09  1.99e+02 1.16e-10  2.23e+02     1s
INFO:gurobipy:  17   3.97029208e+09  3.94691516e+09  1.99e+02 1.16e-10  2.23e+02     1s
  18   3.96254259e+09  3.95624476e+09  3.75e+01 9.31e-10  6.01e+01     1s
INFO:gurobipy:  18   3.96254259e+09  3.95624476e+09  3.75e+01 9.31e-10  6.01e+01     1s
  19   3.96082802e+09  3.95950248e+09  4.36e+00 9.31e-10  1.26e+01     1s
INFO:gurobipy:  19   3.96082802e+09  3.95950248e+09  4.36e+00 9.31e-10  1.26e+01     1s
  20   3.96067454e+09  3.96012457e+09  2.03e+00 2.00e-10  5.25e+00     1s
INFO:gurobipy:  20   3.96067454e+09  3.96012457e+09  2.03e+00 2.00e-10  5.25e+00     1s
  21   3.96059198e+09  3.96035461e+09  8.59e-01 6.98e-10  2.26e+00     1s
INFO:gurobipy:  21   3.96059198e+09  3.96035461e+09  8.59e-01 6.98e-10  2.26e+00     1s
  22   3.96055144e+09  3.96044644e+09  2.98e-01 3.38e-10  1.00e+00     1s
INFO:gurobipy:  22   3.96055144e+09  3.96044644e+09  2.98e-01 3.38e-10  1.00e+00     1s
  23   3.96053227e+09  3.96050959e+09  4.04e-02 4.66e-10  2.16e-01     1s
INFO:gurobipy:  23   3.96053227e+09  3.96050959e+09  4.04e-02 4.66e-10  2.16e-01     1s
  24   3.96052862e+09  3.96052693e+09  2.84e-04 2.10e-09  1.61e-02     1s
INFO:gurobipy:  24   3.96052862e+09  3.96052693e+09  2.84e-04 2.10e-09  1.61e-02     1s
  25   3.96052836e+09  3.96052833e+09  1.16e-05 7.88e-08  2.90e-04     1s
INFO:gurobipy:  25   3.96052836e+09  3.96052833e+09  1.16e-05 7.88e-08  2.90e-04     1s
  26   3.96052835e+09  3.96052834e+09  9.16e-07 4.16e-09  1.19e-05     1s
INFO:gurobipy:  26   3.96052835e+09  3.96052834e+09  9.16e-07 4.16e-09  1.19e-05     1s
  27   3.96052834e+09  3.96052834e+09  1.04e-07 7.05e-09  3.18e-08     1s
INFO:gurobipy:  27   3.96052834e+09  3.96052834e+09  1.04e-07 7.05e-09  3.18e-08     1s
  28   3.96052834e+09  3.96052834e+09  9.03e-08 7.19e-09  4.13e-11     1s
INFO:gurobipy:  28   3.96052834e+09  3.96052834e+09  9.03e-08 7.19e-09  4.13e-11     1s

INFO:gurobipy:
Barrier solved model in 28 iterations and 1.13 seconds (0.92 work units)
INFO:gurobipy:Barrier solved model in 28 iterations and 1.13 seconds (0.92 work units)
Optimal objective 3.96052834e+09
INFO:gurobipy:Optimal objective 3.96052834e+09

INFO:gurobipy:
Crossover log...
INFO:gurobipy:Crossover log...

INFO:gurobipy:
     108 DPushes remaining with DInf 0.0000000e+00                 1s
INFO:gurobipy:     108 DPushes remaining with DInf 0.0000000e+00                 1s
       0 DPushes remaining with DInf 0.0000000e+00                 1s
INFO:gurobipy:       0 DPushes remaining with DInf 0.0000000e+00                 1s
Warning: Markowitz tolerance tightened to 0.5
INFO:gurobipy:Warning: Markowitz tolerance tightened to 0.5

INFO:gurobipy:
    6353 PPushes remaining with PInf 0.0000000e+00                 1s
INFO:gurobipy:    6353 PPushes remaining with PInf 0.0000000e+00                 1s
       0 PPushes remaining with PInf 0.0000000e+00                 2s
INFO:gurobipy:       0 PPushes remaining with PInf 0.0000000e+00                 2s

INFO:gurobipy:
  Push phase complete: Pinf 0.0000000e+00, Dinf 2.3367310e-09      2s
INFO:gurobipy:  Push phase complete: Pinf 0.0000000e+00, Dinf 2.3367310e-09      2s

INFO:gurobipy:
Crossover time: 0.59 seconds (1.79 work units)
INFO:gurobipy:Crossover time: 0.59 seconds (1.79 work units)

INFO:gurobipy:
Solved with barrier
INFO:gurobipy:Solved with barrier
Iteration    Objective       Primal Inf.    Dual Inf.      Time
INFO:gurobipy:Iteration    Objective       Primal Inf.    Dual Inf.      Time
    6464    3.9605283e+09   0.000000e+00   0.000000e+00      2s
INFO:gurobipy:    6464    3.9605283e+09   0.000000e+00   0.000000e+00      2s

INFO:gurobipy:
Solved in 6464 iterations and 1.75 seconds (2.76 work units)
INFO:gurobipy:Solved in 6464 iterations and 1.75 seconds (2.76 work units)
Optimal objective  3.960528345e+09
INFO:gurobipy:Optimal objective  3.960528345e+09
INFO:linopy.constants: Optimization successful: 
Status: ok
Termination condition: optimal
Solution: 52564 primals, 122645 duals
Objective: 3.96e+09
Solver model: available
Solver message: 2

INFO:pypsa.optimization.optimize:The shadow-prices of the constraints Generator-ext-p-lower, Generator-ext-p-upper, StorageUnit-ext-p_dispatch-lower, StorageUnit-ext-p_dispatch-upper, StorageUnit-ext-p_store-lower, StorageUnit-ext-p_store-upper, StorageUnit-ext-state_of_charge-lower, StorageUnit-ext-state_of_charge-upper, StorageUnit-energy_balance were not assigned to the network.
WARNING:pypsa.consistency:The following buses have carriers which are not defined:
Index(['electricity'], dtype='object', name='name')
WARNING:pypsa.consistency:The following sub_networks have carriers which are not defined:
Index(['0'], dtype='object', name='name')
INFO:linopy.model: Solve problem using Gurobi solver
INFO:linopy.io:Writing objective.
Writing constraints.: 100%|██████████| 13/13 [00:00<00:00, 47.28it/s]
Writing continuous variables.: 100%|██████████| 6/6 [00:00<00:00, 406.23it/s]
INFO:linopy.io: Writing time: 0.3s
Set parameter Username
INFO:gurobipy:Set parameter Username
Set parameter LicenseID to value 2767832
INFO:gurobipy:Set parameter LicenseID to value 2767832
Academic license - for non-commercial use only - expires 2027-01-20
INFO:gurobipy:Academic license - for non-commercial use only - expires 2027-01-20
Read LP format model from file /private/var/folders/zg/by4_k0616s98pw41wld9475c0000gp/T/linopy-problem-3pqm10s2.lp
INFO:gurobipy:Read LP format model from file /private/var/folders/zg/by4_k0616s98pw41wld9475c0000gp/T/linopy-problem-3pqm10s2.lp
Reading time = 0.16 seconds
INFO:gurobipy:Reading time = 0.16 seconds
obj: 122645 rows, 52564 columns, 240922 nonzeros
INFO:gurobipy:obj: 122645 rows, 52564 columns, 240922 nonzeros
Gurobi Optimizer version 13.0.0 build v13.0.0rc1 (mac64[arm] - Darwin 25.3.0 25D2128)
INFO:gurobipy:Gurobi Optimizer version 13.0.0 build v13.0.0rc1 (mac64[arm] - Darwin 25.3.0 25D2128)

INFO:gurobipy:
CPU model: Apple M3
INFO:gurobipy:CPU model: Apple M3
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads
INFO:gurobipy:Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

INFO:gurobipy:
Optimize a model with 122645 rows, 52564 columns and 240922 nonzeros (Min)
INFO:gurobipy:Optimize a model with 122645 rows, 52564 columns and 240922 nonzeros (Min)
Model fingerprint: 0x0c7af7d1
INFO:gurobipy:Model fingerprint: 0x0c7af7d1
Model has 26284 linear objective coefficients
INFO:gurobipy:Model has 26284 linear objective coefficients
Coefficient statistics:
INFO:gurobipy:Coefficient statistics:
  Matrix range     [1e-03, 2e+00]
INFO:gurobipy:  Matrix range     [1e-03, 2e+00]
  Objective range  [1e-02, 1e+05]
INFO:gurobipy:  Objective range  [1e-02, 1e+05]
  Bounds range     [0e+00, 0e+00]
INFO:gurobipy:  Bounds range     [0e+00, 0e+00]
  RHS range        [3e+03, 1e+06]
INFO:gurobipy:  RHS range        [3e+03, 1e+06]
Presolve removed 56926 rows and 4362 columns
INFO:gurobipy:Presolve removed 56926 rows and 4362 columns
Presolve time: 0.22s
INFO:gurobipy:Presolve time: 0.22s
Presolved: 65719 rows, 48202 columns, 179634 nonzeros
INFO:gurobipy:Presolved: 65719 rows, 48202 columns, 179634 nonzeros

INFO:gurobipy:
Concurrent LP optimizer: primal simplex, dual simplex, and barrier
INFO:gurobipy:Concurrent LP optimizer: primal simplex, dual simplex, and barrier
Showing barrier log only...
INFO:gurobipy:Showing barrier log only...

INFO:gurobipy:
Ordering time: 0.02s
INFO:gurobipy:Ordering time: 0.02s

INFO:gurobipy:
Barrier statistics:
INFO:gurobipy:Barrier statistics:
 Dense cols : 4
INFO:gurobipy: Dense cols : 4
 AA' NZ     : 1.577e+05
INFO:gurobipy: AA' NZ     : 1.577e+05
 Factor NZ  : 7.408e+05 (roughly 50 MB of memory)
INFO:gurobipy: Factor NZ  : 7.408e+05 (roughly 50 MB of memory)
 Factor Ops : 8.664e+06 (less than 1 second per iteration)
INFO:gurobipy: Factor Ops : 8.664e+06 (less than 1 second per iteration)
 Threads    : 1
INFO:gurobipy: Threads    : 1

INFO:gurobipy:
                  Objective                Residual
INFO:gurobipy:                  Objective                Residual
Iter       Primal          Dual         Primal    Dual     Compl     Time
INFO:gurobipy:Iter       Primal          Dual         Primal    Dual     Compl     Time
   0   1.85730363e+11  0.00000000e+00  1.02e+09 0.00e+00  1.98e+08     0s
INFO:gurobipy:   0   1.85730363e+11  0.00000000e+00  1.02e+09 0.00e+00  1.98e+08     0s
   1   2.26880830e+11 -4.12701575e+10  1.73e+08 1.92e+02  4.44e+07     0s
INFO:gurobipy:   1   2.26880830e+11 -4.12701575e+10  1.73e+08 1.92e+02  4.44e+07     0s
   2   1.49807579e+11 -2.75706008e+10  1.13e+07 2.06e+01  5.69e+06     0s
INFO:gurobipy:   2   1.49807579e+11 -2.75706008e+10  1.13e+07 2.06e+01  5.69e+06     0s
   3   5.30399391e+10 -3.81060293e+09  6.81e+05 1.81e+00  8.33e+05     0s
INFO:gurobipy:   3   5.30399391e+10 -3.81060293e+09  6.81e+05 1.81e+00  8.33e+05     0s
   4   2.95413833e+10 -1.15841084e+09  2.79e+05 6.68e-01  3.69e+05     0s
INFO:gurobipy:   4   2.95413833e+10 -1.15841084e+09  2.79e+05 6.68e-01  3.69e+05     0s
   5   1.52664740e+10  4.69404083e+08  1.09e+05 1.46e-01  1.55e+05     0s
INFO:gurobipy:   5   1.52664740e+10  4.69404083e+08  1.09e+05 1.46e-01  1.55e+05     0s
   6   8.99039106e+09  1.30837158e+09  5.12e+04 4.12e-02  7.69e+04     1s
INFO:gurobipy:   6   8.99039106e+09  1.30837158e+09  5.12e+04 4.12e-02  7.69e+04     1s
   7   6.90664380e+09  1.71338762e+09  3.26e+04 1.43e-02  5.13e+04     1s
INFO:gurobipy:   7   6.90664380e+09  1.71338762e+09  3.26e+04 1.43e-02  5.13e+04     1s
   8   6.01337829e+09  2.00821766e+09  2.44e+04 4.98e-03  3.93e+04     1s
INFO:gurobipy:   8   6.01337829e+09  2.00821766e+09  2.44e+04 4.98e-03  3.93e+04     1s
   9   5.49463689e+09  2.31637444e+09  1.90e+04 9.28e-04  3.11e+04     1s
INFO:gurobipy:   9   5.49463689e+09  2.31637444e+09  1.90e+04 9.28e-04  3.11e+04     1s
  10   5.08953911e+09  2.83530840e+09  1.36e+04 9.02e-10  2.19e+04     1s
INFO:gurobipy:  10   5.08953911e+09  2.83530840e+09  1.36e+04 9.02e-10  2.19e+04     1s
  11   4.72816358e+09  3.31300313e+09  8.07e+03 3.78e-10  1.37e+04     1s
INFO:gurobipy:  11   4.72816358e+09  3.31300313e+09  8.07e+03 3.78e-10  1.37e+04     1s
  12   4.62184296e+09  3.52747587e+09  6.15e+03 8.73e-11  1.06e+04     1s
INFO:gurobipy:  12   4.62184296e+09  3.52747587e+09  6.15e+03 8.73e-11  1.06e+04     1s
  13   4.55549089e+09  3.66776046e+09  4.84e+03 5.24e-10  8.58e+03     1s
INFO:gurobipy:  13   4.55549089e+09  3.66776046e+09  4.84e+03 5.24e-10  8.58e+03     1s
  14   4.49260117e+09  3.80799207e+09  3.41e+03 1.46e-11  6.62e+03     1s
INFO:gurobipy:  14   4.49260117e+09  3.80799207e+09  3.41e+03 1.46e-11  6.62e+03     1s
  15   4.45157009e+09  4.07901110e+09  2.28e+03 2.33e-10  3.60e+03     1s
INFO:gurobipy:  15   4.45157009e+09  4.07901110e+09  2.28e+03 2.33e-10  3.60e+03     1s
  16   4.40980039e+09  4.32887771e+09  7.85e+02 2.04e-10  7.79e+02     1s
INFO:gurobipy:  16   4.40980039e+09  4.32887771e+09  7.85e+02 2.04e-10  7.79e+02     1s
  17   4.38625367e+09  4.36151304e+09  1.52e+02 3.49e-10  2.38e+02     1s
INFO:gurobipy:  17   4.38625367e+09  4.36151304e+09  1.52e+02 3.49e-10  2.38e+02     1s
  18   4.38189223e+09  4.37141441e+09  5.99e+01 8.44e-10  1.01e+02     1s
INFO:gurobipy:  18   4.38189223e+09  4.37141441e+09  5.99e+01 8.44e-10  1.01e+02     1s
  19   4.37974285e+09  4.37534230e+09  1.79e+01 2.62e-10  4.22e+01     1s
INFO:gurobipy:  19   4.37974285e+09  4.37534230e+09  1.79e+01 2.62e-10  4.22e+01     1s
  20   4.37916760e+09  4.37693972e+09  7.01e+00 2.91e-11  2.14e+01     1s
INFO:gurobipy:  20   4.37916760e+09  4.37693972e+09  7.01e+00 2.91e-11  2.14e+01     1s
  21   4.37895053e+09  4.37777355e+09  2.95e+00 4.07e-10  1.13e+01     1s
INFO:gurobipy:  21   4.37895053e+09  4.37777355e+09  2.95e+00 4.07e-10  1.13e+01     1s
  22   4.37883810e+09  4.37814213e+09  1.09e+00 1.82e-11  6.67e+00     1s
INFO:gurobipy:  22   4.37883810e+09  4.37814213e+09  1.09e+00 1.82e-11  6.67e+00     1s
  23   4.37881847e+09  4.37847337e+09  8.04e-01 4.85e-09  3.31e+00     1s
INFO:gurobipy:  23   4.37881847e+09  4.37847337e+09  8.04e-01 4.85e-09  3.31e+00     1s
  24   4.37877496e+09  4.37849594e+09  1.59e-01 3.05e-09  2.67e+00     1s
INFO:gurobipy:  24   4.37877496e+09  4.37849594e+09  1.59e-01 3.05e-09  2.67e+00     1s
  25   4.37876533e+09  4.37869440e+09  6.28e-02 8.70e-09  6.80e-01     1s
INFO:gurobipy:  25   4.37876533e+09  4.37869440e+09  6.28e-02 8.70e-09  6.80e-01     1s
  26   4.37876109e+09  4.37873173e+09  2.02e-02 2.09e-08  2.81e-01     1s
INFO:gurobipy:  26   4.37876109e+09  4.37873173e+09  2.02e-02 2.09e-08  2.81e-01     1s
  27   4.37875844e+09  4.37875197e+09  2.74e-03 2.90e-08  6.20e-02     1s
INFO:gurobipy:  27   4.37875844e+09  4.37875197e+09  2.74e-03 2.90e-08  6.20e-02     1s
  28   4.37875782e+09  4.37875578e+09  8.97e-05 8.18e-09  1.95e-02     1s
INFO:gurobipy:  28   4.37875782e+09  4.37875578e+09  8.97e-05 8.18e-09  1.95e-02     1s
  29   4.37875773e+09  4.37875766e+09  2.29e-06 3.78e-10  6.64e-04     1s
INFO:gurobipy:  29   4.37875773e+09  4.37875766e+09  2.29e-06 3.78e-10  6.64e-04     1s
  30   4.37875769e+09  4.37875769e+09  1.78e-06 3.06e-09  1.94e-06     1s
INFO:gurobipy:  30   4.37875769e+09  4.37875769e+09  1.78e-06 3.06e-09  1.94e-06     1s
  31   4.37875769e+09  4.37875769e+09  1.16e-07 2.36e-09  2.32e-11     1s
INFO:gurobipy:  31   4.37875769e+09  4.37875769e+09  1.16e-07 2.36e-09  2.32e-11     1s

INFO:gurobipy:
Barrier solved model in 31 iterations and 1.07 seconds (1.01 work units)
INFO:gurobipy:Barrier solved model in 31 iterations and 1.07 seconds (1.01 work units)
Optimal objective 4.37875769e+09
INFO:gurobipy:Optimal objective 4.37875769e+09

INFO:gurobipy:
Crossover log...
INFO:gurobipy:Crossover log...

INFO:gurobipy:
      91 DPushes remaining with DInf 0.0000000e+00                 1s
INFO:gurobipy:      91 DPushes remaining with DInf 0.0000000e+00                 1s
       0 DPushes remaining with DInf 0.0000000e+00                 1s
INFO:gurobipy:       0 DPushes remaining with DInf 0.0000000e+00                 1s
Warning: Markowitz tolerance tightened to 0.25
INFO:gurobipy:Warning: Markowitz tolerance tightened to 0.25

INFO:gurobipy:
    6418 PPushes remaining with PInf 0.0000000e+00                 1s
INFO:gurobipy:    6418 PPushes remaining with PInf 0.0000000e+00                 1s
       0 PPushes remaining with PInf 0.0000000e+00                 1s
INFO:gurobipy:       0 PPushes remaining with PInf 0.0000000e+00                 1s

INFO:gurobipy:
  Push phase complete: Pinf 0.0000000e+00, Dinf 3.0220989e-09      1s
INFO:gurobipy:  Push phase complete: Pinf 0.0000000e+00, Dinf 3.0220989e-09      1s

INFO:gurobipy:
Crossover time: 0.31 seconds (0.89 work units)
INFO:gurobipy:Crossover time: 0.31 seconds (0.89 work units)

INFO:gurobipy:
Solved with barrier
INFO:gurobipy:Solved with barrier
Iteration    Objective       Primal Inf.    Dual Inf.      Time
INFO:gurobipy:Iteration    Objective       Primal Inf.    Dual Inf.      Time
    6512    4.3787577e+09   0.000000e+00   0.000000e+00      1s
INFO:gurobipy:    6512    4.3787577e+09   0.000000e+00   0.000000e+00      1s

INFO:gurobipy:
Solved in 6512 iterations and 1.45 seconds (1.95 work units)
INFO:gurobipy:Solved in 6512 iterations and 1.45 seconds (1.95 work units)
Optimal objective  4.378757687e+09
INFO:gurobipy:Optimal objective  4.378757687e+09
INFO:linopy.constants: Optimization successful: 
Status: ok
Termination condition: optimal
Solution: 52564 primals, 122645 duals
Objective: 4.38e+09
Solver model: available
Solver message: 2

INFO:pypsa.optimization.optimize:The shadow-prices of the constraints Generator-ext-p-lower, Generator-ext-p-upper, StorageUnit-ext-p_dispatch-lower, StorageUnit-ext-p_dispatch-upper, StorageUnit-ext-p_store-lower, StorageUnit-ext-p_store-upper, StorageUnit-ext-state_of_charge-lower, StorageUnit-ext-state_of_charge-upper, StorageUnit-energy_balance were not assigned to the network.
WARNING:pypsa.consistency:The following buses have carriers which are not defined:
Index(['electricity'], dtype='object', name='name')
WARNING:pypsa.consistency:The following sub_networks have carriers which are not defined:
Index(['0'], dtype='object', name='name')
INFO:linopy.model: Solve problem using Gurobi solver
INFO:linopy.io:Writing objective.
Writing constraints.: 100%|██████████| 13/13 [00:00<00:00, 92.04it/s]
Writing continuous variables.: 100%|██████████| 6/6 [00:00<00:00, 550.81it/s]
INFO:linopy.io: Writing time: 0.16s
Set parameter Username
INFO:gurobipy:Set parameter Username
Set parameter LicenseID to value 2767832
INFO:gurobipy:Set parameter LicenseID to value 2767832
Academic license - for non-commercial use only - expires 2027-01-20
INFO:gurobipy:Academic license - for non-commercial use only - expires 2027-01-20
Read LP format model from file /private/var/folders/zg/by4_k0616s98pw41wld9475c0000gp/T/linopy-problem-u59lhrqu.lp
INFO:gurobipy:Read LP format model from file /private/var/folders/zg/by4_k0616s98pw41wld9475c0000gp/T/linopy-problem-u59lhrqu.lp
Reading time = 0.11 seconds
INFO:gurobipy:Reading time = 0.11 seconds
obj: 122645 rows, 52564 columns, 240922 nonzeros
INFO:gurobipy:obj: 122645 rows, 52564 columns, 240922 nonzeros
Gurobi Optimizer version 13.0.0 build v13.0.0rc1 (mac64[arm] - Darwin 25.3.0 25D2128)
INFO:gurobipy:Gurobi Optimizer version 13.0.0 build v13.0.0rc1 (mac64[arm] - Darwin 25.3.0 25D2128)

INFO:gurobipy:
CPU model: Apple M3
INFO:gurobipy:CPU model: Apple M3
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads
INFO:gurobipy:Thread count: 8 physical cores, 8 logical processors, using up to 8 threads

INFO:gurobipy:
Optimize a model with 122645 rows, 52564 columns and 240922 nonzeros (Min)
INFO:gurobipy:Optimize a model with 122645 rows, 52564 columns and 240922 nonzeros (Min)
Model fingerprint: 0xade94a09
INFO:gurobipy:Model fingerprint: 0xade94a09
Model has 26284 linear objective coefficients
INFO:gurobipy:Model has 26284 linear objective coefficients
Coefficient statistics:
INFO:gurobipy:Coefficient statistics:
  Matrix range     [1e-03, 2e+00]
INFO:gurobipy:  Matrix range     [1e-03, 2e+00]
  Objective range  [1e-02, 1e+05]
INFO:gurobipy:  Objective range  [1e-02, 1e+05]
  Bounds range     [0e+00, 0e+00]
INFO:gurobipy:  Bounds range     [0e+00, 0e+00]
  RHS range        [3e+03, 9e+03]
INFO:gurobipy:  RHS range        [3e+03, 9e+03]
Presolve removed 65687 rows and 13123 columns
INFO:gurobipy:Presolve removed 65687 rows and 13123 columns
Presolve time: 0.05s
INFO:gurobipy:Presolve time: 0.05s
Presolved: 56958 rows, 39441 columns, 144594 nonzeros
INFO:gurobipy:Presolved: 56958 rows, 39441 columns, 144594 nonzeros

INFO:gurobipy:
Concurrent LP optimizer: primal simplex, dual simplex, and barrier
INFO:gurobipy:Concurrent LP optimizer: primal simplex, dual simplex, and barrier
Showing barrier log only...
INFO:gurobipy:Showing barrier log only...

INFO:gurobipy:
Ordering time: 0.02s
INFO:gurobipy:Ordering time: 0.02s

INFO:gurobipy:
Barrier statistics:
INFO:gurobipy:Barrier statistics:
 Dense cols : 3
INFO:gurobipy: Dense cols : 3
 AA' NZ     : 1.227e+05
INFO:gurobipy: AA' NZ     : 1.227e+05
 Factor NZ  : 6.854e+05 (roughly 40 MB of memory)
INFO:gurobipy: Factor NZ  : 6.854e+05 (roughly 40 MB of memory)
 Factor Ops : 9.072e+06 (less than 1 second per iteration)
INFO:gurobipy: Factor Ops : 9.072e+06 (less than 1 second per iteration)
 Threads    : 1
INFO:gurobipy: Threads    : 1

INFO:gurobipy:
                  Objective                Residual
INFO:gurobipy:                  Objective                Residual
Iter       Primal          Dual         Primal    Dual     Compl     Time
INFO:gurobipy:Iter       Primal          Dual         Primal    Dual     Compl     Time
   0   2.15403751e+10  0.00000000e+00  6.26e+04 0.00e+00  3.57e+07     0s
INFO:gurobipy:   0   2.15403751e+10  0.00000000e+00  6.26e+04 0.00e+00  3.57e+07     0s
   1   4.10982043e+10 -2.49321666e+10  5.96e+03 1.82e+02  8.12e+06     0s
INFO:gurobipy:   1   4.10982043e+10 -2.49321666e+10  5.96e+03 1.82e+02  8.12e+06     0s
   2   2.42798812e+10 -3.67728043e+09  1.04e-09 1.72e+01  9.48e+05     0s
INFO:gurobipy:   2   2.42798812e+10 -3.67728043e+09  1.04e-09 1.72e+01  9.48e+05     0s
   3   1.32608347e+10 -6.14864518e+08  5.60e-10 7.78e+00  4.29e+05     0s
INFO:gurobipy:   3   1.32608347e+10 -6.14864518e+08  5.60e-10 7.78e+00  4.29e+05     0s
   4   1.08385702e+10  5.50839376e+08  1.10e-09 5.21e+00  2.82e+05     0s
INFO:gurobipy:   4   1.08385702e+10  5.50839376e+08  1.10e-09 5.21e+00  2.82e+05     0s
   5   8.55884116e+09  1.54478931e+09  2.95e-09 2.68e+00  1.64e+05     0s
INFO:gurobipy:   5   8.55884116e+09  1.54478931e+09  2.95e-09 2.68e+00  1.64e+05     0s
   6   7.71895394e+09  3.09856606e+09  4.01e-08 1.12e+00  8.66e+04     0s
INFO:gurobipy:   6   7.71895394e+09  3.09856606e+09  4.01e-08 1.12e+00  8.66e+04     0s
   7   7.42609295e+09  4.55348967e+09  1.89e-07 6.33e-01  5.32e+04     0s
INFO:gurobipy:   7   7.42609295e+09  4.55348967e+09  1.89e-07 6.33e-01  5.32e+04     0s
   8   6.91550218e+09  5.24741275e+09  2.37e-07 3.09e-01  2.89e+04     0s
INFO:gurobipy:   8   6.91550218e+09  5.24741275e+09  2.37e-07 3.09e-01  2.89e+04     0s
   9   6.77044739e+09  5.63010803e+09  7.93e-07 1.83e-01  1.91e+04     0s
INFO:gurobipy:   9   6.77044739e+09  5.63010803e+09  7.93e-07 1.83e-01  1.91e+04     0s
  10   6.86316839e+09  6.31242229e+09  2.01e-06 3.41e-02  7.87e+03     0s
INFO:gurobipy:  10   6.86316839e+09  6.31242229e+09  2.01e-06 3.41e-02  7.87e+03     0s
  11   6.65558504e+09  6.54238068e+09  2.51e-06 3.62e-03  1.55e+03     0s
INFO:gurobipy:  11   6.65558504e+09  6.54238068e+09  2.51e-06 3.62e-03  1.55e+03     0s
  12   6.62093553e+09  6.58900571e+09  3.90e-06 7.09e-04  4.34e+02     0s
INFO:gurobipy:  12   6.62093553e+09  6.58900571e+09  3.90e-06 7.09e-04  4.34e+02     0s
  13   6.61289699e+09  6.60040038e+09  7.74e-06 1.90e-04  1.68e+02     0s
INFO:gurobipy:  13   6.61289699e+09  6.60040038e+09  7.74e-06 1.90e-04  1.68e+02     0s
  14   6.60998053e+09  6.60431305e+09  2.92e-06 6.98e-05  7.62e+01     0s
INFO:gurobipy:  14   6.60998053e+09  6.60431305e+09  2.92e-06 6.98e-05  7.62e+01     0s
  15   6.60875473e+09  6.60686284e+09  5.52e-06 3.81e-09  2.48e+01     0s
INFO:gurobipy:  15   6.60875473e+09  6.60686284e+09  5.52e-06 3.81e-09  2.48e+01     0s
  16   6.60793692e+09  6.60748760e+09  5.24e-06 9.90e-09  5.87e+00     0s
INFO:gurobipy:  16   6.60793692e+09  6.60748760e+09  5.24e-06 9.90e-09  5.87e+00     0s
  17   6.60780395e+09  6.60762717e+09  4.35e-06 2.97e-09  2.30e+00     0s
INFO:gurobipy:  17   6.60780395e+09  6.60762717e+09  4.35e-06 2.97e-09  2.30e+00     0s
  18   6.60775547e+09  6.60769085e+09  2.23e-06 2.76e-08  8.30e-01     0s
INFO:gurobipy:  18   6.60775547e+09  6.60769085e+09  2.23e-06 2.76e-08  8.30e-01     0s
  19   6.60771618e+09  6.60770879e+09  1.20e-06 6.32e-09  9.43e-02     0s
INFO:gurobipy:  19   6.60771618e+09  6.60770879e+09  1.20e-06 6.32e-09  9.43e-02     0s
  20   6.60771208e+09  6.60771182e+09  2.25e-08 2.91e-10  3.33e-03     1s
INFO:gurobipy:  20   6.60771208e+09  6.60771182e+09  2.25e-08 2.91e-10  3.33e-03     1s
  21   6.60771198e+09  6.60771198e+09  1.46e-09 1.12e-08  4.36e-05     1s
INFO:gurobipy:  21   6.60771198e+09  6.60771198e+09  1.46e-09 1.12e-08  4.36e-05     1s
  22   6.60771198e+09  6.60771198e+09  8.51e-10 3.89e-08  5.10e-08     1s
INFO:gurobipy:  22   6.60771198e+09  6.60771198e+09  8.51e-10 3.89e-08  5.10e-08     1s
  23   6.60771198e+09  6.60771198e+09  1.46e-11 1.18e-08  5.10e-11     1s
INFO:gurobipy:  23   6.60771198e+09  6.60771198e+09  1.46e-11 1.18e-08  5.10e-11     1s

INFO:gurobipy:
Barrier solved model in 23 iterations and 0.55 seconds (0.67 work units)
INFO:gurobipy:Barrier solved model in 23 iterations and 0.55 seconds (0.67 work units)
Optimal objective 6.60771198e+09
INFO:gurobipy:Optimal objective 6.60771198e+09

INFO:gurobipy:
Crossover log...
INFO:gurobipy:Crossover log...

INFO:gurobipy:
      21 DPushes remaining with DInf 0.0000000e+00                 1s
INFO:gurobipy:      21 DPushes remaining with DInf 0.0000000e+00                 1s
       0 DPushes remaining with DInf 0.0000000e+00                 1s
INFO:gurobipy:       0 DPushes remaining with DInf 0.0000000e+00                 1s

INFO:gurobipy:
    4497 PPushes remaining with PInf 0.0000000e+00                 1s
INFO:gurobipy:    4497 PPushes remaining with PInf 0.0000000e+00                 1s
       0 PPushes remaining with PInf 0.0000000e+00                 1s
INFO:gurobipy:       0 PPushes remaining with PInf 0.0000000e+00                 1s

INFO:gurobipy:
  Push phase complete: Pinf 0.0000000e+00, Dinf 1.9500402e-10      1s
INFO:gurobipy:  Push phase complete: Pinf 0.0000000e+00, Dinf 1.9500402e-10      1s

INFO:gurobipy:
Crossover time: 0.07 seconds (0.09 work units)
INFO:gurobipy:Crossover time: 0.07 seconds (0.09 work units)

INFO:gurobipy:
Solved with barrier
INFO:gurobipy:Solved with barrier
Iteration    Objective       Primal Inf.    Dual Inf.      Time
INFO:gurobipy:Iteration    Objective       Primal Inf.    Dual Inf.      Time
    4521    6.6077120e+09   0.000000e+00   0.000000e+00      1s
INFO:gurobipy:    4521    6.6077120e+09   0.000000e+00   0.000000e+00      1s

INFO:gurobipy:
Solved in 4521 iterations and 0.64 seconds (0.80 work units)
INFO:gurobipy:Solved in 4521 iterations and 0.64 seconds (0.80 work units)
Optimal objective  6.607711978e+09
INFO:gurobipy:Optimal objective  6.607711978e+09
INFO:linopy.constants: Optimization successful: 
Status: ok
Termination condition: optimal
Solution: 52564 primals, 122645 duals
Objective: 6.61e+09
Solver model: available
Solver message: 2

INFO:pypsa.optimization.optimize:The shadow-prices of the constraints Generator-ext-p-lower, Generator-ext-p-upper, StorageUnit-ext-p_dispatch-lower, StorageUnit-ext-p_dispatch-upper, StorageUnit-ext-p_store-lower, StorageUnit-ext-p_store-upper, StorageUnit-ext-state_of_charge-lower, StorageUnit-ext-state_of_charge-upper, StorageUnit-energy_balance were not assigned to the network.
df = pd.DataFrame(sensitivity).T.div(1e3)  # billion Euro/a
df.plot.area(
    stacked=True,
    linewidth=0,
    color=df.columns.map(n.carriers.color),
    figsize=(4, 4),
    xlim=(0, 5),
    xlabel=r"CO$_2$ emissions [Mt/a]",
    ylabel="System cost [bn€/a]",
    ylim=(0, 4),
)
plt.legend(frameon=False, loc=(1.05, 0))
plt.gca().invert_xaxis()
../_images/16f99ae33851f649f4db4f80eee4747c11023f69291f4b9f615aef927f49259b.png
co2_price
5      106.265723
4      132.095850
3      179.068159
2      270.257945
1      691.503196
0    29705.768984
dtype: float64
co2_price.plot(figsize=(6, 2), ylabel="CO2 price [EUR/tCO2]")
plt.gca().invert_xaxis()
plt.ylim([0,1000])
(0.0, 1000.0)
../_images/df529eccca28bf52dae0ec8a043f1f6ec68e8dda47071a5906c9b0699ba00c25.png

b) Show what would happen if a CO\(_2\) tax was used instead of a CO\(_2\) limit. You can do this by adding a carbon tax to the relevant generators, and then comparing your results (total system costs, emissions, and generation mix) with the previous section. Make sure to use your results from part (a) for the appropriate carbon taxes.

n = pypsa.Network()

hours_in_2015 = pd.date_range("2015-01-01 00:00Z", "2015-12-31 23:00Z", freq="h")
n.set_snapshots(hours_in_2015.values)

n.add("Bus", "electricity")

carriers = ["onwind", "solar", "OCGT", "battery storage"]
n.add(
    "Carrier",
    carriers,
    color=["dodgerblue", "gold", "indianred", "brown"],
    co2_emissions=[costs.at[c, "CO2 intensity"] for c in carriers],
)

n.add("Load", "demand", bus="electricity", p_set=data_el[country].values)

snapshot_cols = [hour.strftime("%Y-%m-%dT%H:%M:%SZ") for hour in n.snapshots]
for carrier, cf_data in [("onwind", data_wind), ("solar", data_solar)]:
    n.add(
        "Generator",
        carrier,
        bus="electricity",
        carrier=carrier,
        p_max_pu=cf_data[country][snapshot_cols].values,
        capital_cost=costs.at[carrier, "capital_cost"],
        marginal_cost=costs.at[carrier, "marginal_cost"],
        efficiency=costs.at[carrier, "efficiency"],
        p_nom_extendable=True,
    )

n.add(
    "StorageUnit",
    "battery storage",
    bus="electricity",
    carrier="battery storage",
    max_hours=2,
    capital_cost=(
        costs.at["battery inverter", "capital_cost"]
        + 2 * costs.at["battery storage", "capital_cost"]
    ),
    efficiency_store=costs.at["battery inverter", "efficiency"],
    efficiency_dispatch=costs.at["battery inverter", "efficiency"],
    p_nom_extendable=True,
    cyclic_state_of_charge=True,
)
# Compute marginal emissions of OCGT.

ocgt_emissions = costs.at["OCGT", "CO2 intensity"] / costs.at["OCGT", "efficiency"]  # tCO2/MWh_el
total_emissions = {}
tsc = {}
co2_cost = {}

for limit, price in co2_price.items():
    network = n.copy()
    network.add(
        "Generator",
        "OCGT",
        bus="electricity",
        carrier="OCGT",
        capital_cost=costs.at["OCGT", "capital_cost"],
        marginal_cost=costs.at["OCGT", "marginal_cost"] + price * ocgt_emissions,
        efficiency=costs.at["OCGT", "efficiency"],
        p_nom_extendable=True,
    )
    network.optimize(solver_name="gurobi", solver_options={"OutputFlag": 0})
    tsc[limit] = system_cost(network)

    supply_by_carrier = network.statistics.supply().groupby("carrier").sum()
    total_emissions[limit] = (
        supply_by_carrier.at["OCGT"] * ocgt_emissions
        if "OCGT" in supply_by_carrier.index
        else 0
    )
    co2_cost[limit] = price * total_emissions[limit]
WARNING:pypsa.consistency:The following buses have carriers which are not defined:
Index(['electricity'], dtype='object', name='name')
INFO:linopy.model: Solve problem using Gurobi solver
INFO:linopy.model:Solver options:
 - OutputFlag: 0
INFO:linopy.io:Writing objective.
Writing constraints.: 100%|██████████| 12/12 [00:00<00:00, 72.24it/s]
Writing continuous variables.: 100%|██████████| 6/6 [00:00<00:00, 455.75it/s]
INFO:linopy.io: Writing time: 0.19s
Set parameter Username
INFO:gurobipy:Set parameter Username
Set parameter LicenseID to value 2767832
INFO:gurobipy:Set parameter LicenseID to value 2767832
Academic license - for non-commercial use only - expires 2027-01-20
INFO:gurobipy:Academic license - for non-commercial use only - expires 2027-01-20
Read LP format model from file /private/var/folders/zg/by4_k0616s98pw41wld9475c0000gp/T/linopy-problem-qh1ltf6u.lp
INFO:gurobipy:Read LP format model from file /private/var/folders/zg/by4_k0616s98pw41wld9475c0000gp/T/linopy-problem-qh1ltf6u.lp
Reading time = 0.14 seconds
INFO:gurobipy:Reading time = 0.14 seconds
obj: 122644 rows, 52564 columns, 232162 nonzeros
INFO:gurobipy:obj: 122644 rows, 52564 columns, 232162 nonzeros
INFO:linopy.constants: Optimization successful: 
Status: ok
Termination condition: optimal
Solution: 52564 primals, 122644 duals
Objective: 4.00e+09
Solver model: available
Solver message: 2

INFO:pypsa.optimization.optimize:The shadow-prices of the constraints Generator-ext-p-lower, Generator-ext-p-upper, StorageUnit-ext-p_dispatch-lower, StorageUnit-ext-p_dispatch-upper, StorageUnit-ext-p_store-lower, StorageUnit-ext-p_store-upper, StorageUnit-ext-state_of_charge-lower, StorageUnit-ext-state_of_charge-upper, StorageUnit-energy_balance were not assigned to the network.
WARNING:pypsa.consistency:The following buses have carriers which are not defined:
Index(['electricity'], dtype='object', name='name')
INFO:linopy.model: Solve problem using Gurobi solver
INFO:linopy.model:Solver options:
 - OutputFlag: 0
INFO:linopy.io:Writing objective.
Writing constraints.: 100%|██████████| 12/12 [00:00<00:00, 27.11it/s]
Writing continuous variables.: 100%|██████████| 6/6 [00:00<00:00, 311.43it/s]
INFO:linopy.io: Writing time: 0.48s
Set parameter Username
INFO:gurobipy:Set parameter Username
Set parameter LicenseID to value 2767832
INFO:gurobipy:Set parameter LicenseID to value 2767832
Academic license - for non-commercial use only - expires 2027-01-20
INFO:gurobipy:Academic license - for non-commercial use only - expires 2027-01-20
Read LP format model from file /private/var/folders/zg/by4_k0616s98pw41wld9475c0000gp/T/linopy-problem-u8vm3gfx.lp
INFO:gurobipy:Read LP format model from file /private/var/folders/zg/by4_k0616s98pw41wld9475c0000gp/T/linopy-problem-u8vm3gfx.lp
Reading time = 0.46 seconds
INFO:gurobipy:Reading time = 0.46 seconds
obj: 122644 rows, 52564 columns, 232162 nonzeros
INFO:gurobipy:obj: 122644 rows, 52564 columns, 232162 nonzeros
INFO:linopy.constants: Optimization successful: 
Status: ok
Termination condition: optimal
Solution: 52564 primals, 122644 duals
Objective: 4.12e+09
Solver model: available
Solver message: 2

INFO:pypsa.optimization.optimize:The shadow-prices of the constraints Generator-ext-p-lower, Generator-ext-p-upper, StorageUnit-ext-p_dispatch-lower, StorageUnit-ext-p_dispatch-upper, StorageUnit-ext-p_store-lower, StorageUnit-ext-p_store-upper, StorageUnit-ext-state_of_charge-lower, StorageUnit-ext-state_of_charge-upper, StorageUnit-energy_balance were not assigned to the network.
WARNING:pypsa.consistency:The following buses have carriers which are not defined:
Index(['electricity'], dtype='object', name='name')
INFO:linopy.model: Solve problem using Gurobi solver
INFO:linopy.model:Solver options:
 - OutputFlag: 0
INFO:linopy.io:Writing objective.
Writing constraints.: 100%|██████████| 12/12 [00:00<00:00, 96.76it/s] 
Writing continuous variables.: 100%|██████████| 6/6 [00:00<00:00, 509.24it/s]
INFO:linopy.io: Writing time: 0.15s
Set parameter Username
INFO:gurobipy:Set parameter Username
Set parameter LicenseID to value 2767832
INFO:gurobipy:Set parameter LicenseID to value 2767832
Academic license - for non-commercial use only - expires 2027-01-20
INFO:gurobipy:Academic license - for non-commercial use only - expires 2027-01-20
Read LP format model from file /private/var/folders/zg/by4_k0616s98pw41wld9475c0000gp/T/linopy-problem-mt_bdwj6.lp
INFO:gurobipy:Read LP format model from file /private/var/folders/zg/by4_k0616s98pw41wld9475c0000gp/T/linopy-problem-mt_bdwj6.lp
Reading time = 0.17 seconds
INFO:gurobipy:Reading time = 0.17 seconds
obj: 122644 rows, 52564 columns, 232162 nonzeros
INFO:gurobipy:obj: 122644 rows, 52564 columns, 232162 nonzeros
INFO:linopy.constants: Optimization successful: 
Status: ok
Termination condition: optimal
Solution: 52564 primals, 122644 duals
Objective: 4.28e+09
Solver model: available
Solver message: 2

INFO:pypsa.optimization.optimize:The shadow-prices of the constraints Generator-ext-p-lower, Generator-ext-p-upper, StorageUnit-ext-p_dispatch-lower, StorageUnit-ext-p_dispatch-upper, StorageUnit-ext-p_store-lower, StorageUnit-ext-p_store-upper, StorageUnit-ext-state_of_charge-lower, StorageUnit-ext-state_of_charge-upper, StorageUnit-energy_balance were not assigned to the network.
WARNING:pypsa.consistency:The following buses have carriers which are not defined:
Index(['electricity'], dtype='object', name='name')
INFO:linopy.model: Solve problem using Gurobi solver
INFO:linopy.model:Solver options:
 - OutputFlag: 0
INFO:linopy.io:Writing objective.
Writing constraints.: 100%|██████████| 12/12 [00:00<00:00, 48.09it/s]
Writing continuous variables.: 100%|██████████| 6/6 [00:00<00:00, 95.91it/s]
INFO:linopy.io: Writing time: 0.35s
Set parameter Username
INFO:gurobipy:Set parameter Username
Set parameter LicenseID to value 2767832
INFO:gurobipy:Set parameter LicenseID to value 2767832
Academic license - for non-commercial use only - expires 2027-01-20
INFO:gurobipy:Academic license - for non-commercial use only - expires 2027-01-20
Read LP format model from file /private/var/folders/zg/by4_k0616s98pw41wld9475c0000gp/T/linopy-problem-3bbsapql.lp
INFO:gurobipy:Read LP format model from file /private/var/folders/zg/by4_k0616s98pw41wld9475c0000gp/T/linopy-problem-3bbsapql.lp
Reading time = 0.16 seconds
INFO:gurobipy:Reading time = 0.16 seconds
obj: 122644 rows, 52564 columns, 232162 nonzeros
INFO:gurobipy:obj: 122644 rows, 52564 columns, 232162 nonzeros
INFO:linopy.constants: Optimization successful: 
Status: ok
Termination condition: optimal
Solution: 52564 primals, 122644 duals
Objective: 4.50e+09
Solver model: available
Solver message: 2

INFO:pypsa.optimization.optimize:The shadow-prices of the constraints Generator-ext-p-lower, Generator-ext-p-upper, StorageUnit-ext-p_dispatch-lower, StorageUnit-ext-p_dispatch-upper, StorageUnit-ext-p_store-lower, StorageUnit-ext-p_store-upper, StorageUnit-ext-state_of_charge-lower, StorageUnit-ext-state_of_charge-upper, StorageUnit-energy_balance were not assigned to the network.
WARNING:pypsa.consistency:The following buses have carriers which are not defined:
Index(['electricity'], dtype='object', name='name')
INFO:linopy.model: Solve problem using Gurobi solver
INFO:linopy.model:Solver options:
 - OutputFlag: 0
INFO:linopy.io:Writing objective.
Writing constraints.: 100%|██████████| 12/12 [00:00<00:00, 80.30it/s]
Writing continuous variables.: 100%|██████████| 6/6 [00:00<00:00, 593.52it/s]
INFO:linopy.io: Writing time: 0.18s
Set parameter Username
INFO:gurobipy:Set parameter Username
Set parameter LicenseID to value 2767832
INFO:gurobipy:Set parameter LicenseID to value 2767832
Academic license - for non-commercial use only - expires 2027-01-20
INFO:gurobipy:Academic license - for non-commercial use only - expires 2027-01-20
Read LP format model from file /private/var/folders/zg/by4_k0616s98pw41wld9475c0000gp/T/linopy-problem-tct9eu5v.lp
INFO:gurobipy:Read LP format model from file /private/var/folders/zg/by4_k0616s98pw41wld9475c0000gp/T/linopy-problem-tct9eu5v.lp
Reading time = 0.11 seconds
INFO:gurobipy:Reading time = 0.11 seconds
obj: 122644 rows, 52564 columns, 232162 nonzeros
INFO:gurobipy:obj: 122644 rows, 52564 columns, 232162 nonzeros
INFO:linopy.constants: Optimization successful: 
Status: ok
Termination condition: optimal
Solution: 52564 primals, 122644 duals
Objective: 5.07e+09
Solver model: available
Solver message: 2

INFO:pypsa.optimization.optimize:The shadow-prices of the constraints Generator-ext-p-lower, Generator-ext-p-upper, StorageUnit-ext-p_dispatch-lower, StorageUnit-ext-p_dispatch-upper, StorageUnit-ext-p_store-lower, StorageUnit-ext-p_store-upper, StorageUnit-ext-state_of_charge-lower, StorageUnit-ext-state_of_charge-upper, StorageUnit-energy_balance were not assigned to the network.
WARNING:pypsa.consistency:The following buses have carriers which are not defined:
Index(['electricity'], dtype='object', name='name')
INFO:linopy.model: Solve problem using Gurobi solver
INFO:linopy.model:Solver options:
 - OutputFlag: 0
INFO:linopy.io:Writing objective.
Writing constraints.: 100%|██████████| 12/12 [00:00<00:00, 90.26it/s]
Writing continuous variables.: 100%|██████████| 6/6 [00:00<00:00, 549.26it/s]
INFO:linopy.io: Writing time: 0.15s
Set parameter Username
INFO:gurobipy:Set parameter Username
Set parameter LicenseID to value 2767832
INFO:gurobipy:Set parameter LicenseID to value 2767832
Academic license - for non-commercial use only - expires 2027-01-20
INFO:gurobipy:Academic license - for non-commercial use only - expires 2027-01-20
Read LP format model from file /private/var/folders/zg/by4_k0616s98pw41wld9475c0000gp/T/linopy-problem-na7ts3tn.lp
INFO:gurobipy:Read LP format model from file /private/var/folders/zg/by4_k0616s98pw41wld9475c0000gp/T/linopy-problem-na7ts3tn.lp
Reading time = 0.13 seconds
INFO:gurobipy:Reading time = 0.13 seconds
obj: 122644 rows, 52564 columns, 232162 nonzeros
INFO:gurobipy:obj: 122644 rows, 52564 columns, 232162 nonzeros
INFO:linopy.constants: Optimization successful: 
Status: ok
Termination condition: optimal
Solution: 52564 primals, 122644 duals
Objective: 6.61e+09
Solver model: available
Solver message: 2

INFO:pypsa.optimization.optimize:The shadow-prices of the constraints Generator-ext-p-lower, Generator-ext-p-upper, StorageUnit-ext-p_dispatch-lower, StorageUnit-ext-p_dispatch-upper, StorageUnit-ext-p_store-lower, StorageUnit-ext-p_store-upper, StorageUnit-ext-state_of_charge-lower, StorageUnit-ext-state_of_charge-upper, StorageUnit-energy_balance were not assigned to the network.
df_tsc = pd.DataFrame(tsc).T
df_co2 = pd.Series(co2_cost).div(1e6)  # bn€/a

# Separate CO2 cost from gas cost to compare a) and b).
cost_comparison = df_tsc.copy()
cost_comparison["CO2"] = df_co2
cost_comparison["OCGT"] = cost_comparison["OCGT"] - cost_comparison["CO2"]

fig, axes = plt.subplots(1, 3, figsize=(14, 4))

shared_kwargs = dict(
    stacked=True,
    linewidth=0,
    xlim=(0, 5),
    xlabel=r"CO$_2$ emissions [Mt/a]",
    ylabel="System cost [bn€/a]",
    ylim=(0, 4),
)
legend_kwargs = dict(frameon=False, loc=(1.05, 0))

df.plot.area(
    **shared_kwargs,
    color=df.columns.map(n.carriers.color),
    ax=axes[0],
)
axes[0].legend(**legend_kwargs)
axes[0].invert_xaxis()
axes[0].set_title("a) CO2 limit")

cost_comparison.div(1e3).plot.area(
    **shared_kwargs,
    color=["indianred", "brown", "dodgerblue", "gold", "black"],
    ax=axes[1],
)
axes[1].set_title("b) CO2 price")
axes[1].legend(**legend_kwargs)
axes[1].invert_xaxis()

df_tsc.div(1e3).plot.area(
    **shared_kwargs,
    color=df_tsc.columns.map(network.carriers.color),
    ax=axes[2],
)
axes[2].set_title("b) CO2 price (full costs)")
axes[2].legend(**legend_kwargs)
axes[2].invert_xaxis()

plt.tight_layout()
../_images/ec966f1980057c80ba75b77ad31f0d2f425f50250986c610988fce8aa76da6b3.png
total_emissions
{5: np.float64(4996470.728304001),
 4: np.float64(4005041.1373628783),
 3: np.float64(2999173.5590970735),
 2: np.float64(1996019.5443765367),
 1: np.float64(993436.695465366),
 0: 0}