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

modify the generator object to process np.array argument (and convert from string to list) #355

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 4 additions & 1 deletion aepsych/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"(?<!,)\s+", ",", v)
if re.search(r"^\[.*\]$", v, flags=re.DOTALL):
if v == "[]": # empty list
return []
else:
Expand Down
6 changes: 6 additions & 0 deletions aepsych/generators/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import abc
from inspect import signature
from typing import Any, Dict, Generic, Protocol, runtime_checkable, TypeVar, Optional
import re

import torch
from aepsych.config import Config
Expand Down Expand Up @@ -73,9 +74,14 @@ def _get_acqf_options(cls, acqf: AcquisitionFunction, config: Config):
for k in acqf_args_expected:
# if this thing is configured
if k in full_section.keys():
v = config.get(acqf_name, k)
# if it's an object make it an object
if full_section[k] in Config.registered_names.keys():
extra_acqf_args[k] = config.getobj(acqf_name, k)
elif re.search(
r"^\[.*\]$", v, flags=re.DOTALL
): # use regex to check if the value is a list
extra_acqf_args[k] = config._str_to_list(v) # type: ignore
else:
# otherwise try a float
try:
Expand Down
Loading