CADETProcess.evaluation_pipeline.EvaluationPipeline#
- class CADETProcess.evaluation_pipeline.EvaluationPipeline(space: ParameterSpace, cache_dir: str | Path | None = None)[source]#
Bases:
objectDAG-based evaluation engine backed by pipefunc.Pipeline.
Parameterized by a ParameterSpace; cannot be constructed without one. evaluate(x) writes x into the evaluation objects via space.set_values, then runs the registered node graph and returns all (or selected) named outputs.
pipefunc is an internal implementation detail. No PipeFunc or Pipeline objects appear in the public API.
- Parameters:
- spaceParameterSpace
Owns the evaluation objects and knows how to write parameter values into them. evaluate decodes the vector and delegates to space.set_values.
Examples
>>> pipeline = EvaluationPipeline(space) >>> pipeline.add_evaluator(simulate, output_name="simulation_results") >>> pipeline.add_evaluator( ... fractionate, output_name="fractionation_results", ... requires=["simulation_results"], ... ) >>> results = pipeline.evaluate({"length": 0.5}) >>> results["fractionation_results"]
- add_evaluator(func: Callable, output_name: str, requires: list[str] | None = None, cache: bool = True) None[source]#
Register a callable as a named node in the evaluation DAG.
- Parameters:
- funccallable
The function to register. Its return value becomes the named output. When requires is None, func’s own argument names must match upstream output_name values so pipefunc can wire them. When requires is given, a wrapper is generated whose argument names match the requires list, so func’s argument names are irrelevant.
- output_namestr
Name of this node’s output in the DAG. Must be a valid Python identifier and unique within this pipeline.
- requireslist[str], optional
Ordered list of upstream output names to inject as positional arguments to func. When given, func must accept
len(requires)positional arguments. When None, pipefunc wires func by its own argument names.- cachebool
Whether to cache the output of this node. Defaults to True. Pass False for nodes with side effects (e.g. callbacks) where repeated execution is intentional and results need not be stored.
- Raises:
- TypeError
If func is not callable.
- ValueError
If output_name is already registered or is not a valid identifier, or if any entry in requires is not a valid identifier.
- evaluate(assignment: Mapping[str, Any], targets: list[str] | None = None, bypass_cache: bool = False, evaluation_objects: list[Any] | None = None) dict[str, Any][source]#
Set parameter values and run the evaluation graph.
The Pipeline instance is reused across calls. Cache invalidation is handled by
_EvaluationContext: each call constructs a context keyed on(x_key, obj_uuid), wherex_keyis the registration-ordered(name, value)tuple of the independent assignment. Results for different assignments are naturally distinct cache entries without manual cache clearing; assignments that only differ in a categorical value are distinct entries too. Intermediate nodes shared by multiple targets within a single call are computed only once.When the parameter space has no evaluation objects, the assignment itself becomes the root: root nodes (those without
requires) receive the assignment mapping instead of an evaluation object, and the run follows the single-result return convention.- Parameters:
- assignmentMapping
Values for the independent parameters by name, in physical units. Order-insensitive. Numeric vectors are an encoding owned by
TransformedSpace; decode first:pipeline.evaluate(space.transformed_space.decode(x)).- targetslist[str], optional
Output names to compute. None computes all registered outputs. Requesting a subset exploits pipefunc’s lazy evaluation: only the subgraph needed for the requested outputs is executed.
- bypass_cachebool
When True, clear the pipeline cache before evaluating so all nodes are recomputed from scratch. Useful for debugging to confirm that results are not stale.
- evaluation_objectslist, optional
Restrict the run to these registered evaluation objects. None runs all registered objects. The return convention follows the selected subset: one object gives plain values, several give lists.
- Returns:
- dict[str, Any]
Mapping from output name to result. For a single evaluation object (or none registered) the values are plain results (or EvaluationFailure). For multiple evaluation objects the values are lists indexed by evaluation object. Results may be EvaluationFailure instances when a node failed.