Metadata-Version: 2.4
Name: pyfmto
Version: 0.1.1
Summary: A Python library for federated many-task optimization research
Author-email: Xiaoxu Zhang <xxzhang_official@163.com>
License:                                  Apache License
                                   Version 2.0, January 2004
                                http://www.apache.org/licenses/
        
           TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
        
           1. Definitions.
        
              "License" shall mean the terms and conditions for use, reproduction,
              and distribution as defined by Sections 1 through 9 of this document.
        
              "Licensor" shall mean the copyright owner or entity authorized by
              the copyright owner that is granting the License.
        
              "Legal Entity" shall mean the union of the acting entity and all
              other entities that control, are controlled by, or are under common
              control with that entity. For the purposes of this definition,
              "control" means (i) the power, direct or indirect, to cause the
              direction or management of such entity, whether by contract or
              otherwise, or (ii) ownership of fifty percent (50%) or more of the
              outstanding shares, or (iii) beneficial ownership of such entity.
        
              "You" (or "Your") shall mean an individual or Legal Entity
              exercising permissions granted by this License.
        
              "Source" form shall mean the preferred form for making modifications,
              including but not limited to software source code, documentation
              source, and configuration files.
        
              "Object" form shall mean any form resulting from mechanical
              transformation or translation of a Source form, including but
              not limited to compiled object code, generated documentation,
              and conversions to other media types.
        
              "Work" shall mean the work of authorship, whether in Source or
              Object form, made available under the License, as indicated by a
              copyright notice that is included in or attached to the work
              (an example is provided in the Appendix below).
        
              "Derivative Works" shall mean any work, whether in Source or Object
              form, that is based on (or derived from) the Work and for which the
              editorial revisions, annotations, elaborations, or other modifications
              represent, as a whole, an original work of authorship. For the purposes
              of this License, Derivative Works shall not include works that remain
              separable from, or merely link (or bind by name) to the interfaces of,
              the Work and Derivative Works thereof.
        
              "Contribution" shall mean any work of authorship, including
              the original version of the Work and any modifications or additions
              to that Work or Derivative Works thereof, that is intentionally
              submitted to Licensor for inclusion in the Work by the copyright owner
              or by an individual or Legal Entity authorized to submit on behalf of
              the copyright owner. For the purposes of this definition, "submitted"
              means any form of electronic, verbal, or written communication sent
              to the Licensor or its representatives, including but not limited to
              communication on electronic mailing lists, source code control systems,
              and issue tracking systems that are managed by, or on behalf of, the
              Licensor for the purpose of discussing and improving the Work, but
              excluding communication that is conspicuously marked or otherwise
              designated in writing by the copyright owner as "Not a Contribution."
        
              "Contributor" shall mean Licensor and any individual or Legal Entity
              on behalf of whom a Contribution has been received by Licensor and
              subsequently incorporated within the Work.
        
           2. Grant of Copyright License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              copyright license to reproduce, prepare Derivative Works of,
              publicly display, publicly perform, sublicense, and distribute the
              Work and such Derivative Works in Source or Object form.
        
           3. Grant of Patent License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              (except as stated in this section) patent license to make, have made,
              use, offer to sell, sell, import, and otherwise transfer the Work,
              where such license applies only to those patent claims licensable
              by such Contributor that are necessarily infringed by their
              Contribution(s) alone or by combination of their Contribution(s)
              with the Work to which such Contribution(s) was submitted. If You
              institute patent litigation against any entity (including a
              cross-claim or counterclaim in a lawsuit) alleging that the Work
              or a Contribution incorporated within the Work constitutes direct
              or contributory patent infringement, then any patent licenses
              granted to You under this License for that Work shall terminate
              as of the date such litigation is filed.
        
           4. Redistribution. You may reproduce and distribute copies of the
              Work or Derivative Works thereof in any medium, with or without
              modifications, and in Source or Object form, provided that You
              meet the following conditions:
        
              (a) You must give any other recipients of the Work or
                  Derivative Works a copy of this License; and
        
              (b) You must cause any modified files to carry prominent notices
                  stating that You changed the files; and
        
              (c) You must retain, in the Source form of any Derivative Works
                  that You distribute, all copyright, patent, trademark, and
                  attribution notices from the Source form of the Work,
                  excluding those notices that do not pertain to any part of
                  the Derivative Works; and
        
              (d) If the Work includes a "NOTICE" text file as part of its
                  distribution, then any Derivative Works that You distribute must
                  include a readable copy of the attribution notices contained
                  within such NOTICE file, excluding those notices that do not
                  pertain to any part of the Derivative Works, in at least one
                  of the following places: within a NOTICE text file distributed
                  as part of the Derivative Works; within the Source form or
                  documentation, if provided along with the Derivative Works; or,
                  within a display generated by the Derivative Works, if and
                  wherever such third-party notices normally appear. The contents
                  of the NOTICE file are for informational purposes only and
                  do not modify the License. You may add Your own attribution
                  notices within Derivative Works that You distribute, alongside
                  or as an addendum to the NOTICE text from the Work, provided
                  that such additional attribution notices cannot be construed
                  as modifying the License.
        
              You may add Your own copyright statement to Your modifications and
              may provide additional or different license terms and conditions
              for use, reproduction, or distribution of Your modifications, or
              for any such Derivative Works as a whole, provided Your use,
              reproduction, and distribution of the Work otherwise complies with
              the conditions stated in this License.
        
           5. Submission of Contributions. Unless You explicitly state otherwise,
              any Contribution intentionally submitted for inclusion in the Work
              by You to the Licensor shall be under the terms and conditions of
              this License, without any additional terms or conditions.
              Notwithstanding the above, nothing herein shall supersede or modify
              the terms of any separate license agreement you may have executed
              with Licensor regarding such Contributions.
        
           6. Trademarks. This License does not grant permission to use the trade
              names, trademarks, service marks, or product names of the Licensor,
              except as required for reasonable and customary use in describing the
              origin of the Work and reproducing the content of the NOTICE file.
        
           7. Disclaimer of Warranty. Unless required by applicable law or
              agreed to in writing, Licensor provides the Work (and each
              Contributor provides its Contributions) on an "AS IS" BASIS,
              WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
              implied, including, without limitation, any warranties or conditions
              of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
              PARTICULAR PURPOSE. You are solely responsible for determining the
              appropriateness of using or redistributing the Work and assume any
              risks associated with Your exercise of permissions under this License.
        
           8. Limitation of Liability. In no event and under no legal theory,
              whether in tort (including negligence), contract, or otherwise,
              unless required by applicable law (such as deliberate and grossly
              negligent acts) or agreed to in writing, shall any Contributor be
              liable to You for damages, including any direct, indirect, special,
              incidental, or consequential damages of any character arising as a
              result of this License or out of the use or inability to use the
              Work (including but not limited to damages for loss of goodwill,
              work stoppage, computer failure or malfunction, or any and all
              other commercial damages or losses), even if such Contributor
              has been advised of the possibility of such damages.
        
           9. Accepting Warranty or Additional Liability. While redistributing
              the Work or Derivative Works thereof, You may choose to offer,
              and charge a fee for, acceptance of support, warranty, indemnity,
              or other liability obligations and/or rights consistent with this
              License. However, in accepting such obligations, You may act only
              on Your own behalf and on Your sole responsibility, not on behalf
              of any other Contributor, and only if You agree to indemnify,
              defend, and hold each Contributor harmless for any liability
              incurred by, or claims asserted against, such Contributor by reason
              of your accepting any such warranty or additional liability.
        
           END OF TERMS AND CONDITIONS
        
           APPENDIX: How to apply the Apache License to your work.
        
              To apply the Apache License to your work, attach the following
              boilerplate notice, with the fields enclosed by brackets "[]"
              replaced with your own identifying information. (Don't include
              the brackets!)  The text should be enclosed in the appropriate
              comment syntax for the file format. We also recommend that a
              file or class name and description of purpose be included on the
              same "printed page" as the copyright notice for easier
              identification within third-party archives.
        
           Copyright [yyyy] [name of copyright owner]
        
           Licensed under the Apache License, Version 2.0 (the "License");
           you may not use this file except in compliance with the License.
           You may obtain a copy of the License at
        
               http://www.apache.org/licenses/LICENSE-2.0
        
           Unless required by applicable law or agreed to in writing, software
           distributed under the License is distributed on an "AS IS" BASIS,
           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
           See the License for the specific language governing permissions and
           limitations under the License.
        
