diff --git a/libensemble/gen_funcs/persistent_ax_multitask.py b/libensemble/gen_funcs/persistent_ax_multitask.py index 397cd184a..270f59e8d 100644 --- a/libensemble/gen_funcs/persistent_ax_multitask.py +++ b/libensemble/gen_funcs/persistent_ax_multitask.py @@ -87,6 +87,7 @@ TaskChoiceToIntTaskChoice, ] + # get_MTGP based on https://ax.dev/docs/tutorials/multi_task/ def get_MTGP( experiment: Experiment, diff --git a/libensemble/sim_funcs/rosenbrock.py b/libensemble/sim_funcs/rosenbrock.py index 67c4e0ba3..7925e0a2b 100644 --- a/libensemble/sim_funcs/rosenbrock.py +++ b/libensemble/sim_funcs/rosenbrock.py @@ -8,6 +8,7 @@ __all__ = ["rosenbrock_eval"] + def EvaluateFunction(x, component=None): """ Evaluates the chained Rosenbrock function diff --git a/scripts/aposmm_min_loc.py b/scripts/aposmm_min_loc.py index cc6b1eba6..2251b5cb5 100644 --- a/scripts/aposmm_min_loc.py +++ b/scripts/aposmm_min_loc.py @@ -19,9 +19,9 @@ N = 6 # number of opt runs to show. -x_name = 'x0' -y_name = 'x1' -z_name = 'x2' +x_name = "x0" +y_name = "x1" +z_name = "x2" full_bounds = False # For entire input space enter bounds below @@ -35,7 +35,7 @@ # Find the most recent .npy and pickle files try: H_file = max(glob.glob("*.npy"), key=os.path.getmtime) - persis_info_file = max(glob.iglob('*.pickle'), key=os.path.getctime) + persis_info_file = max(glob.iglob("*.pickle"), key=os.path.getctime) except Exception: sys.exit("Need a *.npy and a *.pickle files in run dir. Exiting...") @@ -45,30 +45,30 @@ index_sets = pickle.load(f)["run_order"] # Filter best N opt runs for clearer graph -trimmed_index_sets = {key: indices[:-1] for key, indices in index_sets.items()} -min_f_per_set = [(key, indices, H['f'][indices].min()) for key, indices in trimmed_index_sets.items() if len(indices) > 0] +trim_sets = {key: indices[:-1] for key, indices in index_sets.items()} +min_f_per_set = [(key, indices, H["f"][indices].min()) for key, indices in trim_sets.items() if len(indices) > 0] min_f_per_set_sorted = sorted(min_f_per_set, key=lambda x: x[2])[:N] # Plotting fig = plt.figure(figsize=(6, 6)) -ax = fig.add_subplot(111, projection='3d') +ax = fig.add_subplot(111, projection="3d") for key, indices, _ in min_f_per_set_sorted: - min_f_index = indices[np.argmin(H['f'][indices])] + min_f_index = indices[np.argmin(H["f"][indices])] # Extract the corresponding 3D x position from H try: - x, y, z = H['x'][min_f_index] + x, y, z = H["x"][min_f_index] except ValueError: x = H[x_name][min_f_index] y = H[y_name][min_f_index] z = H[z_name][min_f_index] # Plot the 3D point - ax.scatter(x, y, z, marker='o', s=50, label=f'Opt run {key}') + ax.scatter(x, y, z, marker="o", s=50, label=f"Opt run {key}") # Draw a line from the point to the XY plane (z=0) - ax.plot([x, x], [y, y], [0, z], color='grey', linestyle='--') + ax.plot([x, x], [y, y], [0, z], color="grey", linestyle="--") if full_bounds: ax.set_xlim(x0_min, x0_max) @@ -79,6 +79,6 @@ ax.set_xlabel(x_name) ax.set_ylabel(y_name) ax.set_zlabel(z_name) -ax.set_title('Locations of best points from each optimization run') -ax.legend(bbox_to_anchor=(-0.1, 0.9), loc='upper left', borderaxespad=0) +ax.set_title("Locations of best points from each optimization run") +ax.legend(bbox_to_anchor=(-0.1, 0.9), loc="upper left", borderaxespad=0) plt.savefig(f"location_min_best{N}.png") diff --git a/scripts/aposmm_plot_local_runs.py b/scripts/aposmm_plot_local_runs.py index f94ecb13a..e6a61e814 100755 --- a/scripts/aposmm_plot_local_runs.py +++ b/scripts/aposmm_plot_local_runs.py @@ -21,7 +21,7 @@ # Find the most recent .npy and pickle files try: H_file = max(glob.glob("*.npy"), key=os.path.getmtime) - persis_info_file = max(glob.iglob('*.pickle'), key=os.path.getctime) + persis_info_file = max(glob.iglob("*.pickle"), key=os.path.getctime) except Exception: sys.exit("Need a *.npy and a *.pickle files in run dir. Exiting...") @@ -31,38 +31,38 @@ index_sets = pickle.load(f)["run_order"] # Filter best N opt runs for clearer graph -trimmed_index_sets = {key: indices[:-1] for key, indices in index_sets.items()} -min_f_per_set = [(key, indices, H['f'][indices].min()) for key, indices in trimmed_index_sets.items() if len(indices) > 0] +trim_sets = {key: indices[:-1] for key, indices in index_sets.items()} +min_f_per_set = [(key, indices, H["f"][indices].min()) for key, indices in trim_sets.items() if len(indices) > 0] min_f_per_set_sorted = sorted(min_f_per_set, key=lambda x: x[2])[:N] # Plotting plt.figure(figsize=(10, 6)) -plt.scatter(range(len(H['f'])), H['f'], color='lightgrey', label='Other points', zorder=1) +plt.scatter(range(len(H["f"])), H["f"], color="lightgrey", label="Other points", zorder=1) num_runs = len(index_sets) # for key, indices in index_sets.items(): for key, indices, _ in min_f_per_set_sorted: # Extract the 'f' values for each index set - f_values = H['f'][indices] + f_values = H["f"][indices] - ratio = (f_values[-1] - f_values[-2])/ f_values[-2] + ratio = (f_values[-1] - f_values[-2]) / f_values[-2] # print(f"Tolerance of the last two values for {key}: {ratio}") - plt.plot(indices, f_values, marker='o', label=f'Opt run {key}', zorder=2) + plt.plot(indices, f_values, marker="o", label=f"Opt run {key}", zorder=2) # Identify the index and value of the minimum f min_index = indices[np.argmin(f_values)] min_f_value = np.min(f_values) # Mark the minimum f value with a distinct marker - plt.scatter(min_index, min_f_value, color='red', edgecolor='black', s=50, zorder=3) + plt.scatter(min_index, min_f_value, color="red", edgecolor="black", s=50, zorder=3) # Add a dummy point to the legend for "minima of opt run" -plt.scatter([], [], color='red', edgecolor='black', s=50, label='Best value of opt run') +plt.scatter([], [], color="red", edgecolor="black", s=50, label="Best value of opt run") -plt.xlabel('Simulation ID') -plt.ylabel('Objective value') -plt.title(f'Objective values by Optimization runs. Best {N} runs from {num_runs}') +plt.xlabel("Simulation ID") +plt.ylabel("Objective value") +plt.title(f"Objective values by Optimization runs. Best {N} runs from {num_runs}") plt.legend() plt.grid(True) plt.savefig(f"opt_runs_best{N}.png")