Skip to main content

A high-performance Python library for material simulation and analysis

Project description

MaterForge - Materials Formulation Engine with Python

A high-performance Python library for materials modeling and simulation. MaterForge enables efficient definition of any material - metals, alloys, polymers, ceramics, composites, or hypothetical materials - through YAML configuration files, providing symbolic and numerical property evaluation as a function of any SymPy symbol.

DOI Python Latest Release License Documentation Status CI codecov

Documentation: https://materforge.readthedocs.io

Table of Contents


🚀 Key Features

  • Schema-Agnostic Material Definition: Any material kind, any property name - the YAML schema drives everything with no hardcoded material types or required fields
  • Dependency-Driven Properties: Properties expressed as symbolic functions of any independent variable - temperature, pressure, composition, strain, or any SymPy symbol
  • Modular Architecture: Clean separation with algorithms, parsing, and visualization modules
  • Symbolic Mathematics: Built on SymPy for precise mathematical expressions
  • Piecewise Functions: Advanced piecewise function support with regression capabilities
  • Property Inversion: Create inverse functions for any piecewise-linear property
  • Visualization: Automatic plotting during a build, plus post-build, notebook-friendly helpers that return a Matplotlib Axes for fit, residual, and cross-material compare plots
  • Fit-Quality Metrics: R², RMSE, MAE, and residuals for every data-backed property, so you can check how faithfully a fit reproduces its source data
  • Multiple Property Types: Constants, step functions, file-based data, tabular data, piecewise equations, and computed properties
  • Regression Analysis: Built-in piecewise linear fitting with configurable parameters

📦 Installation

Install from PyPI

pip install materforge

All required dependencies are installed automatically.

For contributors

Clone the repository and install in editable mode:

git clone https://github.com/rahildoshi97/materforge.git
cd materforge
pip install -e .

Note: The -e flag (--editable) installs the package by symlinking directly to the source directory. Changes to source files take effect immediately without reinstalling - intended for development only. Use pip install materforge for regular use.


🏃 Quick Start

Basic Material Creation

import sympy as sp
from materforge import create_material

# Any SymPy symbol works as the dependency variable
T = sp.Symbol('T')

# Load a material from YAML (see examples/myAlloy.yaml)
mat = create_material('examples/myAlloy.yaml', dependency=T, enable_plotting=True)

# Access symbolic property expressions directly
print(mat.heat_capacity)   # SymPy Piecewise expression in T
print(mat.density)         # 7000.0 (constant float)

# Evaluate all properties at a specific value (returns a new Material)
results = mat.evaluate(T, 500.0)
print(results.heat_capacity)   # float

Bundled Example Materials

MaterForge is designed for you to write your own YAML configs. For convenience, a few reference materials ship with the package and can be loaded by name - handy for demos and quick experiments:

import sympy as sp
from materforge import list_materials, load_material

print(list_materials())                       # ['1.4301', 'Al', 'Al2O3']
steel = load_material('1.4301', sp.Symbol('T'))

These are examples, not a curated database. See the bundled materials guide for details.

Command-Line Interface

Installing the package also provides a materforge command for working with YAML files straight from a shell - no Python required:

materforge list                       # bundled example materials
materforge validate my_material.yaml  # check a file is structurally valid
materforge info my_material.yaml       # name, properties, and property types
materforge plot my_material.yaml       # write a property figure
materforge evaluate my_material.yaml 500   # evaluate every property at T=500
materforge fit my_material.yaml         # R²/RMSE for every data-backed property

Each subcommand wraps the same public API shown above. See the CLI guide for the full reference.

Fast Evaluation Over Many Values

evaluate() is convenient for a single value. To sweep a range, compile the material once - each property is lambdified and cached, so an array is evaluated in a single vectorised call:

import numpy as np

evaluate = mat.compile()              # cache numeric callables once

evaluate(500.0)                       # scalar -> {'density': 7861.2, ...}
table = evaluate(np.linspace(300, 1800, 500))   # array -> dict of arrays
table['density'].shape                # (500,)

See the fast evaluation guide for details.

Assess Fit Quality & Visualize

Every data-backed property (file-import, tabular, or computed) keeps the points it was fit from, so you can score the fit and plot it after the build - no re-parsing:

import materforge as mf

# How well does each stored curve reproduce its source data?
print(mf.fit_quality(mat, 'heat_capacity'))     # R²=0.9996  RMSE=8.9  ...
report = mf.fit_report(mat)                      # dict: name -> FitQuality

# Plotting helpers return a Matplotlib Axes - they render inline in Jupyter and
# never save or close the figure, so you stay in control of styling and output:
mf.plot_property(mat, 'heat_capacity')           # fitted curve + the source points
mf.plot_residuals(mat, 'heat_capacity')          # residuals with a zero reference line
mf.compare_materials([steel, alloy], 'density')  # the same property, several materials

Fit quality measures the stored curve against its source points: for a property with regression: {simplify: pre/post} that is the genuine fit error; plain interpolation passes through every point, so it reads ~0. See the fit-quality and visualization guides.

Cached Builds

The slow part of create_material is the piecewise regression. MaterForge caches the built result on disk (keyed by the YAML, its data files, the dependency, and the library versions), so reloading an unchanged material skips the refit:

# First call builds and caches; later calls of the unchanged YAML are instant.
mat = create_material('steel.yaml', dependency=T)

On by default (a plotting build always rebuilds); disable with MATERFORGE_DISABLE_CACHE=1, relocate with MATERFORGE_CACHE_DIR, or empty it via clear_cache(). See the cache guide.

