AI for Chemical Engineers · Week 1

Week 1: From Process Prediction to Decisions

Define a process decision problem, build a reproducible baseline, and check the selected operating point with a reference CSTR model.

Learning objectives

After this lesson, you should be able to write the inputs, outputs, fixed context, units, and operating domain of a surrogate; distinguish training from operational optimization; construct a steady-state and a dynamic CSTR example; and check whether a surrogate-selected operating point satisfies the reference model’s constraints.

1. Begin with the decision

Suppose a reactor operator wants high conversion at a low operating cost. Predicting conversion at a proposed temperature is one task. Choosing temperature and residence time while meeting a conversion requirement is another task. The second task repeatedly queries the model in regions favored by the optimizer, which may differ from a typical held-out test sample.

Write four items before selecting a network: what can be changed, what is fixed for this decision, what must be predicted, and what counts as a satisfactory operating point. A small prediction error averaged across the domain does not tell us whether a constraint is satisfied at the selected point.

Role Meaning Example in this lesson
Decision variables Quantities selected by the optimization Reactor temperature T and residence time τ
Fixed context Known quantities held fixed for one solve Feed concentration set to 1.2 mol/L for the decision comparison
Model outputs Quantities predicted for a proposed input Outlet concentration and conversion
State A quantity that evolves in a dynamic model Reactor concentration
Domain Conditions over which the model is evaluated Stated bounds on temperature, residence time, and feed concentration

Training adjusts model parameters using data. Operational optimization holds the trained parameters fixed and changes the decision variables. These are different optimization problems.

2. A reference process we can check

Use an ideal, perfectly mixed, constant-volume, isothermal CSTR with a first-order reaction A → B, constant density, and no B in the feed. Reactor temperature T is an operating input.

dCAdt=CAf−CAτ−k(T)CA

Here concentrations are in mol/L, time and residence time in minutes, T in kelvin, and k in inverse minutes. The flow-to-volume ratio is the reciprocal of residence time. The inlet–outlet term and the reaction term therefore both have units of mol/(L·min).

The rate constant depends on temperature as follows:

k(T)=krefexp[β(1Tref−1T)]
Parameter or input Value or range Interpretation
Reference rate constant 0.2 per minute Rate at the reference temperature
Reference temperature 330 K Rate-law reference
β = E/R 6000 K Synthetic temperature-sensitivity parameter
Temperature 300–360 K Sampling and decision domain
Residence time 1–10 min Sampling and decision domain
Feed A concentration 0.8–1.5 mol/L Sampling domain; fixed to 1.2 for optimization

3. Derive the steady-state map

Set the time derivative to zero, multiply by residence time, and collect the terms containing outlet concentration. The resulting mapping and conversion are:

CA=CAf1+k(T)τ,X=1−CACAf=k(T)τ1+k(T)τ

This gives a three-input, two-output map: temperature, residence time, and feed concentration map to outlet concentration and conversion. In this first-order model, conversion is independent of feed concentration.

A worked check: at 330 K and 5 min, the product kτ is 1, so conversion is 0.5 and outlet A concentration is half the inlet concentration. For the 1.2 mol/L feed, the outlet is 0.6 mol/L.

Reference CSTR conversion across temperature and residence time, with the 0.8 conversion contour.
Reference-model conversion. The contour marks the conversion requirement used in the decision exercise.

4. State the optimization problem

Minimize the following dimensionless operating-cost index:

J(T,τ)=T−300 K20 K+τ10 min

The index penalizes higher temperature and longer residence time. At a fixed feed concentration of 1.2 mol/L, minimize this index over the stated bounds subject to predicted conversion of at least 0.8. Also require predicted concentration to lie between zero and the feed concentration, and predicted conversion not to exceed one.

For the reference map, conversion of at least 0.8 is equivalent to kτ of at least 4. This follows by multiplying the conversion inequality by the positive denominator. It gives a useful independent check on the feasible region.

Surrogate prediction errors can change the feasible set. Run the selected temperature and residence time through the reference model and check whether the conversion requirement is met.

5. Design data for the intended use

