Skip to content

Commit

Permalink
Activate response validation
Browse files Browse the repository at this point in the history
Also fix related formatting of expected minimum
  • Loading branch information
langdal committed Mar 14, 2023
1 parent 02bf185 commit 5e1371c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
11 changes: 9 additions & 2 deletions optimizerapi/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ def process_result(result, optimizer, dimensions, cfg, extras, data, space):
experiment_suggestion_count = extras["experimentSuggestionCount"]

next_exp = optimizer.ask(n_points=experiment_suggestion_count)
if len(next_exp) > 0 and not any(isinstance(x, list) for x in next_exp): next_exp = [next_exp]
if len(next_exp) > 0 and not any(isinstance(x, list) for x in next_exp):
next_exp = [next_exp]
result_details["next"] = round_to_length_scales(next_exp, optimizer.space)

if len(data) >= cfg["initialPoints"]:
Expand All @@ -209,7 +210,7 @@ def process_result(result, optimizer, dimensions, cfg, extras, data, space):

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

Expand All @@ -228,6 +229,12 @@ def process_result(result, optimizer, dimensions, cfg, extras, data, space):
add_version_info(result_details["extras"])

# print(str(response))
org_models = response["result"]['models']
for model in org_models:
# Flatten expected minimum entries
model['expected_minimum'] = [[
item for sublist in [x if isinstance(
x, list) else [x] for x in model['expected_minimum']] for item in sublist]]
return response


Expand Down
3 changes: 2 additions & 1 deletion optimizerapi/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
get_crypto()
app = connexion.FlaskApp(
__name__, port=9090, specification_dir='./openapi/')
app.add_api('specification.yml', strict_validation=True)
app.add_api('specification.yml', strict_validation=True,
validate_responses=True)

DEVELOPMENT = "development"
flask_env = os.getenv("FLASK_ENV", DEVELOPMENT)
Expand Down

0 comments on commit 5e1371c

Please sign in to comment.