Skip to content

Commit

Permalink
Changed examples to be consistent with EMB
Browse files Browse the repository at this point in the history
  • Loading branch information
JulStraus committed Mar 3, 2024
1 parent c5df45a commit b48c174
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 103 deletions.
146 changes: 82 additions & 64 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,88 +1,106 @@
Release notes
=============

Version 0.5.3 (2024-01-30)
--------------------------
* Updated the restrictions on the fields individual types to be consistent.
* Added option to not include the field `data` for the individual `TransmissionMode`s.

Version 0.5.2 (2024-01-19)
--------------------------
* Updated the documenation to be in line with the updated done in `EnergyModelsBsae`.
* Moved `RegHydroStor` to a new file, `legacy_constructors.jl` to highlight that a user should use the new types, namely `HydroStor` and `PumpedHydroStor`.

Version 0.5.1 (2024-01-17)
--------------------------
* Update the method `constraints_level` to match the signature updates for these methods in `EnergyModelsBase`. This includes renaming `constraints_level` to `constraints_level_sp`.
* Moved the function to `EMB.constraints_level_sp` to avoid problems.

Version 0.5.0 (2023-12-18)
--------------------------
# Release notes

## Unversioned

### Examples

* Fixed a bug when running the examples from a non-cloned version of `EnergyModelsRenewableProducers`.
* This was achieved through a separate Project.toml in the examples.

### NonDIsRes node

* Moved the capcity constraints through the profile to the function `constraints_capacity(n::NonDisRES, ...)`, and hence, removed the function `EMB.create_node(n::NonDisRES, ...)`.

## Version 0.5.3 (2024-01-30)

* Updated the restrictions on the fields individual types to be consistent.
* Added option to not include the field `data` for the individual `TransmissionMode`s.

## Version 0.5.2 (2024-01-19)

* Updated the documenation to be in line with the updated done in `EnergyModelsBsae`.
* Moved `RegHydroStor` to a new file, `legacy_constructors.jl` to highlight that a user should use the new types, namely `HydroStor` and `PumpedHydroStor`.

## Version 0.5.1 (2024-01-17)

* Update the method `constraints_level` to match the signature updates for these methods in `EnergyModelsBase`. This includes renaming `constraints_level` to `constraints_level_sp`.
* Moved the function to `EMB.constraints_level_sp` to avoid problems.

## Version 0.5.0 (2023-12-18)

### Adjustment to release in EMB 0.6.0
* Adjusted the code for the new release.
* Implementation of support for `RepresentativePeriods` for `HydroStorage` nodes.

Version 0.4.2 (2023-09-01)
--------------------------
### Create a variable :spill for hydro storage node.
* This variable enables hydro storage nodes to spill water from the reservoir without
* Adjusted the code for the new release.
* Implementation of support for `RepresentativePeriods` for `HydroStorage` nodes.

## Version 0.4.2 (2023-09-01)

### Create a variable :spill for hydro storage node

* This variable enables hydro storage nodes to spill water from the reservoir without
producing energy.

Version 0.4.1 (2023-08-31)
--------------------------
## Version 0.4.1 (2023-08-31)

### Split the hydro storage node into to separate nodes
* Split `RegHydroStor` into to types `PumpedHydroStor` and `HydroStor`. Both are subtypes

* Split `RegHydroStor` into to types `PumpedHydroStor` and `HydroStor`. Both are subtypes
of the new abstract type `HydroStorage <: EMB.Storage`.
* Fix: variational OPEX for `HydroStor` now depends on `flow_out` instead of
* Fix: variational OPEX for `HydroStor` now depends on `flow_out` instead of
`flow_in`. The new type `PumpedHydroStor` has a separate parameter for variational OPEX
for the pumps, which depends on `flow_in`.

Version 0.4.0 (2023-06-06)
--------------------------
## Version 0.4.0 (2023-06-06)

