Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion stubs/pyomo/core/base/param.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Param(IndexedComponent, IndexedComponent_NDArrayMixin):
def sparse_keys(self): ...
def sparse_values(self): ...
def sparse_items(self): ...
def sparse_iterkeys(self): ...
def sparse_keys(self): ...
def sparse_itervalues(self): ...
def sparse_iteritems(self): ...
def extract_values(self): ...
Expand Down
16 changes: 8 additions & 8 deletions temoa/_internal/table_data_puller.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def poll_flow_results(model: TemoaModel, epsilon: float = 1e-5) -> dict[FI, dict
res[fi][FlowType.OUT] -= flow

# construction flows
for r, i, t, v in model.construction_input.sparse_iterkeys():
for r, i, t, v in model.construction_input.sparse_keys():
annual = (
value(model.construction_input[r, i, t, v])
* value(model.v_new_capacity[r, t, v])
Expand All @@ -231,7 +231,7 @@ def poll_flow_results(model: TemoaModel, epsilon: float = 1e-5) -> dict[FI, dict
res[fi][FlowType.IN] = flow

# end of life flows
for r, t, v, o in model.end_of_life_output.sparse_iterkeys():
for r, t, v, o in model.end_of_life_output.sparse_keys():
if (r, t, v) not in model.retirement_periods:
continue
for p in model.retirement_periods[r, t, v]:
Expand Down Expand Up @@ -335,7 +335,7 @@ def poll_cost_results(
entries: dict[tuple[Region, Period, Technology, Vintage], dict[CostType, float]] = defaultdict(
dict
)
for r, t, v in model.cost_invest.sparse_iterkeys(): # Returns only non-zero values
for r, t, v in model.cost_invest.sparse_keys(): # Returns only non-zero values
# gather details...
cap = value(model.v_new_capacity[r, t, v])
if abs(cap) < epsilon:
Expand Down Expand Up @@ -395,7 +395,7 @@ def poll_cost_results(
{CostType.D_INVEST: model_loan_cost, CostType.INVEST: undiscounted_cost}
)

for r, p, t, v in model.cost_fixed.sparse_iterkeys():
for r, p, t, v in model.cost_fixed.sparse_keys():
cap = value(model.v_capacity[r, p, t, v])
if abs(cap) < epsilon:
continue
Expand Down Expand Up @@ -436,7 +436,7 @@ def poll_cost_results(
}
)

for r, p, t, v in model.cost_variable.sparse_iterkeys():
for r, p, t, v in model.cost_variable.sparse_keys():
if t not in model.tech_annual:
activity = sum(
value(model.v_flow_out[r, p, S_s, S_d, S_i, t, v, S_o])
Expand Down Expand Up @@ -622,7 +622,7 @@ def poll_emissions(

base = [
(r, p, e, i, t, v, o)
for (r, e, i, t, v, o) in model.emission_activity.sparse_iterkeys()
for (r, e, i, t, v, o) in model.emission_activity.sparse_keys()
for p in model.time_optimize
if (r, p, t, v) in model.process_inputs
]
Expand Down Expand Up @@ -683,7 +683,7 @@ def poll_emissions(

# iterate through embodied flows
embodied_flows: dict[EI, float] = defaultdict(float)
for r, e, t, v in model.emission_embodied.sparse_iterkeys():
for r, e, t, v in model.emission_embodied.sparse_keys():
embodied_flows[EI(r, v, t, v, e)] += value(
model.v_new_capacity[r, t, v]
* model.emission_embodied[r, e, t, v]
Expand Down Expand Up @@ -731,7 +731,7 @@ def poll_emissions(

# iterate through end of life flows
eol_flows: dict[EI, float] = defaultdict(float)
for r, e, t, v in model.emission_end_of_life.sparse_iterkeys():
for r, e, t, v in model.emission_end_of_life.sparse_keys():
if (r, t, v) not in model.retirement_periods:
continue
for p in model.retirement_periods[r, t, v]:
Expand Down
18 changes: 9 additions & 9 deletions temoa/components/capacity.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def check_capacity_factor_process(model: TemoaModel) -> None:
count_rptv[r, p, t, v] = 0

# Check for bad values and count up the good ones
for r, p, _s, _d, t, v in model.capacity_factor_process.sparse_iterkeys():
for r, p, _s, _d, t, v in model.capacity_factor_process.sparse_keys():
if v not in model.process_vintages[r, p, t]:
msg = f'Invalid process {p, v} for {r, t} in capacity_factor_process table'
logger.error(msg)
Expand Down Expand Up @@ -85,7 +85,7 @@ def create_capacity_factors(model: TemoaModel) -> None:
capacity_factor_process = model.capacity_factor_process

# Step 1
processes = {(r, t, v) for r, i, t, v, o in model.efficiency.sparse_iterkeys()}
processes = {(r, t, v) for r, i, t, v, o in model.efficiency.sparse_keys()}

all_cfs = {
(r, p, s, d, t, v)
Expand All @@ -95,7 +95,7 @@ def create_capacity_factors(model: TemoaModel) -> None:
}

# Step 2
unspecified_cfs = all_cfs.difference(capacity_factor_process.sparse_iterkeys())
unspecified_cfs = all_cfs.difference(capacity_factor_process.sparse_keys())

# Step 3

Expand Down Expand Up @@ -234,7 +234,7 @@ def capacity_factor_process_indices(
model: TemoaModel,
) -> set[tuple[Region, Season, TimeOfDay, Technology, Vintage]]:
indices: set[tuple[Region, Season, TimeOfDay, Technology, Vintage]] = set()
for r, _i, t, v, _o in model.efficiency.sparse_iterkeys():
for r, _i, t, v, _o in model.efficiency.sparse_keys():
for p in model.time_optimize:
for s in model.time_season[p]:
for d in model.time_of_day:
Expand Down Expand Up @@ -604,8 +604,8 @@ def create_capacity_and_retirement_sets(model: TemoaModel) -> None:

logger.debug('Creating capacity, retirement, and construction/EOL sets.')
# Calculate retirement periods based on lifetime and survival curves
unique_rtv = {(r, t, v) for r, _i, t, v, _o in model.efficiency.sparse_iterkeys()} | set(
model.existing_capacity.sparse_iterkeys()
unique_rtv = {(r, t, v) for r, _i, t, v, _o in model.efficiency.sparse_keys()} | set(
model.existing_capacity.sparse_keys()
)
for r, t, v in unique_rtv:
if t in model.tech_uncap:
Expand Down Expand Up @@ -637,19 +637,19 @@ def create_capacity_and_retirement_sets(model: TemoaModel) -> None:
model.retirement_periods.setdefault((r, t, v), set()).add(p)

# Link construction materials to technologies
for r, i, t, v in model.construction_input.sparse_iterkeys():
for r, i, t, v in model.construction_input.sparse_keys():
model.capacity_consumption_techs.setdefault((r, v, i), set()).add(t)
model.used_techs.add(t)

# Link end-of-life materials to retiring technologies
for r, t, v, o in model.end_of_life_output.sparse_iterkeys():
for r, t, v, o in model.end_of_life_output.sparse_keys():
if (r, t, v) in model.retirement_periods:
for p in model.retirement_periods[r, t, v]:
model.retirement_production_processes.setdefault((r, p, o), set()).add((t, v))
model.used_techs.add(t)

# Link end-of-life emissions to retiring technologies
for r, _e, t, v in model.emission_end_of_life.sparse_iterkeys():
for r, _e, t, v in model.emission_end_of_life.sparse_keys():
if (r, t, v) in model.retirement_periods:
model.used_techs.add(t)

Expand Down
16 changes: 8 additions & 8 deletions temoa/components/commodities.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ def create_technology_and_commodity_sets(model: TemoaModel) -> None:
- M.tech_demand: Technologies that directly satisfy an end-use demand.
"""
logger.debug('Creating technology and commodity subsets.')
for _r, _i, t, _v, o in model.efficiency.sparse_iterkeys():
for _r, _i, t, _v, o in model.efficiency.sparse_keys():
if t in model.tech_flex and o not in model.commodity_flex:
model.commodity_flex.add(o)

Expand Down Expand Up @@ -729,7 +729,7 @@ def create_demands(model: TemoaModel) -> None:
demand_specific_distributon_dem = iget(4)

# Step 1: Check if any demand commodities are going unused
used_dems = {dem for r, p, dem in model.demand.sparse_iterkeys()}
used_dems = {dem for r, p, dem in model.demand.sparse_keys()}
unused_dems = sorted(model.commodity_demand.difference(used_dems))
if unused_dems:
for dem in unused_dems:
Expand All @@ -741,8 +741,8 @@ def create_demands(model: TemoaModel) -> None:
# makes sense to just use segment_fraction directly
# Step 2: Build the demand default distribution (= segment_fraction)
# DDD = M.DemandDefaultDistribution # Shorter, for us lazy programmer types
# unset_defaults = set(M.segment_fraction.sparse_iterkeys())
# unset_defaults.difference_update(DDD.sparse_iterkeys())
# unset_defaults = set(M.segment_fraction.sparse_keys())
# unset_defaults.difference_update(DDD.sparse_keys())
# if unset_defaults:
# Some hackery because Pyomo thinks that this Param is constructed.
# However, in our view, it is not yet, because we're specifically
Expand All @@ -760,7 +760,7 @@ def create_demands(model: TemoaModel) -> None:
# # errors associated with the specification of demand shares by time slice,
# # but we check to make sure it is within the specified tolerance.

# key_padding = max(map(get_str_padding, DDD.sparse_iterkeys()))
# key_padding = max(map(get_str_padding, DDD.sparse_keys()))

# fmt = '%%-%ds = %%s' % key_padding
# # Works out to something like "%-25s = %s"
Expand All @@ -784,7 +784,7 @@ def create_demands(model: TemoaModel) -> None:
demands_specified = set(
map(
demand_specific_distributon_dem,
(i for i in demand_specific_distribution.sparse_iterkeys()),
(i for i in demand_specific_distribution.sparse_keys()),
)
)
unset_demand_distributions = used_dems.difference(
Expand All @@ -811,12 +811,12 @@ def create_demands(model: TemoaModel) -> None:
# Also check that all keys are made... The demand distro should be supported
# by the full set of (r, p, dem) keys because it is an equality constraint
# and we need to ensure even the zeros are passed in
used_rp_dems = {(r, p, dem) for r, p, dem in model.demand.sparse_iterkeys()}
used_rp_dems = {(r, p, dem) for r, p, dem in model.demand.sparse_keys()}
for r, p, dem in used_rp_dems:
expected_key_length = len(model.time_season[p]) * len(model.time_of_day)
keys = [
k
for k in demand_specific_distribution.sparse_iterkeys()
for k in demand_specific_distribution.sparse_keys()
if demand_specific_distribution_region(k) == r
and demand_specific_distribution_period(k) == p
and demand_specific_distributon_dem(k) == dem
Expand Down
22 changes: 11 additions & 11 deletions temoa/components/costs.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def lifetime_loan_process_indices(model: TemoaModel) -> set[tuple[Region, Techno
because in myopic mode, previously optimized vintages remain active in later
windows and their data must be accepted by the param's index set.
"""
indices = {(r, t, v) for r, i, t, v, o in model.efficiency.sparse_iterkeys()}
indices = {(r, t, v) for r, i, t, v, o in model.efficiency.sparse_keys()}

return indices

Expand Down Expand Up @@ -335,7 +335,7 @@ def period_cost_rule(model: TemoaModel, p: int) -> float | Expression:
global_discount_rate,
vintage=S_v,
)
for r, S_t, S_v in model.cost_invest.sparse_iterkeys()
for r, S_t, S_v in model.cost_invest.sparse_keys()
if S_v == p and not model.is_survival_curve_process[r, S_t, S_v]
)
loan_costs += quicksum(
Expand All @@ -352,7 +352,7 @@ def period_cost_rule(model: TemoaModel, p: int) -> float | Expression:
p_e,
global_discount_rate,
)
for r, S_t, S_v in model.cost_invest.sparse_iterkeys()
for r, S_t, S_v in model.cost_invest.sparse_keys()
if S_v == p and model.is_survival_curve_process[r, S_t, S_v]
)

Expand All @@ -365,7 +365,7 @@ def period_cost_rule(model: TemoaModel, p: int) -> float | Expression:
p_0,
p=p,
)
for r, S_p, S_t, S_v in model.cost_fixed.sparse_iterkeys()
for r, S_p, S_t, S_v in model.cost_fixed.sparse_keys()
if S_p == p
)

Expand All @@ -378,7 +378,7 @@ def period_cost_rule(model: TemoaModel, p: int) -> float | Expression:
p_0,
p,
)
for r, S_p, S_t, S_v in model.cost_variable.sparse_iterkeys()
for r, S_p, S_t, S_v in model.cost_variable.sparse_keys()
if S_p == p and S_t not in model.tech_annual
for S_i in model.process_inputs[r, S_p, S_t, S_v]
for S_o in model.process_outputs_by_input[r, S_p, S_t, S_v, S_i]
Expand All @@ -395,7 +395,7 @@ def period_cost_rule(model: TemoaModel, p: int) -> float | Expression:
p_0,
p,
)
for r, S_p, S_t, S_v in model.cost_variable.sparse_iterkeys()
for r, S_p, S_t, S_v in model.cost_variable.sparse_keys()
if S_p == p and S_t in model.tech_annual
for S_i in model.process_inputs[r, S_p, S_t, S_v]
for S_o in model.process_outputs_by_input[r, S_p, S_t, S_v, S_i]
Expand All @@ -417,7 +417,7 @@ def period_cost_rule(model: TemoaModel, p: int) -> float | Expression:

base = [
(r, p, e, i, t, v, o)
for (r, e, i, t, v, o) in model.emission_activity.sparse_iterkeys()
for (r, e, i, t, v, o) in model.emission_activity.sparse_keys()
if (r, p, e) in model.cost_emission # tightest filter first
and (r, p, t, v) in model.process_inputs
]
Expand Down Expand Up @@ -484,7 +484,7 @@ def period_cost_rule(model: TemoaModel, p: int) -> float | Expression:
p_0=p_0,
p=p,
)
for (r, e, t, v) in model.emission_embodied.sparse_iterkeys()
for (r, e, t, v) in model.emission_embodied.sparse_keys()
if (r, p, e) in model.cost_emission
if v == p
)
Expand All @@ -502,7 +502,7 @@ def period_cost_rule(model: TemoaModel, p: int) -> float | Expression:
p_0=p_0,
p=p,
)
for (r, e, t, v) in model.emission_end_of_life.sparse_iterkeys()
for (r, e, t, v) in model.emission_end_of_life.sparse_keys()
if (r, p, e) in model.cost_emission
if (r, t, v) in model.retirement_periods and p in model.retirement_periods[r, t, v]
)
Expand Down Expand Up @@ -687,8 +687,8 @@ def create_costs(model: TemoaModel) -> None:
var_indices = set(model.cost_variable_rptv)

