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

Update capacity.jl to use the new attach functions and update tables #963

Merged
merged 5 commits into from
Dec 13, 2024

Conversation

abelsiqueira
Copy link
Member

@abelsiqueira abelsiqueira commented Dec 12, 2024

  • Update capacity.jl to use attach and update tables related to it

Part of #961

Copy link

codecov bot commented Dec 12, 2024

Codecov Report

Attention: Patch coverage is 94.91525% with 3 lines in your changes missing coverage. Please review.

Project coverage is 95.27%. Comparing base (c05fe7d) to head (eb4dcdd).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/structures.jl 66.66% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #963      +/-   ##
==========================================
- Coverage   95.45%   95.27%   -0.18%     
==========================================
  Files          29       29              
  Lines        1034     1059      +25     
==========================================
+ Hits          987     1009      +22     
- Misses         47       50       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@abelsiqueira abelsiqueira added the benchmark PR only - Run benchmark on PR label Dec 12, 2024
Copy link
Contributor

github-actions bot commented Dec 12, 2024

Benchmark Results

c05fe7d... eb4dcdd... c05fe7d.../eb4dcdd5554588...
energy_problem/create_model 46.5 ± 1.7 s 39.8 ± 2 s 1.17
energy_problem/input_and_constructor 16.3 ± 0.21 s 15.5 ± 0.37 s 1.05
time_to_load 4 ± 0.034 s 4.03 ± 0.043 s 0.993
c05fe7d... eb4dcdd... c05fe7d.../eb4dcdd5554588...
energy_problem/create_model 0.707 G allocs: 22.8 GB 0.611 G allocs: 21 GB 1.09
energy_problem/input_and_constructor 0.0521 G allocs: 1.98 GB 0.0521 G allocs: 1.98 GB 1
time_to_load 0.159 k allocs: 11.2 kB 0.159 k allocs: 11.2 kB 1

Benchmark Plots

A plot of the benchmark results have been uploaded as an artifact to the workflow run for this PR.
Go to "Actions"->"Benchmark a pull request"->[the most recent run]->"Artifacts" (at the bottom).

@abelsiqueira abelsiqueira changed the title 642 capacity Update capacity.jl to use the new attach functions and update tables Dec 12, 2024
@abelsiqueira abelsiqueira marked this pull request as ready for review December 12, 2024 15:27
@abelsiqueira
Copy link
Member Author

This is not the whole of #961, but it's already a lot of changes - because it's one of the hardest files, I think.
Benchmarks say things are faster, though it might be randomness still. Otherwise, a reason could be that things are more type stable, with the attach functions, but I'm guessing.

@datejada, what do you think? Does it look clean enough?

Copy link
Member

@datejada datejada left a comment

Choose a reason for hiding this comment

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

@abelsiqueira I have committed my proposed changes. Let me know if you agree on them to continue. Thanks!

]
profile_times_capacity = Dict(
key => begin
table_name = Symbol("ramping_$(key)_unit_commitment")
Copy link
Member

Choose a reason for hiding this comment

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

Also, it reads better below if the keys are :with_unit_commitment and :without_unit_commitment

So, please change it either here or in the other PR you are working for the ramping. Thanks!

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree. I will change in the next PR, because I had to completely change the keys to the table names, since they are used in other tables as well

Copy link
Member Author

@abelsiqueira abelsiqueira left a comment

Choose a reason for hiding this comment

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

Thanks for the commits. I left a comment and I'll check your comments on this PR now

@@ -149,7 +171,7 @@ function _create_constraints_tables(connection)
DuckDB.query(
connection,
"CREATE OR REPLACE TEMP SEQUENCE id START 1;
CREATE OR REPLACE TABLE cons_capacity_outgoing_binary AS
CREATE OR REPLACE TABLE cons_capacity_outgoing_storage_with_binary AS
Copy link
Member Author

Choose a reason for hiding this comment

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

Took me a while, but if I understood correctly, this table should have a WHERE condition to check NOT asset.investable for it to be equal to the old code.

My logic (and I will use initials to avoid writing for 30 minutes) is that initially you had two tables: COB and COBI

  • For COB, if investable, use (c * aiu + ail) * (1 - ch) else use c * aiu * (1 - ch)
  • FOR COBI, use c * (aiu * (1 - ch) + aiusm)

Now you have three tables, COSB, COISB, COISLB.

  • For COSB, c * aiu * (1 - ch), so COSB = COB + not investable
  • For COISB, c * (aiu * (1 - ch) + aiusm), so COISB = COBI
  • For COISLB, (c * aiu + ail) * (1 - ch), so COISLB is COB + investable (which is COBI, I think)

If that is the case, you can also reuse the COISB table - you still separate the constraints to avoid the if condition, you just attach to the same constraint.
I checked the formulation, and indeed it separates like these tables, but I think that the formulation is also missing a a \not \in A_y^I or similar for that constraint.

Let me know if this makes sense or not

Copy link
Member

Choose a reason for hiding this comment

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

It makes sense, I left a couple of comments where I see we need the changes and also a rename in one of the constraints to make it explicit.

Copy link
Member

Choose a reason for hiding this comment

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

We need to update the formulation, too

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks. Do you want to finish the PR with these changes?

src/constraints/create.jl Outdated Show resolved Hide resolved
src/constraints/create.jl Outdated Show resolved Hide resolved
src/constraints/create.jl Outdated Show resolved Hide resolved
src/constraints/create.jl Outdated Show resolved Hide resolved
src/constraints/create.jl Outdated Show resolved Hide resolved
@datejada datejada self-requested a review December 13, 2024 15:56
Copy link
Member

@datejada datejada left a comment

Choose a reason for hiding this comment

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

Thanks! LGTM

@datejada datejada merged commit d42650e into main Dec 13, 2024
4 of 5 checks passed
@datejada datejada deleted the 642-capacity branch December 13, 2024 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
benchmark PR only - Run benchmark on PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants