Skip to content

Commit

Permalink
Fix merge error and move MissingDependencyError into metahyper
Browse files Browse the repository at this point in the history
  • Loading branch information
karibbov committed Nov 21, 2023
1 parent a07bc60 commit 4885382
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 24 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ typing-extensions = "^4"
# jahs-bench = {git = "https://github.com/automl/jahs_bench_201.git", rev = "v1.0.2"}
mkdocs-material = "^8.1.3"
mike = "^1.1.2"
torchvision = "<0.16.0" # Used in examples


[tool.poetry.group.experimental]
optional = true

[tool.poetry.group.experimental.dependencies]
gpytorch = "1.8.0"
torchvision = "<0.16.0" # Used in examples

[build-system]
requires = ["poetry-core>=1.1.0"]
Expand Down
19 changes: 16 additions & 3 deletions src/metahyper/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ def get_data_representation(data: Any):
return data


class MissingDependencyError(Exception):
def __init__(self, dep: str, cause: Exception, *args: Any):
super().__init__(dep, cause, *args)
self.dep = dep
self.__cause__ = cause # This is what `raise a from b` does

def __str__(self) -> str:
return (
f"Some required dependency-({self.dep}) to use this optional feature is "
f"missing. Please, include neps[experimental] dependency group in your "
f"installation of neps to be able to use all the optional features."
f" Otherwise, just install ({self.dep})"
)


class YamlSerializer:
SUFFIX = ".yaml"
PRE_SERIALIZE = True
Expand Down Expand Up @@ -140,9 +155,7 @@ def instance_from_map(
else:
raise ValueError(f"Object {request} invalid key for {name}")

# The case for MissingDependencyError,
# but can't import it here due to circular import risk
if isinstance(instance, Exception):
if isinstance(instance, MissingDependencyError):
raise instance

# Check if the request is a class if it is mandatory
Expand Down
7 changes: 3 additions & 4 deletions src/neps/optimizers/bayesian_optimization/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from ....utils.common import MissingDependencyError
from metahyper.utils import MissingDependencyError

from .gp import ComprehensiveGP
from .gp_hierarchy import ComprehensiveGPHierarchy

Expand All @@ -16,7 +17,5 @@
"deep_gp": DeepGP,
"gp": ComprehensiveGP,
"gp_hierarchy": ComprehensiveGPHierarchy,
"pfn": PFN_SURROGATE
"pfn": PFN_SURROGATE,
}


16 changes: 0 additions & 16 deletions src/neps/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import os
import random
from pathlib import Path
from typing import Any

import numpy as np
import torch
Expand Down Expand Up @@ -271,21 +270,6 @@ def set_rnd_state(state: dict):
)


class MissingDependencyError(Exception):
def __init__(self, dep: str, cause: Exception, *args: Any):
super().__init__(dep, cause, *args)
self.dep = dep
self.__cause__ = cause # This is what `raise a from b` does

def __str__(self) -> str:
return (
f"Some required dependency-({self.dep}) to use this optional feature is "
f"missing. Please, include neps[experimental] dependency group in your "
f"installation of neps to be able to use all the optional features."
f" Otherwise, just install ({self.dep})"
)


class AttrDict(dict):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand Down

0 comments on commit 4885382

Please sign in to comment.