PyPSA / linopy

Linear optimization with N-D labeled arrays in Python
https://linopy.readthedocs.io
MIT License
162 stars 44 forks source link

Add a subsection for modification of variable bounds in docs #269

Closed fwitte closed 5 months ago

fwitte commented 5 months ago

I was trying to modify variable bounds instead of creating additional constraints for already instantiated variables and could not find a subsection in the respective chapter. It does not work with something like variable.loc[slice, other_slice].lower = 42 and I did not immediately understand why, so I thought a hint on how to do this might be useful.

If this is bad practice, I would be happy to get a rejection of the PR (and also be curious why it would be :)).

Thank you!

codecov[bot] commented 5 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 85.78%. Comparing base (3c11dc5) to head (8678fa7).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #269 +/- ## ========================================== - Coverage 88.94% 85.78% -3.16% ========================================== Files 15 15 Lines 3645 3645 Branches 856 856 ========================================== - Hits 3242 3127 -115 - Misses 279 403 +124 + Partials 124 115 -9 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

fwitte commented 5 months ago

I blindly overlook the section, I was only reading the variables one... Nevertheless, including how to slice variable.lower.loc[slice, other] instead of variable.loc[slice, other].lower might be useful

FabianHofmann commented 5 months ago

@fwitte thank you for your contribution. Setting the bounds on a selection of variables does not work, as the .loc function returns a copy of the original data. Therefore, the bound will only set to the copy and not the variable selection itself. Would you mind adding a note there, that this case is not supported (yet)?

FabianHofmann commented 5 months ago

I blindly overlook the section, I was only reading the variables one... Nevertheless, including how to slice variable.lower.loc[slice, other] instead of variable.loc[slice, other].lower might be useful

no worries

fwitte commented 5 months ago

It does work, if you access the xarray.DataArray like this: variable.lower.loc[slice, other], not sure if it is intentional.

fwitte commented 5 months ago

I added the hint and explanation, which of both version work. It is now in the Variables section. If this is of interest, let me know if I should reopen the PR and/or move the information to the Modifying the Model section.

Have a nice day