-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into ensemble_manager
- Loading branch information
Showing
12 changed files
with
611 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
views_pipeline_core/templates/ensemble/template_config_deployment.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
from typing import Dict | ||
from utils import utils_script_gen | ||
from pathlib import Path | ||
import logging | ||
|
||
logging.basicConfig(level=logging.INFO) | ||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def generate( | ||
script_dir: Path, | ||
deployment_type: str = "shadow", | ||
additional_settings: Dict[str, any] = None, | ||
) -> bool: | ||
""" | ||
Generates a script that defines the `get_deployment_config` function for configuring the deployment status and settings. | ||
Parameters: | ||
script_dir (Path): The directory where the generated deployment configuration script will be saved. | ||
This should be a valid writable path. | ||
deployment_type (str, optional): | ||
The type of deployment. Must be one of "shadow", "deployed", "baseline", or "deprecated". | ||
Default is "shadow". | ||
- "shadow": The deployment is shadowed and not yet active. | ||
- "deployed": The deployment is active and in use. | ||
- "baseline": The deployment is in a baseline state, for reference or comparison. | ||
- "deprecated": The deployment is deprecated and no longer supported. | ||
additional_settings (dict, optional): | ||
A dictionary of additional settings to include in the deployment configuration. | ||
These settings will be merged with the default configuration. Defaults to None. | ||
Raises: | ||
ValueError: If `deployment_type` is not one of the valid types. | ||
Returns: | ||
bool: True if the script was written and compiled successfully, False otherwise. | ||
""" | ||
valid_types = {"shadow", "deployed", "baseline", "deprecated"} | ||
if deployment_type.lower() not in valid_types: | ||
logging.error( | ||
f"Invalid deployment_type: {deployment_type}. Must be one of {valid_types}." | ||
) | ||
raise ValueError( | ||
f"Invalid deployment_type: {deployment_type}. Must be one of {valid_types}." | ||
) | ||
|
||
deployment_config = {"deployment_status": deployment_type.lower()} | ||
|
||
# Merge additional settings if provided | ||
if additional_settings and isinstance(additional_settings, dict): | ||
deployment_config.update(additional_settings) | ||
|
||
# Generate the script code | ||
code = f"""\"\"\" | ||
Deployment Configuration Script | ||
This script defines the deployment configuration settings for the application. | ||
It includes the deployment status and any additional settings specified. | ||
Deployment Status: | ||
- shadow: The deployment is shadowed and not yet active. | ||
- deployed: The deployment is active and in use. | ||
- baseline: The deployment is in a baseline state, for reference or comparison. | ||
- deprecated: The deployment is deprecated and no longer supported. | ||
Additional settings can be included in the configuration dictionary as needed. | ||
\"\"\" | ||
def get_deployment_config(): | ||
# Deployment settings | ||
deployment_config = {deployment_config} | ||
return deployment_config | ||
""" | ||
return utils_script_gen.save_script(script_dir, code) |
29 changes: 29 additions & 0 deletions
29
views_pipeline_core/templates/ensemble/template_config_hyperparameters.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from utils import utils_script_gen | ||
from pathlib import Path | ||
|
||
|
||
def generate(script_dir: Path) -> bool: | ||
""" | ||
Generates a script that defines a function for obtaining hyperparameter configurations | ||
necessary for model training. | ||
Parameters: | ||
script_dir (Path): | ||
The directory where the generated deployment configuration script will be saved. | ||
This should be a valid writable path. | ||
model_algorithm (str): | ||
The architecture of the model to be used for training. This string will be included in the | ||
hyperparameter configuration and can be modified to test different algorithms. | ||
Returns: | ||
bool: | ||
True if the script was written and compiled successfully, False otherwise. | ||
""" | ||
code = """def get_hp_config(): | ||
hp_config = { | ||
"steps": [*range(1, 36 + 1, 1)] | ||
} | ||
return hp_config | ||
""" | ||
return utils_script_gen.save_script(script_dir, code) |
39 changes: 39 additions & 0 deletions
39
views_pipeline_core/templates/ensemble/template_config_meta.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from utils import utils_script_gen | ||
from pathlib import Path | ||
|
||
|
||
def generate(script_dir: Path, model_name: str) -> bool: | ||
""" | ||
Generates a script that defines the `get_meta_config` function for model metadata. | ||
Parameters: | ||
script_dir (Path): | ||
The directory where the generated deployment configuration script will be saved. | ||
This should be a valid writable path. | ||
model_name (str): | ||
The name of the model. This will be included in the metadata configuration. | ||
Returns: | ||
bool: | ||
True if the script was written and compiled successfully, False otherwise. | ||
""" | ||
code = f"""def get_meta_config(): | ||
\""" | ||
Contains the metadata for the model (model architecture, name, target variable, and level of analysis). | ||
This config is for documentation purposes only, and modifying it will not affect the model, the training, or the evaluation. | ||
Returns: | ||
- meta_config (dict): A dictionary containing model meta configuration. | ||
\""" | ||
meta_config = {{ | ||
"name": "{model_name}", # Eg. "happy_kitten" | ||
"models": [], # Eg. ["model1", "model2", "model3"] | ||
"depvar": "ln_ged_sb_dep", # Eg. "ln_ged_sb_dep" | ||
"level": "pgm", # Eg. "pgm", "cm" | ||
"aggregation": "median", # Eg. "median", "mean" | ||
"creator": "Your name here" | ||
}} | ||
return meta_config | ||
""" | ||
return utils_script_gen.save_script(script_dir, code) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from utils import utils_script_gen | ||
from pathlib import Path | ||
|
||
|
||
def generate(script_dir: Path) -> bool: | ||
""" | ||
Generates a script that sets up the project paths, parses command-line arguments, | ||
sets up logging, and executes a single model run. | ||
Parameters: | ||
script_dir (Path): | ||
The directory where the generated script will be saved. | ||
This should be a valid writable path. | ||
Returns: | ||
bool: | ||
True if the script was written and compiled successfully, False otherwise. | ||
""" | ||
code = """import wandb | ||
import sys | ||
import warnings | ||
from pathlib import Path | ||
PATH = Path(__file__) | ||
sys.path.insert(0, str(Path( | ||
*[i for i in PATH.parts[:PATH.parts.index("views_pipeline") + 1]]) / "common_utils")) # PATH_COMMON_UTILS | ||
from set_path import setup_project_paths | ||
setup_project_paths(PATH) | ||
from utils_cli_parser import parse_args, validate_arguments | ||
from utils_logger import setup_logging | ||
from execute_model_runs import execute_single_run | ||
warnings.filterwarnings("ignore") | ||
try: | ||
from common_utils.ensemble_path import EnsemblePath | ||
from common_utils.global_cache import GlobalCache | ||
model_name = EnsemblePath.get_model_name_from_path(PATH) | ||
GlobalCache["current_model"] = model_name | ||
except ImportError as e: | ||
warnings.warn(f"ImportError: {e}. Some functionalities (model separated log files) may not work properly.", ImportWarning) | ||
except Exception as e: | ||
warnings.warn(f"An unexpected error occurred: {e}.", RuntimeWarning) | ||
logger = setup_logging("run.log") | ||
if __name__ == "__main__": | ||
wandb.login() | ||
args = parse_args() | ||
validate_arguments(args) | ||
execute_single_run(args) | ||
""" | ||
return utils_script_gen.save_script(script_dir, code) |
75 changes: 75 additions & 0 deletions
75
views_pipeline_core/templates/model/template_config_deployment.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
from typing import Dict | ||
from views_pipeline_core.templates.utils import save_script | ||
from pathlib import Path | ||
import logging | ||
|
||
logging.basicConfig(level=logging.INFO) | ||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def generate( | ||
script_dir: Path, | ||
deployment_type: str = "shadow", | ||
additional_settings: Dict[str, any] = None, | ||
) -> bool: | ||
""" | ||
Generates a script that defines the `get_deployment_config` function for configuring the deployment status and settings. | ||
Parameters: | ||
script_dir (Path): The directory where the generated deployment configuration script will be saved. | ||
This should be a valid writable path. | ||
deployment_type (str, optional): | ||
The type of deployment. Must be one of "shadow", "deployed", "baseline", or "deprecated". | ||
Default is "shadow". | ||
- "shadow": The deployment is shadowed and not yet active. | ||
- "deployed": The deployment is active and in use. | ||
- "baseline": The deployment is in a baseline state, for reference or comparison. | ||
- "deprecated": The deployment is deprecated and no longer supported. | ||
additional_settings (dict, optional): | ||
A dictionary of additional settings to include in the deployment configuration. | ||
These settings will be merged with the default configuration. Defaults to None. | ||
Raises: | ||
ValueError: If `deployment_type` is not one of the valid types. | ||
Returns: | ||
bool: True if the script was written and compiled successfully, False otherwise. | ||
""" | ||
valid_types = {"shadow", "deployed", "baseline", "deprecated"} | ||
if deployment_type.lower() not in valid_types: | ||
logging.error( | ||
f"Invalid deployment_type: {deployment_type}. Must be one of {valid_types}." | ||
) | ||
raise ValueError( | ||
f"Invalid deployment_type: {deployment_type}. Must be one of {valid_types}." | ||
) | ||
|
||
deployment_config = {"deployment_status": deployment_type.lower()} | ||
|
||
# Merge additional settings if provided | ||
if additional_settings and isinstance(additional_settings, dict): | ||
deployment_config.update(additional_settings) | ||
|
||
# Generate the script code | ||
code = f"""\"\"\" | ||
Deployment Configuration Script | ||
This script defines the deployment configuration settings for the application. | ||
It includes the deployment status and any additional settings specified. | ||
Deployment Status: | ||
- shadow: The deployment is shadowed and not yet active. | ||
- deployed: The deployment is active and in use. | ||
- baseline: The deployment is in a baseline state, for reference or comparison. | ||
- deprecated: The deployment is deprecated and no longer supported. | ||
Additional settings can be included in the configuration dictionary as needed. | ||
\"\"\" | ||
def get_deployment_config(): | ||
# Deployment settings | ||
deployment_config = {deployment_config} | ||
return deployment_config | ||
""" | ||
return save_script(script_dir, code) |
35 changes: 35 additions & 0 deletions
35
views_pipeline_core/templates/model/template_config_hyperparameters.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from views_pipeline_core.templates.utils import save_script | ||
from pathlib import Path | ||
|
||
|
||
def generate(script_dir: Path) -> bool: | ||
""" | ||
Generates a script that defines a function for obtaining hyperparameter configurations | ||
necessary for model training. | ||
Parameters: | ||
script_dir (Path): | ||
The directory where the generated deployment configuration script will be saved. | ||
This should be a valid writable path. | ||
Returns: | ||
bool: | ||
True if the script was written and compiled successfully, False otherwise. | ||
""" | ||
code = f""" | ||
def get_hp_config(): | ||
\""" | ||
Contains the hyperparameter configurations for model training. | ||
This configuration is "operational" so modifying these settings will impact the model's behavior during the training. | ||
Returns: | ||
- hyperparameters (dict): A dictionary containing hyperparameters for training the model, which determine the model's behavior during the training phase. | ||
\""" | ||
hyperparameters = {{ | ||
'steps': [*range(1, 36 + 1, 1)], | ||
# Add more hyperparameters as needed | ||
}} | ||
return hyperparameters | ||
""" | ||
return save_script(script_dir, code) |
44 changes: 44 additions & 0 deletions
44
views_pipeline_core/templates/model/template_config_meta.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from views_pipeline_core.templates.utils import save_script | ||
from pathlib import Path | ||
|
||
|
||
def generate(script_dir: Path, model_name: str, model_algorithm: str) -> bool: | ||
""" | ||
Generates a script that defines the `get_meta_config` function for model metadata. | ||
Parameters: | ||
script_dir (Path): | ||
The directory where the generated deployment configuration script will be saved. | ||
This should be a valid writable path. | ||
model_name (str): | ||
The name of the model. This will be included in the metadata configuration. | ||
model_algorithm (str): | ||
The algorithm of the model. This string will also be included in the metadata configuration. | ||
Returns: | ||
bool: | ||
True if the script was written and compiled successfully, False otherwise. | ||
""" | ||
code = f"""def get_meta_config(): | ||
\""" | ||
Contains the meta data for the model (model algorithm, name, target variable, and level of analysis). | ||
This config is for documentation purposes only, and modifying it will not affect the model, the training, or the evaluation. | ||
Returns: | ||
- meta_config (dict): A dictionary containing model meta configuration. | ||
\""" | ||
meta_config = {{ | ||
"name": "{model_name}", | ||
"algorithm": "{model_algorithm}", | ||
# Uncomment and modify the following lines as needed for additional metadata: | ||
# "depvar": "ln_ged_sb_dep", | ||
# "queryset": "escwa001_cflong", | ||
# "level": "pgm", | ||
# "creator": "Your name here" | ||
}} | ||
return meta_config | ||
""" | ||
return save_script(script_dir, code) |
Oops, something went wrong.