Project-URL: Homepage, https://github.com/Xiaoxu-Zhang/pyfmto
Classifier: Development Status :: 4 - Beta
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Intended Audience :: Science/Research
Classifier: Intended Audience :: Education
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Operating System :: POSIX :: Linux
Classifier: Operating System :: MacOS :: MacOS X
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: NOTICE.txt
Requires-Dist: fastapi
Requires-Dist: jinja2
Requires-Dist: matplotlib
Requires-Dist: msgpack
Requires-Dist: numpy
Requires-Dist: openpyxl
Requires-Dist: opfunu
Requires-Dist: pandas
Requires-Dist: pillow
Requires-Dist: pydantic
Requires-Dist: pydantic_core
Requires-Dist: pyDOE
Requires-Dist: pyvista
Requires-Dist: pyyaml
Requires-Dist: requests
Requires-Dist: ruamel-yaml
Requires-Dist: scienceplots
Requires-Dist: scikit-learn
Requires-Dist: scipy
Requires-Dist: seaborn
Requires-Dist: setproctitle
Requires-Dist: tabulate
Requires-Dist: tqdm
Requires-Dist: uvicorn
Requires-Dist: wrapt
Provides-Extra: dev
Requires-Dist: build; extra == "dev"
Requires-Dist: pyproject_hooks; extra == "dev"
Requires-Dist: setuptools; extra == "dev"
Requires-Dist: coverage; extra == "dev"
Requires-Dist: pytest; extra == "dev"
Requires-Dist: pytest-cov; extra == "dev"
Requires-Dist: pytest-env; extra == "dev"
Requires-Dist: iniconfig; extra == "dev"
Requires-Dist: mypy; extra == "dev"
Requires-Dist: mypy_extensions; extra == "dev"
Requires-Dist: types-PyYAML; extra == "dev"
Requires-Dist: types-tabulate; extra == "dev"
Requires-Dist: types-requests; extra == "dev"
Requires-Dist: typing-inspection; extra == "dev"
Requires-Dist: typing_extensions; extra == "dev"
Requires-Dist: flake8; extra == "dev"
Requires-Dist: flake8-pyproject; extra == "dev"
Requires-Dist: pycodestyle; extra == "dev"
Requires-Dist: pyflakes; extra == "dev"
Requires-Dist: mccabe; extra == "dev"
Requires-Dist: click; extra == "dev"
Requires-Dist: pluggy; extra == "dev"
Requires-Dist: sniffio; extra == "dev"
Requires-Dist: psutil; extra == "dev"
Requires-Dist: threadpoolctl; extra == "dev"
Requires-Dist: six; extra == "dev"
Requires-Dist: zipp; extra == "dev"
Requires-Dist: packaging; extra == "dev"
Requires-Dist: tomli; extra == "dev"
Requires-Dist: certifi; extra == "dev"
Requires-Dist: charset-normalizer; extra == "dev"
Requires-Dist: idna; extra == "dev"
Requires-Dist: urllib3; extra == "dev"
Requires-Dist: h11; extra == "dev"
Requires-Dist: annotated-types; extra == "dev"
Requires-Dist: contourpy; extra == "dev"
Requires-Dist: cycler; extra == "dev"
Requires-Dist: fonttools; extra == "dev"
Requires-Dist: kiwisolver; extra == "dev"
Requires-Dist: pyparsing; extra == "dev"
Requires-Dist: joblib; extra == "dev"
Requires-Dist: python-dateutil; extra == "dev"
Requires-Dist: starlette; extra == "dev"
Requires-Dist: deepdiff; extra == "dev"
Dynamic: license-file