# Step 2
unspecified_fixed_prices = fixed_indices.difference(cost_fixed.sparse_iterkeys())
unspecified_var_prices = var_indices.difference(cost_variable.sparse_iterkeys())
unspecified_fixed_prices = fixed_indices.difference(cost_fixed.sparse_keys())
unspecified_var_prices = var_indices.difference(cost_variable.sparse_keys())

# Step 3

Expand Down
4 changes: 2 additions & 2 deletions temoa/components/emissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def emission_activity_indices(
) -> set[tuple[Region, Commodity, Commodity, Technology, Vintage, Commodity]]:
indices = {
(r, e, i, t, v, o)
for r, i, t, v, o in model.efficiency.sparse_iterkeys()
for r, i, t, v, o in model.efficiency.sparse_keys()
for e in model.commodity_emissions
if r in model.regions # omit any exchange/groups
}
Expand All @@ -53,7 +53,7 @@ def linked_tech_constraint_indices(
) -> set[tuple[Region, Period, Season, TimeOfDay, Technology, Vintage, Commodity]]:
linkedtech_indices = {
(r, p, s, d, t, v, e)
for r, t, e in model.linked_techs.sparse_iterkeys()
for r, t, e in model.linked_techs.sparse_keys()
for p in model.time_optimize
if (r, p, t) in model.process_vintages
for v in model.process_vintages[r, p, t]
Expand Down
2 changes: 1 addition & 1 deletion temoa/components/geography.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def create_geography_sets(model: TemoaModel) -> None:
of (region_from, t, v, i) tuples.
"""
logger.debug('Creating geography-related sets for exchange technologies.')
for r, i, t, v, o in model.efficiency.sparse_iterkeys():
for r, i, t, v, o in model.efficiency.sparse_keys():
if t not in model.tech_exchange:
continue

Expand Down
Loading
Loading