From 4a789cfef7efa8de80402b1b638a468852f6e6d3 Mon Sep 17 00:00:00 2001 From: Alexandros Evangelou Date: Thu, 21 Nov 2024 15:48:13 +0200 Subject: [PATCH 1/2] fix update setup info add default keyword argument block=True in update_setup_info and not only when status is in info Thsi is done because PyWelocme in order to update the task_idx with update_setup_info and we want to make sure it is done before open the window for starting the experiment. Also by adding makes it more clear when the block is used or not --- core/Experiment.py | 5 +++-- core/Logger.py | 25 ++++++++++++------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/core/Experiment.py b/core/Experiment.py index 811b6a21..d0f3de7f 100644 --- a/core/Experiment.py +++ b/core/Experiment.py @@ -1,4 +1,5 @@ import itertools +import logging import time from dataclasses import dataclass, field @@ -240,11 +241,11 @@ def _get_new_cond(self): if perf >= self.curr_cond['stair_up']: self.cur_block = self.curr_cond['next_up'] self.cur_block_sz = 0 - self.logger.update_setup_info({'difficulty': self.cur_block}) + self.logger.update_setup_info({'difficulty': self.cur_block, 'block': False}) elif perf < self.curr_cond['stair_down']: self.cur_block = self.curr_cond['next_down'] self.cur_block_sz = 0 - self.logger.update_setup_info({'difficulty': self.cur_block}) + self.logger.update_setup_info({'difficulty': self.cur_block, 'block': False}) if self.curr_cond['antibias']: anti_bias = self._anti_bias(choice_h, self.un_choices[self.un_blocks == self.cur_block]) condition_idx = np.logical_and(self.choices == anti_bias, self.blocks == self.cur_block) diff --git a/core/Logger.py b/core/Logger.py index 360741ab..63d09e2b 100755 --- a/core/Logger.py +++ b/core/Logger.py @@ -779,22 +779,22 @@ def check_connection(self, host="8.8.8.8", port=53, timeout=0.1): except socket.error: return False - def update_setup_info(self, info: Dict[str, Any], key: Optional[Dict[str, Any]] = None): + def update_setup_info(self, info: Dict[str, Any], key: Optional[Dict[str, Any]] = None, block: bool = True): """ - This method updates the setup information in Control table with the provided info and key. + Updates the setup information in the Control table with the provided info and key. - It first fetches the existing setup information from the experiment's Control table, - then updates it with the provided info. If 'status' is in the provided info, it blocks - and validates the update operation. + This method fetches the existing setup information from the experiment's Control table, + updates it with the provided info. If 'status' is included in the info, it sets the update status and + logs the caller's information. Args: - info (dict): The information to update the setup with. - key (dict, optional): Additional keys to fetch the setup information with. - Defaults to an empty dict. + info (dict): The information to update the setup with. This should include any + relevant fields, such as 'status' and 'notes'. + key (dict, optional): Additional keys to filter the setup information. If None, + defaults to an empty dictionary. - Side Effects: - Updates the setup_info attribute with the new setup information. - Updates the setup_status attribute with the new status. + Raises: + Exception: If an exception has occurred in threads running in logger. """ if self.thread_exception: self.thread_exception = None @@ -805,8 +805,7 @@ def update_setup_info(self, info: Dict[str, Any], key: Optional[Dict[str, Any]] if not public_conn.is_connected: set_connection() - block = True if "status" in info else False - if block: + if "status" in info: self.update_status.set() caller = inspect.stack()[1] caller_info = (f"Function called by {caller.function} " From 5bb10be6a13c4990b9778d81c7732c83b1298e22 Mon Sep 17 00:00:00 2001 From: Alexandros Evangelou Date: Thu, 21 Nov 2024 15:51:54 +0200 Subject: [PATCH 2/2] add missing keys in skipping and use logging when skipping use logging to show which keys are missing from the table --- core/Experiment.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/Experiment.py b/core/Experiment.py index d0f3de7f..37b73b53 100644 --- a/core/Experiment.py +++ b/core/Experiment.py @@ -184,8 +184,8 @@ def log_conditions(self, conditions, condition_tables=['Condition'], schema='exp for ctable in condition_tables: # insert dependant condition tables core = [field for field in self.logger.get_table_keys(schema, ctable, key_type='primary') if field != hsh] fields = [field for field in self.logger.get_table_keys(schema, ctable)] - if not np.all([np.any(np.array(k) == list(cond.keys())) for k in fields]): - if self.logger.manual_run: print('skipping ', ctable) + if not all(k in cond for k in fields): + logging.warning("skipping table: %s, because of missing attributes: %s", ctable, [k for k in fields if k not in cond]) continue # only insert complete tuples if core and hasattr(cond[core[0]], '__iter__'): for idx, pcond in enumerate(cond[core[0]]):