deduplicate opt container keys; start addressing issue 18.#36
deduplicate opt container keys; start addressing issue 18.#36luke-kiernan wants to merge 2 commits intomainfrom
Conversation
|
I also changed things to move away from global symbols and dictionaries towards types and multiple dispatch. E.g. use |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #36 +/- ##
==========================================
+ Coverage 20.88% 20.95% +0.06%
==========================================
Files 72 73 +1
Lines 5430 5326 -104
==========================================
- Hits 1134 1116 -18
+ Misses 4296 4210 -86
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR addresses issues #18 and #19 by replacing copy-pasted per-type function definitions with @generated functions that use centralized type-to-field and type-to-key mappings. It also begins migrating from passing instances to passing types in various getter functions.
Changes:
- Introduces
optimization_container_utils.jlwithfield_for_type,key_for_type,store_field_for_type(and unusedfield_for_key) mappings, then replaces ~5 copy-paste variants of each getter/checker with a single@generatedfunction inoptimization_container.jl,abstract_model_store.jl,dataset_container.jl, andinitial_conditions.jl. - Migrates callers throughout objective function and common model files from instance-based (
T()) to type-based (T) getter calls, keeping deprecated instance-based wrappers for backward compatibility with POM. - Adds
IpoptandSCStotest/Project.toml(previously missing despite being used in test solver definitions).
Reviewed changes
Copilot reviewed 28 out of 28 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/core/optimization_container_utils.jl |
New file: centralized type↔field↔key mapping functions |
src/core/optimization_container.jl |
Major refactor: has_container_key, _get_entry, _add_container!, get_optimization_container_key as @generated; all per-type getters/setters delegate to generic versions; deprecated instance wrappers kept |
src/core/abstract_model_store.jl |
list_fields, list_keys, get_value as @generated; adds STORE_CONTAINER_TYPES tuple |
src/core/dataset_container.jl |
get_dataset, get_dataset_values as @generated with deprecated instance wrappers |
src/core/initial_conditions.jl |
get_initial_condition_value, has_initial_condition_value as @generated with deprecated instance wrappers |
src/operation/operation_model_interface.jl |
list_names replaces _list_names; all list_*_keys/list_*_names use type-based list_keys/list_names |
src/core/standard_variables_expressions.jl |
ProductionCostExpression container creation uses _add_container! |
src/objective_function/*.jl |
Instance-to-type migration for get_variable, get_expression, get_parameter, get_parameter_array, get_parameter_multiplier_array calls |
src/common_models/*.jl |
Instance-to-type migration for get_variable, get_expression, get_parameter, get_constraint, get_initial_condition calls |
src/utils/print_pt_v2.jl, src/utils/print_pt_v3.jl |
Added FIXME comments about get_optimization_container_key 1-arg version |
src/InfrastructureOptimizationModels.jl |
Added include for optimization_container_utils.jl |
test/Project.toml |
Added Ipopt and SCS dependencies; reordered [sources] section |
test/**/*.jl |
Instance-to-type migration in test utility and test files |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Address issue #19: replace "copy-paste nearly identical definition and change a few things" with generated functions. Relevant functions that are now generated:
abstract_model_store.jl:list_{fields/keys}, get_valuedataset_container.jl:get_dataset{_values}initial_conditions.jl:{has/get}_initial_condition_valueoptimization_container.jl:has_container_key, add_container!, _get_entry, get_optimization_container_keyThen the 5 different variations all call the generated one. The last file has the biggest changes. See the issue for details
The other changes are all "start addressing issue #18:" replace instance with type in various getters. I decided to leave the instance versions in place for now (they call the type version) just in case I run into stuff in POM where it turns out I need the instance.