paths
orchard.core.paths
¶
Filesystem Authority and Path Orchestration Package.
Centralizes all path-related logic for Orchard ML using a three-layer approach:
-
Constants Layer (constants module):
-
SUPPORTED_RESOLUTIONS, METRIC_*, LOGGER_NAME: Pure project constants
-
LogStyle: Unified logging style constants (symbols, separators, ANSI)
-
Root Discovery Layer (root module):
-
PROJECT_ROOT: Dynamically resolved project root
-
DATASET_DIR, OUTPUTS_ROOT: Global directory constants
-
Dynamic Layer (RunPaths class):
-
Experiment-specific directory management
- Atomic run isolation via deterministic hashing
- Automatic subdirectory creation (figures, models, reports, logs, etc.)
Example
from orchard.core.paths import PROJECT_ROOT, RunPaths, LogStyle print(PROJECT_ROOT) PosixPath('/home/user/orchard-ml')
LogStyle
¶
Unified logging style constants for consistent visual hierarchy.
Provides separators, symbols, indentation, and ANSI color codes used
by all logging modules. Placed here (in paths.constants) rather
than in logger.styles so that low-level packages (environment,
config) can reference the constants without triggering circular
imports.
RunPaths
¶
Bases: BaseModel
Immutable container for experiment-specific directory paths.
Implements atomic run isolation using a deterministic hashing strategy that combines DATE + DATASET_SLUG + MODEL_SLUG + CONFIG_HASH to create unique, collision-free directory structures. The Pydantic frozen model ensures paths cannot be modified after creation.
Attributes:
| Name | Type | Description |
|---|---|---|
run_id |
str
|
Unique identifier in format YYYYMMDD_dataset_model_hash. |
dataset_slug |
str
|
Normalized lowercase dataset name. |
architecture_slug |
str
|
Sanitized alphanumeric architecture identifier. |
root |
Path
|
Base directory for all run artifacts. |
figures |
Path
|
Directory for plots, confusion matrices, ROC curves. |
checkpoints |
Path
|
Directory for saved checkpoints (.pth files). |
reports |
Path
|
Directory for config mirrors, CSV/XLSX summaries. |
logs |
Path
|
Directory for training logs and session output. |
database |
Path
|
Directory for SQLite optimization studies. |
exports |
Path
|
Directory for production exports (ONNX). |
Example
Directory structure created::
outputs/20260208_organcmnist_efficientnetb0_a3f7c2/
├── figures/
├── checkpoints/
├── reports/
├── logs/
├── database/
└── exports/
best_model_path
property
¶
Path for the best-performing model checkpoint.
Returns:
| Type | Description |
|---|---|
Path
|
Path in format: checkpoints/best_{architecture_slug}.pth |
final_report_path
property
¶
Path for the comprehensive experiment summary report.
Returns:
| Type | Description |
|---|---|
Path
|
Path to reports/training_summary.xlsx |
create(dataset_slug, architecture_name, training_cfg, base_dir=None)
classmethod
¶
Factory method to create and initialize a unique run environment.
Creates a new RunPaths instance with a deterministic unique ID based on dataset, model, and training configuration. Physically creates all subdirectories on the filesystem.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_slug
|
str
|
Dataset identifier (e.g., 'organcmnist'). Will be normalized to lowercase. |
required |
architecture_name
|
str
|
Human-readable model name (e.g., 'EfficientNet-B0'). Special characters are stripped, converted to lowercase. |
required |
training_cfg
|
dict[str, Any]
|
Dictionary of hyperparameters used for hash generation. Supports nested dicts, but only hashable primitives (int, float, str, bool, list) contribute to the hash. |
required |
base_dir
|
Path | None
|
Custom base directory for outputs. Defaults to OUTPUTS_ROOT (typically './outputs'). |
None
|
Returns:
| Type | Description |
|---|---|
'RunPaths'
|
Fully initialized RunPaths instance with all directories created. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If dataset_slug or architecture_name is not a string. |
Example
paths = RunPaths.create( ... dataset_slug="OrganCMNIST", ... architecture_name="EfficientNet-B0", ... training_cfg={"batch_size": 32, "lr": 0.001} ... ) paths.dataset_slug 'organcmnist' paths.architecture_slug 'efficientnetb0'
Source code in orchard/core/paths/run_paths.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
get_fig_path(filename)
¶
Generate path for a visualization artifact.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Name of the figure file (e.g., 'confusion_matrix.png'). |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Absolute path within the figures directory. |
Source code in orchard/core/paths/run_paths.py
get_config_path()
¶
Get path for the archived run configuration.
Returns:
| Type | Description |
|---|---|
Path
|
Path to reports/config.yaml |
get_db_path()
¶
Get path for Optuna SQLite study database.
The database directory is created during RunPaths initialization, ensuring the parent directory exists before Optuna writes to it.
Returns:
| Type | Description |
|---|---|
Path
|
Path to database/study.db |
Source code in orchard/core/paths/run_paths.py
get_project_root()
¶
Dynamically locate the project root by searching for anchor files.
Traverses upward from current file's directory until finding a marker file (.git or pyproject.toml). Supports Docker environments via IN_DOCKER environment variable override.
Returns:
| Type | Description |
|---|---|
Path
|
Resolved absolute Path to the project root directory. |
Note:
- IN_DOCKER=1 or IN_DOCKER=TRUE returns /app
- Falls back to fixed parent traversal if no markers found
Source code in orchard/core/paths/root.py
setup_static_directories()
¶
Ensure core project directories exist at startup.
Creates DATASET_DIR and OUTPUTS_ROOT if they do not exist, preventing runtime errors during data fetching or artifact creation. Uses mkdir(parents=True, exist_ok=True) for idempotent operation.