From 49af53a8d84f2718b75f4b77d49209a041903cff Mon Sep 17 00:00:00 2001 From: Hallie Dunham <70401017+hdunham@users.noreply.github.com> Date: Thu, 13 Jun 2024 15:20:50 -0600 Subject: [PATCH] try to set reopt_version in APIMeta automatically --- julia_src/http.jl | 7 +++++-- reoptjl/api.py | 2 +- reoptjl/models.py | 1 + reoptjl/src/run_jump_model.py | 2 ++ 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/julia_src/http.jl b/julia_src/http.jl index 8d3a38eaa..ea7627839 100644 --- a/julia_src/http.jl +++ b/julia_src/http.jl @@ -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" @@ -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 @@ -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 diff --git a/reoptjl/api.py b/reoptjl/api.py index bd90ef685..480460721 100644 --- a/reoptjl/api.py +++ b/reoptjl/api.py @@ -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}) diff --git a/reoptjl/models.py b/reoptjl/models.py index e9419054b..7b6aeb964 100644 --- a/reoptjl/models.py +++ b/reoptjl/models.py @@ -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." ) diff --git a/reoptjl/src/run_jump_model.py b/reoptjl/src/run_jump_model.py index 6499068ff..34ab85812 100644 --- a/reoptjl/src/run_jump_model.py +++ b/reoptjl/src/run_jump_model.py @@ -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 @@ -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)