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

Remove topological sort #550

Open
wants to merge 1 commit into
base: patch/fddaq-v5.2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions python/daqconf/cider/app_structures/main_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ class MainScreen(Screen):
BINDINGS = [
# Binding("ctrl+s", "save_configuration", "Save Configuration"),
Binding("ctrl+s", "save_configuration_with_message", "Save Configuration"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason to keep the Ctrl modifier for save and quit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For save it's just because ctrl+s is the standard save option. For quit+delete there's no reason beyond it being slightly harder to accidentally hit those keys and bring up an annoying popup menu

Binding("ctrl+o", "open_configuration", "Open Configuration"),
Binding("o", "open_configuration", "Open Configuration"),
Binding("ctrl+q", "request_quit", "Exit Cider"),
Binding("ctrl+e", "modify_relations", "Modify Relation to Object"),
Binding("ctrl+r", "rename_configuration", "Rename Conf Object"),
Binding("e", "modify_relations", "Modify Relation to Object"),
Binding("r", "rename_configuration", "Rename Conf Object"),
Binding("d", "toggle_disable", "Toggle Disable"),
Binding("ctrl+a", "add_configuration", "Add Conf Object"),
Binding("a", "add_configuration", "Add Conf Object"),
Binding("ctrl+d", "destroy_configuration", "Delete Conf Object"),
]

Expand Down
47 changes: 42 additions & 5 deletions python/daqconf/cider/data_structures/relational_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,39 @@

from daqconf.cider.data_structures.configuration_handler import ConfigurationHandler

class RelationalGraph:
def __init__(self, config_handler: ConfigurationHandler):
self._handler = config_handler

self.__generate_adjacency_matrix()

def __generate_adjacency_matrix(self):
"""Generates adjacency matrix from configuration handler object i.e. finds connected DALs
"""
self._adjacency_matrix = np.zeros((self._handler.n_dals, self._handler.n_dals))

for i, dal in enumerate(self._handler.conf_obj_list):
for connection_category in self._handler.get_relationships_for_conf_object(dal):
# Allows for multiply connected nodes
for connection in list(connection_category.values())[0]:
# Loop over just conf objects
self._adjacency_matrix[i][self._handler.conf_obj_list.index(connection)] += 1

@property
def adjacency_matrix(self)->NDArray:
return self._adjacency_matrix

@property
def top_level_nodes(self):
# Means we automatically rebuild the graph, this is inefficient but vaguely fine
self.__generate_adjacency_matrix()
return [dal for i, dal in enumerate(self._handler.conf_obj_list) if np.all(self.adjacency_matrix[i])==0]


'''
HW: Leaving here for now for posterity, this is a great way to organise a FIXED configuration
but is horribly slow for constant updates

class RelationalGraph:
def __init__(self, config_handler: ConfigurationHandler):
"""Construct relational graph
Expand Down Expand Up @@ -105,24 +138,28 @@ def __longest_path(self, start_id: int):
return dist

def __calculate_longest_paths(self)->None:
'''
"""
Idea is to find shortest paths on -G for each top level node where G is the connection graph.
Layer each item lives on is then simply max(longest_path) for each top level item
'''
"""

self._topological_ordered_matrix = self.__get_topological_order()
for node_id in range(self._handler.n_dals):
self._max_distance = np.maximum(self._max_distance, self.__longest_path(node_id))

self._max_distance = self._max_distance.astype(int)

def add_node(self, node_dal):
pass

def remove_node(self, node_dal):
pass

@property
def top_level_nodes(self):
# Means we automatically rebuild the graph
if len(self._max_distance!=len(self._handler.conf_obj_list)):
self.generate_graph()

return [dal for i, dal in enumerate(self._handler.conf_obj_list) if self._max_distance[i]==0]



'''