Skip to content
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

[Backport] Improve ordering in k_matrix involved_compartments function #791

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions glotaran/builtin/models/kinetic_image/k_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,16 @@ def empty(cls, label: str, compartments: list[str]) -> KMatrix:

def involved_compartments(self) -> list[str]:
"""A list of all compartments in the Matrix."""
# TODO: find a better way that preserves ordering as defined in initial_concentrations
compartments = []
for index in self.matrix:
compartments.append(index[0])
compartments.append(index[1])
if index[0] not in compartments:
compartments.append(index[0])
if index[1] not in compartments:
compartments.append(index[1])

compartments = list(set(compartments))
# Don't use set, it randomly reorders the compartments.
# compartments = list(set(compartments))
return compartments

def combine(self, k_matrix: KMatrix) -> KMatrix:
Expand Down