Skip to content

Commit

Permalink
Remove children_list as it shadows children
Browse files Browse the repository at this point in the history
Remove unused RealStatusColorHint
Fix get_successful_realizations
  • Loading branch information
andreas-el committed Aug 29, 2024
1 parent 3bbf851 commit 2448875
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/ert/ensemble_evaluator/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def get_successful_realizations(self) -> typing.List[int]:
return [
int(real_idx)
for real_idx, real_data in self._realization_states.items()
if real_data[ids.STATUS] == state.REALIZATION_STATE_FINISHED
if real_data.get(ids.STATUS, "") == state.REALIZATION_STATE_FINISHED
]

def aggregate_real_states(self) -> typing.Dict[str, int]:
Expand Down
6 changes: 0 additions & 6 deletions src/ert/gui/model/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,12 @@ def row(self) -> int:
class RootNode(_Node):
parent: None = field(default=None, init=False)
children: dict[str, IterNode] = field(default_factory=dict)
children_list: list[IterNode] = field(default_factory=list)
max_memory_usage: Optional[int] = None

def add_child(self, node: _Node) -> None:
node = cast(IterNode, node)
node.parent = self
self.children[node.id_] = node
self.children_list.append(node)


@dataclass
Expand All @@ -61,13 +59,11 @@ class IterNode(_Node):
parent: Optional[RootNode] = None
data: IterNodeData = field(default_factory=IterNodeData)
children: dict[str, RealNode] = field(default_factory=dict)
children_list: list[RealNode] = field(default_factory=list)

def add_child(self, node: _Node) -> None:
node = cast(RealNode, node)
node.parent = self
self.children[node.id_] = node
self.children_list.append(node)


@dataclass
Expand All @@ -89,13 +85,11 @@ class RealNode(_Node):
parent: Optional[IterNode] = None
data: RealNodeData = field(default_factory=RealNodeData)
children: dict[str, ForwardModelStepNode] = field(default_factory=dict)
children_list: list[ForwardModelStepNode] = field(default_factory=list)

def add_child(self, node: _Node) -> None:
node = cast(ForwardModelStepNode, node)
node.parent = self
self.children[node.id_] = node
self.children_list.append(node)


@dataclass
Expand Down
11 changes: 4 additions & 7 deletions src/ert/gui/model/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
UserRole = Qt.ItemDataRole.UserRole
NodeRole = UserRole + 1
RealJobColorHint = UserRole + 2
RealStatusColorHint = UserRole + 3
RealLabelHint = UserRole + 4
ProgressRole = UserRole + 5
FileRole = UserRole + 6
Expand Down Expand Up @@ -269,10 +268,10 @@ def _add_snapshot(self, snapshot: Snapshot, iter_: str) -> None:
real_node.add_child(job_node)

if iter_ in self.root.children:
self.modelAboutToBeReset.emit()
self.root.children[iter_] = snapshot_tree
self.beginResetModel()
snapshot_tree.parent = self.root
self.modelReset.emit()
self.root.children[iter_] = snapshot_tree
self.endResetModel()
return

parent = QModelIndex()
Expand Down Expand Up @@ -382,8 +381,6 @@ def _real_data(_: QModelIndex, node: RealNode, role: int) -> Any:
return node.id_
if role == IterNum:
return node.parent.id_ if node.parent else None
if role == RealStatusColorHint:
return node.data.real_status_color
if role == StatusRole:
return node.data.status
if role == MemoryUsageRole:
Expand Down Expand Up @@ -491,7 +488,7 @@ def index(

parent_item = self.root if not parent.isValid() else parent.internalPointer()
try:
child_item = parent_item.children_list[row]
child_item = list(parent_item.children.values())[row]
except KeyError:
return QModelIndex()
else:
Expand Down
17 changes: 14 additions & 3 deletions tests/unit_tests/gui/model/test_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from qtpy.QtGui import QColor

from ert.ensemble_evaluator.state import COLOR_FAILED
from ert.gui.model.snapshot import RealJobColorHint, RealStatusColorHint, SnapshotModel
from ert.gui.model.snapshot import RealJobColorHint, SnapshotModel

from .gui_models_utils import finish_snapshot

Expand Down Expand Up @@ -44,9 +44,20 @@ def test_realization_state_is_queue_finalized_state(fail_snapshot):
model._add_snapshot(SnapshotModel.prerender(fail_snapshot), "0")
first_real = model.index(0, 0, model.index(0, 0))

queue_color = model.data(first_real, RealStatusColorHint)
assert queue_color == QColor(*COLOR_FAILED)
color, done_count, full_count = model.data(first_real, RealJobColorHint)
assert color == QColor(*COLOR_FAILED)
assert done_count == 1
assert full_count == 1


def test_snapshot_model_data_intact_on_full_update(full_snapshot, fail_snapshot):
model = SnapshotModel()
model._add_snapshot(SnapshotModel.prerender(full_snapshot), "0")

first_real = model.index(0, 0, model.index(0, 0))
assert first_real.internalPointer().children["0"].data["status"] == "Pending"
# Update with a different snapshot, -- data should change accordingly
model._add_snapshot(SnapshotModel.prerender(fail_snapshot), "0")
first_real = model.index(0, 0, model.index(0, 0))

assert first_real.internalPointer().children["0"].data["status"] == "Finished"

0 comments on commit 2448875

Please sign in to comment.