Skip to content

Clean up some methods in dual module#629

Merged
bobbyxng merged 5 commits into
dualfrom
dual-cleanup
Apr 8, 2026
Merged

Clean up some methods in dual module#629
bobbyxng merged 5 commits into
dualfrom
dual-cleanup

Conversation

@brynpickering

Copy link
Copy Markdown
Contributor

Suggestions to:

  • improve maintainability by spinning out repeated code into reusable functions
  • reduce memory overhead by avoiding creating flattened arrays where possible

Checklist

  • Code changes are sufficiently documented; i.e. new functions contain docstrings and further explanations may be given in doc.
  • Unit tests for new features were added (if applicable).
  • A note for the release notes doc/release_notes.rst of the upcoming release is included.
  • I consent to the release of this PR's code under the MIT license.

@brynpickering
brynpickering requested a review from bobbyxng March 20, 2026 16:31
@brynpickering brynpickering mentioned this pull request Mar 20, 2026
4 tasks
@FabianHofmann

Copy link
Copy Markdown
Collaborator

@bobbyxng pinging you on this :)

@bobbyxng

bobbyxng commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

Just got back from holidays, sorry for the late feedback! @FabianHofmann @brynpickering
Thanks a lot @brynpickering for the improvements, this looks way more efficient. I tested this branch and everything still works as it's supposed to, so I will merge your changes into the dual branch.

@bobbyxng
bobbyxng merged commit 3e0f512 into dual Apr 8, 2026
4 of 17 checks passed
@bobbyxng
bobbyxng deleted the dual-cleanup branch April 8, 2026 11:53
FabianHofmann added a commit that referenced this pull request Jun 9, 2026
* Added m.copy() method.

* Added testing suite for m.copy().

* Fix solver_dir type annotation.

* Bug fix: xarray copyies need to be .

* Intial commit: Working dualizer for LPs.

* Fixed typing issues. Initialise dual objective with LinearExpression(None) instead of 0.

* Fixed more typing issues.

* Added code-block to dualize() examples.

* Fix more typing issues.

* Fixed variable bounds for dualisation of max problems (primal) --> reverse sign.

* Updated docstrings for max -> min.

* Moved copy to io.py, added deep-copy to all xarray operations.

* Improved copy method: Strengtheninc copy protocol compatibility, check for deep copy independence.

* Added release notes.

* Made Model.copy defaulting to deep copy more explicit.

* Fine-tuned docs and added to read the docs api.rst.

* Clean up some methods in `dual` module (#629)

* Clean up some methods in `dual` module

* Typing fix (L434).

* Ignore type assessment in expressions.py

---------

Co-authored-by: Bobby Xiong <bobbyxng@gmail.com>
Co-authored-by: Lukas Trippe <lkstrp@pm.me>

* fix: use dimension coords only when adding dual variables to avoid scalar coord conflicts.

* fix CI testing issues

* refactor dualisation, update tests, modularise functions and vectorise code

* rename to _lift_bounds_to_constraints and make private

* refactor, improve docstrings

* improve readability, docstring formats, testing suite

* fix typing in pytests

* fix typing in pytests

* improve test coverage and remove non-supported objective constant

* Fix cases where constraints and variables of the same block/name can have different signs and/or bounds. Add tests

* revert test-models.yml environments to upstream, see PR 522

* add release notes and improve docstrings of m.dualize()

* docstring improvements

* Rename dual.py to dualization.py; fix array coords, strip comments, dedupe lookups

Use con.indexes[dim] (pd.Index) for dual variable coords so dualizing
dimensioned models no longer raises TypeError. Collapse the duplicated
bounded-gather and bound-lifting blocks into shared helpers.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Annotate _gather_with_default result to satisfy mypy

---------

Co-authored-by: Bryn Pickering <17178478+brynpickering@users.noreply.github.com>
Co-authored-by: Lukas Trippe <lkstrp@pm.me>
Co-authored-by: Fabian Hofmann <fab.hof@gmx.de>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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.

4 participants