mlwiz 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. mlwiz-1.0.0/LICENSE +28 -0
  2. mlwiz-1.0.0/PKG-INFO +87 -0
  3. mlwiz-1.0.0/README.md +63 -0
  4. mlwiz-1.0.0/mlwiz/__init__.py +0 -0
  5. mlwiz-1.0.0/mlwiz/build_dataset.py +38 -0
  6. mlwiz-1.0.0/mlwiz/data/__init__.py +0 -0
  7. mlwiz-1.0.0/mlwiz/data/dataset.py +629 -0
  8. mlwiz-1.0.0/mlwiz/data/provider.py +707 -0
  9. mlwiz-1.0.0/mlwiz/data/sampler.py +32 -0
  10. mlwiz-1.0.0/mlwiz/data/splitter.py +580 -0
  11. mlwiz-1.0.0/mlwiz/data/util.py +176 -0
  12. mlwiz-1.0.0/mlwiz/evaluation/__init__.py +0 -0
  13. mlwiz-1.0.0/mlwiz/evaluation/config.py +82 -0
  14. mlwiz-1.0.0/mlwiz/evaluation/evaluator.py +1208 -0
  15. mlwiz-1.0.0/mlwiz/evaluation/grid.py +196 -0
  16. mlwiz-1.0.0/mlwiz/evaluation/random_search.py +102 -0
  17. mlwiz-1.0.0/mlwiz/evaluation/util.py +541 -0
  18. mlwiz-1.0.0/mlwiz/experiment/__init__.py +1 -0
  19. mlwiz-1.0.0/mlwiz/experiment/experiment.py +362 -0
  20. mlwiz-1.0.0/mlwiz/launch_experiment.py +260 -0
  21. mlwiz-1.0.0/mlwiz/log/__init__.py +0 -0
  22. mlwiz-1.0.0/mlwiz/log/logger.py +41 -0
  23. mlwiz-1.0.0/mlwiz/model/__init__.py +3 -0
  24. mlwiz-1.0.0/mlwiz/model/graph.py +89 -0
  25. mlwiz-1.0.0/mlwiz/model/interface.py +46 -0
  26. mlwiz-1.0.0/mlwiz/model/timeseries.py +53 -0
  27. mlwiz-1.0.0/mlwiz/model/vector.py +118 -0
  28. mlwiz-1.0.0/mlwiz/static.py +110 -0
  29. mlwiz-1.0.0/mlwiz/training/__init__.py +0 -0
  30. mlwiz-1.0.0/mlwiz/training/callback/__init__.py +0 -0
  31. mlwiz-1.0.0/mlwiz/training/callback/early_stopping.py +178 -0
  32. mlwiz-1.0.0/mlwiz/training/callback/engine_callback.py +107 -0
  33. mlwiz-1.0.0/mlwiz/training/callback/gradient_clipping.py +30 -0
  34. mlwiz-1.0.0/mlwiz/training/callback/metric.py +1363 -0
  35. mlwiz-1.0.0/mlwiz/training/callback/optimizer.py +117 -0
  36. mlwiz-1.0.0/mlwiz/training/callback/plotter.py +101 -0
  37. mlwiz-1.0.0/mlwiz/training/callback/scheduler.py +115 -0
  38. mlwiz-1.0.0/mlwiz/training/engine.py +846 -0
  39. mlwiz-1.0.0/mlwiz/training/event/__init__.py +0 -0
  40. mlwiz-1.0.0/mlwiz/training/event/dispatcher.py +54 -0
  41. mlwiz-1.0.0/mlwiz/training/event/handler.py +389 -0
  42. mlwiz-1.0.0/mlwiz/training/event/state.py +52 -0
  43. mlwiz-1.0.0/mlwiz/training/profiler.py +170 -0
  44. mlwiz-1.0.0/mlwiz/training/util.py +23 -0
  45. mlwiz-1.0.0/mlwiz/util.py +58 -0
  46. mlwiz-1.0.0/mlwiz.egg-info/PKG-INFO +87 -0
  47. mlwiz-1.0.0/mlwiz.egg-info/SOURCES.txt +51 -0
  48. mlwiz-1.0.0/mlwiz.egg-info/dependency_links.txt +1 -0
  49. mlwiz-1.0.0/mlwiz.egg-info/entry_points.txt +3 -0
  50. mlwiz-1.0.0/mlwiz.egg-info/requires.txt +10 -0
  51. mlwiz-1.0.0/mlwiz.egg-info/top_level.txt +1 -0
  52. mlwiz-1.0.0/pyproject.toml +39 -0
  53. mlwiz-1.0.0/setup.cfg +4 -0
