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

Implement OptimizerProtocol for mypy checking. #103

Closed
c-bata opened this issue Apr 4, 2021 · 0 comments
Closed

Implement OptimizerProtocol for mypy checking. #103

c-bata opened this issue Apr 4, 2021 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@c-bata
Copy link
Collaborator

c-bata commented Apr 4, 2021

To implement CMA-ES variants, it is better to provide a protocol for optimizer API (See PEP 544 or Python docs for details).

Probably, the protocol will be like this:

import numpy as np
from typing import List, Optional, Tuple

try:
    from typing import Protocol
except ImportError:
    from typing_extensions import Protocol


class Optimizer(Protocol):
    @property
    def dim(self) -> int:
        """A number of dimensions"""

    @property
    def generation(self) -> int:
        """Generation number which is monotonically incremented
        when multi-variate gaussian distribution is updated."""

    @property
    def population_size(self) -> int:
        """A population size"""

    def ask(self) -> np.ndarray:
        """Sample a parameter"""

    def tell(self, solutions: List[Tuple[np.ndarray, float]]) -> None:
        """Tell evaluation values"""

    def set_bounds(self, bounds: Optional[np.ndarray]) -> None:
        """Update boundary constraints"""
@c-bata c-bata added the enhancement New feature or request label Apr 4, 2021
@c-bata c-bata self-assigned this Sep 1, 2021
@c-bata c-bata closed this as completed Mar 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant