Skip to content

Tidy decisions code#846

Draft
tsmbland wants to merge 4 commits into
mainfrom
tidy_decisions_code
Draft

Tidy decisions code#846
tsmbland wants to merge 4 commits into
mainfrom
tidy_decisions_code

Conversation

@tsmbland

@tsmbland tsmbland commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

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

  • New feature (non-breaking change which adds functionality)
  • Optimization (non-breaking, back-end change that speeds up the code)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (whatever its nature)

Key checklist

  • All tests pass: $ python -m pytest
  • The documentation builds and looks OK: $ python -m sphinx -b html docs docs/build

Further checks

  • Code is commented, particularly in hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

Comment thread src/muse/decisions.py Fixed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) within src/muse/decisions.py and removes the old utilities.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 thread src/muse/decisions.py
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 thread src/muse/decisions.py
Comment on lines +401 to 403
# Remove obj_data parameters if present
optimize_name, optimize_minimize, _ = parameters[0]

Comment thread src/muse/decisions.py
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 thread docs/inputs/agents.rst
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 thread docs/inputs/agents.rst
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 thread docs/inputs/agents.rst
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 thread src/muse/decisions.py
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 thread src/muse/decisions.py
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``.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants