Skip to content
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

Add new tests for seven modules. Include GH workflow. #563

Merged
merged 12 commits into from
Nov 13, 2023

Conversation

lbonaldo
Copy link
Collaborator

@lbonaldo lbonaldo commented Oct 12, 2023

Description

This PR adds seven more tests that are executed whenever a pull request is opened, synchronize, and reopened, or at every push targeting main or develop. The tests are:

  • test_threezones.jl: tests GenX over three zones and five representative days;
  • test_multistage.jl: tests the multistage module over a single zone and five representative days;
  • test_electrolyzer.jl: tests the electrolyzer module over five representative days;
  • test_VREStor.jl: tests VRE and storage over 24 hours;
  • test_piecewisefuel_CO2.jl: tests the piecewise fuel CO2 module over 24 hours;
  • test_time_domain_reduction.jl: tests the TDR module;
  • test_methodofmorris.jl: tests the Method of Morris module.

For the first five cases, the tests are passed if the value of the objective function is consistent over time (up to the tolerance of the solver). The results are stored in a log folder updated in a separate repository (GenXProject/GenX-testlog.git).
The tests in test_time_domain_reduction.jl validate the clustering for the TDR module by computing the rand index and the mutual information and by comparing the output files.
For the Method of Morris module, we are testing if the module is correctly built, and if the output is consistent over time.

I'd appreciate any critiques or suggestions on how to improve these tests.

What type of PR is this?

  • Feature

Checklist

  • Code changes are sufficiently documented; i.e. new functions contain docstrings and .md files under /docs/src have been updated if necessary.
  • The latest changes on the target branch have been incorporated, so that any conflicts are taken care of before merging. This can be accomplished either by merging in the target branch (e.g. 'git merge develop') or by rebasing on top of the target branch (e.g. 'git rebase develop'). Please do not hesitate to reach out to the GenX development team if you need help with this.
  • Code has been tested to ensure all functionality works as intended.
  • CHANGELOG.md has been updated (if this is a 'notable' change).
  • I consent to the release of this PR's code under the GNU General Public license.

How this can be tested

After checking out develop, enter the package manager and run test or test GenX. The tests should run automatically.

Post-approval checklist for GenX core developers

After the PR is approved

  • Check that the latest changes on the target branch are incorporated, either via merge or rebase
  • Remember to squash and merge if incorporating into develop

@lbonaldo lbonaldo marked this pull request as draft October 12, 2023 04:37
@lbonaldo lbonaldo added this to the v0.4 milestone Oct 12, 2023
@codecov-commenter
Copy link

codecov-commenter commented Oct 12, 2023

Codecov Report

❗ No coverage uploaded for pull request base (develop@60ca831). Click here to learn what that means.
The diff coverage is n/a.

@@            Coverage Diff             @@
##             develop     #563   +/-   ##
==========================================
  Coverage           ?   40.83%           
==========================================
  Files              ?      126           
  Lines              ?     6482           
  Branches           ?        0           
==========================================
  Hits               ?     2647           
  Misses             ?     3835           
  Partials           ?        0           

@lbonaldo lbonaldo added enhancement New feature or request and removed enhancement New feature or request labels Oct 12, 2023
Copy link
Collaborator

@cfe316 cfe316 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great. My comments are mostly cosmetic, except for the possible interactions with Gabe's commerical-solver-use PR (see test/utilities.jl). Approving because I think this should still work.

version:
- "1.6"
- "1.7"
- "1.8"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be good to ensure we're testing on 1.9 (though I guess this is covered by 1 for "latest"?)

There's some new features in 1.9 that might motivate us to stop supporting older versions in GenX v0.4.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, '1' ensures we're testing on the latest stable release. We could also keep only the current stable release ('1'), and the long-term support (LTS) release (right now, v1.6.7) as other packages do.

Comment on lines 35 to 36
git config --local user.name lbonaldo
git config --local user.email "[email protected]"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of random, but I'm a bit surprised to see your name here.

I had thought maybe we had a project-wide github account?

Project.toml Outdated
Comment on lines 45 to 44
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"

LoggingExtras = "e6f89c97-d47a-5376-807f-9c37f3926c36"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10 points for alphabetizing our dependencies! 🎉

Comment on lines 1 to 13
# HiGHS Solver Parameters
# Common solver settings
Feasib_Tol: 1.0e-04 # Primal feasibility tolerance # [type: double, advanced: false, range: [1e-10, inf], default: 1e-07]
Optimal_Tol: 1.0e-04 # Dual feasibility tolerance # [type: double, advanced: false, range: [1e-10, inf], default: 1e-07]
TimeLimit: 1.0e23 # Time limit # [type: double, advanced: false, range: [0, inf], default: inf]
Pre_Solve: on # Presolve option: "off", "choose" or "on" # [type: string, advanced: false, default: "choose"]
Method: ipm #HiGHS-specific solver settings # Solver option: "simplex", "choose" or "ipm" # [type: string, advanced: false, default: "choose"]

