Skip to content

Commit

Permalink
Merge pull request #47 from BoostV/104_option_for_no_plot
Browse files Browse the repository at this point in the history
Option for no plot
  • Loading branch information
SRFU-NN authored Sep 9, 2022
2 parents 7bfa06f + b0d3107 commit 0173688
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 18 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
**.pyc
.vscode
/tmp
version.txt
version.txt
.env
39 changes: 22 additions & 17 deletions optimizerapi/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ def process_result(result, optimizer, dimensions, cfg, extras, data, space):
"plots": plots,
"result": result_details
}
# GraphFormat should, at the moment, be either "png" or "none". Default (legacy)
# behavior is "png", so the API returns png images. Any other input is interpreted
# as "None" at the moment.
graph_format = extras.get("graphFormat", "png")

# In the following section details that should be reported to
# clients should go into the "resultDetails" dictionary and plots
Expand All @@ -195,23 +199,24 @@ def process_result(result, optimizer, dimensions, cfg, extras, data, space):
# processed more than "initialPoints" data points
result_details["models"] = [process_model(
model, optimizer) for model in result]
for idx, model in enumerate(result):
plot_convergence(model)
add_plot(plots, f"convergence_{idx}")

plot_objective(model, dimensions=dimensions,
usepartialdependence=False,
show_confidence=True)
add_plot(plots, f"objective_{idx}")

if optimizer.n_objectives == 1:
minimum = expected_minimum(result[0])

result_details["expected_minimum"] = [
round_to_length_scales(minimum[0], optimizer.space), round(minimum[1], 2)]
else:
plot_Pareto(optimizer)
add_plot(plots, "pareto")
if graph_format == "png":
for idx, model in enumerate(result):
plot_convergence(model)
add_plot(plots, f"convergence_{idx}")

plot_objective(model, dimensions=dimensions,
usepartialdependence=False,
show_confidence=True)
add_plot(plots, f"objective_{idx}")

if optimizer.n_objectives == 1:
minimum = expected_minimum(result[0])

result_details["expected_minimum"] = [
round_to_length_scales(minimum[0], optimizer.space), round(minimum[1], 2)]
else:
plot_Pareto(optimizer)
add_plot(plots, "pareto")

result_details["pickled"] = pickleToString(
result, get_crypto())
Expand Down
34 changes: 34 additions & 0 deletions tests/test_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,40 @@ def test_generates_plots_when_run_with_more_than_initialPoints_samples():
assert len(result["plots"]) == 2


def test_specifying_png_plots():
result = optimizer.run(body={
"data": sampleData,
"optimizerConfig": sampleConfig,
"extras": {"graphFormat": "png"}
})
validateResult(result)
assert len(result["result"]["models"]) > 0
assert len(result["plots"]) == 2


def test_specifying_empty_extras_preserve_legacy_plotting():
result = optimizer.run(body={
"data": sampleData,
"optimizerConfig": sampleConfig,
"extras": {}
})
validateResult(result)
assert len(result["result"]["models"]) > 0
assert len(result["plots"]) == 2


def test_deselecting_plots():
# If graphFormat is none, no plots should be returned. This should be faster.
result = optimizer.run(body={
"data": sampleData,
"optimizerConfig": sampleConfig,
"extras": {"graphFormat": "none"}
})
validateResult(result)
assert len(result["result"]["models"]) > 0
assert len(result["plots"]) == 0


def test_can_accept_multi_objective_data():
result = optimizer.run(body={
"data": sampleMultiObjectiveData,
Expand Down

0 comments on commit 0173688

Please sign in to comment.