Skip to content

Fugacio

Open, differentiable thermodynamics and process simulation, with an AI design copilot. See the project README for the full overview.

Fugacio is built as three layered packages (strict direction thermo < sim < copilot, enforced in CI):

  • fugacio.thermo, differentiable properties + phase equilibrium: a curated open component database, ideal-gas correlations, cubic equations of state (vdW / RK / SRK / PR) with fugacity coefficients, reference multiparameter Helmholtz EOS (IAPWS-95 water/steam, Span–Wagner CO₂, 26 fluids, with steam-table state functions and IAPWS transport), property packages that own phase equilibrium and energy for every method class (residual functions, enthalpy/entropy, isenthalpic & isentropic flashes, stability), liquid & transport properties (density, viscosity, thermal conductivity, surface tension, diffusivity, both pure and mixture), activity-coefficient models (Margules, van Laar, Wilson, NRTL, UNIQUAC), group contribution (UNIFAC + Dortmund, Joback), EOS and γ–φ equilibrium solvers (Rachford-Rice, PT flash, saturation, bubble/dew), rigorous LLE / VLLE and tangent-plane stability, parameter regression with a bundled ThermoML parameter bank, and reaction thermochemistry, equilibrium, and kinetics.
  • fugacio.sim, flowsheet / unit-operation engine (depends on thermo): a differentiable Stream pytree, energy-balanced unit operations (flash_drum, adiabatic_flash, heater, valve, pump, compressor, turbine, mix, splitter), each a compile-once kernel that reports or raises on failure, a recycle/tear solver with implicit-diff gradients (tear_solve, Flowsheet), distillation columns (shortcut FUG and a rigorous equilibrium-stage model), binary diagrams / azeotropes / residue-curve maps, reactors (equilibrium, stoichiometric, CSTR, PFR, batch), reactive separations (reactive flash & reactive MESH columns), steam & cooling-water utilities on IAPWS-95, differentiable optimization, design specs & process economics (constrained NLP with implicit-diff argmin, controllers, Turton costing, TAC/NPV), time-domain dynamics & process control (differentiable ODE integrators with a continuous adjoint, a filtered anti-windup PID, dynamic unit operations, DynamicFlowsheet, and gradient-based controller tuning), advanced control (a differentiable OSQP-style QP, condensed offset-free linear MPC, Kalman / extended / unscented / moving-horizon estimation, nonlinear & economic MPC, and gradient-based weight tuning), and heat integration & pinch analysis (differentiable minimum-utility/pinch targets, composite & grand composite curves, area/cost supertargeting for the optimal dt_min, and heat-exchanger-network synthesis).
  • fugacio.copilot, LLM design agent (depends on sim): a JSON tool registry over the engine (properties, steam tables & reference fluids, unit operations, distillation, reactors, reaction equilibrium, optimization, sizing & costing, FOPDT identification & PID tuning, LQR & Kalman design, MPC simulation & tuning, heat-integration targets & network synthesis), plus a vendor-neutral provider layer (OpenAI / Anthropic / mock) and a multi-turn, tool-calling agent loop.

Everything is written in JAX and the iterative solvers carry implicit-function-theorem gradient rules, so an entire flowsheet is end-to-end differentiable, including through phase equilibrium.

import jax
import jax.numpy as jnp
from fugacio.sim import Stream, flash_drum

feed = Stream.from_fractions(
    ("methane", "propane", "n-pentane"),
    jnp.array([0.5, 0.3, 0.2]),
    flow=100.0, t=320.0, p=20e5,
)
vapor, liquid = flash_drum(feed, 320.0, 20e5)

# Exact sensitivity of vapor product flow to drum temperature:
jax.grad(lambda T: flash_drum(feed, T, 20e5)[0].total)(320.0)

A failed solve never returns a plausible number: value-only calls return NaN, checked *_with_info calls return a report, and an eager unit raises (see reliability). Upgrading from 0.8? See upgrading to 0.9.

Correctness as an executable harness

Physical correctness is continuously machine-checked: first-principles consistency laws that need no external data (Gibbs-Duhem, equifugacity, fugacity-pressure identity, the Gibbs-Helmholtz and fugacity-enthalpy consistency of property packages, phase stability), automatic-differentiation gradients checked against finite differences, and opt-in differential testing against open reference codes: CoolProp and chemicals for pure-fluid properties and the reference Helmholtz EOS layer (IAPWS-95, Span–Wagner), thermo / Clapeyron.jl for activity coefficients, and Cantera for reaction equilibrium and standard-state thermochemistry.