From 6a5ddb83b48dc48e6fab066b47ac9c706660583b Mon Sep 17 00:00:00 2001 From: Wenxuan Guo Date: Thu, 6 Jun 2024 08:45:48 -0700 Subject: [PATCH] modify the generator object to process np.array argument (and convert from string to list) (#355) Summary: Pull Request resolved: https://github.com/facebookresearch/aepsych/pull/355 We modified the generator object to process np.array argument: In the config dictionary, we specify the target argument of any child class of the `LookaheadAcquisitionFunction` class as a numpy array. The config processed the numpy array as a string using self.from_dict. We have modified (1) the `_str_to_list` function of the Config class in config.py to accept a broader range of string representations of lists, including those with "\n" escape characters and white spaces. The function will properly convert these strings to list. (2) the `_get_acqf_options` function of the `AEPsychGenerator` class in base.py. The function uses regex to detect list argument in a string for any acquisition arguments and calls the `_str_to_list` function to convert it to a list. Reviewed By: crasanders Differential Revision: D58163715 fbshipit-source-id: e0654a011c8168f88321fd022ba08704b3c91b01 --- aepsych/config.py | 5 ++++- aepsych/generators/base.py | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/aepsych/config.py b/aepsych/config.py index bf1024c12..b3e8f209e 100644 --- a/aepsych/config.py +++ b/aepsych/config.py @@ -6,6 +6,7 @@ # LICENSE file in the root directory of this source tree. import abc import ast +import re import configparser import json import warnings @@ -163,7 +164,9 @@ def update( del self["experiment"] def _str_to_list(self, v: str, element_type: _T = float) -> List[_T]: - if v[0] == "[" and v[-1] == "]": + v = re.sub(r"\n ", ",", v) + v = re.sub(r"(?