-
Notifications
You must be signed in to change notification settings - Fork 81
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
Initial refactor of cost functions #1071
Merged
Merged
Changes from all commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
5818ed1
delete old cost data
jd-lara 23c6e0d
add ProductionVariableCosts
jd-lara f7c1aab
add ThermalGenerationCost
jd-lara 4f1a34a
delete old exports
jd-lara 1fc21fb
delete outdated setter
jd-lara a39cff7
partially update the structs
jd-lara 771b98b
add new cost functions
jd-lara 779f537
format run
jd-lara f8c28fe
some updates
jd-lara 6a267a6
Fix typos; minor refactors for legibility
GabrielKS 6d19398
Add LoadCost
GabrielKS 6ed554b
Add cost function includes
GabrielKS ddd5d08
Eliminate TwoPartCost in generated structs
GabrielKS 2d434dd
Refine usage of `LoadCost`
GabrielKS 3032e2d
Fix serialization, typos
GabrielKS cdfd673
Fix `OperationalCost` constructors, test
GabrielKS 0156734
Make `OperationalCost` structs take the right kind of `ProductionVari…
GabrielKS 7af370b
Remove `PolynomialFunctionData`
GabrielKS d7ff445
Accommodate `FunctionData` refactors
GabrielKS 44e5f1a
Add `ValueCurve` for input-output, incremental, average rate curves
GabrielKS d9f1e1d
`ValueCurves`: add documentation, support serialization
GabrielKS 652d09c
Redefine `CostCurve`, `FuelCurve` in terms of `ValueCurve`
GabrielKS d63dae6
Add some `zero` methods
GabrielKS 31b848a
Standardize `OperationalCost` naming
GabrielKS f0fdd47
Make `test_cost_functions` pass
GabrielKS d055875
Export new cost structs
GabrielKS 2d82421
Refine cost struct constructors
GabrielKS a292ca0
Make further use of new cost structs throughout PSY
GabrielKS 3db189b
Fix cost struct parameterized type specifications
GabrielKS ccd9145
Revert `power_system_table_data` math, update accessors in test
GabrielKS 187bdc0
Move `operational_cost.jl`
GabrielKS b824da4
Fine-tune exports
GabrielKS b114f59
Fix operational cost field types
GabrielKS 5923544
Remove more references to old cost structs
GabrielKS 28220f1
Add x-axis units in `CostCurve` and `FuelCurve`
GabrielKS dd537cb
Update Project.toml
jd-lara 982861b
Add rough draft of cost function aliases and documentation
GabrielKS 9346083
Add operational cost conversion logic
GabrielKS a25c586
Fine-tune cost structs
GabrielKS a49da75
Add cost aliases docs and tests
GabrielKS 259b6cb
Rename `PiecewiseSlopeCurve`, revert ill-advised constructor refactor
GabrielKS 0afc7bc
Save `MarketBidCost` refactor progress before HDF5 transformations work
GabrielKS bd1cfeb
Implement HDF serialization properly for `ValueCurve`s
GabrielKS d758391
Wrap up high-level cost structs in time series for MarketBidCost
GabrielKS b26d639
Run formatter
GabrielKS e8193dd
Update test for new cost structs
GabrielKS f524e21
Rename `MarketBidCost.ancillary_services` -> `ancillary_service_offers
GabrielKS 234936e
Use cost function aliases
GabrielKS b0f4f60
Fix typo
GabrielKS 39c87fb
Merge branch 'psy4' into jdgk/cost_functions
GabrielKS 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 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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# PowerSystems Cost Functions | ||
|
||
PowerSystems.jl provides an extensive type hierarchy to explicitly express relationships between power production and cost. This lets the modeler represent cost functions as linear, quadratic, or piecewise input-output curves, potentially piecewise marginal heat rates, average heat rates, and more, as best fits the input data. | ||
|
||
To represent a cost for a particular [`Component`](@ref), the modeler first chooses one of the variable cost representations in the table below. Then, they wrap this [`ProductionVariableCost`](@ref) in either a [`CostCurve`](@ref) to indicate a cost in currency or in a [`FuelCurve`](@ref) to indicate a cost per unit of fuel plus a fuel cost. Finally, the user creates a domain-specific [`OperationalCost`](@ref) that contains this variable cost as well as other costs that may exist in that domain, such as a fixed cost that is always incurred when the unit is on. For instance, we may have `RenewableGenerationCost(CostCurve(TODO), 0.0)` to represent the cost of a renewable unit that produces at TODO, or `ThermalGenerationCost(; variable = FuelCurve(TODO), fixed = TODO, start_up = TODO, shut_down = TODO)` to represent the cost of a thermal unit that produces at TODO. Below, we give the options for `ProductionVariableCost`s. Information on what domain-specific cost must be provided for a given component type can be found in that component type's documentation. | ||
|
||
## Variable Cost Representations | ||
For more details, see the documentation page for each type. | ||
| Type alias | Description | Constructor parameters | Example | | ||
| --- | --- | --- | --- | | ||
| `LinearCurve` | Linear input-output curve with zero no-load cost (constant average rate) | Average/marginal rate | `LinearCurve(3.0)` | | ||
| `LinearCurve` | Linear input-output curve with nonzero no-load cost (constant marginal rate) | Marginal rate, cost at zero production | `LinearCurve(3.0, 5.0)` | | ||
| `QuadraticCurve` | Quadratic input-output curve, may have nonzero no-load cost | Quadratic, proportional, and constant terms of input-output curve | `QuadraticCurve(1.0, 1.0, 18.0)` | | ||
| `PiecewisePointCurve` | Piecewise linear curve specified by cost values at production points | Vector of (production, cost) pairs | `PiecewisePointCurve([(1.0, 20.0), (2.0, 24.0), (3.0, 30.0)])` | | ||
| `PiecewiseIncrementalCurve` | Piecewise linear curve specified by marginal rates (slopes) between production points, may have nonzero initial value | Cost at minimum production point, vector of $n$ production points, vector of $n-1$ marginal rates/slopes of the curve segments between the points | `PiecewiseIncrementalCurve(20., [1.0, 2.0, 3.0], [4.0, 6.0])` | | ||
| `PiecewiseAverageCurve` | Piecewise linear curve specified by average rates between production points, may have nonzero initial value | Cost at minimum production point, vector of $n$ production points, vector of average rates at the $n-1$ latter points | `PiecewiseAverageCurve(20., [1.0, 2.0, 3.0], [12.0, 10.0])` | |
This file contains 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 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 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 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 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 |
---|---|---|
|
@@ -90,23 +90,43 @@ function _convert_cost(points::Vector) | |
@assert all(length.(points) .== 2) | ||
@assert all([all(typeof.(point) .<: Real) for point in points]) | ||
# NOTE: old representation stored points as (y, x); new representation is (x, y) | ||
return PiecewiseLinearPointData([(x, y) for (y, x) in points]) | ||
return PiecewiseLinearData([(x, y) for (y, x) in points]) | ||
end | ||
|
||
# _convert_op_cost: take a component type, an old operational cost type, and old operational | ||
# cost data; and create the proper new operational cost struct. Some of these cost structs | ||
# no longer exist, so we dispatch instead on symbols. | ||
_convert_op_cost(::Val{:ThermalStandard}, ::Val{:ThreePartCost}, op_cost::Dict) = | ||
ThermalGenerationCost( | ||
CostCurve(InputOutputCurve(op_cost["variable"])), | ||
op_cost["fixed"], | ||
op_cost["start_up"], | ||
op_cost["shut_down"], | ||
) | ||
|
||
# TODO implement remaining _convert_op_cost methods | ||
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. Does this need to happen? |
||
|
||
function _convert_data!( | ||
raw::Dict{String, Any}, | ||
::Val{Symbol("3.0.0")}, | ||
::Val{Symbol("4.0.0")}, | ||
) | ||
for component in vcat(raw["data"]["components"], raw["data"]["masked_components"]) | ||
# Convert costs: all old cost structs are in fields named `operation_cost` | ||
if haskey(component, "operation_cost") | ||
op_cost = component["operation_cost"] | ||
# Step 1: insert a FunctionData | ||
if op_cost["__metadata__"]["type"] in COST_CONTAINERS && | ||
haskey(op_cost["variable"], "cost") | ||
old_cost = op_cost["variable"]["cost"] | ||
new_cost = IS.serialize(_convert_cost(old_cost)) | ||
new_cost = _convert_cost(old_cost) | ||
op_cost["variable"] = new_cost | ||
end | ||
# Step 2: convert TwoPartCost/ThreePartCost to new domain-specific cost structs | ||
comp_type = Val{Symbol(component["__metadata__"]["type"])}() | ||
op_cost_type = Val{Symbol(op_cost["__metadata__"]["type"])}() | ||
new_op_cost = IS.serialize(_convert_op_cost(comp_type, op_cost_type, op_cost)) | ||
component["operation_cost"] = new_op_cost | ||
end | ||
end | ||
end | ||
|
This file contains 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.
Can the TODOs get completed?