Skip to main content

A Python library for industrial calculations with support for formula dependencies, caching, and automatic evaluation ordering.

Project description

XMOF - Industrial Formula Calculator

A powerful Python library for managing and evaluating complex industrial calculations with automatic dependency resolution and caching.

Features

  • 🔄 Automatic dependency resolution for complex formula chains
  • 🚀 Efficient caching system with time-based expiration
  • 📐 Configurable precision control with per-formula rounding
  • 🔍 Built-in mathematical constants (π, e)
  • 🛡️ Circular dependency detection
  • 📊 Rich calculation metadata and error reporting

Installation

pip install xmof

Quick Start

from xmof import IndustrialCalculator

# Initialize calculator with default 2 decimal rounding
calculator = IndustrialCalculator(default_rounding=2)

# Define your calculations
config = {
    "input_values": {
        "temperature": 25.0,
        "pressure": 101.325
    },
    "calculations": {
        "vapor_pressure": {
            "name": "Vapor Pressure",
            "description": "Antoine equation for vapor pressure",
            "expression": "10**(7.96681 - 1668.21/(temperature + 228.0))",
            "units": "kPa"
        },
        "relative_humidity": {
            "name": "Relative Humidity",
            "description": "Ratio of vapor pressures",
            "expression": "vapor_pressure/pressure * 100",
            "units": "%"
        }
    }
}

# Parse configuration and evaluate
calculator.parse_config(config)
result = calculator.evaluate()
print(result["results"])

Configuration Format

The calculator accepts a configuration dictionary with the following structure:

{
    "input_values": {
        "variable1": value1,
        "variable2": value2
    },
    "calculations": {
        "calc1": {
            "name": "Display Name",
            "description": "Formula description",
            "expression": "mathematical expression",
            "units": "units of measurement",
            "rounding": 2  # optional, overrides default
        }
    },
    "default_rounding": 2  # optional
}

Features in Detail

Dependency Management

  • Automatically detects dependencies between formulas
  • Creates optimal calculation order
  • Prevents circular dependencies
  • Caches dependency graphs for improved performance

Formula Support

  • Full mathematical expression support via SymPy
  • Access to mathematical constants (π, e)
  • Support for unit tracking
  • Per-formula rounding control

Error Handling

  • Comprehensive error reporting
  • Clear circular dependency detection
  • Invalid expression handling
  • Missing variable detection

Performance Considerations

The calculator uses caching to optimize performance:

  • Dependency graphs are cached with a configurable TTL
  • Default cache size: 100 entries
  • Default cache TTL: 3600 seconds (1 hour)

Example Use Cases

# Process engineering calculations
config = {
    "input_values": {
        "flow_rate": 100,
        "density": 1000
    },
    "calculations": {
        "mass_flow": {
            "name": "Mass Flow Rate",
            "description": "Mass flow calculation",
            "expression": "flow_rate * density",
            "units": "kg/h"
        }
    }
}

# Chemical reaction yields
config = {
    "input_values": {
        "initial_concentration": 2.0,
        "time": 3600
    },
    "calculations": {
        "final_concentration": {
            "name": "Final Concentration",
            "description": "First-order reaction kinetics",
            "expression": "initial_concentration * e**(-0.0005 * time)",
            "units": "mol/L"
        }
    }
}

Contributing

Contributions are welcome! Please feel free to contact XMPro.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

For support, please contact XMPro.

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

xmof-0.0.5.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

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

xmof-0.0.5-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

Details for the file xmof-0.0.5.tar.gz.

File metadata

  • Download URL: xmof-0.0.5.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.9

File hashes

Hashes for xmof-0.0.5.tar.gz
Algorithm Hash digest
SHA256 e521a8191746d6a5c935023ff60288dc11b605c6cd686de08f7c34858619f06d
MD5 dac14fd899cbbf95615e33d7a1275d13
BLAKE2b-256 9c45fbe9373aea35bbe8b97b8794c5284bb76de21e175f1a49da66f9f8d99e87

See more details on using hashes here.

File details

Details for the file xmof-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: xmof-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 3.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.9

File hashes

Hashes for xmof-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 bdf4f2d12184c0d0471c71ae0f011e1b9c24a5967b8f9326a844f7f64ac03fa7
MD5 43a1722bf36582a9c8094aa6af47d98a
BLAKE2b-256 f87ed002512560a85e6b7919265943d34563fa3b9c5b76875ddc5d8779262237

See more details on using hashes here.

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