cursus.core.base¶
Core base classes for the cursus framework.
This module provides the foundational base classes that are used throughout the cursus framework for configuration, contracts, specifications, and builders.
- class DependencyType(*values)[source]¶
Bases:
EnumTypes of dependencies in the pipeline.
- MODEL_ARTIFACTS = 'model_artifacts'¶
- PROCESSING_OUTPUT = 'processing_output'¶
- TRAINING_DATA = 'training_data'¶
- HYPERPARAMETERS = 'hyperparameters'¶
- PAYLOAD_SAMPLES = 'payload_samples'¶
- CUSTOM_PROPERTY = 'custom_property'¶
- class NodeType(*values)[source]¶
Bases:
EnumTypes of nodes in the pipeline based on their dependency/output characteristics.
- SOURCE = 'source'¶
- INTERNAL = 'internal'¶
- SINK = 'sink'¶
- SINGULAR = 'singular'¶
- class ValidationResult(*, is_valid, errors=<factory>, warnings=<factory>)[source]¶
Bases:
BaseModelResult of script contract validation
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class ScriptAnalyzer(script_path)[source]¶
Bases:
objectAnalyzes Python scripts to extract I/O patterns and environment variable usage
- class StepInterface(*, step_type, node_type=NodeType.INTERNAL, registry=<factory>, compute=<factory>, patterns=<factory>, contract, spec=<factory>, variants=<factory>)[source]¶
Bases:
BaseModelValidated representation of a .step.yaml file.
This is the single message passed among dep resolver, builder, and assembler. Replaces the previous (ScriptContract|StepContract, StepSpecification) tuple.
Build it from a parsed YAML dict via
from_yaml(), which applies any requestedjob_typevariant before validation.- property dependencies: Dict[str, DependencyDecl]¶
- classmethod from_yaml(data, job_type=None)[source]¶
Build a StepInterface from a parsed
.step.yamldict, resolving variants.When
job_typenames a variant, that variant’sspec/contractoverrides are deep-merged over the base sections before validation. The merge is recursive: a variant that lists only a subset ofspec.dependencies(oroutputs/ contractinputs) overrides just those ports’ fields and leaves the rest of the base set intact — it does not replace the whole nested dict. Steps without a matching variant fall back to the base sections unchanged.A shallow merge here was a latent bug: because variants routinely restate only the ports they tweak,
{**base, **variant}at the section level dropped every base port the variant happened to omit (e.g. it droppedhyperparameters_s3_urifromRiskTableMapping’s variants, which then violated the contract↔spec alignment invariant and raised at construction).
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- property outputs: Dict[str, OutputDecl]¶
- property script_contract: ContractSection¶
Legacy StepSpecification.script_contract accessor.
- validate_contract_alignment()[source]¶
Validate that the contract aligns with the spec.
Mirrors legacy StepSpecification.validate_contract_alignment: every contract input must have a matching spec dependency, and every contract output a matching spec output (extra spec deps/outputs and output aliases allowed). Returns a ValidationResult (is_valid / errors).
- registry: RegistrySection¶
- compute: ComputeSpec¶
Declarative COMPUTE descriptor (FZ 31e1d3k) — a TOP-LEVEL section (peer of contract/spec) because it describes the BUILDER’s compute object (processor/estimator/model/transformer), not the script contract: script-less steps (CreateModel/Transform) carry a near-empty contract but a full compute.
_sync_and_alignmirrors it ontocontract.computefor back-compat. Empty (kind=None) ⇒ the step keeps its own factory.
- patterns: PatternsSection¶
Per-axis STRATEGY-SELECTION knobs (FZ 31e1d3f1) — the blueprint that wires pattern injection (step_assembly / include_job_type_in_path / direct_input_keys), read into the bound handler by
_auto_bind_handlerso the YAML steers the build, not a builder shell.
- contract: ContractSection¶
- spec: SpecSection¶
- variants: Dict[str, VariantDecl]¶
- class ModelHyperparameters(*, full_field_list, cat_field_list, tab_field_list, id_name, label_name, multiclass_categories, categorical_features_to_encode=<factory>, model_class='base_model', device=-1, header=0, lr=3e-05, batch_size=2, eval_batch_size_multiplier=2.0, max_epochs=3, metric_choices=['f1_score', 'auroc'], optimizer='SGD', class_weights=None, **extra_data)[source]¶
Bases:
BaseModelBase model hyperparameters for training tasks.
Fields are organized into three tiers: 1. Tier 1: Essential User Inputs - fields that users must explicitly provide 2. Tier 2: System Inputs with Defaults - fields with reasonable defaults that can be overridden 3. Tier 3: Derived Fields - fields calculated from other fields (private attributes with properties)
- categorize_fields()[source]¶
Categorize all fields into three tiers: 1. Tier 1: Essential User Inputs - fields with no defaults (required) 2. Tier 2: System Inputs - fields with defaults (optional) 3. Tier 3: Derived Fields - properties that access private attributes
- classmethod from_base_hyperparam(base_hyperparam, **kwargs)[source]¶
Create a new hyperparameter instance from a base hyperparameter. This is a virtual method that all derived classes can use to inherit from a parent config.
- Parameters:
base_hyperparam (ModelHyperparameters) – Parent ModelHyperparameters instance
**kwargs (Any) – Additional arguments specific to the derived class
- Returns:
A new instance of the derived class initialized with parent fields and additional kwargs
- Return type:
- get_public_init_fields()[source]¶
Get a dictionary of public fields suitable for initializing a child hyperparameter. Only includes fields that should be passed to child class constructors. Both essential user inputs and system inputs with defaults or user-overridden values are included to ensure all user customizations are properly propagated.
- Returns:
Dictionary of field names to values for child initialization
- Return type:
Dict[str, Any]
- model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'allow', 'protected_namespaces': (), 'validate_assignment': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_post_init(context, /)¶
This function is meant to behave like a BaseModel method to initialize private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
- Parameters:
self (BaseModel) – The BaseModel instance.
context (Any) – The context.
Modules
Template-based step builder + construction-verb handlers (Phase 0c of the simplification). |
|
Base Pipeline Configuration with Self-Contained Derivation Logic |
|
Base Script Validation Classes |
|
Shared enums for the cursus core base classes. |
|
StepContract — immutable data loaded from .step.yaml. |
|
StepInterface — the single Pydantic-validated data structure for a .step.yaml. |