Neqsim model calibration and data reconciliation

From equinor/neqsim · View interactive version

Neqsim model calibration and data reconciliation is an AI agent skill from the GitHub repository equinor/neqsim. Model calibration and data reconciliation workflow for NeqSim digital twins. USE WHEN: reducing model-vs-plant mismatch, tuning process model parameters from historian data, reconciling noisy measurements, or building validation reports for calibrated simulations. Covers tag mapping, data quality ga

How to use this skill

Skill file

Model Calibration and Data Reconciliation

A practical workflow for calibrating NeqSim models against plant historian data

and producing auditable validation output.

When to Use This Skill

Scope and Non-Goals

This skill focuses on steady-state calibration and data reconciliation.

This skill does not replace dynamic controller tuning. For transient tuning,

load neqsim-dynamic-simulation in addition.

Required Companion Skills

Calibration Workflow

  1. Define objective and acceptance criteria.
  2. Build a trusted tag map from plant tags to model variables.
  3. Read, clean, and quality-filter plant data.
  4. Detect steady-state windows for fitting.
  5. Choose tunable model parameters with hard physical bounds.
  6. Run bounded optimization and re-simulate the full NeqSim process each iteration.
  7. Validate on holdout windows and publish fit diagnostics.

For the replay and validation steps use neqsim.process.operations.replay.ProcessReplay:

it runs a tag-bound time series through the calibrated model with a convergence gate,

records failed rows without aborting, and gives per-window bias/RMS, baseline-standardised

residuals and CUSUM change points (ReplayResult.setBaselineWindow, detectChangePoints),

exportable as CSV/JSON. See docs/process/process_replay.md.

Typical Tunable Parameters

| Equipment | Parameters to Tune | Keep Fixed Unless Needed |

|-----------|--------------------|--------------------------|

| Compressor | Polytropic efficiency, pressure ratio correction, anti-surge margin | Driver type, map family |

| Heat exchanger | UA correction factor, fouling factor | Duty sign convention, stream topology |

| Separator | Entrainment assumptions, liquid carry-over tuning factors | Phase model and EOS |

| Valve/choke | Cv multiplier, discharge coefficient | Control architecture |

| Pipeline | Roughness, overall heat transfer coefficient | Length and diameter |

Data Reconciliation Quality Gates

Apply these gates before calibration:

Python Pattern: Bounded Calibration Loop

import numpy as np
from scipy.optimize import least_squares

# Example: tune compressor efficiency and HX UA multiplier
# x[0] -> compressor efficiency, x[1] -> UA multiplier
LOWER = np.array([0.60, 0.60])
UPPER = np.array([0.90, 1.40])
X0 = np.array([0.75, 1.00])

# Weights for [discharge pressure, discharge temperature, outlet temperature]
W = np.array([1.0, 1.0, 0.8])

def run_model_and_extract_outputs(process, x):
    # Example parameter writes using automation addresses
    auto = process.getAutomation()
    auto.setVariableValue("Main Compressor.polytropicEfficiency", float(x[0]), "")
    auto.setVariableValue("Main Cooler.UA_multiplier", float(x[1]), "")

    process.run()

    p_out = auto.getVariableValue("Main Compressor.outStream.pressure", "bara")
    t_out = auto.getVariableValue("Main Compressor.outStream.temperature", "C")
    t_cool = auto.getVariableValue("Main Cooler.outStream.temperature", "C")
    return np.array([p_out, t_out, t_cool])


def residuals(x, process, y_target):
    y_model = run_model_and_extract_outputs(process, x)
    return W * (y_model - y_target)


# y_target should come from a selected steady-state time window average
res = least_squares(
    fun=residuals,
    x0=X0,
    bounds=(LOWER, UPPER),
    args=(process, y_target),
    method="trf",
    max_nfev=150,
)

x_opt = res.x
print("Optimized parameters:", x_opt)
print("Cost:", res.cost)

Objective Design Guidance

Use a weighted residual vector with consistent scaling.

A common objective is:

$$

J(\theta) = \sum_{i=1}^{N} w_i\left(\frac{y_i^{model}(\theta) - y_i^{meas}}{s_i}\right)^2

$$

Where:

Train/Validation Split Pattern

  1. Train on at least two steady windows from different operating regions.
  2. Validate on one holdout window not used in fitting.
  3. Report both train and validation metrics.

Recommended minimum metrics:

Common Failure Modes and Fixes

| Failure Mode | Likely Cause | Corrective Action |

|--------------|--------------|-------------------|

