# How should CADET-Process handle evaluation failures in optimization?

**URL:** <https://forum.cadet-web.de/t/how-should-cadet-process-handle-evaluation-failures-in-optimization/1483>\
**Category:** CADET Development\
**Created:** [December 4, 2026, 5:24pm UTC](https://forum.cadet-web.de/t/how-should-cadet-process-handle-evaluation-failures-in-optimization/1483 "2026-12-04T17:24:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![j.schmoelder](https://forum.cadet-web.de/user_avatar/forum.cadet-web.de/j.schmoelder/32/93_2.png) [@j.schmoelder](https://forum.cadet-web.de/u/j.schmoelder)\
**Post date:** [December 4, 2026, 5:24pm UTC](https://forum.cadet-web.de/t/how-should-cadet-process-handle-evaluation-failures-in-optimization/1483/1 "2026-12-04T17:24:21Z")

</div>

In a CADET-Process optimization, evaluating a candidate can mean applying a salt concentration, running a simulation, and calculating product purity. In v0.13.0, an evaluation pipeline does this work for the optimizer and for `Problem.evaluate_batch()`, which users call to sample points or generate surrogate training data.

An error during evaluation can mean four different things, and each should have its own outcome and today these cases are not kept apart:

- **The setup is invalid.** A required parameter is missing or the cycle time is not set, so the process fails its configuration check. Raise because changing the candidate cannot fix the setup.
- **The candidate fails.** The solver does not converge, no fraction meets the purity requirement, or the process does not reach cyclic stationarity within the maximum number of cycles. Return a failure for that point and let the batch finish. Only the optimizer substitutes `bad_metrics`. Cache the failure if it’s repeatable.
- **The code has a bug.** The purity function reads `process.slat`, or a metric indexes a component the process does not have. Raise so the caller can fix it, and don’t cache it, so a rerun after the fix recomputes.
- **The failure may be transient.** A solver times out on a busy machine. A retry may succeed, so such failures need their own retry and caching policy.

What happens to an exception today:

1. **The pipeline** [catches any exception](https://github.com/fau-advanced-separations/CADET-Process/blob/f6e181ca5bcb7192fcc8640130c6c8f75168dc43/CADETProcess/evaluation_pipeline/pipeline.py#L173-L179) raised by a step, whether a `CADETProcessError` or an ordinary Python exception from a bug (`AttributeError`, `KeyError`, `IndexError`, …), and puts an `EvaluationFailure` in place of the result: an object holding the original exception, the failed step and the error message. Steps that need that result are skipped, and other candidates continue. Failures from a `CADETProcessError` are cacheable by default and others are not; an exception can override this through a `recoverable` attribute.
2. **`evaluate_batch()`** returns these failures to its caller without raising, whatever the original exception. It also [wraps any exception raised while evaluating a candidate](https://github.com/fau-advanced-separations/CADET-Process/blob/f6e181ca5bcb7192fcc8640130c6c8f75168dc43/CADETProcess/problem.py#L296-L303), such as one raised by another backend, in an `EvaluationFailure` the same way. A sampler that hits a bug therefore records 200 failed points instead of one error.
3. **The optimizer** [inspects the stored exception](https://github.com/fau-advanced-separations/CADET-Process/blob/f6e181ca5bcb7192fcc8640130c6c8f75168dc43/CADETProcess/optimization/optimization_problem.py#L2428-L2435): it uses `bad_metrics` for a `CADETProcessError` and re-raises the original exception for anything else.

Because step 3 goes by type alone, other mistakes get scored too. An [invalid setup](https://github.com/fau-advanced-separations/CADET-Process/blob/f6e181ca5bcb7192fcc8640130c6c8f75168dc43/CADETProcess/simulator/simulator.py#L243) and a [solver timeout](https://github.com/fau-advanced-separations/CADET-Process/blob/f6e181ca5bcb7192fcc8640130c6c8f75168dc43/CADETProcess/simulator/cadetAdapter.py#L287) both raise `CADETProcessError`, so, following the linked code, both can produce fallback scores, and the timeout is cached. An objective that returns the wrong number of values is caught by the optimizer’s [own wrapper](https://github.com/fau-advanced-separations/CADET-Process/blob/f6e181ca5bcb7192fcc8640130c6c8f75168dc43/CADETProcess/optimization/optimization_problem.py#L2305-L2307), which raises `CADETProcessError` before step 1; running it gives the objective’s fallback score instead of an error, for a mistake in the user’s code.

The script below reproduces the typo through both entry points. It was run on [`f6e181ca`](https://github.com/fau-advanced-separations/CADET-Process/tree/f6e181ca5bcb7192fcc8640130c6c8f75168dc43).

```python
from CADETProcess.optimization import OptimizationProblem

class Process:
    name = "Batch elution"
    salt = 100.0

def purity(process):
    return process.slat / 1000 # typo: a bug, not a failed simulation

problem = OptimizationProblem("demo", use_diskcache=False)
problem.add_evaluation_object(Process())
problem.add_variable("salt", lb=0, ub=500)
problem.add_objective(purity, bad_metrics=[999.0])

print(problem.evaluate_batch([{"salt": 120.0}]))
problem.evaluate_objectives([120.0])

```

```auto
[{'purity': EvaluationFailure(stage='purity', reason="'Process' object has no attribute 'slat'", recoverable=True)}]
AttributeError: 'Process' object has no attribute 'slat'

```

## Why this needs to change

- **Mistakes look like results.** Bugs that raise ordinary Python exceptions are exposed by the optimizer but hidden from batch callers. Errors reported as `CADETProcessError`, such as an invalid setup or a wrong-length objective, can instead become fallback scores: the run finishes, and the user may conclude that the process cannot be simulated in that region instead of fixing one line.
- **The same error behaves differently depending on the entry point.** The typo raises in the optimizer but not in `evaluate_batch()`. Anyone who writes a sampler or a surrogate trainer has to know about the optimizer’s check and repeat it.
- **Caching makes wrong classifications stick.** A failure from a `CADETProcessError` is cached, so a timeout or a wrong-length objective is reused as a bad candidate for that point instead of being evaluated again.
- **The contract is about to become public.** `evaluate_batch()` ships in v0.13.0 as the entry point for sampling and surrogate training, and the planned surrogate backend needs to know which exception to raise. Changing the behavior after the release would break callers that rely on it.

## Two decisions before v0.13.0

1. **What marks a failed candidate?** An error that the code detecting it can identify as an expected outcome for that candidate. Options: keep `CADETProcessError`, add a dedicated exception, or add a flag on the exception, which could build on the `recoverable` attribute the pipeline already reads for caching.

2. **Where should bugs and setup errors raise?** Leave it to callers, apply the rule in `Problem` to both failures a backend returns and exceptions it raises, or let each backend propagate errors. I lean toward `Problem`, for both `evaluate()` and `evaluate_batch()`, so samplers and optimizers behave the same across backends. Unexpected errors would then propagate to the caller; whether the other points of a parallel batch still finish is a separate detail. The cost: a surrogate must report an out-of-domain point explicitly; a bare `ValueError` would stop the batch.

Would you choose differently on either point? Is there a caller that needs bugs returned as batch results, or a backend that would struggle to identify expected candidate failures?