```

                               ____                __         
            ____     __  __   / __/  ____ ___     / /_   ____ 
           / __ \   / / / /  / /_   / __ `__ \   / __/  / __ \
          / /_/ /  / /_/ /  / __/  / / / / / /  / /_   / /_/ /
         / .___/   \__, /  /_/    /_/ /_/ /_/   \__/   \____/ 
        /_/       /____/                                      


```

# PyFMTO

[![build](https://github.com/Xiaoxu-Zhang/pyfmto/workflows/build/badge.svg)](https://github.com/Xiaoxu-Zhang/pyfmto/actions?query=workflow%3Abuild)
[![coverage](https://img.shields.io/codecov/c/github/Xiaoxu-Zhang/pyfmto)](https://codecov.io/gh/Xiaoxu-Zhang/pyfmto)
[![pypi](https://img.shields.io/pypi/v/pyfmto.svg)](https://pypi.org/project/pyfmto/)
[![support-version](https://img.shields.io/pypi/pyversions/pyfmto)](https://img.shields.io/pypi/pyversions/pyfmto)
[![license](https://img.shields.io/github/license/Xiaoxu-Zhang/pyfmto)](https://github.com/Xiaoxu-Zhang/pyfmto/blob/master/LICENSE)
[![commit](https://img.shields.io/github/last-commit/Xiaoxu-Zhang/pyfmto)](https://github.com/Xiaoxu-Zhang/pyfmto/commits/main)
[![Linux Support](https://img.shields.io/badge/OS-Linux-green.svg)](https://www.kernel.org/)
[![MacOS Support](https://img.shields.io/badge/OS-MacOS-green.svg)](https://www.apple.com/macos/)


**PyFMTO** is a pure Python library for federated many-task optimization research

<table align="center">
  <tr>
    <td align="center">
      <img src="https://github.com/Xiaoxu-Zhang/zxx-assets/raw/main/pyfmto-demo.gif" 
width="95%"/><br>
      Run experiments
    </td>
    <td align="center">
      <img src="https://github.com/Xiaoxu-Zhang/zxx-assets/raw/main/pyfmto-iplot.gif" 
width="95%"/><br>
      Plot tasks
    </td>
  </tr>
</table>

## Usage

> PyFMTO is developed and tested on Linux and macOS. It may not work well on Windows.

### Quick Start

Clone the [fmto](https://github.com/Xiaoxu-Zhang/fmto.git) repository ([why?](#about-fmto)):

```bash
git clone https://github.com/Xiaoxu-Zhang/fmto.git
cd fmto
```

Create an environment (`conda` is recommended) and install PyFMTO:

```bash
conda create -n fmto python=3.10
conda activate fmto
pip install pyfmto
```

Start the experiments:

```bash
pyfmto run
```

Generate reports:

```bash
pyfmto report
```

The reports will be saved in the folder `out/results/<today>`

### Command-line Interface (CLI)

PyFMTO provides a command-line interface (CLI) for running experiments, analyzing results and 
get helps. The CLI layers are as follows:

```txt
pyfmto
   ├── -h/--help
   ├── run [-c/--config <config_file>]
   ├── report [-c/--config <config_file>]
   ├── list algorithms/problems/reports
   └── show <result of list>
