Skip to content

Commit

Permalink
removes external black boxes and problem factory scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgondu committed Jul 25, 2024
1 parent b275ae2 commit 44ab475
Show file tree
Hide file tree
Showing 11 changed files with 10 additions and 540 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

5 changes: 1 addition & 4 deletions src/poli/core/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@
"""

import configparser
import subprocess
import warnings
from pathlib import Path
from typing import Dict, List, Type, Union
from typing import List, Type, Union

from poli.core.abstract_black_box import AbstractBlackBox
from poli.core.abstract_isolated_function import AbstractIsolatedFunction
from poli.core.abstract_problem_factory import AbstractProblemFactory
from poli.core.util.abstract_observer import AbstractObserver
from poli.core.util.objective_management.make_run_script import (
make_isolated_function_script,
make_observer_script,
make_run_script,
)

# from poli.objective_repository import AVAILABLE_PROBLEM_FACTORIES, AVAILABLE_OBJECTIVES
Expand Down
133 changes: 0 additions & 133 deletions src/poli/core/util/isolation/external_black_box.py

This file was deleted.

59 changes: 7 additions & 52 deletions src/poli/core/util/objective_management/make_run_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
from pathlib import Path
from typing import List, Type, Union

from poli import external_isolated_function_script, external_problem_factory_script
from poli.core.abstract_black_box import AbstractBlackBox
from poli import external_isolated_function_script
from poli.core.abstract_isolated_function import AbstractIsolatedFunction
from poli.core.abstract_problem_factory import AbstractProblemFactory
from poli.core.util import observer_wrapper
from poli.core.util.abstract_observer import AbstractObserver
from poli.external_problem_factory_script import ADDITIONAL_IMPORT_SEARCH_PATHES_KEY
from poli.external_isolated_function_script import ADDITIONAL_IMPORT_SEARCH_PATHES_KEY

# By default, we will store the run scripts inside the
# home folder of the user, on the hidden folder
Expand Down Expand Up @@ -52,44 +50,11 @@ def make_isolated_function_script(
"""
command = inspect.getfile(external_isolated_function_script)
return _make_run_script(
return _make_run_script_from_template(
command, isolated_function, conda_environment_name, python_paths, cwd, **kwargs
)


def make_run_script(
problem_factory: Type[AbstractProblemFactory],
conda_environment_name: Union[str, Path] = None,
python_paths: List[str] = None,
cwd=None,
**kwargs,
) -> str:
"""
Create a run script for a given problem factory.
Parameters
----------
problem_factory : AbstractProblemFactory
The problem factory to create the run script for.
conda_environment_name : str or Path, optional
The conda environment to use for the run script.
Either a string containing the name, or a path to the environment.
python_paths : list of str, optional
A list of paths to append to the python path of the run script.
cwd : str or Path, optional
The working directory of the run script.
Returns
-------
run_script: str
The generated run script.
"""
command = inspect.getfile(external_problem_factory_script)
return _make_run_script(
command, problem_factory, conda_environment_name, python_paths, cwd, **kwargs
)


def make_observer_script(
observer: Type[AbstractObserver],
conda_environment: Union[str, Path] = None,
Expand Down Expand Up @@ -117,27 +82,17 @@ def make_observer_script(
"""
command = inspect.getfile(observer_wrapper)
return _make_run_script(command, observer, conda_environment, python_paths, cwd)


def _make_black_box_script(
command: str,
command_for_instancing_the_black_box: str,
conda_environment_name: Union[str, Path],
python_paths: List[str],
cwd=None,
):
# TODO: implement in such a way that
...
return _make_run_script_from_template(
command, observer, conda_environment, python_paths, cwd
)


def _make_run_script(
def _make_run_script_from_template(
command: str,
non_instantiated_object,
conda_environment_name: Union[str, Path],
python_paths: List[str],
cwd=None,
**kwargs,
):
"""
An internal function for creating run scripts; returns the location of the run script.
Expand Down
5 changes: 1 addition & 4 deletions src/poli/core/util/observer_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@

from poli.core.util.abstract_observer import AbstractObserver
from poli.core.util.inter_process_communication.process_wrapper import get_connection
from poli.external_problem_factory_script import (
dynamically_instantiate,
parse_factory_kwargs,
)
from poli.external_isolated_function_script import dynamically_instantiate


def start_observer_process(observer_name, port: int, password: str):
Expand Down
Loading

0 comments on commit 44ab475

Please sign in to comment.