Skip to content

Commit

Permalink
fix tutorial (was based on outdated version)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcw92 committed May 13, 2024
1 parent 37ca096 commit 572252c
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions tutorials/nm_example.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#!/usr/bin/env python3
import pathlib
import random

import numpy as np
from mpi4py import MPI

from propulate import Propulator
from propulate.propagators.nm import AdaptedNM
from propulate.propagators.nm import ParallelNelderMead
from propulate.utils import set_logger_config
from propulate.utils.benchmark_functions import (
get_function_search_space,
Expand Down Expand Up @@ -42,23 +41,25 @@
config.function
) # Get callable function + search-space limits.

# randomly choose a start point from within the limits
# Randomly choose a start point from within the limits.
low = np.array([v[0] for v in limits.values()])
high = np.array([v[1] for v in limits.values()])
start_point = np.random.default_rng(seed=config.seed + 235231).uniform(
low=low, high=high
)
propagator = AdaptedNM(limits, rng=rng, start=start_point)
# Set up propulator performing actual optimization.
propagator = ParallelNelderMead(limits, rng=rng, start=start_point)
# Set up Propulator performing actual optimization.
propulator = Propulator(
loss_fn=function,
propagator=propagator,
comm=comm,
generations=config.generations,
checkpoint_directory=config.checkpoint,
rng=rng,
propulate_comm=comm,
generations=config.generations,
checkpoint_path=config.checkpoint,
)

# Run optimization and print summary of results.
propulator.propulate(logging_interval=config.logging_int, debug=config.verbosity)
propulator.propulate(
logging_interval=config.logging_interval, debug=config.verbosity
)
propulator.summarize(top_n=config.top_n, debug=config.verbosity)

0 comments on commit 572252c

Please sign in to comment.