forked from experimental-design/bofire
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Task Feature (experimental-design#360)
- Loading branch information
Showing
8 changed files
with
136 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from typing import ClassVar, List, Literal | ||
|
||
import numpy as np | ||
from pydantic import model_validator | ||
|
||
from bofire.data_models.features.categorical import CategoricalInput | ||
|
||
|
||
class TaskInput(CategoricalInput): | ||
order_id: ClassVar[int] = 8 | ||
type: Literal["TaskInput"] = "TaskInput" | ||
fidelities: List[int] = [] | ||
|
||
@model_validator(mode="after") | ||
def validate_fidelities(self): | ||
n_tasks = len(self.categories) | ||
if self.fidelities == []: | ||
for _ in range(n_tasks): | ||
self.fidelities.append(0) | ||
if len(self.fidelities) != n_tasks: | ||
raise ValueError( | ||
"Length of fidelity lists must be equal to the number of tasks" | ||
) | ||
if list(set(self.fidelities)) != list(range(np.max(self.fidelities) + 1)): | ||
raise ValueError( | ||
"Fidelities must be a list containing integers, starting from 0 and increasing by 1" | ||
) | ||
return self |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from bofire.data_models.features.api import TaskInput | ||
|
||
|
||
def test_validate_fidelities_default_generation(): | ||
feat = TaskInput( | ||
key="task", | ||
categories=["p1", "p2"], | ||
) | ||
assert feat.fidelities == [0, 0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters