Tidy decisions code#846
Draft
tsmbland wants to merge 4 commits into
Draft
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors (“tidies”) the lexicographic (lexo) and epsilon decision-method implementations in muse.decisions and updates tests/documentation to match the new structure and improved inline explanations.
Changes:
- Moves/rewrites lexicographic tuple construction into a private helper (
_lexical_comparison) withinsrc/muse/decisions.pyand removes the oldutilities.lexical_comparison. - Refactors epsilon/retro-epsilon constraint logic for readability and updates tests accordingly.
- Updates agent input documentation to better describe decision methods and objective parameter columns.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
tests/test_utilities.py |
Removes the prior lexical_comparison test helpers/tests from utilities tests. |
tests/test_decisions.py |
Updates decision tests (lexo + epsilon) and improves test documentation/comments. |
src/muse/utilities.py |
Removes the old lexical_comparison helper implementation. |
src/muse/decisions.py |
Major refactor of lexo/retro-lexo and epsilon/retro-epsilon logic; adds _lexical_comparison. |
docs/inputs/agents.rst |
Documentation updates for obj_data* meaning and decision method descriptions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+449
to
+456
| # Work in the same transformed logic as epsilon_constraints | ||
| sign = -1 if minimize else 1 | ||
|
|
||
| # Ensure current asset is not excluded by its own constraint | ||
| adjusted = current.where( | ||
| (sign * current) <= (sign * epsilon), | ||
| epsilon, | ||
| ) |
Comment on lines
+401
to
403
| # Remove obj_data parameters if present | ||
| optimize_name, optimize_minimize, _ = parameters[0] | ||
|
|
Comment on lines
+312
to
+316
| Lexical comparison operates by binning the objectives into bins of width | ||
| ``binwidths``. Once binned, dimensions other than ``asset`` and | ||
| ``replacement`` are reduced by taking the maximum (e.g. the largest | ||
| constraint). Finally, the objectives are ranked lexicographically in the | ||
| order given by ``order``. |
Comment on lines
104
to
+106
| ``obj_data1`` | ||
| A weight associated with the objective. | ||
| Whether it is used will depend in large part on the :ref:`decision method <decision_method>`. | ||
| A value associated with the objective. | ||
| Its meaning, and whether it is used at all, will depend in large part on the :ref:`decision method <decision_method>`. |
Comment on lines
+176
to
+180
| - :py:func:`lexical_comparion <lexical_comparison>`: Ranks technologies using a | ||
| priority ordering of objectives. The first objective is considered within a | ||
| tolerance defined by ``obj_data1`` (e.g. 0.1 corresponds to a 10% tolerance), and | ||
| only distinguishes technologies outside this tolerance. Subsequent objectives | ||
| (``obj_data2``, ``obj_data3``) are used to break ties. Aliased to "lexo". |
Comment on lines
+181
to
+184
| - :py:func:`retro_lexical_comparion <retro_lexical_comparison>`: A variant of lexical | ||
| comparison where tolerances are adjusted so that existing technologies remain | ||
| feasible for comparison. Otherwise, behaviour matches ``lexical_comparison``. | ||
| Aliased to "retro_lexo". |
Comment on lines
+183
to
+187
| where o_i^j are the objective values of the candidate replacements and the | ||
| minimum is taken over the replacement dimension. Once binned, dimensions | ||
| other than ``asset`` and ``replacement`` are reduced by taking the maximum | ||
| (e.g. the largest constraint). Finally, the objectives are ranked | ||
| lexicographically in the order given by ``parameters``. |
Comment on lines
+256
to
+259
| where o_i are the objective values of the current assets. Once binned, | ||
| dimensions other than ``asset`` and ``replacement`` are reduced by taking | ||
| the maximum (e.g. the largest constraint). Finally, the objectives are | ||
| ranked lexicographically in the order given by ``parameters``. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Tidying the lexico/epsilon decisions code to make it more readable. Shouldn't be any functional changes here.
Also improving the documentation.
Fixes # (issue)
Type of change
Key checklist
$ python -m pytest$ python -m sphinx -b html docs docs/buildFurther checks