"_term" error when adding more than 1 passive branch in PyPSA

9 views Asked by At

I'm running into issues when I setup a network with more than 1 passive branch. Simple replicable example is below.

Note: I realize that this network isn't ideal, but I'm trying to replicate some examples from another piece of software and these examples have more than 1 passive branch.

Any help is much appreciated. Thanks so much!

This solves "Ok, Optimal"

import pypsa
import numpy as np

# Create a new PyPSA Network
n = pypsa.Network(snapshots=range(5))

lines = [('LINE1', 'NODE2', 'NODE1'),
]

for name, from_bus, to_bus in lines:
    n.add("Line",
          name,
          bus0=from_bus,
          bus1=to_bus,
          s_nom=100,
          )
    
line_buses = np.array([n.lines.bus0.unique(), n.lines.bus1.unique()])
line_buses = np.concatenate(line_buses, dtype='object')

buses = ['NODE1', 'NODE2', 'NODE3']
buses = [x for x in buses if x in line_buses]

for bus in buses:
    n.add("Bus",
          bus,
          )

# load_bus = np.random.choice(n.buses.index) 
load_bus = 'NODE1'
n.add("Load", "MyLoad", bus=load_bus, p_set=10)  # 10 MW load
print("load bus: ", load_bus)

# Assuming a simple fixed profile for solar generation
solar_bus = load_bus
solar_pu = [0.6, 0.6, 0.6, 0.6, 0.6]  # Example solar generation pattern

n.add("Generator", "MySolar", bus=solar_bus, p_nom=20, p_max_pu=solar_pu, marginal_cost=0.5)  # 20 MW solar generator
print("solar bus: ", solar_bus)

print(n.consistency_check())

n.optimize()

This doesn't solve and throws a "ValueError: Variables {'_term'} are coordinates in some datasets but not others."

n = pypsa.Network(snapshots=range(5))

lines = [('LINE1', 'NODE2', 'NODE1'),
 ('LINE2', 'NODE2', 'NODE3'),
]

for name, from_bus, to_bus in lines:
    n.add("Line",
          name,
          bus0=from_bus,
          bus1=to_bus,
          s_nom=100,
          )
    
line_buses = np.array([n.lines.bus0.unique(), n.lines.bus1.unique()])
line_buses = np.concatenate(line_buses, dtype='object')

buses = ['NODE1', 'NODE2', 'NODE3']
buses = [x for x in buses if x in line_buses]

for bus in buses:
    n.add("Bus",
          bus,
          )

# load_bus = np.random.choice(n.buses.index) 
load_bus = 'NODE1'
n.add("Load", "MyLoad", bus=load_bus, p_set=10)  # 10 MW load
print("load bus: ", load_bus)

# Assuming a simple fixed profile for solar generation
solar_bus = load_bus
solar_pu = [0.6, 0.6, 0.6, 0.6, 0.6]  # Example solar generation pattern

n.add("Generator", "MySolar", bus=solar_bus, p_nom=20, p_max_pu=solar_pu, marginal_cost=0.5)  # 20 MW solar generator
print("solar bus: ", solar_bus)

print(n.consistency_check())

n.optimize()
0

There are 0 answers