Skip to content

add force isolation, add force register to create #273

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

Open
wants to merge 10 commits into
base: dev
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
18 changes: 9 additions & 9 deletions src/poli/objective_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,16 +173,16 @@ def create(
**kwargs_for_factory,
)

# instantiate observer (if desired)
observer = _instantiate_observer(observer_name, quiet)
observer_info = observer.initialize_observer(
problem.black_box.info, observer_init_info, seed
)

f = problem.black_box
f.set_observer(observer)
f.set_observer_info(observer_info)
problem.set_observer(AlgorithmObserverWrapper(observer), observer_info)
# instantiate observer (if desired)
if observer_name is not None:
observer = _instantiate_observer(observer_name, quiet)
observer_info = observer.initialize_observer(
problem.black_box.info, observer_init_info, seed
)
f.set_observer(observer)
f.set_observer_info(observer_info)
problem.set_observer(AlgorithmObserverWrapper(observer), observer_info)

return problem

Expand Down
4 changes: 4 additions & 0 deletions src/poli/objective_repository/gfp_cbas/cbas_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
from pathlib import Path

import numpy as np
import tensorflow as tf

tf.compat.v1.enable_eager_execution()
tf.config.run_functions_eagerly(True)
import torch
import torch.nn as nn
from scipy.stats import norm as StandardNormal
Expand Down
6 changes: 3 additions & 3 deletions src/poli/objective_repository/gfp_cbas/make_vae.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import tensorflow as tf

tf.compat.v1.enable_eager_execution()

from tensorflow import keras
from tensorflow.keras.layers import (
Add,
Expand All @@ -12,9 +15,6 @@
from tensorflow.keras.models import Model
from tensorflow.python.keras import backend as K

tf.compat.v1.disable_v2_behavior()


MAKE_DETERMINISTIC = True


Expand Down
15 changes: 7 additions & 8 deletions src/poli/objective_repository/gfp_cbas/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,9 @@ def __init__(
self.seed = seed
self.negate = negate

inner_function = get_inner_function(
isolated_function_name="gfp_cbas__isolated",
class_name="GFPCBasIsolatedLogic",
module_to_import="poli.objective_repository.gfp_cbas.isolated_function",
seed=self.seed,
force_isolation=self.force_isolation,
quiet=False,
# NOTE: do NOT us get_inner_function -> importlib resets existing tf import and we CANNOT recover tf.v1 eager execution
from .isolated_function import GFPCBasIsolatedLogic # encapsulate as to not break poli imports
inner_function = GFPCBasIsolatedLogic(
problem_type=self.problem_type,
info=self.get_black_box_info(),
n_starting_points=self.n_starting_points,
Expand Down Expand Up @@ -120,6 +116,8 @@ def create(
num_workers: int = None,
evaluation_budget: int = float("inf"),
negate: bool = False,
force_isolation: bool = False,
force_register: bool = False, # TODO: this is not functional requires correction
) -> Problem:
"""
Seed value required to shuffle the data, otherwise CSV asset data index unchanged.
Expand All @@ -129,7 +127,7 @@ def create(
self.problem_type = problem_type
if seed is not None:
seed_python_numpy_and_torch(seed)
problem_info = self.get_problem_name()

f = GFPCBasBlackBox(
problem_type=problem_type,
functional_only=functional_only,
Expand All @@ -141,6 +139,7 @@ def create(
seed=seed,
evaluation_budget=evaluation_budget,
negate=negate,
force_isolation=force_isolation,
)
x0 = f.x0

Expand Down
Loading