Skip to content

Commit

Permalink
Fix a few bugs in the Profet tasks (#1030)
Browse files Browse the repository at this point in the history
* Use better comments / names in control_randomness

Signed-off-by: Fabrice Normandin <[email protected]>

* Fix a bug in downloading of profet data, gitignore

Signed-off-by: Fabrice Normandin <[email protected]>

Signed-off-by: Fabrice Normandin <[email protected]>
  • Loading branch information
lebrice authored Jan 13, 2023
1 parent 92f7f5d commit 0c12564
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
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

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()

0 comments on commit 0c12564

Please sign in to comment.