| Excellent train fit, poor validation | Overfit on narrow operating range | Add windows across wider throughput and pressure range |

| Non-physical fitted parameters | Missing bounds | Enforce hard bounds and pre-check with input validation |

| Optimization stalls | Flat objective or too many coupled variables | Reduce parameter count, stage the tuning in phases |

| Noisy residuals | Sensor spikes and transient periods | Increase filtering and steady-state screening |

| Unstable run during optimization | Recycle sensitivity | Start from converged base case and use troubleshooting recovery patterns |

| Compressor discharge T low even at a plausible efficiency | Heavy model gas, anti-surge recycle, or a truly low effective efficiency | Diagnose in order, each with a measurement: (1) gas mole weight / composition, (2) anti-surge valve opening, (3) independent motor or shaft power. If 1 and 2 are clean, fit an effective efficiency to T (compressor.setOutTemperature(T) then compressor.solveEfficiency(T), or the log-ratio update eta*ln(T2m/T1)/ln(T2p/T1) between runs) and check it against the power that was not fitted (Johan Sverdrup stage 3/4: 0.35-0.42 fitted, power within -13 to -27 %). Never widen the efficiency bound before 1-3 |

| Separator gas flow meters disagree with the gas balance by a constant factor on every train | Meter basis (actual vs standard m3/h) or gas allocation | Treat as a data question; calibrate gas to the metered platform gas, do not tune GOR to the meter, and report the meter gap |

| Compressor.solveEfficiency(T) returns an efficiency of 1.0 (or the lower limit) and the outlet is not at T | Older NeqSim builds: the unguarded secant step overshoots when the target needs an efficiency far from the start (e.g. wet gas at 134 C from 0.75 start, true value ~0.36). Fixed with a bracketed (safeguarded) secant in Compressor.solveEfficiency, test CompressorSolveEfficiencyTest. A phase-boundary jump can stall one initial guess about 0.1 K off the target; the solve then uses a local secant and interior restarts, still at the 0.01 K tolerance | Always read back compressor.getOutletStream().getTemperature("C") after the solve and compare with the target; on an older build bisect the efficiency between 0.3 and 0.95 yourself (outlet T usually falls as efficiency rises, but it can chatter across a phase boundary). Report the result as an effective efficiency (it lumps anti-surge recycle heating and composition error) and re-fit it after any change of gas composition or calibration factor |

Reporting Pattern for results.json

Add a calibration block to the task results.json:

{
  "calibration": {
    "calibrated_parameters": [
      {
        "name": "Main Compressor.polytropicEfficiency",
        "unit": "",
        "value": 0.781,
        "lower_bound": 0.60,
        "upper_bound": 0.90
      },
      {
        "name": "Main Cooler.UA_multiplier",
        "unit": "",
        "value": 1.12,
        "lower_bound": 0.60,
        "upper_bound": 1.40
      }
    ],
    "fit_metrics": {
      "train_rmse": {
        "compressor_outlet_pressure_bara": 0.84,
        "compressor_outlet_temperature_C": 1.6,
        "cooler_outlet_temperature_C": 0.9
      },
      "train_mape_pct": 1.8,
      "train_bias": {
        "compressor_outlet_pressure_bara": -0.22,
        "compressor_outlet_temperature_C": 0.35,
        "cooler_outlet_temperature_C": -0.10
      }
    },
    "validation_metrics": {
      "validation_mape_pct": 2.4,
      "max_abs_error": {
        "compressor_outlet_pressure_bara": 1.7,
        "compressor_outlet_temperature_C": 3.1,
        "cooler_outlet_temperature_C": 1.8
      }
    },
    "recommended_model_updates": [
      "Update base compressor efficiency from 0.75 to 0.78 for this operating period.",
      "Retain UA multiplier 1.12 and re-check after next exchanger cleaning campaign."
    ],
    "calibration_risks": [
      "Tag TT-402 intermittently flagged suspect quality during two windows.",
      "Calibration is validated for 70-90% throughput; extrapolation outside this range is not qualified."
    ]
  }
}

Validation Checklist

Identified Dynamics from Plant Data (TimeSeriesAnalysis)

Calibration fits steady parameters; neqsim-dynamic-model-identification (community skill; equinor/TimeSeriesAnalysis through pythonnet) supplies the dynamics and a cross-check:

Keep the calibration window and the residual baseline window the same healthy period, and never shuffle time-series rows into training and test. Worked example: NeqSim x TimeSeriesAnalysis notebook.

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.