cursus.core.compiler¶
Pipeline compiler module.
This module provides high-level interfaces for compiling PipelineDAG structures directly into executable SageMaker pipelines without requiring custom template classes.
- compile_dag_to_pipeline(dag=None, dag_path=None, config_path=None, sagemaker_session=None, role=None, pipeline_name=None, **kwargs)[source]¶
Compile a PipelineDAG into a complete SageMaker Pipeline.
This is the main entry point for users who want a simple, one-call compilation from DAG to pipeline.
- Parameters:
dag (PipelineDAG | None) – PipelineDAG instance defining the pipeline structure (optional if dag_path provided)
dag_path (str | None) – Path to serialized DAG JSON file (optional if dag provided)
config_path (str) – Path to configuration file containing step configs
sagemaker_session (PipelineSession | None) – SageMaker session for pipeline execution
role (str | None) – IAM role for pipeline execution
pipeline_name (str | None) – Optional pipeline name override
**kwargs (Any) – Additional arguments passed to template constructor
- Returns:
Generated SageMaker Pipeline ready for execution
- Raises:
ValueError – If neither dag nor dag_path provided, or if DAG is invalid
FileNotFoundError – If dag_path or config_path files not found
ConfigurationError – If configuration validation fails
RegistryError – If step builders not found for config types
- Return type:
Pipeline
Example
>>> # Option 1: Using PipelineDAG instance >>> dag = PipelineDAG() >>> dag.add_node("data_load") >>> dag.add_node("preprocess") >>> dag.add_edge("data_load", "preprocess") >>> >>> pipeline = compile_dag_to_pipeline( ... dag=dag, ... config_path="configs/my_pipeline.json", ... sagemaker_session=session, ... role="arn:aws:iam::123456789012:role/SageMakerRole" ... ) >>> pipeline.upsert() >>> >>> # Option 2: Loading DAG from file >>> pipeline = compile_dag_to_pipeline( ... dag_path="saved_dags/my_pipeline.json", ... config_path="configs/my_pipeline.json", ... sagemaker_session=session, ... role="arn:aws:iam::123456789012:role/SageMakerRole" ... )
- compile_single_node_to_pipeline(dag, config_path, target_node, manual_inputs, sagemaker_session=None, role=None, pipeline_name=None, validate_inputs=True, config_map=None, pipeline_parameters=None, **kwargs)[source]¶
Compile a single-node pipeline with manual input overrides.
IMPROVED API: config_map is now optional and will be automatically loaded from config_path if not provided, matching the API consistency of compile_dag_to_pipeline().
This function creates a SingleNodeCompiler and delegates to its compile method, providing a simple one-line API for single-node execution.
- Parameters:
dag (PipelineDAG | str) – PipelineDAG instance or path to serialized DAG file
config_path (str) – Path to configuration JSON file
target_node (str) – Name of node to execute in isolation
manual_inputs (Dict[str, str]) – Dict mapping logical input names to S3 URIs Example: {“input_path”: “s3://bucket/previous-run/output/”}
sagemaker_session (Any | None) – SageMaker session for pipeline execution
role (str | None) – IAM role ARN for SageMaker permissions
pipeline_name (str | None) – Optional custom pipeline name Default: “{target_node}-isolated”
validate_inputs (bool) – Whether to validate inputs before compilation Checks: S3 URI format, node existence (default: True)
config_map (Dict | None) – Optional pre-loaded config map for advanced use cases If None (default), automatically loaded from config_path
pipeline_parameters (List[str | ParameterString] | None) – Pipeline parameters to pass to compiler. If None, uses default parameters (EXECUTION_S3_PREFIX, KMS_KEY, etc.)
**kwargs (Any) – Additional arguments passed to SingleNodeCompiler
- Returns:
Single-node Pipeline ready for execution via pipeline.start()
- Raises:
ValueError – If validation fails or node not found
FileNotFoundError – If config_path doesn’t exist
- Return type:
- Example (Simple - Config Auto-Loaded):
>>> # After a 5-hour run where preprocess succeeded but train failed >>> manual_inputs = { ... "input_path": "s3://my-bucket/run-123/preprocess/output/" ... } >>> >>> pipeline = compile_single_node_to_pipeline( ... dag=my_dag, ... config_path="configs/pipeline.json", # ✓ Auto-loads config ... target_node="train", ... manual_inputs=manual_inputs, ... sagemaker_session=session, ... role=role ... ) >>> >>> # Execute just the train step - no 5-hour wait! >>> execution = pipeline.start()
- Example (Advanced - Pre-Loaded Config):
>>> # For performance optimization when config already loaded >>> config_map = load_configs("configs/pipeline.json") >>> >>> pipeline = compile_single_node_to_pipeline( ... dag=my_dag, ... config_path="configs/pipeline.json", ... target_node="train", ... manual_inputs={"input_path": "s3://..."}, ... config_map=config_map, # Pass pre-loaded config ... sagemaker_session=session, ... role=role ... )
- Benefits:
28% time savings on debugging failed pipelines
33% cost savings by avoiding redundant computation
3× faster iteration cycles during development
API consistency with compile_dag_to_pipeline()
- class PipelineDAGCompiler(config_path, sagemaker_session=None, role=None, config_resolver=None, step_catalog=None, pipeline_parameters=None, project_root=None, anchor_file=None, workspace_dirs=None, **kwargs)[source]¶
Bases:
objectAdvanced API for DAG-to-template compilation with additional control.
This class provides more control over the compilation process, including validation, debugging, and customization options.
- analyze_pipeline_structure()[source]¶
Analyze and print the complete pipeline structure.
Delegates to the template’s analyze_pipeline_structure method. Must be called after compile() or compile_with_report().
- Raises:
AttributeError – If called before compilation
- compile(dag, pipeline_name=None, **kwargs)[source]¶
Compile DAG to pipeline with full control.
- Parameters:
dag (PipelineDAG | str) – PipelineDAG instance or path to serialized DAG file
pipeline_name (str | None) – Optional pipeline name override
**kwargs (Any) – Additional arguments for template
- Returns:
Generated SageMaker Pipeline
- Raises:
PipelineAPIError – If compilation fails
- Return type:
Pipeline
- compile_with_report(dag, pipeline_name=None, **kwargs)[source]¶
Compile DAG to pipeline and return detailed compilation report.
- Parameters:
dag (PipelineDAG | str) – PipelineDAG instance or path to serialized DAG file
pipeline_name (str | None) – Optional pipeline name override
**kwargs (Any) – Additional arguments for template
- Returns:
Tuple of (Pipeline, ConversionReport)
- Return type:
Tuple[Pipeline, ConversionReport]
- create_template(dag, **kwargs)[source]¶
Create a pipeline template from the DAG without generating the pipeline.
This allows inspecting or modifying the template before pipeline generation.
- Parameters:
dag (PipelineDAG) – PipelineDAG instance to create a template for
**kwargs (Any) – Additional arguments for template
- Returns:
DynamicPipelineTemplate instance ready for pipeline generation
- Raises:
PipelineAPIError – If template creation fails
- Return type:
- get_last_template()[source]¶
Get the last template used during compilation.
This template will have its pipeline_metadata populated from the generation process. Use this method to get access to a template that has gone through the complete pipeline generation process, particularly useful for execution document generation.
- Returns:
The last template used in compilation, or None if no compilation has occurred
- Return type:
Optional[‘DynamicPipelineTemplate’]
- get_supported_step_types()[source]¶
Get list of supported step types.
- Returns:
List of supported step type names
- Return type:
- preview_resolution(dag)[source]¶
Preview how DAG nodes will be resolved to configs and builders.
Returns a detailed preview showing: - Node → Configuration mappings - Configuration → Step Builder mappings - Detected step types and dependencies - Potential issues or ambiguities
- Parameters:
dag (PipelineDAG | str) – PipelineDAG instance or path to serialized DAG file
- Returns:
ResolutionPreview with detailed resolution information
- Return type:
- validate_dag_compatibility(dag)[source]¶
Validate that DAG nodes have corresponding configurations.
Returns detailed validation results including: - Missing configurations - Unresolvable step builders - Configuration validation errors - Dependency resolution issues
- Parameters:
dag (PipelineDAG | str) – PipelineDAG instance or path to serialized DAG file
- Returns:
ValidationResult with detailed validation information
- Return type:
- class SingleNodeCompiler(config_path, sagemaker_session=None, role=None, step_catalog=None, pipeline_parameters=None, project_root=None, anchor_file=None, **kwargs)[source]¶
Bases:
objectSpecialized compiler for single-node pipeline execution.
Enables rapid debugging by creating isolated pipelines containing just one node, with manual input overrides bypassing normal dependency resolution.
Example
>>> compiler = SingleNodeCompiler( ... config_path="configs/pipeline.json", ... sagemaker_session=session, ... role=role ... ) >>> >>> # Validate before execution >>> validation = compiler.validate_node_and_inputs( ... dag=dag, ... target_node="train", ... manual_inputs={"input_path": "s3://bucket/data/"} ... ) >>> >>> if validation.is_valid: ... pipeline = compiler.compile( ... dag=dag, ... target_node="train", ... manual_inputs={"input_path": "s3://bucket/data/"} ... )
- compile(dag, target_node, manual_inputs, pipeline_name=None, validate_inputs=True, config_map=None, **assembler_kwargs)[source]¶
Compile single-node pipeline with manual inputs.
IMPROVED: config_map is now optional! If not provided, it will be automatically loaded from the config_path using the same mechanism as compile_dag_to_pipeline().
- Parameters:
dag (PipelineDAG | str) – PipelineDAG instance or path to serialized DAG file
target_node (str) – Name of node to execute
manual_inputs (Dict[str, str]) – Manual input paths (logical_name -> s3_uri)
pipeline_name (str | None) – Optional pipeline name
validate_inputs (bool) – Whether to validate inputs (default: True)
config_map (Dict | None) – Optional pre-loaded config map (auto-loaded if None)
**assembler_kwargs (Any) – Additional arguments for PipelineAssembler
- Returns:
Single-node Pipeline ready for execution
- Raises:
ValueError – If validation fails or compilation errors occur
FileNotFoundError – If config file not found (when auto-loading)
- Return type:
- preview_execution(dag, target_node, manual_inputs)[source]¶
Preview execution without creating pipeline.
- Parameters:
- Returns:
ExecutionPreview with detailed execution information
- Return type:
- StepConfigResolver¶
alias of
StepConfigResolverAdapter
- class ValidationResult(*, is_valid, missing_configs=<factory>, unresolvable_builders=<factory>, config_errors=<factory>, dependency_issues=<factory>, warnings=<factory>)[source]¶
Bases:
BaseModelResult of DAG-config compatibility validation.
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- SingleNodeValidationResult¶
alias of
ValidationResult
- class ExecutionPreview(target_node, step_type, config_type, input_mappings=<factory>, missing_required_inputs=<factory>, missing_optional_inputs=<factory>, output_paths=<factory>, estimated_instance_type='Unknown', estimated_duration=None, warnings=<factory>)[source]¶
Bases:
objectPreview of single-node execution.
- class ResolutionPreview(*, node_config_map, config_builder_map, resolution_confidence, ambiguous_resolutions=<factory>, recommendations=<factory>)[source]¶
Bases:
BaseModelPreview of how DAG nodes will be resolved.
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class ConversionReport(*, pipeline_name, steps, resolution_details, avg_confidence, warnings=<factory>, metadata=<factory>)[source]¶
Bases:
BaseModelReport generated after successful pipeline conversion.
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class ValidationEngine[source]¶
Bases:
objectEngine for validating DAG-config compatibility.
- validate_dag_compatibility(dag_nodes, available_configs, config_map, builder_registry, metadata=None)[source]¶
Validate DAG-config compatibility.
- Parameters:
available_configs (Dict[str, Any]) – Available configuration instances
config_map (Dict[str, Any]) – Resolved node-to-config mapping
metadata (Dict[str, Any] | None) – Optional pipeline metadata; its
config_typesmap (node -> config class) records USER-AUTHORED node→config bindings. The node-vs-config cross-check honors it, so a deliberately off-convention node name explicitly mapped there is not flagged as a misresolution.
- Returns:
ValidationResult with detailed validation information
- Return type:
- validate_pipeline_name(name)[source]¶
Validate that a pipeline name conforms to SageMaker constraints.
- sanitize_pipeline_name(name)[source]¶
Sanitize a pipeline name to conform to SageMaker constraints.
This function: 1. Replaces dots with hyphens 2. Replaces underscores with hyphens 3. Removes any other special characters 4. Ensures the name starts with an alphanumeric character 5. Ensures the name ends with an alphanumeric character
- generate_pipeline_name(base_name, version='1.0')[source]¶
Generate a valid pipeline name with the format: {base_name}-{random_word}-{version}-pipeline
This function ensures the generated name conforms to SageMaker constraints by sanitizing it before returning.
- exception ConfigurationError(message, missing_configs=None, available_configs=None)[source]¶
Bases:
PipelineAPIErrorRaised when configuration-related errors occur.
- exception AmbiguityError(message, node_name=None, candidates=None)[source]¶
Bases:
PipelineAPIErrorRaised when multiple configurations could match a DAG node.
- exception ValidationError(message, validation_errors=None)[source]¶
Bases:
PipelineAPIErrorRaised when DAG-config validation fails.
- exception ResolutionError(message, failed_nodes=None, suggestions=None)[source]¶
Bases:
PipelineAPIErrorRaised when DAG node resolution fails.
Modules
DAG Compiler for the Pipeline API. |
|
Dynamic Pipeline Template for the Pipeline API. |
|
Exception classes for the Pipeline API. |
|
Name generator utilities for pipeline naming. |
|
Single node execution compiler for debugging and rapid iteration. |
|
Validation and preview classes for the Pipeline API. |