-
Notifications
You must be signed in to change notification settings - Fork 16
Set period length parameters as indexed parameters #76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
esrawli
wants to merge
22
commits into
IDAES:main
Choose a base branch
from
esrawli:indexing-period-lengths
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
91f1223
Remove period length from ramping constraints since ramp rates are di…
esrawli 22047dd
Replace periodLength parameters with new indexed parameters
esrawli e670b24
Run black
esrawli 98b19d7
Rename PeriodLength parameters in each stage to avoid confusion when …
esrawli 44cfd15
Update period length parameters names in test and run black
esrawli 46afec6
Improve period structure handling to allow integer inputs for number …
esrawli c27a645
Remove argument from class since it not needed anymore
esrawli 13ec972
Remove len_reps since it is no longer needed or used
esrawli bfa512b
Merge branch 'IDAES:main' into indexing-period-lengths
esrawli 47b397a
Add new file "utils" that includes functions to generate the period s…
esrawli 807f490
Improve period structure in class to read number of periods and their…
esrawli cd0bcbf
Merge remote-tracking branch 'github-idaesgtep-esrawli/main' into ind…
esrawli e894155
Update test to call scalars from data file and not as an argument in …
esrawli e7877a1
Move new arguments from expansion class to data class and update driv…
esrawli 0b0baf0
Add consistency check for the duration of dispatch periods and update…
esrawli 570b10d
Add test for dispatch duration consistency check
esrawli 1db3276
Add consistency check for sum of commitment duration and update test …
esrawli 730ba25
Add new duration for representative period to avoid touching consiste…
esrawli 7017099
Add header
esrawli 2e6632f
Use Pyomo’s TempfileManager to create a temporary directory and .json…
esrawli 34a7a29
Add functions that expand the period structure to a dictionary and th…
esrawli 069625f
remove duration for commitment and dispatch as an argument in the cla…
esrawli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ | |
| import json | ||
| import numpy as np | ||
| import re | ||
| import os | ||
|
|
||
| import pyomo.environ as pyo | ||
| from pyomo.environ import units as u | ||
|
|
@@ -52,6 +53,13 @@ | |
| import gtep.model_library.storage as stor | ||
| import gtep.model_library.transmission as transm | ||
|
|
||
| from gtep.utils import ( | ||
| _set_period_structure_dict, | ||
| check_period_structure_consistency, | ||
| ) | ||
|
|
||
| curr_dir = os.path.dirname(os.path.abspath(__file__)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is fragile (and does not appear to be used). Remove? |
||
|
|
||
| # Define what a USD is for pyomo units purposes. This will be set to a | ||
| # base year and we will do NPV calculations based on automatic Pyomo | ||
| # unit transformations. | ||
|
|
@@ -99,17 +107,64 @@ def __init__( | |
| :return: Pyomo model for full GTEP | ||
| """ | ||
|
|
||
| self.config = _get_model_config() | ||
| self.timer = TicTocTimer() | ||
|
|
||
| self.stages = data.stages | ||
| self.formulation = formulation | ||
| self.data = data | ||
| self.cost_data = cost_data | ||
| self.num_reps = data.num_reps | ||
| self.len_reps = data.len_reps | ||
| self.num_commit = data.num_commit | ||
| self.num_dispatch = data.num_dispatch | ||
| self.duration_dispatch = data.duration_dispatch | ||
| self.config = _get_model_config() | ||
| self.timer = TicTocTimer() | ||
| self.save_period_structure_file = data.save_period_structure_file | ||
| self.period_structure_json_file = data.period_structure_json_file | ||
|
|
||
| # Calculate commitment and dispatch period durations using | ||
| # provided scalars for the duration of representative period | ||
| # and number of commitment and dispatch periods. Note: We are | ||
| # assuming that all periods within their parent are of equal | ||
| # length. | ||
| duration_commitment = data.duration_representative_period / data.num_commit | ||
| duration_dispatch = pyo.value( | ||
| pyo.units.convert( | ||
| (duration_commitment / data.num_dispatch) * u.hours, | ||
| to_units=u.minutes, | ||
| ) | ||
| ) | ||
|
|
||
| # Generate the period structure dictionary from provided | ||
| # scalars, or load it from a .json file if specified. In | ||
| # either case, the period structure is returned as a | ||
| # dictionary. | ||
| period_dict = _set_period_structure_dict( | ||
| data.num_reps, | ||
| data.num_commit, | ||
| data.num_dispatch, | ||
| data.duration_representative_period, | ||
| duration_commitment, | ||
| duration_dispatch, | ||
| self.save_period_structure_file, | ||
| self.period_structure_json_file, | ||
| ) | ||
|
|
||
| # Assign period structure attributes from the dictionary | ||
| self.num_reps = period_dict.get("number_representative", data.num_reps) | ||
| self.num_commit = period_dict["number_commitment"] | ||
| self.num_dispatch = period_dict["number_dispatch"] | ||
| self.duration_representative_period = period_dict[ | ||
| "duration_representative_period" | ||
| ] | ||
| self.duration_commitment = period_dict["duration_commitment"] | ||
| self.duration_dispatch = period_dict["duration_dispatch"] | ||
|
|
||
| # Run a consistency check on commitment and dispatch | ||
| # durations. | ||
| check_period_structure_consistency( | ||
| self.num_reps, | ||
| self.num_commit, | ||
| self.num_dispatch, | ||
| self.duration_representative_period, | ||
| self.duration_commitment, | ||
| self.duration_dispatch, | ||
| ) | ||
|
|
||
| _add_common_configs(self.config) | ||
| _add_investment_configs(self.config) | ||
|
|
@@ -151,15 +206,18 @@ def create_model(self): | |
| m, self.stages, rep_per=[i for i in range(1, self.num_reps + 1)] | ||
| ) | ||
|
|
||
| comps.add_model_parameters( | ||
| comps.add_model_parameters(m) | ||
|
|
||
| create_stages( | ||
| m, | ||
| self.stages, | ||
| self.num_commit, | ||
| self.num_dispatch, | ||
| self.duration_representative_period, | ||
| self.duration_commitment, | ||
| self.duration_dispatch, | ||
| ) | ||
|
|
||
| create_stages(m, self.stages) | ||
|
|
||
| obj_comp.create_objective_function(m) | ||
|
|
||
| self.model = m | ||
|
|
@@ -202,8 +260,24 @@ def report_large_coefficients(self, outfile, magnitude_cutoff=1e5): | |
| with open(outfile, "w") as fil: | ||
| json.dump(really_bad_var_coef_list, fil) | ||
|
|
||
| return ( | ||
| num_commit_dict, | ||
| num_dispatch_dict, | ||
| duration_rep_dict, | ||
| duration_commit_dict, | ||
| duration_dispatch_dict, | ||
| ) | ||
|
|
||
|
|
||
| def create_stages(m, stages): | ||
| def create_stages( | ||
| m, | ||
| stages, | ||
| num_commit, | ||
| num_dispatch, | ||
| duration_representative_period, | ||
| duration_commitment, | ||
| duration_dispatch, | ||
| ): | ||
| """This method constructs the block structure for the Generation | ||
| and Transmission Expansion Planning (GTEP) model. It creates | ||
| investment, representative period, and commitment blocks for each | ||
|
|
@@ -247,6 +321,13 @@ def create_stages(m, stages): | |
| # representative_period. | ||
| for representative_period in b_inv.representativePeriods: | ||
| b_rep = b_inv.representativePeriod[representative_period] | ||
|
|
||
| b_rep.representativePeriodLength = pyo.Param( | ||
| initialize=duration_representative_period[representative_period], | ||
| within=pyo.PositiveReals, | ||
| units=u.hr, | ||
| ) | ||
|
|
||
| b_rep.representative_date = m.data.representative_dates[ | ||
| representative_period - 1 | ||
| ] | ||
|
|
@@ -258,28 +339,33 @@ def create_stages(m, stages): | |
| # b_rep.day = int(broken_date[2]) | ||
| b_rep.currentPeriod = representative_period | ||
|
|
||
| # [ESR NOTE: Include commitment blocks regardless of the | ||
| # value of include_commitment. When include_commitment is | ||
| # False, generators are assumed to be always online, and | ||
| # Include commitment blocks regardless of the value of | ||
| # include_commitment. When False, generators are on and | ||
| # operational costs are determined solely by dispatch | ||
| # decisions. No redispatch for now.] | ||
| # if m.config["include_commitment"] or m.config["include_redispatch"]: | ||
| b_rep.commitmentPeriods = pyo.RangeSet( | ||
| m.numCommitmentPeriods[representative_period] | ||
| ) | ||
| # decisions. | ||
| n_commit = num_commit[representative_period] | ||
| b_rep.commitmentPeriods = pyo.RangeSet(n_commit) | ||
| b_rep.commitmentPeriod = pyo.Block(b_rep.commitmentPeriods) | ||
|
|
||
| # --.--.--.--.--.--.----.--.--.--.--.--.----.--.--.--.--.--.-- | ||
| # Add commitment Block and all its equations and | ||
| # constraints | ||
| for commitment_period in b_rep.commitmentPeriods: | ||
| b_comm = b_rep.commitmentPeriod[commitment_period] | ||
|
|
||
| b_comm.commitmentPeriodLength = pyo.Param( | ||
| initialize=duration_commitment[representative_period][ | ||
| commitment_period | ||
| ], | ||
| within=pyo.PositiveReals, | ||
| units=u.hr, | ||
| ) | ||
|
|
||
| b_comm.commitmentPeriod = commitment_period | ||
|
|
||
| if m.config["include_redispatch"]: | ||
| b_comm.dispatchPeriods = pyo.RangeSet( | ||
| m.numDispatchPeriods[b_rep.currentPeriod] | ||
| ) | ||
| n_dispatch = num_dispatch[representative_period][commitment_period] | ||
| b_comm.dispatchPeriods = pyo.RangeSet(n_dispatch) | ||
| b_comm.dispatchPeriod = pyo.Block(b_comm.dispatchPeriods) | ||
|
|
||
| # [TODO: update properties for this time period!] | ||
|
|
@@ -299,21 +385,22 @@ def create_stages(m, stages): | |
|
|
||
| # [TODO: This feels REALLY inelegant and | ||
| # bad. Check a better way of declaring these.] | ||
| for period in b_comm.dispatchPeriods: | ||
| b_comm.dispatchPeriod[period].periodLength = pyo.Param( | ||
| initialize=1, | ||
| for dispatch_period in b_comm.dispatchPeriods: | ||
| b_disp = b_comm.dispatchPeriod[dispatch_period] | ||
| b_disp.dispatchPeriodLength = pyo.Param( | ||
| initialize=duration_dispatch[representative_period][ | ||
| commitment_period | ||
| ][dispatch_period], | ||
| within=pyo.PositiveReals, | ||
| # units=u.minutes, | ||
| units=u.minutes, | ||
| ) | ||
|
|
||
| disp.add_dispatch_variables( | ||
| b_comm.dispatchPeriod[period], | ||
| period, | ||
| m.dispatchPeriodLength, | ||
| ) | ||
| disp.add_dispatch_constraints( | ||
| b_comm.dispatchPeriod[period], period | ||
| b_disp, | ||
| dispatch_period, | ||
| b_disp.dispatchPeriodLength, | ||
| ) | ||
| disp.add_dispatch_constraints(b_disp, dispatch_period) | ||
|
|
||
| # =.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=. | ||
|
|
||
|
|
@@ -338,8 +425,8 @@ def create_stages(m, stages): | |
| rep_period.add_representative_period_variables(b_rep, representative_period) | ||
|
|
||
| if m.config["include_commitment"]: | ||
| # These logical constraint ensure the state | ||
| # disjuncts stay consistent. | ||
| # These logical constraints ensure the state disjuncts | ||
| # stay consistent. | ||
| rep_period.add_representative_period_logical_constraints( | ||
| b_rep, representative_period | ||
| ) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this br
24 * units.hour?