Command Line Entrypoint
Relevant source files
The following files were used as context for generating this wiki page:
The Command Line Entrypoint serves as the primary interface for interacting with the AlphaPy machine learning pipeline. It provides a standardized way to initialize models, process data, and execute training or prediction workflows through three main console scripts: alphapy, mflow (MarketFlow), and sflow (SportFlow). These entrypoints handle environment setup, logging initialization, and configuration parsing before delegating to specific pipeline implementations.
The architecture follows a modular pattern where specific entrypoints (for market or sports data) prepare specialized data frames and configurations before invoking the core AlphaPy main_pipeline. This ensures a unified model lifecycle management while allowing for domain-specific preprocessing and feature engineering.
Sources: setup.py:61-65, alphapy/__main__.py:461-512, alphapy/market_flow.py:345-427, alphapy/sport_flow.py:463-549
Console Scripts and Registration
AlphaPy defines three primary entrypoints in its packaging configuration. These are registered as console scripts using setuptools, allowing users to execute the pipelines directly from the terminal.
| Command | Module Entrypoint | Purpose |
|---|---|---|
alphapy | alphapy.__main__:main | Core AlphaPy pipeline for general machine learning tasks. |
mflow | alphapy.market_flow:main | Specialized pipeline for financial market analysis and trading systems. |
sflow | alphapy.sport_flow:main | Specialized pipeline for predicting sporting event outcomes. |
Sources: setup.py:61-65
Core Entrypoint Execution Flow
The alphapy entrypoint (defined in __main__.py) follows a structured execution sequence:
- Logging Initialization: Sets up file-based (
alphapy.log) and console logging. - Argument Parsing: Processes command-line flags such as
--trainor--predict. - Configuration Loading: Reads
model.ymlto define model specifications. - Environment Preparation: Creates necessary output directories (config, data, input, etc.).
- Model Instantiation: Creates a
Modelobject containing specifications. - Pipeline Delegation: Calls
main_pipelinewhich routes to eithertraining_pipelineorprediction_pipeline.
Core Pipeline Flow
The following diagram illustrates the high-level logic within the main entrypoint:
Domain-Specific Entrypoints
MarketFlow (mflow)
The market_flow.py entrypoint is tailored for financial speculators. It introduces market-specific arguments like --tdate (train date) and --pdate (predict date). It coordinates the loading of market.yml, retrieval of market data via get_market_data, and optional execution of a System for trading analysis.
Sources: alphapy/market_flow.py:345-427, alphapy/market_flow.py:284-340
SportFlow (sflow)
The sport_flow.py entrypoint focuses on sports statistics. It processes historical game data to generate team-specific features and seasonal deltas. After preparing a specialized final_frame (model frame), it invokes the core main_pipeline.
Sources: alphapy/sport_flow.py:463-549, alphapy/sport_flow.py:607-610
Command Line Arguments
Each entrypoint utilizes argparse to handle user input. While the core entrypoint focuses on the mode of operation, specialized entrypoints include date-based filtering.
| Argument | Destination | Description | Entrypoints |
|---|---|---|---|
--predict | predict_mode=True | Runs the prediction pipeline using a saved model. | All |
--train | predict_mode=False | Runs the training pipeline (Default). | All |
--pdate | predict_date | The date for starting predictions (YYYY-MM-DD). | mflow, sflow |
--tdate | train_date | The date for starting training (YYYY-MM-DD). | mflow, sflow |
Sources: alphapy/__main__.py:488-492, alphapy/market_flow.py:382-390, alphapy/sport_flow.py:504-512
Data and Directory Management
Upon execution, the entrypoint ensures the local environment is prepared by verifying or creating a specific directory structure relative to the project directory defined in model.yml.
# Directory creation logic in alphapy.__main__.py
output_dirs = ['config', 'data', 'input', 'model', 'output', 'plots']
for od in output_dirs:
output_dir = SSEP.join([specs['directory'], od])
if not os.path.exists(output_dir):
logger.info("Creating directory %s", output_dir)
os.makedirs(output_dir)
Sources: alphapy/__main__.py:497-502, alphapy/market_flow.py:413-418
Summary
The Command Line Entrypoint is the gateway to AlphaPy's functionality, abstracting the complexity of model initialization and pipeline orchestration. By providing distinct commands for general, market, and sports contexts, the system allows developers and data scientists to move seamlessly from raw data ingestion to predictive modeling and performance evaluation.
Sources: alphapy/__main__.py:461-512, alphapy/market_flow.py:345-427, alphapy/sport_flow.py:463-549