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.

Start a calculation Explore validation

torch-flash — Differentiable Thermodynamics powered by PyTorch
Research developed by and at
Native PyTorch Float64 reference calculations with device, dtype, batching, and automatic differentiation kept explicit.
Thermodynamic scope Cubic, association, activity-coefficient, and multiparameter models behind a consistent typed interface.
Auditable evidence Verification, experimental validation, numerical diagnostics, provenance, and limitations documented together.

Installation and package extras

Install the default package capability from Conda-Forge:

conda install -c conda-forge torch-flash

The default package is also available from PyPI:

python -m pip install torch-flash

The Conda-Forge package currently provides the default capability. Three optional PyPI extras expose package-level integrations:

python -m pip install "torch-flash[groups]"
python -m pip install "torch-flash[intel]"
python -m pip install "torch-flash[gpu]"

The intel and gpu extras are currently active on Linux and Windows. The GPU extra also requires a compatible CUDA runtime and device.

The normal installation is the default capability; it is not named torch-flash[default]. Development, testing, documentation, notebooks, external comparisons, and benchmarks use dedicated Pixi environments rather than pip extras. Maintainers should follow the dependency and release metadata workflow.

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 Getting Started guide gives complete runnable examples for homogeneous properties, automatic derivatives, two-phase flash, and fixed-phase-count multiphase flash. The Theoretical Background connects chemical equilibrium, flash algorithms, fugacity and activity models, property derivatives, and heavy-end characterization to the corresponding torch-flash APIs. 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 high-performance setup and benchmark guide documents hardware-aware installation, native batching, torch.compile, CPU-thread selection, device-resident GPU execution, 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.