```

**Examples:**

- Get help:
    ```bash
    pyfmto -h # or ↓
    # pyfmto --help
    # pyfmto list -h
    ```
- Run experiments:
    ```bash
    pyfmto run # or ↓
    # pyfmto run -c config.yaml
    ```
- Generate reports:
    ```bash
    pyfmto report # or ↓
    # pyfmto report -c config.yaml
    ```
- List something:
    ```bash
    pyfmto list algorithms
    ```
    output:
    ```txt
    Found 6 Available Algorithms:
    FDEMD
    ADDFBO
    BO
    FMTBO
    IAFFBO
    ALG
    ```
- Show supported configurations:
    ```bash
    pyfmto show ALG
    # pyfmto will automatically find the name in 'algorithms', 'problems' and 'reports'
    ```
    output:
    ```txt
    client:   
      alpha: 0.2
    
    server:
      beta: 0.5
    ```

### Use PyFMTO in python

```python
from pyfmto import Launcher, Reporter

if __name__ == '__main__':
    launcher = Launcher()
    launcher.run()
    
    reports = Reports()
    reports.to_curve()
    # reporter.to_ ...
```

## Architecture and Ecosystem

<div align="center">
  <img src="https://github.com/Xiaoxu-Zhang/zxx-assets/raw/main/pyfmto-architecture.svg" 
width="90%">
</div>

Where the filled area represents the fully developed modules. And the non-filled area represents
the base modules that can be inherited and extended.

The bottom layer listed the core technologies used in PyFMTO for computing, communicating, plotting 
and testing.

## About fmto

The repository [fmto](https://github.com/Xiaoxu-Zhang/fmto) is the official collection of 
published FMTO algorithms. The relationship between the `fmto` and `PyFMTO` is as follows:

<p align="center">
    <img src="https://github.com/Xiaoxu-Zhang/zxx-assets/raw/main/fmto-relation.svg"/>
<p>

The `fmto` is designed to provide a platform for researchers to compare and evaluate the 
performance of different FMTO algorithms. The repository is built on top of the PyFMTO library, 
which provides a flexible and extensible framework for implementing FMTO algorithms.

It also serves as a practical example of how to structure and perform experiments. The repository 
includes the following components:

- A collection of published FMTO algorithms.
- A config file (config.yaml) that provides guidance on how to set up and configure the experiments.
- A template algorithm named "ALG" that you can use as a basis for implementing your own algorithm.
- A template problem named "PROB" that you can use as a basis for implementing your own problem.

The `config.yaml`, `ALG` and `PROB` provided detailed instructions, you can even start your 
research without additional documentation. The fmto repository is currently in the early stages 
of development. I'm actively working on improving existing algorithms and adding new algorithms.

## Algorithm's Components

An algorithm includes two parts: the client and the server. The client is responsible for 
optimizing the local problem and the server is responsible for aggregating the knowledge from 
the clients. The required components for client and server are as follows:

```python
# myalg_client.py
from pyfmto import Client, Server

