diff --git a/src/askem_beaker/contexts/mira_config_edit/context.py b/src/askem_beaker/contexts/mira_config_edit/context.py index a8657b7..fd3f695 100644 --- a/src/askem_beaker/contexts/mira_config_edit/context.py +++ b/src/askem_beaker/contexts/mira_config_edit/context.py @@ -54,6 +54,7 @@ async def set_model_config(self, item_id, agent=None, parent_header={}): meta_url = f"{os.environ['DATA_SERVICE_URL']}/model_configurations/{self.config_id}" logger.error(f"Meta url: {meta_url}") self.configuration = requests.get(meta_url).json() + logger.error(f"Succeeded in fetching model configuration, proceeding.") self.amr = self.configuration.get("configuration") self.original_amr = copy.deepcopy(self.amr) if self.amr: @@ -86,4 +87,33 @@ async def send_mira_preview_message( "iopub", "model_preview", content, parent_header=parent_header ) except Exception as e: - raise \ No newline at end of file + raise + + @intercept() + async def save_model_config_request(self, message): + ''' + Updates the model configuration in place. + ''' + content = message.content + + new_model: dict = ( + await self.evaluate( + f"template_model_to_petrinet_json({self.var_name})" + ) + )["return"] + + model_config = self.configuration + model_config["configuration"] = new_model + + create_req = requests.put( + f"{os.environ['DATA_SERVICE_URL']}/model_configurations/{self.config_id}", json=model_config + ) + + if create_req.status_code == 200: + logger.error(f"Successfuly updated model config {self.config_id}") + response_id = create_req.json()["id"] + + content = {"model_configuration_id": response_id} + self.beaker_kernel.send_response( + "iopub", "save_model_response", content, parent_header=message.header + ) \ No newline at end of file diff --git a/src/askem_beaker/contexts/mira_config_edit/procedures/python3/update_params.py b/src/askem_beaker/contexts/mira_config_edit/procedures/python3/update_params.py index d7be80a..2d5c7bb 100644 --- a/src/askem_beaker/contexts/mira_config_edit/procedures/python3/update_params.py +++ b/src/askem_beaker/contexts/mira_config_edit/procedures/python3/update_params.py @@ -1,3 +1,3 @@ -parameter_values = {{ parameter_values }}['parameter_values'] +parameter_values = {{ parameter_values['parameter_values'] }} for kk, vv in parameter_values.items(): {{ var_name|default("model_config") }}.parameters[kk].value = vv \ No newline at end of file