#highs-specific solver settings

# run the crossover routine for ipx
# [type: string, advanced: "on", range: {"off", "on"}, default: "off"]
run_crossover: "on"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit surprised to see highs_settings.yml in the same folder as the rest of the case. And where is genx_settings.yml? Usually these are both in a Settings subfolder.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay I think I see how you're doing this below, by using a run_genx_case_testing function. Cool!


# Define test inputs
genx_setup = Dict(
"MacOrWindows" => "Mac",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MaxOrWindows is obsolete and can be removed

Comment on lines 28 to 29
"ModelingToGenerateAlternatives" => 0,
"ModelingtoGenerateAlternativeSlack" => 0.1,
"ModelingToGenerateAlternativeIterations" => 3,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably these can be removed if they're not being used (since the default is to have them be zero anyway)


include(joinpath(@__DIR__, "utilities.jl"))

obj_true = 6.9602085499e+03
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did you get these numbers? Did you set the solver tolerance to be super super low?
If not, probably we should truncate to the number of digits used by that solver.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I run the example several times and check if the value of the objective function was stable.
You're right, thanks, I will round them to match the tolerance (I'm using Optimal_Tol: 1.0e-05 )

Comment on lines 24 to 47
function run_genx_case_simple_testing(test_path::AbstractString, genx_setup::Dict)
# Run the case
OPTIMIZER = configure_solver(genx_setup["Solver"], test_path)
inputs = load_inputs(genx_setup, test_path)
EP = generate_model(genx_setup, inputs, OPTIMIZER)
EP, _ = solve_model(EP, genx_setup)
return EP, inputs, OPTIMIZER
end

function run_genx_case_multistage_testing(test_path::AbstractString, genx_setup::Dict)
# Run the case
OPTIMIZER = configure_solver(genx_setup["Solver"], test_path)

model_dict = Dict()
inputs_dict = Dict()

for t in 1:genx_setup["MultiStageSettingsDict"]["NumStages"]
# Step 0) Set Model Year
genx_setup["MultiStageSettingsDict"]["CurStage"] = t

# Step 1) Load Inputs
inpath_sub = joinpath(test_path, string("Inputs_p", t))
inputs_dict[t] = load_inputs(genx_setup, inpath_sub)
inputs_dict[t] = configure_multi_stage_inputs(inputs_dict[t], genx_setup["MultiStageSettingsDict"], genx_setup["NetworkExpansion"])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might consider how this will work with Gabe's optimizer-separating PR.

Spur of the moment idea:
For both, we might consider using keyword arguments. Something like
run_genx_case(path; optimizer:All=HiGHS.Optimizer, genx_setup::Union{nothing,Dict})
and then only what is not already supplied could be loaded.

Comment on lines 61 to 92
if !isdir(joinpath("Logs"))
mkdir(joinpath("Logs"))
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can just do "Logs" without joinpath

Comment on lines +1 to +33
Period_Index,Rep_Period,Rep_Period_Index
1,72,2
2,72,2
3,72,2
4,72,2
5,72,2
6,72,2
7,72,2
8,72,2
9,72,2
10,72,2
11,72,2
12,72,2
13,72,2
14,72,2
15,72,2
16,72,2
17,72,2
18,72,2
19,72,2
20,72,2
21,72,2
22,72,2
23,72,2
24,72,2
25,72,2
26,72,2
27,27,1
28,72,2
29,72,2
30,72,2
31,72,2
32,72,2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This Period_map file seems odd. Is this 365 days being represented by 5 days?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

@lbonaldo lbonaldo force-pushed the feature-tests branch 2 times, most recently from 593e27a to ff2a8fe Compare November 13, 2023 00:25
@lbonaldo lbonaldo marked this pull request as ready for review November 13, 2023 01:10
@lbonaldo lbonaldo merged commit 8524f4a into GenXProject:develop Nov 13, 2023
7 checks passed
lbonaldo added a commit that referenced this pull request Nov 13, 2023
This PR adds seven more tests to GenX: three-zone, multi-stage,
electrolyzer, VRE+storage, piecewise_fuel+CO2, TDR, and Method of Morris.
The tests are passed if the value of the objective function is
consistent over time (up to the tolerance of the solver).
The tests for the TDR validate the clustering by computing the rand
index and the mutual information and comparing the output files.
For the Method of Morris module, we are testing if the module is
correctly built and if the output is consistent over time.
@lbonaldo lbonaldo deleted the feature-tests branch June 25, 2024 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants