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

Fix a few bugs in the Profet tasks #1030

Merged
merged 3 commits into from
Jan 13, 2023
Merged
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,7 @@ tests/**.ipynb
docs/src/auto_examples
docs/src/auto_tutorials
docs/src/gen_modules


# Data and checkpoints downloaded or generated by the Profet tasks.
profet_data
9 changes: 7 additions & 2 deletions src/orion/benchmark/task/profet/model_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,15 @@ def load_data(
X, Y, and C arrays.
"""
# file = Path(input_path) / NAMES[benchmark]
file = Path(input_path) / self.json_file_name

bouthilx marked this conversation as resolved.
Show resolved Hide resolved
profet_data_dir = Path(input_path)
file = profet_data_dir / "data" / self.json_file_name
if not file.exists():
logger.info(f"File {file} doesn't exist, attempting to download data.")
download_data(input_path)
# NOTE: This downloads the "profet_data" folder, with the "data" folder inside it, so
# we download it to the parent directory of the profet_data dir.
download_data(str(profet_data_dir.parent))

logger.info("Download finished.")
if not file.exists():
raise RuntimeError(
Expand Down
24 changes: 15 additions & 9 deletions src/orion/core/utils/random_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,25 @@ class HasRandomState(Protocol): # pylint: disable=too-few-public-methods


@contextmanager
def control_randomness(has_random_state: HasRandomState):
def control_randomness(object_with_random_state: HasRandomState):
"""Seeds the randomness inside the indented block of code using `self.random_state`."""
if has_random_state.random_state is None:
if object_with_random_state.random_state is None:
yield
return

# Save the initial random state.
# Backup the initial random state to a variable.
initial_rng_state = RandomState.current()
# Set the random state.
has_random_state.random_state.set()

# Set the random state from the object.
object_with_random_state.random_state.set()

# Yield (enter the 'with' indented block). Rng-related code will be executed here and modify
# the state of the random number generators in the various packages.
yield
# Update the stored random state, so that the changes inside the block are
# reflected in the RandomState object.
has_random_state.random_state = RandomState.current()
# Reset the initial state.

# Capture the final state of the RNG's, and save it on the object so we can "resume" at that
# state later.
object_with_random_state.random_state = RandomState.current()

# Reset the initial state of the RNGs.
initial_rng_state.set()