Skip to content

Commit

Permalink
Remove NamedBase class
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelFP committed Sep 27, 2023
1 parent d96813a commit 2177ab0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 44 deletions.
38 changes: 0 additions & 38 deletions optimas/core/base.py

This file was deleted.

18 changes: 15 additions & 3 deletions optimas/core/parameter.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
"""Contains the definition of the various optimization parameters."""

from typing import Optional, Any
import json

from pydantic import validator
from pydantic import BaseModel, Extra, validator
import numpy as np

from .base import NamedBase

def json_dumps_dtype(v, *, default):
"""Add support for dumping numpy dtype to json."""
for key, value in v.items():
if key == 'dtype':
v[key] = np.dtype(value).descr
return json.dumps(v)

class Parameter(NamedBase):

class Parameter(BaseModel):
"""Base class for all optimization parameters.
Parameters
Expand All @@ -19,6 +26,7 @@ class Parameter(NamedBase):
The data type of the parameter. Any object that can be converted to a
numpy dtype.
"""
name: str
dtype: Optional[Any]

def __init__(
Expand All @@ -37,6 +45,10 @@ def check_valid_out(cls, v):
raise ValueError(f"Unable to coerce '{v}' into a NumPy dtype.")
else:
return v

class Config:
extra = Extra.ignore
json_dumps = json_dumps_dtype


class VaryingParameter(Parameter):
Expand Down
7 changes: 4 additions & 3 deletions optimas/core/task.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Contains the definition of the Task class used for multitask optimization"""

from .base import NamedBase
from pydantic import BaseModel


class Task(NamedBase):
class Task(BaseModel):
"""Defines a task to be used in multitask optimization.
Parameters
Expand All @@ -15,6 +15,7 @@ class Task(NamedBase):
n_opt : int
Number of task evaluations to perform per optimization batch.
"""
name: str
n_init: int
n_opt: int

Expand All @@ -24,4 +25,4 @@ def __init__(
n_init: int,
n_opt: int
) -> None:
super().__init__(name, n_init=n_init, n_opt=n_opt)
super().__init__(name=name, n_init=n_init, n_opt=n_opt)

0 comments on commit 2177ab0

Please sign in to comment.