mlwiz-1.0.0/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2024, Federico Errica
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mlwiz-1.0.0/PKG-INFO ADDED
@@ -0,0 +1,87 @@
1
+ Metadata-Version: 2.1
2
+ Name: mlwiz
3
+ Version: 1.0.0
4
+ Summary: Machine Learning Research Wizard
5
+ Author-email: Federico Errica <f.errica@protonmail.com>
6
+ Project-URL: Homepage, https://mlwiz.readthedocs.io/en/latest/
7
+ Keywords: machine-learning,deep-learning,experiments,research,evaluation-framework
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: BSD License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.10
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: PyYAML>=5.4
15
+ Requires-Dist: tqdm>=4.66.1
16
+ Requires-Dist: Requests>=2.31.0
17
+ Requires-Dist: scikit_learn>=1.3.0
18
+ Requires-Dist: tensorboard>=2.11.0
19
+ Requires-Dist: tqdm>=4.47.0
20
+ Requires-Dist: ray>=2.6.0
21
+ Requires-Dist: torchvision>=0.18.1
22
+ Requires-Dist: torch>=2.3.1
23
+ Requires-Dist: torch-geometric<=2.4.0,>=2.3.0
24
+
25
+ <p align="center">
26
+ <img src="https://github.com/diningphil/MLWiz/blob/main/docs/_static/mlwiz-logo.png" width="300"/>
27
+ </p>
28
+
29
+ # MLWiz: the Machine Learning Research Wizard
30
+ [![License](https://img.shields.io/badge/License-BSD_3--Clause-gray.svg)](https://opensource.org/licenses/BSD-3-Clause)
31
+ [![Documentation Status](https://readthedocs.org/projects/mlwiz/badge/?version=latest)](https://mlwiz.readthedocs.io/en/latest/?badge=latest)
32
+ [![Python Package](https://github.com/diningphil/MLWiz/actions/workflows/python-publish.yml/badge.svg)](https://github.com/diningphil/MLWiz/actions/workflows/python-publish.yml)
33
+ [![Downloads](https://static.pepy.tech/personalized-badge/mlwiz?period=total&units=international_system&left_color=grey&right_color=blue&left_text=Downloads)](https://pepy.tech/project/mlwiz)
34
+ [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
35
+ [![Interrogate](https://github.com/diningphil/MLWiz/blob/main/.badges/interrogate_badge.svg)](https://interrogate.readthedocs.io/en/latest/)
36
+ [![Coverage](https://github.com/diningphil/MLWiz/blob/main/.badges/coverage_badge.svg)]()
37
+
38
+ ## [Documentation](https://mlwiz.readthedocs.io/en/latest/index.html)
39
+
40
+ MLWiz is a Python library that fosters machine learning research by reducing the boilerplate code
41
+ to run reproducible experiments. It provides automatic management of data splitting, loading and common
42
+ experimental settings. It especially handles both model selection and risk assessment procedures, by trying many different
43
+ configurations in parallel (CPU or GPU). It is a generalized version of [PyDGN](https://github.com/diningphil/PyDGN)
44
+ that can handle different kinds of data and models (vectors, images, time-series, graphs).
45
+
46
+ ## Installation:
47
+
48
+ Requires at least Python 3.10. Simply run
49
+
50
+ pip install mlwiz
51
+
52
+ ## Quickstart:
53
+
54
+ #### Build dataset and data splits
55
+
56
+ mlwiz-data --config-file examples/DATA_CONFIGS/config_NCI1.yml [--debug]
57
+
58
+ #### Launch experiments
59
+
60
+ mlwiz-exp --config-file examples/MODEL_CONFIGS/config_SupToyDGN.yml [--debug]
61
+
62
+
63
+ #### Stop experiments
64
+ Use ``CTRL-C``, then type ``ray stop --force`` to stop **all** ray processes you have launched.
65
+
66
+ ### Using the Trained Models
67
+
68
+ It's very easy to load the model from the experiments (see also the [Tutorial](https://mlwiz.readthedocs.io/en/latest/tutorial.html)):
69
+
70
+ from mlwiz.evaluation.util import *
71
+
72
+ config = retrieve_best_configuration('RESULTS/supervised_grid_search_toy_NCI1/MODEL_ASSESSMENT/OUTER_FOLD_1/MODEL_SELECTION/')
73
+ splits_filepath = 'examples/DATA_SPLITS/CHEMICAL/NCI1/NCI1_outer10_inner1.splits'
74
+ device = 'cpu'
75
+
76
+ # instantiate dataset
77
+ dataset = instantiate_dataset_from_config(config)
78
+
79
+ # instantiate model
80
+ model = instantiate_model_from_config(config, dataset, config_type="supervised_config")
81
+
82
+ # load model's checkpoint, assuming the best configuration has been loaded
83
+ checkpoint_location = 'RESULTS/supervised_grid_search_toy_NCI1/MODEL_ASSESSMENT/OUTER_FOLD_1/final_run1/best_checkpoint.pth'
84
+ load_checkpoint(checkpoint_location, model, device=device)
85
+
86
+ # you can now call the forward method of your model
87
+ y, embeddings = model(dataset[0])
mlwiz-1.0.0/README.md ADDED
@@ -0,0 +1,63 @@
1
+ <p align="center">
2
+ <img src="https://github.com/diningphil/MLWiz/blob/main/docs/_static/mlwiz-logo.png" width="300"/>
3
+ </p>
4
+
5
+ # MLWiz: the Machine Learning Research Wizard
6
+ [![License](https://img.shields.io/badge/License-BSD_3--Clause-gray.svg)](https://opensource.org/licenses/BSD-3-Clause)
7
+ [![Documentation Status](https://readthedocs.org/projects/mlwiz/badge/?version=latest)](https://mlwiz.readthedocs.io/en/latest/?badge=latest)
8
+ [![Python Package](https://github.com/diningphil/MLWiz/actions/workflows/python-publish.yml/badge.svg)](https://github.com/diningphil/MLWiz/actions/workflows/python-publish.yml)
9
+ [![Downloads](https://static.pepy.tech/personalized-badge/mlwiz?period=total&units=international_system&left_color=grey&right_color=blue&left_text=Downloads)](https://pepy.tech/project/mlwiz)
10
+ [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
11
+ [![Interrogate](https://github.com/diningphil/MLWiz/blob/main/.badges/interrogate_badge.svg)](https://interrogate.readthedocs.io/en/latest/)
12
+ [![Coverage](https://github.com/diningphil/MLWiz/blob/main/.badges/coverage_badge.svg)]()
13
+
14
+ ## [Documentation](https://mlwiz.readthedocs.io/en/latest/index.html)
15
+
16
+ MLWiz is a Python library that fosters machine learning research by reducing the boilerplate code
17
+ to run reproducible experiments. It provides automatic management of data splitting, loading and common
18
+ experimental settings. It especially handles both model selection and risk assessment procedures, by trying many different
19
+ configurations in parallel (CPU or GPU). It is a generalized version of [PyDGN](https://github.com/diningphil/PyDGN)
20
+ that can handle different kinds of data and models (vectors, images, time-series, graphs).
21
+
22
+ ## Installation:
23
+
24
+ Requires at least Python 3.10. Simply run
25
+
26
+ pip install mlwiz
27
+
28
+ ## Quickstart:
29
+
30
+ #### Build dataset and data splits
31
+
32
+ mlwiz-data --config-file examples/DATA_CONFIGS/config_NCI1.yml [--debug]
33
+
34
+ #### Launch experiments
35
+
36
+ mlwiz-exp --config-file examples/MODEL_CONFIGS/config_SupToyDGN.yml [--debug]
37
+
38
+
39
+ #### Stop experiments
40
+ Use ``CTRL-C``, then type ``ray stop --force`` to stop **all** ray processes you have launched.
41
+
42
+ ### Using the Trained Models
43
+
44
+ It's very easy to load the model from the experiments (see also the [Tutorial](https://mlwiz.readthedocs.io/en/latest/tutorial.html)):
45
+
46
+ from mlwiz.evaluation.util import *
47
+
48
+ config = retrieve_best_configuration('RESULTS/supervised_grid_search_toy_NCI1/MODEL_ASSESSMENT/OUTER_FOLD_1/MODEL_SELECTION/')
49
+ splits_filepath = 'examples/DATA_SPLITS/CHEMICAL/NCI1/NCI1_outer10_inner1.splits'
50
+ device = 'cpu'
51
+
52
+ # instantiate dataset
53
+ dataset = instantiate_dataset_from_config(config)
54
+
55
+ # instantiate model
56
+ model = instantiate_model_from_config(config, dataset, config_type="supervised_config")
57
+
58
+ # load model's checkpoint, assuming the best configuration has been loaded
59
+ checkpoint_location = 'RESULTS/supervised_grid_search_toy_NCI1/MODEL_ASSESSMENT/OUTER_FOLD_1/final_run1/best_checkpoint.pth'
60
+ load_checkpoint(checkpoint_location, model, device=device)
61
+
62
+ # you can now call the forward method of your model
63
+ y, embeddings = model(dataset[0])
File without changes
@@ -0,0 +1,38 @@
1
+ import argparse
2
+ import os
3
+ import sys
4
+
5
+ import yaml
6
+
7
+ from mlwiz.data.util import preprocess_data
8
+ from mlwiz.static import CONFIG_FILE_CLI_ARGUMENT, CONFIG_FILE
9
+
10
+
11
+ def get_args_dict() -> dict:
12
+ """
13
+ Processes CLI arguments (i.e., the config file location) and returns
14
+ a dictionary.
15
+
16
+ Returns:
17
+ a dictionary with the name of the configuration file in the
18
+ :obj:`mlwiz.static.CONFIG_FILE` field.
19
+ """
20
+ parser = argparse.ArgumentParser()
21
+ parser.add_argument(
22
+ CONFIG_FILE_CLI_ARGUMENT,
23
+ dest=CONFIG_FILE,
24
+ help="config file to parse the data",
25
+ )
26
+ return vars(parser.parse_args())
27
+
28
+
29
+ def main():
30
+ """
31
+ Launches the data preparation pipeline.
32
+ """
33
+ # Necessary to locate dotted paths in projects that use MLWiz
34
+ sys.path.append(os.getcwd())
35
+
36
+ args = get_args_dict()
37
+ options = yaml.load(open(args[CONFIG_FILE], "r"), Loader=yaml.FullLoader)
38
+ preprocess_data(options)
File without changes