Property Inversion

from materforge.algorithms.piecewise_inverter import PiecewiseInverter
import sympy as sp
from materforge import create_material

T = sp.Symbol('T')
mat = create_material('examples/myAlloy.yaml', dependency=T)

if hasattr(mat, 'energy_density'):
    E = sp.Symbol('E')
    inverse = PiecewiseInverter.create_inverse(mat.energy_density, 'T', 'E')

    # Validate round-trip accuracy
    test_val = 500.0
    e = float(mat.energy_density.subs(T, test_val))
    recovered = float(inverse.subs(E, e))
    print(f"Round-trip: T={test_val} -> E={e:.2e} -> T={recovered:.2f}")

📋 YAML Configuration Format

Supported Property Types

  • CONSTANT_VALUE: Single numeric value - not dependency-driven
  • STEP_FUNCTION: Discontinuous transition at a scalar reference point
  • FILE_IMPORT: Data loaded from CSV, Excel, or text files
  • TABULAR_DATA: Explicit dependency-value pairs
  • PIECEWISE_EQUATION: Symbolic equations over dependency variable ranges
  • COMPUTED_PROPERTY: Properties derived from other defined properties

The symbol used in YAML equations (T) is a placeholder only - MaterForge substitutes it with whatever symbol you pass to create_material(..., dependency=symbol) at runtime.

See the YAML schema documentation for full configuration options.

Example YAML files:


📚 Documentation

Full documentation is available at https://materforge.readthedocs.io

The documentation follows the Diátaxis framework:

Type Content
Tutorials Getting Started · First Simulation
How-to Guides Defining Material Properties · Assess Fit Quality · Visualize Properties · Property Inversion
Reference API Reference · YAML Schema
Explanation Design Philosophy · Material Properties

🤝 Contributing

Contributions are welcome! Please see our Contributing Guide for details on how to get started.


🐛 Known Limitations

  • Piecewise Inverter: Currently supports linear piecewise functions only (degree: 1)
  • File Formats: Limited to CSV, Excel, and text files
  • Memory Usage: Large datasets may require optimization for very high-resolution data
  • Regression: Maximum 8 segments recommended for stability

📄 License

Core Library (BSD-3-Clause)

The MaterForge library itself (src/materforge/, examples/, tests/, docs/) is licensed under the BSD 3-Clause License. See the LICENSE file for full details.

Application Examples (GPL-3.0-or-later)

The apps/ directory contains two demonstration applications that integrate MaterForge with waLBerla and pystencils via code generation — apps/HeatEquationKernel/ (a heat-equation solver with a temperature-dependent material) and apps/CouetteFlow/ (a 3D thermal Couette flow LBM benchmark). Because these dependencies are GPLv3-licensed, the apps directory is licensed under GPL-3.0-or-later. See apps/README.md for the overview and apps/LICENSE for full details.

PyPI Distribution

pip install materforge includes only the BSD-3-Clause licensed core library. The GPL-licensed apps are excluded from the PyPI distribution — they need a C++/CMake/MPI toolchain plus waLBerla that pip cannot provide. To run the demo apps, get them from the source repository:

git clone https://github.com/rahildoshi97/materforge.git
cd materforge
git submodule update --init --recursive   # populates apps/walberla

See apps/README.md for build and run instructions.

Component Location License In PyPI
Core library src/materforge/ BSD-3-Clause
Example scripts examples/ BSD-3-Clause
Tests tests/ BSD-3-Clause
Documentation docs/ BSD-3-Clause
Apps apps/ GPL-3.0-or-later

📖 Citation

If you use MaterForge in your research, please cite it using the information in our CITATION.cff file.


📞 Support


🙏 Acknowledgments

  • Built with SymPy for symbolic mathematics
  • Data handling powered by pandas
  • Uses pwlf for piecewise linear fitting
  • Visualization powered by Matplotlib
  • YAML parsing with ruamel.yaml

MaterForge - Empowering materials simulation with Python

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

materforge-0.10.0.tar.gz (307.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

materforge-0.10.0-py3-none-any.whl (292.8 kB view details)

Uploaded Python 3

File details

Details for the file materforge-0.10.0.tar.gz.

File metadata

  • Download URL: materforge-0.10.0.tar.gz
  • Upload date:
  • Size: 307.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for materforge-0.10.0.tar.gz
Algorithm Hash digest
SHA256 58446cd0719a52c4efa1cee23d221d1ea0dc37fcc902a9ef1468ae01b709c236
MD5 42e64e59f15c9f93b593e85deca58a64
BLAKE2b-256 227111a7b77deb6374bc4f5f715e8b962a4e25ef65eca0542313ed162ed444c7

See more details on using hashes here.

Provenance

The following attestation bundles were made for materforge-0.10.0.tar.gz:

Publisher: ci.yml on rahildoshi97/materforge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file materforge-0.10.0-py3-none-any.whl.

File metadata

  • Download URL: materforge-0.10.0-py3-none-any.whl
  • Upload date:
  • Size: 292.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for materforge-0.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 49948700368cc6fdcbee39a9af0c5896de0a5a242fd3ab3229a52a3f494d79db
MD5 e6715aa6df40b07bb335323828a841dd
BLAKE2b-256 7b4d6d8243e100efa4a4499de31b398e1fedd8c73b332379820767f90f666231

See more details on using hashes here.

Provenance

The following attestation bundles were made for materforge-0.10.0-py3-none-any.whl:

Publisher: ci.yml on rahildoshi97/materforge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page