Skip to content

deduplicate opt container keys; start addressing issue 18.#36

Open
luke-kiernan wants to merge 2 commits intomainfrom
lk/deduplicate-opt-container
Open

deduplicate opt container keys; start addressing issue 18.#36
luke-kiernan wants to merge 2 commits intomainfrom
lk/deduplicate-opt-container

Conversation

@luke-kiernan
Copy link
Collaborator

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_value
  • dataset_container.jl: get_dataset{_values}
  • initial_conditions.jl: {has/get}_initial_condition_value
  • optimization_container.jl: has_container_key, add_container!, _get_entry, get_optimization_container_key

Then 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.

@luke-kiernan luke-kiernan requested review from Copilot and jd-lara and removed request for Copilot March 6, 2026 17:31
@luke-kiernan
Copy link
Collaborator Author

I also changed things to move away from global symbols and dictionaries towards types and multiple dispatch. E.g. use ExpressionType as an intermediate, not :expressions. Symbols are abstract types and thus less compiler-friendly.

@codecov
Copy link

codecov bot commented Mar 6, 2026

Codecov Report

❌ Patch coverage is 30.76923% with 135 lines in your changes missing coverage. Please review.
✅ Project coverage is 20.95%. Comparing base (e7b9279) to head (fbb5ca1).

Files with missing lines Patch % Lines
src/core/optimization_container.jl 58.33% 25 Missing ⚠️
src/common_models/rateofchange_constraints.jl 0.00% 17 Missing ⚠️
src/common_models/range_constraint.jl 0.00% 14 Missing ⚠️
src/core/optimization_container_utils.jl 23.52% 13 Missing ⚠️
src/core/abstract_model_store.jl 8.33% 11 Missing ⚠️
src/operation/operation_model_interface.jl 0.00% 11 Missing ⚠️
src/core/initial_conditions.jl 0.00% 10 Missing ⚠️
src/objective_function/piecewise_linear.jl 40.00% 6 Missing ⚠️
src/objective_function/start_up_shut_down.jl 0.00% 6 Missing ⚠️
src/core/dataset_container.jl 50.00% 5 Missing ⚠️
... and 7 more
Additional details and impacted files

Impacted file tree graph

@@            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     
Flag Coverage Δ
unittests 20.95% <30.76%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/objective_function/proportional.jl 96.96% <100.00%> (ø)
src/utils/print_pt_v2.jl 0.00% <ø> (ø)
src/utils/print_pt_v3.jl 0.00% <ø> (ø)
src/common_models/add_pwl_methods.jl 98.33% <80.00%> (+1.61%) ⬆️
src/common_models/set_expression.jl 0.00% <0.00%> (ø)
src/objective_function/quadratic_curve.jl 92.30% <50.00%> (+1.39%) ⬆️
src/objective_function/common.jl 7.31% <0.00%> (+0.17%) ⬆️
src/core/standard_variables_expressions.jl 12.50% <0.00%> (+1.97%) ⬆️
src/objective_function/cost_term_helpers.jl 76.74% <50.00%> (+1.74%) ⬆️
src/core/dataset_container.jl 59.42% <50.00%> (+11.31%) ⬆️
... and 10 more

... and 9 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.jl with field_for_type, key_for_type, store_field_for_type (and unused field_for_key) mappings, then replaces ~5 copy-paste variants of each getter/checker with a single @generated function in optimization_container.jl, abstract_model_store.jl, dataset_container.jl, and initial_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 Ipopt and SCS to test/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.

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.

2 participants