Merge remote-tracking branch 'origin/dev' into feature/2476-training-schedules-mockup
This commit is contained in:
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- Added ipywidgets to the dependencies
|
- Added ipywidgets to the dependencies
|
||||||
- Added ability to define scenarios that change depending on the episode number.
|
- Added ability to define scenarios that change depending on the episode number.
|
||||||
- Standardised Environment API by renaming the config parameter of `PrimaiteGymEnv` from `game_config` to `env_config`
|
- Standardised Environment API by renaming the config parameter of `PrimaiteGymEnv` from `game_config` to `env_config`
|
||||||
|
- added ability to set PrimAITE between development and production modes via PrimAITE CLI ``mode`` command
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
- Made requests fail to reach their target if the node is off
|
- Made requests fail to reach their target if the node is off
|
||||||
|
|||||||
@@ -141,3 +141,29 @@ of your choice:
|
|||||||
pip install -e .[dev]
|
pip install -e .[dev]
|
||||||
|
|
||||||
To view the complete list of packages installed during PrimAITE installation, go to the dependencies page (:ref:`Dependencies`).
|
To view the complete list of packages installed during PrimAITE installation, go to the dependencies page (:ref:`Dependencies`).
|
||||||
|
|
||||||
|
4. Set PrimAITE to run on development mode
|
||||||
|
|
||||||
|
Running step 3 should have installed PrimAITE, verify this by running
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
:caption: Unix
|
||||||
|
|
||||||
|
primaite setup
|
||||||
|
|
||||||
|
.. code-block:: powershell
|
||||||
|
:caption: Windows (Powershell)
|
||||||
|
|
||||||
|
primaite setup
|
||||||
|
|
||||||
|
To set PrimAITE to run in development mode:
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
:caption: Unix
|
||||||
|
|
||||||
|
primaite mode --dev
|
||||||
|
|
||||||
|
.. code-block:: powershell
|
||||||
|
:caption: Windows (Powershell)
|
||||||
|
|
||||||
|
primaite mode --dev
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from typing_extensions import Annotated
|
|||||||
|
|
||||||
from primaite import PRIMAITE_PATHS
|
from primaite import PRIMAITE_PATHS
|
||||||
|
|
||||||
app = typer.Typer()
|
app = typer.Typer(no_args_is_help=True)
|
||||||
|
|
||||||
|
|
||||||
@app.command()
|
@app.command()
|
||||||
@@ -114,3 +114,47 @@ def setup(overwrite_existing: bool = True) -> None:
|
|||||||
reset_example_configs.run(overwrite_existing=True)
|
reset_example_configs.run(overwrite_existing=True)
|
||||||
|
|
||||||
_LOGGER.info("PrimAITE setup complete!")
|
_LOGGER.info("PrimAITE setup complete!")
|
||||||
|
|
||||||
|
|
||||||
|
@app.command()
|
||||||
|
def mode(
|
||||||
|
dev: Annotated[bool, typer.Option("--dev", help="Activates PrimAITE developer mode")] = None,
|
||||||
|
prod: Annotated[bool, typer.Option("--prod", help="Activates PrimAITE production mode")] = None,
|
||||||
|
) -> None:
|
||||||
|
"""
|
||||||
|
Switch PrimAITE between developer mode and production mode.
|
||||||
|
|
||||||
|
By default, PrimAITE will be in production mode.
|
||||||
|
|
||||||
|
To view the current mode, use: primaite mode
|
||||||
|
|
||||||
|
To set to development mode, use: primaite mode --dev
|
||||||
|
|
||||||
|
To return to production mode, use: primaite mode --prod
|
||||||
|
"""
|
||||||
|
if PRIMAITE_PATHS.app_config_file_path.exists():
|
||||||
|
with open(PRIMAITE_PATHS.app_config_file_path, "r") as file:
|
||||||
|
primaite_config = yaml.safe_load(file)
|
||||||
|
if dev and prod:
|
||||||
|
print("Unable to activate developer and production modes concurrently.")
|
||||||
|
return
|
||||||
|
|
||||||
|
if (dev is None) and (prod is None):
|
||||||
|
is_dev_mode = primaite_config["developer_mode"]
|
||||||
|
|
||||||
|
if is_dev_mode:
|
||||||
|
print("PrimAITE is running in developer mode.")
|
||||||
|
else:
|
||||||
|
print("PrimAITE is running in production mode.")
|
||||||
|
if dev:
|
||||||
|
# activate dev mode
|
||||||
|
primaite_config["developer_mode"] = True
|
||||||
|
with open(PRIMAITE_PATHS.app_config_file_path, "w") as file:
|
||||||
|
yaml.dump(primaite_config, file)
|
||||||
|
print("PrimAITE is running in developer mode.")
|
||||||
|
if prod:
|
||||||
|
# activate prod mode
|
||||||
|
primaite_config["developer_mode"] = False
|
||||||
|
with open(PRIMAITE_PATHS.app_config_file_path, "w") as file:
|
||||||
|
yaml.dump(primaite_config, file)
|
||||||
|
print("PrimAITE is running in production mode.")
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ from pydantic import BaseModel, ConfigDict
|
|||||||
|
|
||||||
from primaite import getLogger, PRIMAITE_PATHS
|
from primaite import getLogger, PRIMAITE_PATHS
|
||||||
from primaite.simulator import LogLevel, SIM_OUTPUT
|
from primaite.simulator import LogLevel, SIM_OUTPUT
|
||||||
|
from src.primaite.utils.primaite_config_utils import is_dev_mode
|
||||||
|
|
||||||
_LOGGER = getLogger(__name__)
|
_LOGGER = getLogger(__name__)
|
||||||
|
|
||||||
@@ -60,7 +61,14 @@ class PrimaiteIO:
|
|||||||
timestamp = datetime.now()
|
timestamp = datetime.now()
|
||||||
date_str = timestamp.strftime("%Y-%m-%d")
|
date_str = timestamp.strftime("%Y-%m-%d")
|
||||||
time_str = timestamp.strftime("%H-%M-%S")
|
time_str = timestamp.strftime("%H-%M-%S")
|
||||||
session_path = PRIMAITE_PATHS.user_sessions_path / date_str / time_str
|
|
||||||
|
# check if running in dev mode
|
||||||
|
if is_dev_mode():
|
||||||
|
# if dev mode, simulation output will be the current working directory
|
||||||
|
session_path = Path.cwd() / "simulation_output" / date_str / time_str
|
||||||
|
else:
|
||||||
|
session_path = PRIMAITE_PATHS.user_sessions_path / date_str / time_str
|
||||||
|
|
||||||
session_path.mkdir(exist_ok=True, parents=True)
|
session_path.mkdir(exist_ok=True, parents=True)
|
||||||
return session_path
|
return session_path
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
# The main PrimAITE application config file
|
# The main PrimAITE application config file
|
||||||
|
|
||||||
|
developer_mode: False # false by default
|
||||||
|
|
||||||
# Logging
|
# Logging
|
||||||
logging:
|
logging:
|
||||||
log_level: INFO
|
log_level: INFO
|
||||||
@@ -9,14 +11,3 @@ logging:
|
|||||||
WARNING: '%(asctime)s::%(levelname)s::%(name)s::%(lineno)s::%(message)s'
|
WARNING: '%(asctime)s::%(levelname)s::%(name)s::%(lineno)s::%(message)s'
|
||||||
ERROR: '%(asctime)s::%(levelname)s::%(name)s::%(lineno)s::%(message)s'
|
ERROR: '%(asctime)s::%(levelname)s::%(name)s::%(lineno)s::%(message)s'
|
||||||
CRITICAL: '%(asctime)s::%(levelname)s::%(name)s::%(lineno)s::%(message)s'
|
CRITICAL: '%(asctime)s::%(levelname)s::%(name)s::%(lineno)s::%(message)s'
|
||||||
|
|
||||||
# Session
|
|
||||||
session:
|
|
||||||
outputs:
|
|
||||||
plots:
|
|
||||||
size:
|
|
||||||
auto_size: false
|
|
||||||
width: 1500
|
|
||||||
height: 900
|
|
||||||
template: plotly_white
|
|
||||||
range_slider: false
|
|
||||||
|
|||||||
11
src/primaite/utils/primaite_config_utils.py
Normal file
11
src/primaite/utils/primaite_config_utils.py
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import yaml
|
||||||
|
|
||||||
|
from primaite import PRIMAITE_PATHS
|
||||||
|
|
||||||
|
|
||||||
|
def is_dev_mode() -> bool:
|
||||||
|
"""Returns True if PrimAITE is currently running in developer mode."""
|
||||||
|
if PRIMAITE_PATHS.app_config_file_path.exists():
|
||||||
|
with open(PRIMAITE_PATHS.app_config_file_path, "r") as file:
|
||||||
|
primaite_config = yaml.safe_load(file)
|
||||||
|
return primaite_config["developer_mode"]
|
||||||
Reference in New Issue
Block a user