Metadata-Version: 2.5
Name: mater
Version: 0.17.0rc1
Summary: Multi-regional Assessment of Technologies, Energy and Resources
Project-URL: Documentation, https://isterre-dynamic-modeling.gricad-pages.univ-grenoble-alpes.fr/mater-project/mater/
Project-URL: repository, https://gricad-gitlab.univ-grenoble-alpes.fr/isterre-dynamic-modeling/mater-project/mater
Author-email: francois-verzier <francois.verzier@univ-grenoble-alpes.fr>, Lauranne Sarribouette <lauranne.sarribouette@univ-grenoble-alpes.fr>
License:                    GNU LESSER GENERAL PUBLIC LICENSE
                               Version 3, 29 June 2007
        
         Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
         Everyone is permitted to copy and distribute verbatim copies
         of this license document, but changing it is not allowed.
        
        
          This version of the GNU Lesser General Public License incorporates
        the terms and conditions of version 3 of the GNU General Public
        License, supplemented by the additional permissions listed below.
        
          0. Additional Definitions.
        
          As used herein, "this License" refers to version 3 of the GNU Lesser
        General Public License, and the "GNU GPL" refers to version 3 of the GNU
        General Public License.
        
          "The Library" refers to a covered work governed by this License,
        other than an Application or a Combined Work as defined below.
        
          An "Application" is any work that makes use of an interface provided
        by the Library, but which is not otherwise based on the Library.
        Defining a subclass of a class defined by the Library is deemed a mode
        of using an interface provided by the Library.
        
          A "Combined Work" is a work produced by combining or linking an
        Application with the Library.  The particular version of the Library
        with which the Combined Work was made is also called the "Linked
        Version".
        
          The "Minimal Corresponding Source" for a Combined Work means the
        Corresponding Source for the Combined Work, excluding any source code
        for portions of the Combined Work that, considered in isolation, are
        based on the Application, and not on the Linked Version.
        
          The "Corresponding Application Code" for a Combined Work means the
        object code and/or source code for the Application, including any data
        and utility programs needed for reproducing the Combined Work from the
        Application, but excluding the System Libraries of the Combined Work.
        
          1. Exception to Section 3 of the GNU GPL.
        
          You may convey a covered work under sections 3 and 4 of this License
        without being bound by section 3 of the GNU GPL.
        
          2. Conveying Modified Versions.
        
          If you modify a copy of the Library, and, in your modifications, a
        facility refers to a function or data to be supplied by an Application
        that uses the facility (other than as an argument passed when the
        facility is invoked), then you may convey a copy of the modified
        version:
        
           a) under this License, provided that you make a good faith effort to
           ensure that, in the event an Application does not supply the
           function or data, the facility still operates, and performs
           whatever part of its purpose remains meaningful, or
        
           b) under the GNU GPL, with none of the additional permissions of
           this License applicable to that copy.
        
          3. Object Code Incorporating Material from Library Header Files.
        
          The object code form of an Application may incorporate material from
        a header file that is part of the Library.  You may convey such object
        code under terms of your choice, provided that, if the incorporated
        material is not limited to numerical parameters, data structure
        layouts and accessors, or small macros, inline functions and templates
        (ten or fewer lines in length), you do both of the following:
        
           a) Give prominent notice with each copy of the object code that the
           Library is used in it and that the Library and its use are
           covered by this License.
        
           b) Accompany the object code with a copy of the GNU GPL and this license
           document.
        
          4. Combined Works.
        
          You may convey a Combined Work under terms of your choice that,
        taken together, effectively do not restrict modification of the
        portions of the Library contained in the Combined Work and reverse
        engineering for debugging such modifications, if you also do each of
        the following:
        
           a) Give prominent notice with each copy of the Combined Work that
           the Library is used in it and that the Library and its use are
           covered by this License.
        
           b) Accompany the Combined Work with a copy of the GNU GPL and this license
           document.
        
           c) For a Combined Work that displays copyright notices during
           execution, include the copyright notice for the Library among
           these notices, as well as a reference directing the user to the
           copies of the GNU GPL and this license document.
        
           d) Do one of the following:
        
               0) Convey the Minimal Corresponding Source under the terms of this
               License, and the Corresponding Application Code in a form
               suitable for, and under terms that permit, the user to
               recombine or relink the Application with a modified version of
               the Linked Version to produce a modified Combined Work, in the
               manner specified by section 6 of the GNU GPL for conveying
               Corresponding Source.
        
               1) Use a suitable shared library mechanism for linking with the
               Library.  A suitable mechanism is one that (a) uses at run time
               a copy of the Library already present on the user's computer
               system, and (b) will operate properly with a modified version
               of the Library that is interface-compatible with the Linked
               Version.
        
           e) Provide Installation Information, but only if you would otherwise
           be required to provide such information under section 6 of the
           GNU GPL, and only to the extent that such information is
           necessary to install and execute a modified version of the
           Combined Work produced by recombining or relinking the
           Application with a modified version of the Linked Version. (If
           you use option 4d0, the Installation Information must accompany
           the Minimal Corresponding Source and Corresponding Application
           Code. If you use option 4d1, you must provide the Installation
           Information in the manner specified by section 6 of the GNU GPL
           for conveying Corresponding Source.)
        
          5. Combined Libraries.
        
          You may place library facilities that are a work based on the
        Library side by side in a single library together with other library
        facilities that are not Applications and are not covered by this
        License, and convey such a combined library under terms of your
        choice, if you do both of the following:
        
           a) Accompany the combined library with a copy of the same work based
           on the Library, uncombined with any other library facilities,
           conveyed under the terms of this License.
        
           b) Give prominent notice with the combined library that part of it
           is a work based on the Library, and explaining where to find the
           accompanying uncombined form of the same work.
        
          6. Revised Versions of the GNU Lesser General Public License.
        
          The Free Software Foundation may publish revised and/or new versions
        of the GNU Lesser General Public License from time to time. Such new
        versions will be similar in spirit to the present version, but may
        differ in detail to address new problems or concerns.
        
          Each version is given a distinguishing version number. If the
        Library as you received it specifies that a certain numbered version
        of the GNU Lesser General Public License "or any later version"
        applies to it, you have the option of following the terms and
        conditions either of that published version or of any later version
        published by the Free Software Foundation. If the Library as you
        received it does not specify a version number of the GNU Lesser
        General Public License, you may choose any version of the GNU Lesser
        General Public License ever published by the Free Software Foundation.
        
          If the Library as you received it specifies that a proxy can decide
        whether future versions of the GNU Lesser General Public License shall
        apply, that proxy's public statement of acceptance of any version is
        permanent authorization for you to choose that version for the
        Library.