### Switch to TimeStruct.jl
* Switched the time structure representation to [TimeStruct.jl](https://github.com/sintefore/TimeStruct.jl)
* TimeStruct.jl is implemented with only the basis features that were available in TimesStructures.jl. This implies that neither operational nor strategic uncertainty is included in the model

* Switched the time structure representation to [TimeStruct.jl](https://github.com/sintefore/TimeStruct.jl).
* TimeStruct.jl is implemented with only the basis features that were available in TimesStructures.jl. This implies that neither operational nor strategic uncertainty is included in the model.

Version 0.3.0 (2023-05-30)
--------------------------
* Adjustment to changes in `EnergyModelsBase` v0.4.0 related to extra input data

Version 0.2.2 (2023-05-15)
--------------------------
* Adjustment to changes in `EnergyModelsBase` v 0.3.3 related to the calls for the constraint functions
* Adjustment to changes in `EnergyModelsBase` v0.4.0 related to extra input data.

## Version 0.2.2 (2023-05-15)

* Adjustment to changes in `EnergyModelsBase` v 0.3.3 related to the calls for the constraint functions.

## Version 0.2.1 (2023-02-03)

Version 0.2.1 (2023-02-03)
--------------------------
* Take the examples out to the folder `examples`.

Version 0.2.0 (2023-02-03)
--------------------------
## Version 0.2.0 (2023-02-03)

### Adjustmends to updates in EnergyModelsBase

Adjustment to version 0.3.0, namely:
* Changed type (`Node`) calls in tests to be consistent with version 0.3.0
* Removal of the type `GlobalData` and replacement with fields in the type `OperationalModel` in all tests
* Changed type structure to be consistent with EMB version 0.3.0
* Substitution of certain constraints in `create_node` through functions which utilize dispatching on `node` types
* Changed the input to the function `variables_node`

Version 0.1.3 (2022-12-12)
--------------------------

* Changed type (`Node`) calls in tests to be consistent with version 0.3.0.
* Removal of the type `GlobalData` and replacement with fields in the type `OperationalModel` in all tests.
* Changed type structure to be consistent with EMB version 0.3.0.
* Substitution of certain constraints in `create_node` through functions which utilize dispatching on `node` types.
* Changed the input to the function `variables_node`.

## Version 0.1.3 (2022-12-12)

### Internal release
* Renamed to follow common prefix naming scheme
* Update README

Version 0.1.2 (2022-12-02)
--------------------------
* Minor test fixes in preparation of internal release
* Renamed to follow common prefix naming scheme.
* Update README.

## Version 0.1.2 (2022-12-02)

* Minor test fixes in preparation of internal release.

## Version 0.1.1 (2021-09-07)

Version 0.1.1 (2021-09-07)
--------------------------
### Changes in naming
* Major changes in both variable and parameter naming, check the commit message for an overview
* Change of structure in composite type "RegHydroStor"

Version 0.1.0 (2021-08-23)
--------------------------
* Major changes in both variable and parameter naming, check the commit message for an overview.
* Change of structure in composite type "RegHydroStor".

## Version 0.1.0 (2021-08-23)

* Initial version with inclusion of nodes for:
* nondispatchable renewable energy sources (NonDisRES)
* regulated hydro generation (RegHydroStor, can be used for pumped hydro storage)
* nondispatchable renewable energy sources (NonDisRES) and
* regulated hydro generation (RegHydroStor, can be used for pumped hydro storage).
8 changes: 8 additions & 0 deletions examples/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[deps]
EnergyModelsBase = "5d7e687e-f956-46f3-9045-6f5a5fd49f50"
EnergyModelsRenewableProducers = "b007c34f-ba52-4995-ba37-fffe79fbde35"
HiGHS = "87dc4568-4c63-4d18-b0c0-bb2238e4078b"
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d"
TimeStruct = "f9ed5ce0-9f41-4eaa-96da-f38ab8df101c"
9 changes: 6 additions & 3 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ How to add packages is explained in the *[Quick start](https://energymodelsx.git
You can run from the Julia REPL the following code:

```julia
# Starts the Julia REPL
# Import EnergyModelsRenewableProducers
using EnergyModelsRenewableProducers

# Get the path of the examples directory
exdir = joinpath(pkgdir(EnergyModelsRenewableProducers), "examples")
# Include the code into the Julia REPL to run the first example of the NonDisRes node

# Include the code into the Julia REPL to run the example of the NonDisRes node
include(joinpath(exdir, "simple_nondisres.jl"))
# Include the code into the Julia REPL to run the first example of the Hydropower node

# Include the code into the Julia REPL to run the example of the Hydropower node
include(joinpath(exdir, "simple_hydro_power.jl"))
```
36 changes: 21 additions & 15 deletions examples/simple_hydro_power.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using Pkg
# Activate the test-environment, where PrettyTables and HiGHS are added as dependencies.
Pkg.activate(joinpath(@__DIR__, "../test"))
# Activate the local environment including EnergyModelsRenewableProducers, HiGHS, PrettyTables
Pkg.activate(@__DIR__)
# Install the dependencies.
Pkg.instantiate()
# Add the current package to the environment.
Pkg.develop(path = joinpath(@__DIR__, ".."))

# Import the required packages
using EnergyModelsBase
using EnergyModelsRenewableProducers
using HiGHS
Expand All @@ -15,8 +14,16 @@ using TimeStruct

const EMB = EnergyModelsBase

function generate_data()
@info "Generate data"
"""
generate_example_data()
Generate the data for an example consisting of a simple electricity network with a
non-dispatchable power source, a regulated hydro power plant, as well as a demand.
It illustrates how the hydro power plant can balance the intermittent renewable power
generation.
"""
function generate_example_data()
@info "Generate case data - Simple `HydroStor` example"

# Define the different resources and their emission intensity in tCO2/MWh
# CO2 has to be defined, even if not used, as it is required for the `EnergyModel` type
Expand All @@ -29,11 +36,10 @@ function generate_data()
op_number = 4 # There are in total 4 operational periods
operational_periods = SimpleTimes(op_number, op_duration)

# The number of operational periods times the duration of the operational periods, which
# can also be extracted using the function `duration` of a `SimpleTimes` structure.
# The number of operational periods times the duration of the operational periods.
# This implies, that a strategic period is 8 times longer than an operational period,
# resulting in the values below as "/8h".
op_per_strat = duration(operational_periods)
op_per_strat = op_duration * op_number

# Create the time structure and global data
T = TwoLevel(2, 1, operational_periods; op_per_strat)
Expand Down Expand Up @@ -68,12 +74,12 @@ function generate_data()
Power, # Stored resource
Dict(Power => 0.9), # Input to the power plant, irrelevant in this case
Dict(Power => 1), # Output from the Node, in this gase, Power
Data[], # Potential additional data
Data[], # Potential additional data
)

# Create a power demand node
sink = RefSink(
"sink", # Node ID
"electricity demand", # Node id
FixedProfile(2), # Demand in MW
Dict(:surplus => FixedProfile(0), :deficit => FixedProfile(1e6)),
# Line above: Surplus and deficit penalty for the node in EUR/MWh
Expand All @@ -84,11 +90,11 @@ function generate_data()
nodes = [av, wind, hydro, sink]

# Connect all nodes with the availability node for the overall energy balance
links = [
links = [
Direct("wind-av", wind, av),
Direct("hy-av", hydro, av),
Direct("av-hy", av, hydro),
Direct("av-si", av, sink),
Direct("av-demand", av, sink),
]

# Create the case dictionary
Expand All @@ -97,8 +103,8 @@ function generate_data()
return case, model
end

# Create the case and model data and run the model
case, model = generate_data()
# Generate the case and model data and run the model
case, model = generate_example_data()
optimizer = optimizer_with_attributes(HiGHS.Optimizer, MOI.Silent() => true)
m = EMB.run_model(case, model, optimizer)

Expand Down
32 changes: 19 additions & 13 deletions examples/simple_nondisres.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using Pkg
# Activate the test-environment, where PrettyTables and HiGHS are added as dependencies.
Pkg.activate(joinpath(@__DIR__, "../test"))
# Activate the local environment including EnergyModelsRenewableProducers, HiGHS, PrettyTables
Pkg.activate(@__DIR__)
# Install the dependencies.
Pkg.instantiate()
# Add the package EnergyModelsRenewableProducers to the environment.
Pkg.develop(path = joinpath(@__DIR__, ".."))

# Import the required packages
using EnergyModelsBase
using EnergyModelsRenewableProducers
using HiGHS
Expand All @@ -15,7 +14,15 @@ using TimeStruct

const EMB = EnergyModelsBase

function demo_data()
"""
generate_example_data()
Generate the data for an example consisting of a simple electricity network with a
non-dispatchable power source, a standard source, as well as a demand.
It illustrates how the non-dispatchable power source requires a balancing power source.
"""
function generate_example_data()
@info "Generate case data - Simple `NonDisRES` example"

# Define the different resources and their emission intensity in tCO2/MWh
# CO2 has to be defined, even if not used, as it is required for the `EnergyModel` type
Expand All @@ -28,11 +35,10 @@ function demo_data()
op_number = 4 # There are in total 4 operational periods
operational_periods = SimpleTimes(op_number, op_duration)

# The number of operational periods times the duration of the operational periods, which
# can also be extracted using the function `duration` of a `SimpleTimes` structure.
# The number of operational periods times the duration of the operational periods.
# This implies, that a strategic period is 8 times longer than an operational period,
# resulting in the values below as "/8h".
op_per_strat = duration(operational_periods)
op_per_strat = op_duration * op_number

# Creation of the time structure and global data
T = TwoLevel(2, 1, operational_periods; op_per_strat)
Expand All @@ -52,7 +58,7 @@ function demo_data()
Dict(Power => 1), # Output from the Node, in this gase, Power
)
sink = RefSink(
"sink", # Node ID
"electricity demand", # Node id
FixedProfile(2), # Demand in MW
Dict(:surplus => FixedProfile(0), :deficit => FixedProfile(1e6)),
# Line above: Surplus and deficit penalty for the node in EUR/MWh
Expand All @@ -62,7 +68,7 @@ function demo_data()

# Connect the two nodes with each other
links = [
Direct(12, nodes[1], nodes[2], Linear())
Direct("source-demand", nodes[1], nodes[2], Linear())
]

# Create the case dictionary
Expand All @@ -80,14 +86,14 @@ function demo_data()

# Update the case data with the non-dispatchable power source and link
push!(case[:nodes], wind)
link = Direct(31, case[:nodes][3], case[:nodes][2], Linear())
link = Direct("wind-demand", case[:nodes][3], case[:nodes][2], Linear())
push!(case[:links], link)

return case, model
end

# Create the case and model data and run the model
case, model = demo_data()
# Generate the case and model data and run the model
case, model = generate_example_data()
optimizer = optimizer_with_attributes(HiGHS.Optimizer, MOI.Silent() => true)
m = EMB.run_model(case, model, optimizer)

Expand Down
2 changes: 0 additions & 2 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
EnergyModelsBase = "5d7e687e-f956-46f3-9045-6f5a5fd49f50"
HiGHS = "87dc4568-4c63-4d18-b0c0-bb2238e4078b"
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
LocalRegistry = "89398ba2-070a-4b16-a995-9893c55d93cf"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TimeStruct = "f9ed5ce0-9f41-4eaa-96da-f38ab8df101c"
7 changes: 1 addition & 6 deletions test/test_examples.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

@testset "Run examples" begin
exdir = joinpath(@__DIR__, "../examples")

files = first(walkdir(exdir))[3]
for file files
if splitext(file)[2] == ".jl"
Expand All @@ -13,9 +12,5 @@
end
end
end

# Cleanup the test environment. Remove EnergyModelsRenewableProducers from
# the environment, since it is added with `Pkg.develop` by the examples. The
# tests can not be run with with the package in the environment.
Pkg.rm("EnergyModelsRenewableProducers")
Pkg.activate(@__DIR__)
end

0 comments on commit b48c174

Please sign in to comment.