fabiencasenave commited on
Commit
0f859ab
·
verified ·
1 Parent(s): 48c7b24

Upload folder using huggingface_hub

Browse files
.vscode/settings.json ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ {
2
+ "python-envs.defaultEnvManager": "ms-python.python:conda",
3
+ "python-envs.defaultPackageManager": "ms-python.python:conda",
4
+ "python-envs.pythonProjects": []
5
+ }
README.md CHANGED
@@ -1,3 +1,41 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ datasets:
4
+ - PLAID-datasets/Tensile2d
5
+ language:
6
+ - en
7
+ pipeline_tag: graph-ml
8
+ ---
9
+ # PCA-GP model for VKILS59 dataset
10
+
11
+ The code used to train this model is given in `train.py`.
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ conda env create -n mmgp_tensile2d -f https://huggingface.co/fabiencasenave/mmgp_tensile2d/resolve/main/environment.yml
17
+ conda mmgp_tensile2d
18
+ pip install git+https://huggingface.co/fabiencasenave/mmgp_tensile2d
19
+ ```
20
+
21
+ ## Use
22
+
23
+ ```python
24
+ from datasets import load_dataset
25
+ from plaid.bridges.huggingface_bridge import huggingface_dataset_to_plaid
26
+ import mmgp_tensile2d
27
+
28
+ model = mmgp_tensile2d.load()
29
+
30
+ hf_dataset = load_dataset("PLAID-datasets/Tensile2d", split="all_samples")
31
+ ids_test = hf_dataset.description["split"]['test']
32
+
33
+ dataset_test, _ = huggingface_dataset_to_plaid(hf_dataset, ids = ids_test, processes_number = 6, verbose = True)
34
+
35
+ print("Check the 'U1' field is not present: dataset_test[0].get_field('U1') =", dataset_test[0].get_field('U1'))
36
+
37
+ print("Run prediction...")
38
+ dataset_pred = model.predict(dataset_test)
39
+
40
+ print("Check the 'U1' field is not present: dataset_pred[0].get_field('U1') =", dataset_pred[0].get_field('U1'))
41
+ ```
config_pipeline.yml ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ mmgp_nodes_transf:
2
+ in_features_identifiers:
3
+ - type: nodes
4
+
5
+ mmgp_u1_transf:
6
+ in_features_identifiers:
7
+ - type: field
8
+ name: U1
9
+
10
+
11
+ input_scalar_scaler:
12
+ in_features_identifiers:
13
+ - type: scalar
14
+ name: P
15
+ - type: scalar
16
+ name: p1
17
+ - type: scalar
18
+ name: p2
19
+ - type: scalar
20
+ name: p3
21
+ - type: scalar
22
+ name: p4
23
+ - type: scalar
24
+ name: p5
25
+
26
+ pca_nodes:
27
+ in_features_identifiers:
28
+ - type: nodes
29
+ out_features_identifiers:
30
+ - type: scalar
31
+ name: reduced_nodes_*
32
+
33
+ pca_u1:
34
+ in_features_identifiers:
35
+ - type: field
36
+ name: U1
37
+ out_features_identifiers:
38
+ - type: scalar
39
+ name: reduced_U1_*
40
+
41
+ regressor_mach:
42
+ in_features_identifiers:
43
+ - type: scalar
44
+ name: P
45
+ - type: scalar
46
+ name: p1
47
+ - type: scalar
48
+ name: p2
49
+ - type: scalar
50
+ name: p3
51
+ - type: scalar
52
+ name: p4
53
+ - type: scalar
54
+ name: p5
55
+ - type: scalar
56
+ name: reduced_nodes_*
57
+ out_features_identifiers:
58
+ - type: scalar
59
+ name: reduced_U1_*
environment.yml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: mmgp_tensile2d
2
+ channels:
3
+ - conda-forge
4
+ - nodefaults
5
+ dependencies:
6
+ - python=3.11
7
+ - muscat=2.4.1
8
+ - pip
9
+ - pip:
10
+ - git+https://github.com/PLAID-lib/plaid.git@11f5912a2ade5dea8e708041d61dc7ab4a32baf4
11
+ - git+https://gitlab.com/drti/mmgp.git
pipeline.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b9950a0b4b472fd87721f54fe271aec7da67cec3afef8045f01e319a6d24cbe3
3
+ size 1996169
pyproject.toml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [build-system]
2
+ requires = [
3
+ "setuptools>=60",
4
+ "setuptools-scm>=8.0"]
5
+ build-backend = "setuptools.build_meta"
6
+
7
+ [project]
8
+ name = "mmgp_tensile2d"
9
+ version = "0.1.0"
10
+ description = "MMGP model for Tensile2d dataset"
11
+ authors = [
12
+ { name = "Fabien Casenave", email = "[email protected]" }
13
+ ]
14
+ readme = "README.md"
15
+ requires-python = ">=3.9"
16
+
17
+ [project.urls]
18
+ Homepage = "https://huggingface.co/fabiencasenave/mmgp_tensile2d"
19
+ Repository = "https://huggingface.co/fabiencasenave/mmgp_tensile2d"
20
+
21
+ [tool.setuptools.packages.find]
22
+ where = ["src"]
23
+ include = ["mmgp_tensile2d*"]
src/mmgp_tensile2d.egg-info/PKG-INFO ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Metadata-Version: 2.4
2
+ Name: mmgp_tensile2d
3
+ Version: 0.1.0
4
+ Summary: MMGP model for Tensile2d dataset
5
+ Author-email: Fabien Casenave <[email protected]>
6
+ Project-URL: Homepage, https://huggingface.co/fabiencasenave/mmgp_tensile2d
7
+ Project-URL: Repository, https://huggingface.co/fabiencasenave/mmgp_tensile2d
8
+ Requires-Python: >=3.9
9
+ Description-Content-Type: text/markdown
10
+
11
+ ---
12
+ license: mit
13
+ datasets:
14
+ - PLAID-datasets/VKI-LS59
15
+ language:
16
+ - en
17
+ pipeline_tag: graph-ml
18
+ ---
19
+ # PCA-GP model for VKILS59 dataset
20
+
21
+ The code used to train this model is given in `train.py`.
22
+
23
+ ## Install
24
+
25
+ ```bash
26
+ pip install git+https://huggingface.co/fabiencasenave/pca_gp_vkils59
27
+ ```
28
+
29
+ ## Use
30
+
31
+ ```python
32
+ from datasets import load_dataset
33
+ from plaid.bridges.huggingface_bridge import huggingface_dataset_to_plaid
34
+ import pca_gp_vkils59
35
+
36
+ model = pca_gp_vkils59.load()
37
+
38
+ hf_dataset = load_dataset("PLAID-datasets/VKI-LS59", split="all_samples")
39
+ ids_test = hf_dataset.description["split"]['test']
40
+
41
+ dataset_test, _ = huggingface_dataset_to_plaid(hf_dataset, ids = ids_test, processes_number = 6, verbose = True)
42
+
43
+ print("Check the 'mach' field is not present: dataset_test[0].get_field('mach', base_name='Base_2_2') =", dataset_test[0].get_field('mach', base_name='Base_2_2'))
44
+
45
+ print("Run prediction...")
46
+ dataset_pred = model.predict(dataset_test)
47
+
48
+ print("Check the 'mach' field is now present: dataset_pred[0].get_field('mach', base_name='Base_2_2') =", dataset_pred[0].get_field('mach', base_name='Base_2_2'))
49
+ ```
src/mmgp_tensile2d.egg-info/SOURCES.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ README.md
2
+ pyproject.toml
3
+ src/mmgp_tensile2d/__init__.py
4
+ src/mmgp_tensile2d/utils.py
5
+ src/mmgp_tensile2d.egg-info/PKG-INFO
6
+ src/mmgp_tensile2d.egg-info/SOURCES.txt
7
+ src/mmgp_tensile2d.egg-info/dependency_links.txt
8
+ src/mmgp_tensile2d.egg-info/top_level.txt
src/mmgp_tensile2d.egg-info/dependency_links.txt ADDED
@@ -0,0 +1 @@
 
 
1
+
src/mmgp_tensile2d.egg-info/top_level.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ mmgp_tensile2d
src/mmgp_tensile2d/__init__.py ADDED
@@ -0,0 +1 @@
 
 
1
+ from .utils import load
src/mmgp_tensile2d/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (225 Bytes). View file
 
src/mmgp_tensile2d/__pycache__/utils.cpython-311.pyc ADDED
Binary file (1.36 kB). View file
 
src/mmgp_tensile2d/utils.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import numpy as np
3
+ import joblib
4
+ from huggingface_hub import hf_hub_download
5
+ from Muscat.Containers.MeshGraphTools import FloaterMeshParametrization, RenumberMeshForParametrization
6
+
7
+ def length_scale_init(X):
8
+ return np.ones(X.shape[1])
9
+
10
+
11
+ def load():
12
+ path = hf_hub_download(repo_id="fabiencasenave/mmgp_tensile2d", filename="pipeline.joblib")
13
+ return joblib.load(path)
14
+
15
+ def morphing(mesh):
16
+ mesh_renumb, _, n_boundary = RenumberMeshForParametrization(
17
+ mesh, inPlace=False)
18
+ mesh_renumb.elemFields = mesh_renumb.nodeFields = {}
19
+ morphed_mesh, _ = FloaterMeshParametrization(
20
+ mesh_renumb, n_boundary)
21
+ return morphed_mesh
test.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datasets import load_dataset
2
+ from plaid.bridges.huggingface_bridge import huggingface_dataset_to_plaid
3
+ import mmgp_tensile2d
4
+
5
+ model = mmgp_tensile2d.load()
6
+
7
+ hf_dataset = load_dataset("PLAID-datasets/Tensile2d", split="all_samples")
8
+ ids_test = hf_dataset.description["split"]['test']
9
+
10
+ dataset_test, _ = huggingface_dataset_to_plaid(hf_dataset, ids = ids_test, processes_number = 6, verbose = True)
11
+
12
+ print("Check the 'U1' field is not present: dataset_test[0].get_field('U1') =", dataset_test[0].get_field('U1'))
13
+
14
+ print("Run prediction...")
15
+ dataset_pred = model.predict(dataset_test)
16
+
17
+ print("Check the 'U1' field is not present: dataset_pred[0].get_field('U1') =", dataset_pred[0].get_field('U1'))
train.py ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ os.environ["OMP_PROC_BIND"] = "spread"
3
+ os.environ["OMP_PLACES"] = "threads"
4
+
5
+ from pathlib import Path
6
+
7
+ import yaml
8
+ import numpy as np
9
+ import joblib
10
+
11
+ from datasets.utils.logging import disable_progress_bar
12
+ from datasets import load_dataset
13
+
14
+ from sklearn.base import clone
15
+ from sklearn.pipeline import Pipeline
16
+
17
+ from sklearn.decomposition import PCA
18
+ from sklearn.preprocessing import MinMaxScaler
19
+ from sklearn.gaussian_process import GaussianProcessRegressor
20
+ from sklearn.gaussian_process.kernels import Matern
21
+ from sklearn.multioutput import MultiOutputRegressor
22
+
23
+ from sklearn.model_selection import KFold, GridSearchCV
24
+
25
+ from plaid.bridges.huggingface_bridge import huggingface_dataset_to_plaid, huggingface_description_to_problem_definition
26
+ from plaid.pipelines.sklearn_block_wrappers import WrappedPlaidSklearnTransformer, WrappedPlaidSklearnRegressor
27
+ from plaid.pipelines.plaid_blocks import PlaidTransformedTargetRegressor, PlaidColumnTransformer
28
+ from mmgp.pipelines.mmgp_blocks import MMGPPreparer, MMGPTransformer
29
+
30
+ from mmgp_tensile2d.utils import length_scale_init, morphing
31
+
32
+
33
+ n_processes = min(max(1, os.cpu_count()), 8)
34
+
35
+
36
+ # load dataset
37
+ hf_dataset = load_dataset("PLAID-datasets/Tensile2d", split="all_samples")
38
+ ids_train = hf_dataset.description["split"]['train_500'][:8]
39
+
40
+ dataset_train, _ = huggingface_dataset_to_plaid(hf_dataset, ids = ids_train, processes_number = n_processes, verbose = True)
41
+
42
+
43
+ # load pipeline configuration and trim dataset
44
+ with open("config_pipeline.yml", 'r') as f:
45
+ config = yaml.safe_load(f)
46
+
47
+ all_feature_id = config['input_scalar_scaler']['in_features_identifiers'] +\
48
+ config['pca_nodes']['in_features_identifiers'] + config['pca_u1']['in_features_identifiers']
49
+
50
+ dataset_train = dataset_train.from_features_identifier(all_feature_id)
51
+
52
+
53
+ # define learning pipeline
54
+ preparator = MMGPPreparer(common_mesh_id = 1, morphing = morphing)
55
+
56
+ input_scalar_scaler = WrappedPlaidSklearnTransformer(MinMaxScaler(), **config['input_scalar_scaler'])
57
+
58
+ nodes_preprocessor = Pipeline(
59
+ steps=[
60
+ ("mmgp_nodes_transf", MMGPTransformer(**config['mmgp_nodes_transf'])),
61
+ ('pca_nodes', WrappedPlaidSklearnTransformer(PCA(n_components=4), **config['pca_nodes'])),
62
+ ]
63
+ )
64
+
65
+ column_preprocessor = PlaidColumnTransformer(
66
+ [
67
+ ('input_scalar_scaler', input_scalar_scaler),
68
+ ('nodes_preprocessor', nodes_preprocessor),
69
+ ]
70
+ )
71
+
72
+ preprocessor = Pipeline(
73
+ steps=[
74
+ ("preparator", preparator),
75
+ ('column_preprocessor', column_preprocessor),
76
+ ]
77
+ )
78
+
79
+
80
+ kernel = Matern(length_scale_bounds=(1e-8, 1e8), nu = 2.5)
81
+
82
+ gpr = GaussianProcessRegressor(
83
+ kernel=kernel,
84
+ optimizer='fmin_l_bfgs_b',
85
+ n_restarts_optimizer=1,
86
+ random_state=42)
87
+
88
+ reg = MultiOutputRegressor(gpr)
89
+
90
+
91
+ dynamics_params_factory = {'estimator__kernel__length_scale':length_scale_init}
92
+
93
+ regressor = WrappedPlaidSklearnRegressor(reg, **config['regressor_mach'], dynamics_params_factory = dynamics_params_factory)
94
+
95
+ postprocessor = Pipeline(
96
+ steps=[
97
+ ("mmgp_u1_transf", MMGPTransformer(**config['mmgp_u1_transf'])),
98
+ ('pca_u1', WrappedPlaidSklearnTransformer(PCA(n_components=4), **config['pca_u1'])),
99
+ ]
100
+ )
101
+
102
+
103
+ target_regressor = PlaidTransformedTargetRegressor(
104
+ regressor=regressor,
105
+ transformer=postprocessor,
106
+ # out_features_identifiers = config['pca_u1']['in_features_identifiers']
107
+ )
108
+
109
+ pipeline = Pipeline(
110
+ steps=[
111
+ ("preprocessor", preprocessor),
112
+ ("regressor", target_regressor),
113
+ ]
114
+ )
115
+
116
+
117
+
118
+ # Set hyperameter that have been optimized by cross-valdiation on the training set
119
+ optimized_pipeline = clone(pipeline).set_params(
120
+ preprocessor__column_preprocessor__nodes_preprocessor__pca_nodes__sklearn_block__n_components = 4,
121
+ regressor__transformer__pca_u1__sklearn_block__n_components = 8
122
+ )
123
+
124
+ # Train the model
125
+ optimized_pipeline.fit(dataset_train)
126
+
127
+ # Save model
128
+ joblib.dump(optimized_pipeline, "pipeline.joblib")