Benchmark select_best_assets - #1446
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1446 +/- ##
==========================================
+ Coverage 89.71% 89.78% +0.07%
==========================================
Files 60 60
Lines 8439 8439
Branches 8439 8439
==========================================
+ Hits 7571 7577 +6
+ Misses 551 545 -6
Partials 317 317 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
alexdewar
left a comment
There was a problem hiding this comment.
This looks cool! Nothing to add really, except that it will be interesting to see how this changes with parallelisation 😄.
I suppose this would potentially make it a little harder to change the interface for select_best_assets as the benchmark will also need updating in that case, but I guess this is the kind of thing that LLMs are good at fixing anyway.
Also, might we want to verify that benchmarks at least compile and maybe run to completion as a CI workflow? Given that we won't be looking at the numbers in this context, we could possibly run it with a reduced number of iterations, if that's an option.
Let's do this as part of #1453 . There's a |
Co-authored-by: Alex Dewar <[email protected]>
|
Looks good! On board with this in principal, just a few comments:
|
I was reluctant to this complex setup, but for functions with complex inputs, there not that many options.
I agree. In Python it would be a piece of cake, but in rust things seem to be quite separated and I'm not sure how easy that would be. We could explore the options, though.
Indeed, that might happen. Just don't do anything else while doing the benchmarking 😅 . Jokes aside, we could explore the options, but it might be simpler to just re-run the benchmark if you spot a weird behaviour.
Yeah, probably not great making things public unless needed.
I haven't explored the options much. There were other plots in the report, and then you could access the individual reports for 1s, 2s, etc. maybe there is a more useful plot. I cannot check today, but can have a look tomorrow. |
There was a problem hiding this comment.
Pull request overview
This PR adds a Criterion benchmark to measure how select_best_assets scales as the number of competing candidate technologies increases, using the two_outputs example model as a realistic input basis. To enable the benchmark to reuse existing internal setup logic without duplicating it, several helper functions were made public and Process was made Clone.
Changes:
- Add
benches/assets.rsCriterion benchmark sweeping the number of competing technologies. - Expose several simulation helper functions (
get_*,flatten_preset_demands_for_year,candidate_assets_for_next_year) for benchmark reuse. - Derive
CloneforProcessand register the new bench target inCargo.toml.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/simulation/market.rs |
Makes market helper functions public for benchmark setup. |
src/simulation/investment.rs |
Makes demand-flattening helper public for benchmark setup. |
src/simulation.rs |
Makes candidate_assets_for_next_year public for benchmark setup. |
src/process.rs |
Derives Clone for Process to support synthetic process generation in the benchmark. |
Cargo.toml |
Registers the new assets benchmark target. |
benches/assets.rs |
Adds the select_best_assets scaling benchmark implementation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let templates: Vec<Rc<Process>> = agent | ||
| .iter_search_space(region_id, &commodity.id, YEAR) | ||
| .cloned() | ||
| .collect(); | ||
|
|
Description
Very much Copilot's work, with me supervising, to be honest. As pointed out, the input to
select_best_assetsis very complicated, so I asked Copilot to create such in input starting from thetwo_outputsexample. Then, I elaborated making a sweep on the number of competing technologies. To avoid code duplication, some functions in MUSE2 were made public, but otherwise left unchanged.To run it use:
cargo bench --bench assetsOr for a quick run:
cargo bench --bench assets -- --quickOne of the outputs is the following plot, which as expected shows a linear dependency with the number of competting assets. When parallelize, we would - hopefully - see a different behaviour.
Fixes #1444
Type of change
Key checklist
$ cargo test$ cargo docpresent in the previous release
Further checks