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

10 add deprecation warning or fallback for old config type = syntax #29

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
21 changes: 16 additions & 5 deletions agentlib/core/module.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""This module contains the base AgentModule."""

from __future__ import annotations

import abc
import json
import logging
Expand All @@ -18,19 +20,19 @@

import pydantic
from pydantic import field_validator, ConfigDict, BaseModel, Field, PrivateAttr
from pydantic_core import core_schema
from pydantic.json_schema import GenerateJsonSchema
from pydantic_core import core_schema

from agentlib.core.environment import CustomSimpyEnvironment
from agentlib.core.errors import ConfigurationError
import agentlib.core.logging_ as agentlib_logging
from agentlib.core import datamodels
from agentlib.core.datamodels import (
AgentVariable,
Source,
AgentVariables,
AttrsToPydanticAdaptor,
)
from agentlib.core import datamodels
import agentlib.core.logging_ as agentlib_logging
from agentlib.core.environment import CustomSimpyEnvironment
from agentlib.core.errors import ConfigurationError
from agentlib.utils.fuzzy_matching import fuzzy_match, RAPIDFUZZ_IS_INSTALLED
from agentlib.utils.validators import (
include_defaults_in_root,
Expand Down Expand Up @@ -366,6 +368,15 @@ def __init__(self, *, config: dict, agent: Agent):

@classmethod
def get_config_type(cls) -> Type[BaseModuleConfigClass]:
if hasattr(cls, "config_type"):
raise AttributeError(
"The 'config_type' attribute is deprecated and has been removed. "
"Please use the following syntax to assign the config of your custom "
f"module '{cls.__name__}': \n"
"class MyModule(agentlib.BaseModule):\n"
" config: MyConfigClass\n"
)

return get_type_hints(cls).get("config")

@abc.abstractmethod
Expand Down
7 changes: 4 additions & 3 deletions agentlib/models/scipy_model.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""This module contains the ScipyStateSpaceModel class."""

import logging
from typing import Union
from pydantic import ValidationError, model_validator

import numpy as np
from pydantic import ValidationError, model_validator

from agentlib.core.errors import OptionalDependencyError

Expand All @@ -25,7 +26,7 @@
class ScipyStateSpaceModelConfig(ModelConfig):
"""Customize config of Model."""

system: Union[dict, list, tuple, signal.ltisys.StateSpaceContinuous]
system: Union[dict, list, tuple, signal.StateSpace]

@model_validator(mode="before")
@classmethod
Expand Down Expand Up @@ -98,7 +99,7 @@ class ScipyStateSpaceModel(Model):
def __init__(self, **kwargs):
super().__init__(**kwargs)
# Check if system was correctly set up
assert isinstance(self.config.system, signal.ltisys.StateSpaceContinuous)
assert isinstance(self.config.system, signal.StateSpace)

def do_step(self, *, t_start, t_sample=None):
if t_sample is None:
Expand Down