class MyClient(Client):
	def __init__(self, problem, **kwargs):
		super().__init__(problem)

	def optimize():
		# implement the optimizer
		pass

class MyServer(Server):
	def __init__(self, **kwargs):
		super().__init__():
	
	def aggregate(self) -> None:
		# implement the aggregate logic
		pass

	def handle_request(self, pkg) -> Any:
		# handle the requests of clients to exchange data
		pass
```

## Problem's Components

There are two types of problems: single-task problems and multitask problems. A single-task 
problem is a problem that has only one objective function. A multitask problem is a problem that 
has multiple single-task problems. To define a multitask problem, you should implement several 
SingleTaskProblem and then define a MultiTaskProblem to aggregate them.

> **Note**: There are some classical SingleTaskProblem defined in `pyfmto.problems.benchmarks` 
> module. You can use them directly.

```python
import numpy as np
from numpy import ndarray
from pyfmto.problems import SingleTaskProblem, MultiTaskProblem
from typing import Union

class MySTP(SingleTaskProblem):

    def __init__(self, dim=2, **kwargs):
        super().__init__(dim=dim, obj=1, lb=0, ub=1, **kwargs)
    
    def _eval_single(self, x: ndarray):
        pass

class MyMTP(MultiTaskProblem):
    is_realworld = False
    intro = "user defined MTP"
    notes = "a demo of user-defined MTP"
    references = ['ref1', 'ref2']
    
    def __init__(self, dim=10, **kwargs):
        super().__init__(dim, **kwargs)
    
    def _init_tasks(self, dim, **kwargs) -> list[SingleTaskProblem]:
        # Duplicate MySTP for 10 here as an example
        return [MySTP(dim=dim, **kwargs) for _ in range(10)]
  ```

## Tools

### list_problems

```python
from pyfmto.problems import list_problems

# list all problems in console
list_problems(print_it=True)

