Metadata-Version: 2.4
Name: mlafactory
Version: 0.2.3
Summary: Digital Multi-Level Assembly (MLA) manufacturing factory simulation made with SimPy
Author-email: "Oscar J. Castro-Lopez" <oscar.castro@uni.lu>
License-Expression: BSD-3-Clause
Project-URL: Homepage, https://gitlab.com/uniluxembourg/hpc/research/cadom/mla_factory
Project-URL: Repository, https://gitlab.com/uniluxembourg/hpc/research/cadom/mla_factory
Project-URL: Documentation, https://gitlab.com/uniluxembourg/hpc/research/cadom/mla_factory
Project-URL: Issues, https://gitlab.com/uniluxembourg/hpc/research/cadom/mla_factory/-/issues
Keywords: simulation,manufacturing,factory,MLA,discrete-event simulation,simpy
Classifier: Development Status :: 3 - Alpha
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Operating System :: OS Independent
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Scientific/Engineering
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: simpy>=4.0
Requires-Dist: numpy>=1.23.2
Requires-Dist: pandas>=1.5
Requires-Dist: pyyaml>=6.0.1
Provides-Extra: test
Requires-Dist: pytest>=7; extra == "test"
Requires-Dist: pytest-cov; extra == "test"
Provides-Extra: dev
Requires-Dist: mlafactory[test]; extra == "dev"
Requires-Dist: ruff==0.15.6; extra == "dev"
Dynamic: license-file

# mlafactory