The lab generates 400 training, 120 validation, and 160 test points independently inside the stated box, using a fixed random seed. Fit model coefficients using training data, use validation for model choices, and reserve the test set for reporting. The baseline uses fixed domain scaling and quadratic features.

The two-output baseline uses ordinary least-squares regression on ten features: a constant, three scaled inputs, their squares, and their pairwise products.

Split measured data by batch, experiment, campaign, or time. For dynamic data, split by entire trajectories so that overlapping windows remain in the same split.

6. Prediction error and decision error

Report concentration RMSE in mol/L and conversion RMSE as a dimensionless fraction. Also report the consistency residual relating the two outputs: predicted outlet concentration plus feed concentration times predicted conversion minus feed concentration. A multi-output fit can disagree with this identity.

The decision comparison enumerates the same grid for the surrogate and reference maps: temperature steps of 0.5 K and residence-time steps of 0.1 min. It finds the lowest-cost feasible candidate on that grid.

Check Result
Held-out concentration RMSE 0.032623 mol/L
Held-out conversion RMSE 0.025608
Selected surrogate decision 347.000000 K; 8.100000 min
Predicted conversion at that decision 0.800144
Reference conversion at that decision 0.797893
Reference conversion shortfall below 0.8 0.002107
Reference cost of the surrogate-selected decision 3.160000
Reference-model feasible grid benchmark cost 3.155000

At the selected point, the surrogate predicts conversion above 0.8, while the reference model falls below 0.8. This point violates the conversion constraint. Compare costs among points that pass the reference feasibility check.

Reference and surrogate conversion along residence time at the selected temperature, with the conversion target.
A local check near the selected decision. Error close to the constraint boundary can change the feasible operating choices.

7. Connect vectors to time series

A steady-state output has no time index. A dynamic output depends on the initial state and the history of control inputs and disturbances. In a planning problem, the model must also receive the future control sequence being considered; predicting from historical measurements alone is insufficient to compare arbitrary future control plans.

The dynamic lab holds the feed concentration and residence time fixed and changes the maintained temperature from 330 to 345 K at 10 min. Within each constant-input interval, the concentration balance has an analytic update:

CA(t+Δt)=CAss+[CA(t)−CAss]exp[−(1τ+k(T))Δt]

For each interval, calculate the steady-state concentration using that interval’s inputs.

The code records input values on intervals and concentration on interval boundaries. At the step time, the concentration is continuous and then approaches the new steady value.

Maintained reactor temperature and concentration response to a temperature step at ten minutes.
Dynamic reference response. An instantaneous steady-state mapping would miss the transient concentration trajectory.

8. Run the lab

Download the notebook or the standalone script, plus requirements.txt.

python -m pip install -r requirements.txt
python week01_lab.py --output-dir week01-results

The script creates the dataset, metrics JSON, dynamic trajectory CSV, and three figures inside the chosen output directory. The published dataset and recorded results are also available for comparison.

9. Exercises and submission

  1. Derive the steady-state concentration and check its units. Explain why increasing either temperature or residence time increases conversion under this model.
  2. Derive the condition kτ ≥ 4 for the conversion target. Check the reference feasible region without fitting a model.
  3. Re-run the lab with a different training seed. Compare test RMSE, the selected operating point, and reference feasibility. Does better RMSE always select a better decision?
  4. Tighten the temperature domain to 330–350 K. Explain how the feasible set and the sampled training domain should change together.
  5. Change the temperature step time. Describe which input intervals and output boundary times change. Explain why a steady-state predictor cannot represent the transient.
  6. Write a one-page problem specification stating the decision variables, fixed context, state, outputs, units, domain, objective, constraints, data split, and revalidation rule.

Reference checks: at 330 K and 5 min, conversion is 0.5; the conversion target requires kτ ≥ 4; increasing T increases k for positive β. The other exercises require your computed results and interpretation, including failed constraints when they occur.

Reading and next lesson

Read selected parts of Boyd and Vandenberghe’s Chapters 2–4 on domains, constraints, convex functions, and optimization problems. Read the OMLT introduction for the role of trained models in larger optimization problems.

Week 2 builds a multi-output MLP using the same data definition and reference checks.