# it also return the dict {ProblemName: ProblemDataInstance} of problems
prob_lst = list_problems()
```

### init_problem

```python
from pyfmto.problems import init_problem

_ = load_problem('Arxiv2017')

# init a problem with customized args
prob = init_problem('Arxiv2017', dim=2, fe_init=20, fe_max=50, npd=5)

# problem instance can be print
print(prob)
```

## Visualization

### SingleTaskProblem Visualization

```python
from pyfmto.problems.benchmarks import Ackley

task = Ackley()
task.plot_2d(f'visualize2D')
task.plot_3d(f'visualize3D')
task.iplot_3d() # interactive plotting
```

### MultiTaskProblem Visualization

The right side interactive plotting at the beginning is generated by the following code:

```python
from pyfmto import init_problem

if __name__ == '__main__':
    prob = init_problem('Arxiv2017', dim=2)
    prob.iplot_tasks_3d(tasks_id=[2, 5, 12, 18])
```

## Contributing

See [contributing](https://github.com/Xiaoxu-Zhang/pyfmto/blob/main/CONTRIBUTING.md) for instructions on how to contribute to PyFMTO.

## Bugs/Requests

Please send bug reports and feature requests through
[github issue tracker](https://github.com/Xiaoxu-Zhang/pyfmto/issues). PyFMTO is 
currently under development now, and it's open to any constructive suggestions.

## License

Copyright (c) 2025 Xiaoxu Zhang

Distributed under the terms of the
[Apache 2.0 license](https://github.com/Xiaoxu-Zhang/pyfmto/blob/main/LICENSE).

## Acknowledgements

### Foundations
This project is supported, in part, by the National Natural Science Foundation of China under 
Grant 62006143; the Natural Science Foundation of Shandong Province under Grants ZR2025MS1012 
and ZR2020MF152. I would like to express our sincere gratitude to **Smart Healthcare and Big Data 
Laboratory, Shandong Women's University**, for providing research facilities and technical support.


### Mentorship and Team Support  
I would like to express my sincere gratitude to the **Computational Intelligence and 
Applications Group** for their invaluable help, encouragement, and collaboration throughout the 
development of this project.  

Special thanks go to my mentor, [Jie Tian](https://github.com/Jetina), whose insightful guidance 
and constructive feedback were crucial in refining and improving the work at every stage.

### Open Source Contributions  
This project would not have been possible without the outstanding contributions of the 
open-source community. I am deeply grateful to the maintainers and contributors of the following 
projects:  

- **[FastAPI](https://fastapi.tiangolo.com)** – A high-performance web framework that made 
  building APIs both fast and efficient.  
- **[NumPy](https://numpy.org)** – The fundamental package for scientific computing in Python, 
  enabling high-speed numerical operations.  
- **[Pandas](https://pandas.pydata.org)** – Powerful data structures and tools that formed the 
  backbone of data analysis in this work.  
- **[Matplotlib](https://matplotlib.org)** and **[Seaborn](https://seaborn.pydata.org)** – 
  Essential for producing high-quality, publication-ready visualizations.  
- **[PyVista](https://docs.pyvista.org)** – An intuitive, high-level 3D plotting and mesh 
  analysis interface, making scientific visualization seamlessly integrated into PyFMTO.  
- **[Scikit-learn](https://scikit-learn.org)** – An extensive set of machine learning algorithms 
  and utilities.  
- **[SciPy](https://scipy.org)** – Fundamental algorithms and mathematical functions critical to 
  scientific computing.  

I would also like to acknowledge the maintainers and contributors of other open-source libraries 
that supported this work, including:  
`jinja2`, `msgpack`, `openpyxl`, `opfunu`, `pillow`, `pydantic`, `pydantic_core`, `pyDOE`, 
`pyyaml`, `requests`, `ruamel-yaml`, `scienceplots`, `setproctitle`, `tabulate`, `tqdm`, 
`uvicorn`, and `wrapt`.  

Your dedication to building and maintaining these tools has made it possible for this project to 
achieve both depth and breadth that would otherwise have been unattainable.  
