Skip to content

Commit

Permalink
Report non-halting errors with forced warn; update deps and version
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler Wolfe-Adam committed Aug 22, 2024
1 parent ec79168 commit c8c61b3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
Binary file not shown.
25 changes: 20 additions & 5 deletions alpyne/sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from typing import Any
import socket
from pathlib import Path
from warnings import warn

import psutil as psutil
import requests
Expand Down Expand Up @@ -435,6 +436,23 @@ def observation(self) -> SimObservation:
"""
return self.status().observation

def _to_status(self, data: dict) -> SimStatus:
"""
A centralized location for the logic to handle the response from a status request
- whether from calling `status` or `lock`.
:param data: The output from GET /status
:return: The SimStatus object
"""
# all attributes in data should match those in the SimStatus object
status = SimStatus(**data)

# when the message it passed, assume some important, but non-halting issue
if status.message: # TODO throw runtime error instead?
warn(status.message)
return status


def status(self) -> SimStatus:
"""
Queries the current status of the model, regardless of its current state
Expand All @@ -443,9 +461,7 @@ def status(self) -> SimStatus:
:return: The current model status
"""
data = self._request("GET", "status")
# received data is a dict matching the SimStatus attributes
status = SimStatus(**data)
return status
return self._to_status(data)

def _engine(self) -> EngineStatus: # TODO remove me? rename?
"""
Expand Down Expand Up @@ -475,8 +491,7 @@ def lock(self, flag: EngineState = None, timeout: int = None) -> SimStatus:

names = [state.name for state in EngineState if flag & state]
data = self._request("GET", "lock", params=dict(state=names, timeout=int(timeout * 1000)))
# received data is a dict matching the ModelStatus attributes
status = SimStatus(**data)
status = self._to_status(data)
self._last_status = status
return status

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name="anylogic-alpyne",
version="1.1.0",
version="1.2.0",
author="Tyler Wolfe-Adam",
author_email="[email protected]",
description="Run AnyLogic models exported from the RL Experiment",
Expand Down

0 comments on commit c8c61b3

Please sign in to comment.