-
Notifications
You must be signed in to change notification settings - Fork 0
Precompilation workload #145
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
Draft
jd-lara
wants to merge
2
commits into
main
Choose a base branch
from
precompilation_workload
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| # Precompilation workload. Exercises the key-type-independent container layers | ||
| # (Settings/container init, JuMP fill of DenseAxisArray containers, objective | ||
| # assembly) against private mock types so downstream consumers skip that compile. | ||
| # Structs sit at top level because @setup_workload lowers into a `let` block. | ||
|
|
||
| mutable struct _WorkloadSystem <: IS.InfrastructureSystemsContainer | ||
| base_power::Float64 | ||
| end | ||
|
|
||
| get_base_power(sys::_WorkloadSystem) = sys.base_power | ||
| stores_time_series_in_memory(::_WorkloadSystem) = true | ||
|
|
||
| struct _WorkloadComponent <: IS.InfrastructureSystemsComponent end | ||
| struct _WorkloadVariable <: VariableType end | ||
| struct _WorkloadConstraint <: ConstraintType end | ||
| struct _WorkloadExpression <: ExpressionType end | ||
|
|
||
| function _run_precompile_workload() | ||
| sys = _WorkloadSystem(100.0) | ||
| settings = Settings( | ||
| sys; | ||
| horizon = Dates.Hour(24), | ||
| resolution = Dates.Hour(1), | ||
| time_series_cache_size = 0, | ||
| ) | ||
| container = OptimizationContainer(sys, settings, nothing, IS.Deterministic) | ||
| set_time_steps!(container, 1:24) | ||
| jump_model = get_jump_model(container) | ||
| names = ["c1", "c2", "c3"] | ||
| time_steps = get_time_steps(container) | ||
| variables = add_variable_container!( | ||
| container, | ||
| _WorkloadVariable, | ||
| _WorkloadComponent, | ||
| names, | ||
| time_steps, | ||
| ) | ||
| for name in names, t in time_steps | ||
| variables[name, t] = JuMP.@variable( | ||
| jump_model, | ||
| base_name = "V_{$(name), $(t)}", | ||
| lower_bound = 0.0, | ||
| upper_bound = 10.0 | ||
| ) | ||
| end | ||
| expressions = add_expression_container!( | ||
| container, | ||
| _WorkloadExpression, | ||
| _WorkloadComponent, | ||
| names, | ||
| time_steps, | ||
| ) | ||
| for name in names, t in time_steps | ||
| expressions[name, t] = JuMP.AffExpr(0.0) | ||
| JuMP.add_to_expression!(expressions[name, t], variables[name, t]) | ||
| end | ||
| constraints = add_constraints_container!( | ||
| container, | ||
| _WorkloadConstraint, | ||
| _WorkloadComponent, | ||
| names, | ||
| time_steps, | ||
| ) | ||
| for name in names, t in time_steps | ||
| constraints[name, t] = JuMP.@constraint(jump_model, expressions[name, t] <= 5.0) | ||
| end | ||
| add_to_objective_invariant_expression!(container, 2.0 * variables["c1", 1]) | ||
| objective_function = get_objective_expression(container) | ||
| objective = get_objective_expression(objective_function) | ||
| JuMP.@objective(jump_model, MOI.MIN_SENSE, objective) | ||
| return | ||
| end | ||
|
|
||
| PrecompileTools.@setup_workload begin | ||
| PrecompileTools.@compile_workload begin | ||
| _run_precompile_workload() | ||
| end | ||
| end | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See one problem with this is that it is precompiling a bunch of methods for
_WorkloadVariable, which will never be used in any user's script.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, we need another strategy here. Perhaps the precompilation workload can use PSY or we can make better methods that can be precompiled correctly with appropriate typing