Skip to content

Commit

Permalink
try to set reopt_version in APIMeta automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
hdunham committed Jun 13, 2024
1 parent 539d481 commit 49af53a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
7 changes: 5 additions & 2 deletions julia_src/http.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ end
function reopt(req::HTTP.Request)
d = JSON.parse(String(req.body))
error_response = Dict()
settings = d["Settings"]
if !isempty(get(d, "api_key", ""))
ENV["NREL_DEVELOPER_API_KEY"] = pop!(d, "api_key")
else
ENV["NREL_DEVELOPER_API_KEY"] = test_nrel_developer_api_key
delete!(d, "api_key")
end
settings = d["Settings"]
solver_name = get(settings, "solver_name", "HiGHS")
if solver_name == "Xpress" && !(xpress_installed=="True")
solver_name = "HiGHS"
Expand Down Expand Up @@ -142,7 +142,8 @@ function reopt(req::HTTP.Request)
@info "REopt model solved with status $(results["status"])."
if results["status"] == "error"
response = Dict(
"results" => results
"results" => results,
"reopt_version" => pkgversion(reoptjl)
)
if !isempty(inputs_with_defaults_set_in_julia)
response["inputs_with_defaults_set_in_julia"] = inputs_with_defaults_set_in_julia
Expand All @@ -151,12 +152,14 @@ function reopt(req::HTTP.Request)
else
response = Dict(
"results" => results,
"reopt_version" => pkgversion(reoptjl),
"inputs_with_defaults_set_in_julia" => inputs_with_defaults_set_in_julia
)
return HTTP.Response(200, JSON.json(response))
end
else
@info "An error occured in the Julia code."
error_response["reopt_version"] = pkgversion(reoptjl)
return HTTP.Response(500, JSON.json(error_response))
end
end
Expand Down
2 changes: 1 addition & 1 deletion reoptjl/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def obj_create(self, bundle, **kwargs):
meta = {
"run_uuid": run_uuid,
"api_version": 3,
"reopt_version": "0.47.1",
# "reopt_version": "0.47.1",
"status": "Validating..."
}
bundle.data.update({"APIMeta": meta})
Expand Down
1 change: 1 addition & 0 deletions reoptjl/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ class APIMeta(BaseModel, models.Model):
created = models.DateTimeField(auto_now_add=True)
reopt_version = models.TextField(
blank=True,
null=True,
default="",
help_text="Version number of the Julia package for REopt that is used to solve the problem."
)
Expand Down
2 changes: 2 additions & 0 deletions reoptjl/src/run_jump_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def run_jump_model(run_uuid):
if response.status_code == 500:
raise REoptFailedToStartError(task=name, message=response_json["error"], run_uuid=run_uuid, user_uuid=user_uuid)
results = response_json["results"]
reopt_version = response_json["reopt_version"]
if results["status"].strip().lower() != "error":
inputs_with_defaults_set_in_julia = response_json["inputs_with_defaults_set_in_julia"]
time_dict["pyjulia_run_reopt_seconds"] = time.time() - t_start
Expand Down Expand Up @@ -107,6 +108,7 @@ def run_jump_model(run_uuid):

profiler.profileEnd()
# TODO save profile times
APIMeta.objects.filter(run_uuid=run_uuid).update(reopt_version=reopt_version)
if status.strip().lower() != 'error':
update_inputs_in_database(inputs_with_defaults_set_in_julia, run_uuid)
process_results(results, run_uuid)
Expand Down

0 comments on commit 49af53a

Please sign in to comment.