License-File: AUTHORS
License-File: LICENSE
Keywords: ecological,energy,materials,research,scientific
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering
Requires-Python: <4.0,>=3.11
Requires-Dist: mater-interface[parquet]>=0.2.0
Requires-Dist: numpy>=2.3.0
Requires-Dist: odfpy>=1.4.1
Requires-Dist: openpyxl>=3.1.5
Requires-Dist: packaging>=24
Requires-Dist: pandas>=2.3.3
Requires-Dist: pint<1,>=0.25
Requires-Dist: pydantic>=2.12.4
Description-Content-Type: text/markdown

# MATER

[![PyPI version](https://img.shields.io/pypi/v/mater.svg)](https://pypi.org/project/mater/)
[![Python](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/downloads/)
![Coverage](https://gricad-gitlab.univ-grenoble-alpes.fr/isterre-dynamic-modeling/mater-project/mater/badges/main/coverage.svg)
[![MATER](https://img.shields.io/badge/framework-MATER-orange.svg)](https://isterre-dynamic-modeling.gricad-pages.univ-grenoble-alpes.fr/mater-project/mater)
[![UV](https://img.shields.io/badge/managed_by-UV-blue.svg)](https://docs.astral.sh/uv/)
[![License](https://img.shields.io/badge/license-LGPLv3-blue.svg)](LICENSE)

**Model-generation framework for stock-regulated socioeconomic metabolism, implemented as a Python library, in the MATER ecosystem.**

**MATER** (*Multi-regional Assessments of Technologies, Energy and Resources*)
is an open-source model-generation framework for stock-regulated
socioeconomic metabolism, implemented as a Python library. A model is
declared by data: the values given to the framework's variables decide its
objects, processes and stocks, and how each stock is controlled.

Its central principle: a stock gap, the difference between a stock and its
reference, activates processes, and these processes change the stocks
through the flow balance.

MATER is designed to support:

- dynamic Material Flow Analysis (dMFA);
- dynamic Input-Output Analysis (dIOA);
- biophysical assessments of technologies, infrastructures, resources, materials and pollutants;
- modelling of constrained transition scenarios.

The package is organized around:

- labelled pandas inputs at the application boundary;
- one flat NumPy vector per variable in the simulation loop, over a generic
  engine that knows no model name;
- composable, documented equation extensions;
- checked inputs, kept at their given years, and outputs in the units of the inputs;
- a ports-and-adapters software architecture.

> MATER is currently under active development. Equations, data examples and taxonomies may evolve in future versions.

---

## Requirements

- Python 3.11 or higher

We recommend using one virtual environment per Python project to manage dependencies and maintain isolation.

You can use [uv](https://docs.astral.sh/uv/) or `pip`.

---

## Installation

Install MATER with `uv`:

```bash
uv add mater
```

Or with `pip`:

```bash
pip install mater
```

---

## Versioning

MATER is in the `0.x` series: a minor version may contain incompatible
changes, which the CHANGELOG and the migration guides of the documentation
list. Only the latest minor version is actively maintained; older releases
remain available for reproducibility but do not normally receive fixes. Pin
the version you use for reproducible work.

MATER `0.17` runs on a new engine (ADR-0011): a step of 365.25 days, outputs
in the units of the inputs, explicit rules for absent values, preparation
checks, and a new extension API. See the migration guide "Migrate from 0.16
to 0.17" in the documentation, from the 0.16.0 release or from the `dev`
branch.

Projects based on `0.14.x` should not assume compatibility with later
versions: the variables of the model changed in 0.15, and no tool converts a
project automatically yet. Pin `0.14.x` while planning an explicit migration
(the migration guide's section "Coming from 0.14").

---

<!-- ## Recommended usage

For most users, we recommend starting from the companion project template:

**[mater-project-manager](https://gricad-gitlab.univ-grenoble-alpes.fr/isterre-dynamic-modeling/mater-project/mater-project-manager)**

It provides a complete project structure, CLI tools and a data pipeline to help you run MATER simulations more easily.

Direct usage of the `mater` package is recommended for:

* custom integrations in existing Python codebases;
* advanced users building specialized tools;
* users who already have MATER-ready labelled input variables;
* contributors to the MATER framework itself.

--- -->

## Public input API

The recommended public input API of MATER is a dictionary mapping variable names to pandas objects:

```python
dict[str, pd.Series | pd.DataFrame | None]
```

Each key is the name of a variable expected by the composed implementation.

Each value can be:

* `pd.Series` for a constant input;
* `pd.DataFrame` for an input given at several dates, interpolated between them;
* `None` for an input that is not given (every input is optional).

When a variable is represented as a `pd.DataFrame`, its columns must be a `pd.DatetimeIndex`.
The index levels are the variable's dimensions, and `attrs["units"]` holds its unit (one
text, or a `pd.Series` with one unit per row).

MATER checks the inputs before the simulation starts: an input that no selected extension
declares, a row given twice or a row without any value is an error that names it.

---

## Quick start: run from pandas variables

Create a Python script named `simulate.py`:

```python
"""
MATER simulation script.
"""

import mater

# These variables must be pandas Series or DataFrames following the
# declarations of the open-loop base and selected extensions.
#
# For the default model, see:
# mater.implementations.mater_default.definition.VARIABLES

variables = {
    "stock": stock,
    "flow_balance": flow_balance,
    "process_capacity_assignment": process_capacity_assignment,
    "process_ref_capacity": process_ref_capacity,
    "allocation_input": allocation_input,
    "life_time_mean_value": life_time_mean_value,
    "reference_stock_input": reference_stock_input,
    "process_input": process_input,
}

mater.run_from_dict(
    variables=variables,
    simulation_name="run0",
    extensions=("regulation", "capital_dynamics"),
    simulation_start_time=1901,
    simulation_end_time=2100,
)
```

Run the script:

```bash
uv run python simulate.py
```

By default, outputs are written to:

```text
outputs/run0/
```

---

## Convenience usage: run from a workbook

MATER also reads workbooks, OpenDocument (`.ods`) or Excel (`.xlsx`), as a convenience loader.

This is useful for examples, tests and manual input files. However, the recommended public API is `run_from_dict`.

```python
"""
MATER simulation script using a workbook.
"""

import mater

mater.run_from_excel(
    file_path="mater_example.ods",
    simulation_name="run0",
    extensions=("regulation", "capital_dynamics"),
    simulation_start_time=2021,
    simulation_end_time=2100,
)
```

Run the script:

```bash
uv run python simulate.py
```

The workbook adapter converts the workbook into the same dictionary format expected by `run_from_dict`.
`mater_example.ods`, the example model of the first-simulation tutorial, is in `docs/source/tutorials/data`.

---

## Advanced APIs

Ordinary users only need imports from `mater`. Two deliberately separate
modules expose advanced features:

- `mater.io` contains typed adapter descriptions such as `ParquetOutput`,
  `ExcelInput` and `ParquetDatasetInput`;
- `mater.extensions` contains the expert contract for declaring variables,
  relations and equations on NumPy vectors.

`run_from_dict`, `run_from_excel` and `run_simulation` also accept
`interpolation=` (a method per input), `on_step=` (a function called after
each step) and `converged=` (solve feedback loops within the step).
`mater.prepare`, `mater.load_prepared` and `mater.run_prepared` prepare a
model once, save it, and run it several times.

Keeping those objects out of the package root makes the common workflow small
without hiding the customization points.

---

## Default scientific composition

Every simulation starts from:

```python
"mater_open_loop"
```

This base is the open loop, trade included: the flows of process activities,
trade and end of life change the stocks. The default run then composes `regulation`
(feedback control: stock gaps activate processes) and `capital_dynamics`
(capital dynamics: the reference of capacity-providing stocks follows the
activities that need them); the latter computes `reference_stock` and
overlays the exogenous `reference_stock_input`.

It is implemented in:

```python
mater.implementations.mater_default
```

Important modules include:

```python
mater.implementations.mater_default.definition  # variables and the three extensions
mater.implementations.mater_default.equations  # relations, masks and equations
```

The default equations are:

* `reference_stock` (`capital_dynamics`)
* `theoretical_flow` and `process` (`regulation`)
* `flow`, `transport_flow`, `end_of_life` and `stock` (`mater_open_loop`)

---

## Outputs

Simulation outputs are written by the configured repository adapter.

By default, MATER uses a Parquet repository and writes results to:

```text
outputs/<simulation_name>/
```

A typical output structure is:

```text
outputs/
└── run0/
    ├── manifest.json
    └── observations/
        ├── stock/
        │   └── part-0.parquet
        ├── flow/
        │   └── part-0.parquet
        └── process/
            └── part-0.parquet
```

This is the versioned Parquet Dataset layout defined by `mater-interface`.
Values are in the units of the inputs, rates per year, and each row carries
its unit. MATER writes bounded batches during the simulation and creates the
manifest once the simulation completes.

---

## Reading outputs

Outputs are standard `mater-interface` Parquet Datasets. Read their metadata
and validated Arrow batches with `mater-interface`:

```python
from mater_interface.serializers.parquet import read_parquet

metadata, batches = read_parquet("outputs/first_run")
for batch in batches:
    print(batch.num_rows, batch.schema.names)
```

Convert individual Arrow batches to pandas only when a downstream analysis
needs it.

---

## Documentation

The online documentation is available here:

[https://isterre-dynamic-modeling.gricad-pages.univ-grenoble-alpes.fr/mater-project/mater/](https://isterre-dynamic-modeling.gricad-pages.univ-grenoble-alpes.fr/mater-project/mater/)

The documentation follows the Diátaxis framework:

* tutorials for guided learning;
* how-to guides for practical modelling tasks;
* reference material for data formats and the Python API;
* explanations of the scientific model and software design.

Component-local architecture decisions and contribution guidance are provided
as complementary sections.

For cross-project architecture, shared data contracts, governance and common
conventions, see the
**[MATER Ecosystem documentation](https://isterre-dynamic-modeling.gricad-pages.univ-grenoble-alpes.fr/mater-project/mater-ecosystem/)**.
Those ecosystem-wide concerns are maintained separately from this library's
scientific concepts, usage guidance and Python API reference.

---

## Citation

If you use MATER in academic work, please cite the associated thesis and the software version used.

The scientific framework behind MATER is associated with:

François Verzier. *Modélisation du métabolisme de la société et de ses trajectoires de transition biophysique*. 2025. DOI: 10.70675/89172c3czbb2bz45abz8b5fza3bb49f30f92

Machine-readable software metadata are provided in `codemeta.json`.

---

## License

MATER is distributed under the terms of the **GNU Lesser General Public License v3.0 or later**.

SPDX identifier:

```text
LGPL-3.0-or-later
```

---

## Contributing

Contributions are welcome.

Please refer to the [CONTRIBUTING.md](CONTRIBUTING.md) file for development guidelines, testing instructions and contribution rules.

---

## Development

Clone the repository:

```bash
git clone https://gricad-gitlab.univ-grenoble-alpes.fr/isterre-dynamic-modeling/mater-project/mater.git
cd mater
```

Install dependencies:

```bash
uv sync
```

Install `just` (cross-platform via uv):

```bash
uv tool install just-bin
```

Or download the binary directly from the [official releases page](https://github.com/casey/just/releases).

> If you see a PATH warning, run `uv tool update-shell` and restart your terminal.

Run the test suite:

```bash
just test
```

Build the documentation locally:

```bash
just docs-build
```
