CADETProcess.problem.Problem#
- class CADETProcess.problem.Problem(parameter_space: ParameterSpace | None = None, metric_space: MetricSpace | None = None, backend: EvaluationBackend | None = None, name: str | None = None)[source]#
Bases:
objectGeneral problem description: parameter space, metric space, backend.
Concrete and directly usable; samplers and surrogates consume it without any optimizer policy.
- Parameters:
- parameter_spaceParameterSpace, optional
Input domain. A fresh empty space is created when omitted.
- metric_spaceMetricSpace, optional
Output declarations. A fresh empty space is created when omitted.
- backendEvaluationBackend, optional
Computes the declared metrics for a named assignment.
evaluateraises until a backend is set.- namestr, optional
Problem name; used in the string representation.
Examples
>>> problem = Problem(parameter_space, metric_space, backend=pipeline) >>> results = problem.evaluate({"length": 0.5}) >>> surrogate_problem = problem.with_evaluator(surrogate)
- property backend: EvaluationBackend | None#
Active evaluation backend; None until one is set.
- evaluate(assignment: Mapping[str, Any], targets: list[str] | None = None) dict[str, Any][source]#
Evaluate the declared metrics for a named parameter assignment.
Delegates to the backend, then validates each declared metric against its declared shape. Backend outputs that are not declared in the metric space (pipeline intermediates) are dropped; declared metric names are always passed to the backend as its targets, so undeclared side-effect nodes (callbacks) never execute.
EvaluationFailurevalues pass through unvalidated; substituting fallback values is optimizer policy and stays out ofProblem.A backend evaluating multiple evaluation objects returns per-object lists (the
EvaluationPipelineconvention). Such values are reduced to the metric’s declared shape here: the entries belonging to the metric’s declaredevaluation_objectcoordinates are selected and stacked object-major. If any selected entry is anEvaluationFailure, the selected per-object list passes through unvalidated instead.- Parameters:
- assignmentMapping
Values for the independent parameters by name, in physical units.
- targetslist[str], optional
Declared metric names to evaluate. None evaluates all declared metrics. A pipeline backend only executes the subgraph the requested metrics need.
- Returns:
- dict[str, Any]
Requested metrics in registration order; values are arrays in canonical shape,
EvaluationFailure, or a per-object list containing at least oneEvaluationFailure.
- Raises:
- RuntimeError
If no backend is set.
- ValueError
If targets contains an undeclared name, the backend result misses a declared metric, or a value does not match its declared shape.
- evaluate_batch(assignments: Sequence[Mapping[str, Any]], targets: list[str] | None = None, parallelization_backend: Any = None) list[dict[str, Any]][source]#
Evaluate the declared metrics for a batch of named assignments.
Uniform batch entry point: optimizers, samplers, and surrogate trainers all dispatch populations through this method. Each assignment is evaluated via
evaluate; a row whose evaluation raises yields anEvaluationFailurefor every requested target instead of aborting the batch. Substituting fallback values for failures remains caller policy.- Parameters:
- assignmentsSequence[Mapping]
One named parameter assignment per row, in physical units.
- targetslist[str], optional
Declared metric names to evaluate. None evaluates all declared metrics.
- parallelization_backendParallelizationBackendBase, optional
When provided, rows are dispatched via
backend.evaluate. When None, evaluation is sequential.
- Returns:
- list[dict[str, Any]]
One result mapping per assignment, in input order.
- Raises:
- RuntimeError
If no backend is set.
- ValueError
If targets contains an undeclared name.
- property metric_space: MetricSpace#
Output declarations and annotations.
- property parameter_space: ParameterSpace#
Input domain.
- with_evaluator(backend: EvaluationBackend) Problem[source]#
Return a new
Problemwith backend as evaluation backend.Non-mutating: the original problem keeps its backend and both share the same parameter and metric spaces. Always returns a plain
Problem, never a subclass: a surrogate-backed problem carries no optimizer policy.