Skip to content
Scientific Python · Native PyTorch

Differentiable thermodynamics, from state properties to phase equilibrium

torch-flash provides typed, differentiable thermodynamic models and phase-equilibrium solvers for research, optimization, and coupled simulation.

Configure a calculation Explore validation

ThermoPhase — Fluid and Complex Systems Research Group
Research developed at
Native PyTorch Float64 reference calculations with device, dtype, batching, and automatic differentiation kept explicit.
Thermodynamic scope Cubic, association, activity-coefficient, and multifluid models behind a consistent typed interface.
Auditable evidence Verification, experimental validation, numerical diagnostics, provenance, and limitations documented together.

Scientific software with explicit thermodynamic state

torch-flash provides differentiable thermodynamic state models and phase-equilibrium calculations on top of PyTorch.

The central design rule is that homogeneous-state properties do not require an equilibrium solve. A supplied (T, P, x) state can be evaluated directly for compressibility, fugacity coefficients, fugacities, dimensionless log fugacities, chemical potentials, reduced chemical potentials, molar Helmholtz and Gibbs energies, reduced free energies, residual caloric properties, and PyTorch derivatives. Flash and saturation solvers are separate consumers of the same model interface.

import torch
from torch_flash import ChemicalState, component_set, configure, peng_robinson_1978
from torch_flash import (
    log_fugacities_tv,
    phase_properties,
    poling_ideal_gas,
    state_derivatives,
    thermal_properties,
)

runtime = configure(device="cpu", dtype=torch.float64)
model = peng_robinson_1978(component_set(("methane", "n_butane")))
state = ChemicalState(
    runtime.tensor(300.0),
    runtime.tensor(5.0e6),
    runtime.tensor([0.7, 0.3]),
)

properties = phase_properties(model, state)
print(properties.fugacities, properties.log_fugacities)
print(properties.chemical_potentials, properties.reduced_chemical_potentials)
print(properties.molar_helmholtz_energy, properties.molar_gibbs_energy)
print(properties.reduced_helmholtz_energy, properties.reduced_gibbs_energy)
derivatives = state_derivatives(model, state)
print(derivatives.dfugacity_dpressure)
print(derivatives.dlog_fugacity_dtemperature)
print(derivatives.dlog_fugacity_coefficient_dmoles)
print(derivatives.dmolar_volume_dpressure)
print(derivatives.dchemical_potential_dindependent_composition)
print(
    log_fugacities_tv(
        model,
        state.temperature,
        properties.molar_volume,
        state.composition,
    )
)
thermal = thermal_properties(
    model,
    state,
    poling_ideal_gas(["methane", "n_butane"]),
)

Version 0.1 is an alpha research release. Read model scope before selecting a model and validation before relying on it outside the tested range. The parameter database guide documents the versioned YAML schemas, canonical component names, SI-unit validation, and custom-parameter APIs. The runtime configuration guide documents construction-time device/dtype policy, CPU threading, GPU selection, and deterministic execution. The scientific reference and data-provenance index identifies primary equation, parameter, experimental-data, and software-baseline sources separately. The performance guide documents native batching, torch.compile, CPU-thread selection, GPU precision limits, and benchmark conditions for ThermoPack, teqp, and NeqSim comparisons.

Detailed equation checks, worked-example reproductions, experimental comparisons, and fitted-model studies are catalogued in verification and validation evidence. That page distinguishes implementation verification from validation against independent measurements and records the applicable model, data, parameter, and temperature ranges.