Skip to content

Commit

Permalink
cleanup where model config is loaded so it can be used globally by th…
Browse files Browse the repository at this point in the history
…e Agent
  • Loading branch information
Brandon Rose authored and Brandon Rose committed Jun 10, 2024
1 parent 44705ec commit d6d232a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/askem_beaker/contexts/mira_config_edit/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
logging.disable(logging.WARNING) # Disable warnings
logger = logging.Logger(__name__)

from mira.sources.amr import model_from_json;

class MiraConfigEditAgent(BaseAgent):
"""
Expand Down Expand Up @@ -82,17 +81,16 @@ async def update_parameters(self, parameter_values: dict, agent: AgentRef, loop:
"""
# load in model config's parameters to use in comparison to the
# user provided parameters to update
model_config = model_from_json(agent.context.amr)
model_params = model_config.parameters.keys()
model_params = agent.context.model_config.parameters.keys()
user_params = parameter_values['parameter_values'].keys()

# check if any in user_params is not in model_params and return an error
if not all(param in model_params for param in user_params):
loop.set_state(loop.STOP_FATAL)
error_message = f"It looks like you're trying to update parameter(s) that don't exist: " \
f"{', '.join(param for param in user_params if param not in model_params)}." \
f"[{', '.join(param for param in user_params if param not in model_params)}]. " \
f"Please ensure you are updating a valid parameter: " \
f"{', '.join(param for param in model_params)}"
f"[{', '.join(param for param in model_params)}]."
return error_message

loop.set_state(loop.STOP_SUCCESS)
Expand Down
2 changes: 2 additions & 0 deletions src/askem_beaker/contexts/mira_config_edit/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

logger = logging.getLogger(__name__)

from mira.sources.amr import model_from_json;

class MiraConfigEditContext(BaseContext):

Expand Down Expand Up @@ -64,6 +65,7 @@ async def set_model_config(self, item_id, agent=None, parent_header={}):
self.original_amr = copy.deepcopy(self.amr)
if self.amr:
await self.load_mira()
self.model_config = model_from_json(self.amr)
else:
raise Exception(f"Model config '{item_id}' not found.")
await self.send_mira_preview_message(parent_header=parent_header)
Expand Down

0 comments on commit d6d232a

Please sign in to comment.