-
Notifications
You must be signed in to change notification settings - Fork 38
Allow for connections including slice specifications #774
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
base: develop
Are you sure you want to change the base?
Changes from all commits
e117db0
5866469
986b536
8f8d5b0
700db44
f414c21
fcd3e02
3ca1e97
2c85261
a6c53cf
97f0fd6
5fc2abd
3ebf8e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,6 +61,31 @@ There are two connection formats: | |
| The `source_parameter` and `destination_parameter` should be input into the array as another array. If it's input as a tuple the model will raise an error. | ||
| ``` | ||
|
|
||
| ##### Slice notation for mismatched shapes | ||
|
|
||
| 3-element connections with different shared parameter names allow the user to append a NumPy-style slice in square brackets to the source and/or destination parameter name. | ||
| This is used to connect variables whose shapes differ, for example feeding a scalar finance output into a per-timestep input. | ||
| The slice is parsed into OpenMDAO `src_indices`, and the bracketed text is stripped from the parameter name before the connection is made. | ||
|
|
||
| ```yaml | ||
| technology_interconnections: [ | ||
| # select a subset of the source to connect to the destination | ||
| ["tech_a", "tech_b", ["source_param[0:100]", "dest_param"]], | ||
| # tile a single source element across an 8760-length destination | ||
| ["finance_subgroup_electricity", "grid_buy", ["LCOE[0]", "electricity_buy_price[0:8760]"]], | ||
| ] | ||
| ``` | ||
|
|
||
| Behavior depends on which side carries a slice: | ||
|
|
||
| - **Source only** (`"source_param[0:100]"`): the slice selects source indices directly (supports start/stop/step, e.g. `[0:100:2]`, and `[:]` for the full range). | ||
| - **Destination only** or **both sides equal**: no `src_indices` are applied (the slice is treated as documentation of the target shape). | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Idk if the definition of "destination only" needs to be explained here? Isn't "Destination only" when we don't specify indices?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that is what it means by "no |
||
| - **Both sides** (`"LCOE[0]"` → `"electricity_buy_price[0:8760]"`): the source indices are *tiled* to fill the destination length. A single index is repeated (e.g. `[0]` → 8760 copies) and a multi-index source such as `[0,1]` is cycled to fill the destination. | ||
|
|
||
| ```{note} | ||
| When the destination has a slice, it must (1) start at `0` (a non-zero start raises a `ValueError`) and (2) include the destination length, e.g. `[0:8760]`. The length is required because the input shape is not known until `prob.setup()` has run. | ||
| ``` | ||
|
|
||
| ### Internal connection logic | ||
|
|
||
| H2Integrate processes these connections in the `connect_technologies()` method of `h2integrate_model.py`. Here's what happens internally: | ||
|
|
||
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.
Clarification question: When it's "Source only", then the destination length isn't needed? Does this mean that if my
source_paramis a 100 element array and my destination is a 50 element array, then I just need to do the connection as["source_tech", "destination_tech", ["source_param[0:100:2]", "destination_param"]]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.
Yes, that is correct.