Skip to content

Commit

Permalink
add save of model configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
brandomr committed Jan 24, 2024
1 parent 82a32bf commit ab05fd5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
32 changes: 31 additions & 1 deletion src/askem_beaker/contexts/mira_config_edit/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -86,4 +87,33 @@ async def send_mira_preview_message(
"iopub", "model_preview", content, parent_header=parent_header
)
except Exception as e:
raise
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
)
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ab05fd5

Please sign in to comment.