[![PyPI version](https://badge.fury.io/py/mlafactory.svg)](https://badge.fury.io/py/mlafactory)
[![License: BSD-3](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)
[![Python 3.11+](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/downloads/)

`mlafactory` is an open-source discrete-event simulation framework for modeling **Multi-Level Assembly (MLA)** manufacturing systems. Built on top of [SimPy](https://simpy.readthedocs.io/), it enables flexible simulation of factories with dynamic inventory management, heterogeneous machine pools, stochastic order arrivals, and configurable production and replenishment policies.

The framework is designed for **research, experimentation, and reproducible evaluation** of manufacturing strategies.

---

## Features

- **Multi-level bill of materials (BOM)** — recursive assembly of products from sub-components and raw materials
- **Heterogeneous machine pools** — multiple machine types with configurable setup times, cycle times, and costs
- **Dynamic inventory management** — min/max stock policies with async waiting and automatic replenishment
- **Stochastic order arrivals** — fixed, random, spread, or distribution-based inter-order intervals
- **Configurable replenishment** — per-component reorder delays for raw materials
- **Multiple inventory initialization strategies** — zero, min, max, or random initial stock levels
- **Rich reporting** — production service levels, machine utilization, and inventory summaries exported as CSV
- **CLI and Python API** — run simulations without writing code or integrate programmatically
- **YAML / JSON configuration** — fully reproducible experiments via configuration files

---

## Requirements

- Python 3.11+
- SimPy >= 4.0
- NumPy
- pandas
- PyYAML

---

## Installation


```bash
pip install mlafactory
```

Install from source:

```bash
git clone https://gitlab.com/uniluxembourg/hpc/research/cadom/mla_factory.git
cd mla_factory
pip install -e .
```

---

## Quick Start

### Command Line

The CLI uses the bundled example configuration when no input options are
provided. Print a summary with:

```bash
mlafactory --print-summary
```

Run a custom YAML or JSON configuration:

```bash
mlafactory --factory-config my_factory.yml --print-summary
```

### Python API

```python
from mlafactory import FactoryRunner

runner = FactoryRunner.from_config("my_factory.yml")
result = runner.run()

print(result.fulfillment_ratio)
print(result.production)  # pandas DataFrame, including a TOTAL row

# Score a run directly. "production" aliases total "produced_qty".
score = runner.run_objective("fulfillment_ratio")
```

To configure a runner in Python, create a `FactoryConfig` and `RunOptions`:

```python
from mlafactory.config.config import FactoryConfig, RunOptions
from mlafactory import FactoryRunner

# config_data is a mapping with the fields in the sample YAML/JSON file.
# congid_data must contain 'orders', 'bom', 'initial_inventory', 'machines', 'inventory_policy_bounds', and 'supplier_lead_times'
config = FactoryConfig.from_dict(config_data)
options = RunOptions(print_summary=True)
runner = FactoryRunner(config, options)
result = runner.run()
```

The full sample configurations are [`min_example.yaml`](src/mlafactory/examples/min_example.yaml) and [`min_example.json`](src/mlafactory/examples/min_example.json).

---

## Documentation

Additional documentation is available in [`docs/`](docs/):

| File | Description |
|---|---|
| [`docs/cli.md`](docs/cli.md) | Additional command-line usage notes |
| [`docs/simulation_model.md`](docs/simulation_model.md) | Simulation architecture and event flow |
---

## Configuration

Use one YAML or JSON configuration file with these top-level sections:

- `orders`: mapping of order IDs to product quantities
- `bom`: products and components, each with a machine `type` and nested `bom`
- `machines`: machine names, types, setup/cycle times, and optional costs
- `supplier_lead_times`: raw material reorder delays
- `inventory_policy_bounds`: `min` and `max` stock limits for every BOM or
  supplier item
- `initial_inventory`: optional explicit starting stock
- Optional run settings include `factory_name`, `months`, `hours_per_month`,
  `seed`, `inventory_strategy`, `order_mode`, and `order_mode_params`

For complete, valid examples, see [`min_example.yaml`](src/mlafactory/examples/min_example.yaml)
or [`min_example.json`](src/mlafactory/examples/min_example.json). Machine setup
and cycle times are expressed in minutes; the simulation duration and reorder
delays use simulation-time hours.

Order interval modes are `fixed`, `random`, `spread`, and `distribution`.
Distribution mode supports `poisson` and `normal`. The configured seed controls
random initial inventory and stochastic order intervals.

To export CSV reports, set `export_reports: true` in the configuration or pass
`--export-reports`; choose the destination with `output_dir` or `--output-dir`.
The CLI options `--print-summary`, `--debug-logs`, and `--export-reports` enable
their respective outputs.

---

## Project Structure

```
mlafactory/
├── src/mlafactory/
│   ├── cli.py                  # command-line entry point
│   ├── runner.py               # public simulation orchestrator
│   ├── config/                 # configuration, validation, and reporting
│   ├── examples/               # bundled YAML/JSON configurations
│   ├── optimization/           # stock-policy optimization adapter
│   ├── scenario/               # initial inventory and order scheduling
│   └── sim/                    # SimPy simulation entities
├── docs/
├── tests/
└── README.md
```

---

## Running Tests

```bash
pip install -e ".[test]"
python -m pytest
```

---

## License

BSD 3-Clause License. See [LICENSE](LICENSE) for details.

---

## Citation

To be completed.
<!--
If you use mlafactory in your research, please cite:

```bibtex
@article{mlafactory2025,
  title   = {mlafactory: A Discrete-Event Simulation Framework for Multi-Level Assembly Systems},
  author  = {Your Name},
  journal = {Journal of Open Source Software},
  year    = {2025},
  doi     = {10.xxxx/joss.xxxxx}
}
```
-->
---

## Authors

Developer and maintainer:

**Oscar J. Castro-Lopez**: 
Research Associate, University of Luxembourg

Contributors:

- **Pierrick Pochelu**  DevOps, LuxProvide
- **Georgios Kafanas**  Infrastructure and Architecture Engineer, University of Luxembourg

Contributions welcome — please open an issue or pull request on GitLab.

## Acknowledgements

This project was created with the support of the Luxembourg National Research Fund (FNR) under project 17941664. Supported by the Ministry of Economy (MECO) under project 17941664.
