digitalhub 0.8.1__py3-none-any.whl → 0.9.0b0__py3-none-any.whl
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.
Potentially problematic release.
This version of digitalhub might be problematic. Click here for more details.
- digitalhub/__init__.py +19 -2
- digitalhub/client/_base/api_builder.py +16 -0
- digitalhub/client/_base/client.py +31 -0
- digitalhub/client/api.py +2 -38
- digitalhub/client/dhcore/api_builder.py +100 -0
- digitalhub/client/dhcore/client.py +77 -24
- digitalhub/client/dhcore/enums.py +26 -0
- digitalhub/client/dhcore/env.py +2 -2
- digitalhub/client/dhcore/utils.py +17 -17
- digitalhub/client/local/api_builder.py +100 -0
- digitalhub/client/local/client.py +20 -0
- digitalhub/context/api.py +3 -38
- digitalhub/context/builder.py +10 -23
- digitalhub/context/context.py +20 -92
- digitalhub/entities/_base/context/entity.py +30 -22
- digitalhub/entities/_base/entity/_constructors/metadata.py +12 -1
- digitalhub/entities/_base/entity/_constructors/name.py +1 -1
- digitalhub/entities/_base/entity/_constructors/spec.py +1 -1
- digitalhub/entities/_base/entity/_constructors/status.py +3 -2
- digitalhub/entities/_base/entity/builder.py +6 -1
- digitalhub/entities/_base/entity/entity.py +30 -10
- digitalhub/entities/_base/entity/metadata.py +22 -0
- digitalhub/entities/_base/entity/spec.py +7 -2
- digitalhub/entities/_base/executable/entity.py +8 -8
- digitalhub/entities/_base/material/entity.py +48 -16
- digitalhub/entities/_base/material/status.py +0 -31
- digitalhub/entities/_base/material/utils.py +106 -0
- digitalhub/entities/_base/project/entity.py +341 -0
- digitalhub/entities/_base/unversioned/entity.py +1 -23
- digitalhub/entities/_base/versioned/entity.py +0 -25
- digitalhub/entities/_commons/enums.py +103 -0
- digitalhub/entities/_commons/utils.py +83 -0
- digitalhub/entities/_operations/processor.py +1747 -0
- digitalhub/entities/artifact/_base/builder.py +1 -1
- digitalhub/entities/artifact/_base/entity.py +1 -1
- digitalhub/entities/artifact/artifact/builder.py +2 -1
- digitalhub/entities/artifact/crud.py +46 -29
- digitalhub/entities/artifact/utils.py +62 -0
- digitalhub/entities/dataitem/_base/builder.py +1 -1
- digitalhub/entities/dataitem/_base/entity.py +6 -6
- digitalhub/entities/dataitem/crud.py +50 -66
- digitalhub/entities/dataitem/dataitem/builder.py +2 -1
- digitalhub/entities/dataitem/iceberg/builder.py +2 -1
- digitalhub/entities/dataitem/table/builder.py +2 -1
- digitalhub/entities/dataitem/table/entity.py +5 -10
- digitalhub/entities/dataitem/table/models.py +4 -5
- digitalhub/entities/dataitem/utils.py +137 -0
- digitalhub/entities/function/_base/builder.py +1 -1
- digitalhub/entities/function/_base/entity.py +5 -1
- digitalhub/entities/function/crud.py +36 -17
- digitalhub/entities/model/_base/builder.py +1 -1
- digitalhub/entities/model/_base/entity.py +1 -1
- digitalhub/entities/model/crud.py +46 -29
- digitalhub/entities/model/huggingface/builder.py +2 -1
- digitalhub/entities/model/huggingface/spec.py +4 -2
- digitalhub/entities/model/mlflow/builder.py +2 -1
- digitalhub/entities/model/mlflow/models.py +17 -9
- digitalhub/entities/model/mlflow/spec.py +6 -1
- digitalhub/entities/model/mlflow/utils.py +4 -2
- digitalhub/entities/model/model/builder.py +2 -1
- digitalhub/entities/model/sklearn/builder.py +2 -1
- digitalhub/entities/model/utils.py +62 -0
- digitalhub/entities/project/_base/builder.py +2 -2
- digitalhub/entities/project/_base/entity.py +82 -272
- digitalhub/entities/project/crud.py +110 -91
- digitalhub/entities/project/utils.py +35 -0
- digitalhub/entities/run/_base/builder.py +3 -1
- digitalhub/entities/run/_base/entity.py +52 -54
- digitalhub/entities/run/_base/spec.py +11 -7
- digitalhub/entities/run/crud.py +35 -17
- digitalhub/entities/secret/_base/builder.py +2 -2
- digitalhub/entities/secret/_base/entity.py +4 -10
- digitalhub/entities/secret/crud.py +36 -21
- digitalhub/entities/task/_base/builder.py +14 -14
- digitalhub/entities/task/_base/entity.py +6 -6
- digitalhub/entities/task/_base/models.py +29 -6
- digitalhub/entities/task/_base/spec.py +44 -13
- digitalhub/entities/task/_base/utils.py +18 -0
- digitalhub/entities/task/crud.py +35 -15
- digitalhub/entities/workflow/_base/builder.py +1 -1
- digitalhub/entities/workflow/_base/entity.py +14 -6
- digitalhub/entities/workflow/crud.py +36 -17
- digitalhub/factory/utils.py +1 -1
- digitalhub/readers/_base/reader.py +2 -2
- digitalhub/readers/_commons/enums.py +13 -0
- digitalhub/readers/api.py +3 -2
- digitalhub/readers/factory.py +12 -6
- digitalhub/readers/pandas/reader.py +20 -8
- digitalhub/runtimes/_base.py +0 -7
- digitalhub/stores/_base/store.py +53 -9
- digitalhub/stores/builder.py +5 -5
- digitalhub/stores/local/store.py +37 -2
- digitalhub/stores/remote/store.py +25 -3
- digitalhub/stores/s3/store.py +34 -7
- digitalhub/stores/sql/store.py +112 -45
- digitalhub/utils/exceptions.py +6 -0
- digitalhub/utils/file_utils.py +60 -2
- digitalhub/utils/generic_utils.py +45 -4
- digitalhub/utils/io_utils.py +18 -0
- digitalhub/utils/uri_utils.py +153 -15
- {digitalhub-0.8.1.dist-info → digitalhub-0.9.0b0.dist-info}/METADATA +2 -2
- {digitalhub-0.8.1.dist-info → digitalhub-0.9.0b0.dist-info}/RECORD +110 -113
- test/testkfp.py +4 -1
- digitalhub/datastores/_base/datastore.py +0 -85
- digitalhub/datastores/api.py +0 -37
- digitalhub/datastores/builder.py +0 -110
- digitalhub/datastores/local/datastore.py +0 -50
- digitalhub/datastores/remote/__init__.py +0 -0
- digitalhub/datastores/remote/datastore.py +0 -31
- digitalhub/datastores/s3/__init__.py +0 -0
- digitalhub/datastores/s3/datastore.py +0 -46
- digitalhub/datastores/sql/__init__.py +0 -0
- digitalhub/datastores/sql/datastore.py +0 -68
- digitalhub/entities/_base/api_utils.py +0 -620
- digitalhub/entities/_base/crud.py +0 -468
- digitalhub/entities/function/_base/models.py +0 -118
- digitalhub/entities/utils/__init__.py +0 -0
- digitalhub/entities/utils/api.py +0 -346
- digitalhub/entities/utils/entity_types.py +0 -19
- digitalhub/entities/utils/state.py +0 -31
- digitalhub/entities/utils/utils.py +0 -202
- /digitalhub/{context → entities/_base/project}/__init__.py +0 -0
- /digitalhub/{datastores → entities/_commons}/__init__.py +0 -0
- /digitalhub/{datastores/_base → entities/_operations}/__init__.py +0 -0
- /digitalhub/{datastores/local → readers/_commons}/__init__.py +0 -0
- {digitalhub-0.8.1.dist-info → digitalhub-0.9.0b0.dist-info}/LICENSE.txt +0 -0
- {digitalhub-0.8.1.dist-info → digitalhub-0.9.0b0.dist-info}/WHEEL +0 -0
- {digitalhub-0.8.1.dist-info → digitalhub-0.9.0b0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import shutil
|
|
4
|
+
import typing
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from digitalhub.context.api import get_context
|
|
8
|
+
from digitalhub.entities._base.entity._constructors.uuid import build_uuid
|
|
9
|
+
from digitalhub.entities._base.material.utils import build_log_path_from_source, eval_local_source
|
|
10
|
+
from digitalhub.entities._commons.enums import EntityKinds, EntityTypes
|
|
11
|
+
from digitalhub.readers._commons.enums import Extensions
|
|
12
|
+
from digitalhub.readers.api import get_reader_by_object
|
|
13
|
+
from digitalhub.utils.generic_utils import slugify_string
|
|
14
|
+
|
|
15
|
+
if typing.TYPE_CHECKING:
|
|
16
|
+
from digitalhub.entities.dataitem._base.entity import Dataitem
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def eval_source(
|
|
20
|
+
source: str | list[str] | None = None,
|
|
21
|
+
data: Any | None = None,
|
|
22
|
+
kind: str | None = None,
|
|
23
|
+
name: str | None = None,
|
|
24
|
+
project: str | None = None,
|
|
25
|
+
) -> Any:
|
|
26
|
+
"""
|
|
27
|
+
Evaluate if source is local.
|
|
28
|
+
|
|
29
|
+
Parameters
|
|
30
|
+
----------
|
|
31
|
+
source : str | list[str]
|
|
32
|
+
Source(s).
|
|
33
|
+
|
|
34
|
+
Returns
|
|
35
|
+
-------
|
|
36
|
+
None
|
|
37
|
+
"""
|
|
38
|
+
if (source is None) == (data is None):
|
|
39
|
+
raise ValueError("You must provide source or data.")
|
|
40
|
+
|
|
41
|
+
if source is not None:
|
|
42
|
+
return eval_local_source(source)
|
|
43
|
+
|
|
44
|
+
if kind == EntityKinds.DATAITEM_TABLE.value:
|
|
45
|
+
ctx = get_context(project)
|
|
46
|
+
pth = ctx.root / f"{slugify_string(name)}.{Extensions.PARQUET.value}"
|
|
47
|
+
reader = get_reader_by_object(data)
|
|
48
|
+
reader.write_parquet(data, pth)
|
|
49
|
+
return str(pth)
|
|
50
|
+
|
|
51
|
+
raise NotImplementedError
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def process_kwargs(
|
|
55
|
+
project: str,
|
|
56
|
+
name: str,
|
|
57
|
+
kind: str,
|
|
58
|
+
source: str | list[str],
|
|
59
|
+
data: Any | None = None,
|
|
60
|
+
path: str | None = None,
|
|
61
|
+
**kwargs,
|
|
62
|
+
) -> dict:
|
|
63
|
+
"""
|
|
64
|
+
Process spec kwargs.
|
|
65
|
+
|
|
66
|
+
Parameters
|
|
67
|
+
----------
|
|
68
|
+
project : str
|
|
69
|
+
Project name.
|
|
70
|
+
name : str
|
|
71
|
+
Object name.
|
|
72
|
+
kind : str
|
|
73
|
+
Kind the object.
|
|
74
|
+
source : str
|
|
75
|
+
Source(s).
|
|
76
|
+
data : Any
|
|
77
|
+
Dataframe to log. Alternative to source.
|
|
78
|
+
path : str
|
|
79
|
+
Destination path of the entity. If not provided, it's generated.
|
|
80
|
+
**kwargs : dict
|
|
81
|
+
Spec parameters.
|
|
82
|
+
|
|
83
|
+
Returns
|
|
84
|
+
-------
|
|
85
|
+
dict
|
|
86
|
+
Kwargs updated.
|
|
87
|
+
"""
|
|
88
|
+
if data is not None:
|
|
89
|
+
if kind == EntityKinds.DATAITEM_TABLE.value:
|
|
90
|
+
reader = get_reader_by_object(data)
|
|
91
|
+
kwargs["schema"] = reader.get_schema(data)
|
|
92
|
+
if path is None:
|
|
93
|
+
uuid = build_uuid()
|
|
94
|
+
kwargs["uuid"] = uuid
|
|
95
|
+
kwargs["path"] = build_log_path_from_source(project, EntityTypes.DATAITEM.value, name, uuid, source)
|
|
96
|
+
else:
|
|
97
|
+
kwargs["path"] = path
|
|
98
|
+
return kwargs
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def clean_tmp_path(pth: str) -> None:
|
|
102
|
+
"""
|
|
103
|
+
Clean temporary path.
|
|
104
|
+
|
|
105
|
+
Parameters
|
|
106
|
+
----------
|
|
107
|
+
pth : str
|
|
108
|
+
Path to clean.
|
|
109
|
+
|
|
110
|
+
Returns
|
|
111
|
+
-------
|
|
112
|
+
None
|
|
113
|
+
"""
|
|
114
|
+
shutil.rmtree(pth, ignore_errors=True)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def post_process(obj: Dataitem, data: Any) -> Dataitem:
|
|
118
|
+
"""
|
|
119
|
+
Post process object.
|
|
120
|
+
|
|
121
|
+
Parameters
|
|
122
|
+
----------
|
|
123
|
+
obj : Dataitem
|
|
124
|
+
The object.
|
|
125
|
+
data : Any
|
|
126
|
+
The data.
|
|
127
|
+
|
|
128
|
+
Returns
|
|
129
|
+
-------
|
|
130
|
+
Dataitem
|
|
131
|
+
The object.
|
|
132
|
+
"""
|
|
133
|
+
if obj.kind == EntityKinds.DATAITEM_TABLE.value:
|
|
134
|
+
reader = get_reader_by_object(data)
|
|
135
|
+
obj.status.preview = reader.get_preview(data)
|
|
136
|
+
obj.save(update=True)
|
|
137
|
+
return obj
|
|
@@ -4,7 +4,7 @@ import typing
|
|
|
4
4
|
|
|
5
5
|
from digitalhub.entities._base.runtime_entity.builder import RuntimeEntityBuilder
|
|
6
6
|
from digitalhub.entities._base.versioned.builder import VersionedBuilder
|
|
7
|
-
from digitalhub.entities.
|
|
7
|
+
from digitalhub.entities._commons.enums import EntityTypes
|
|
8
8
|
|
|
9
9
|
if typing.TYPE_CHECKING:
|
|
10
10
|
from digitalhub.entities.function._base.entity import Function
|
|
@@ -4,7 +4,7 @@ import typing
|
|
|
4
4
|
from concurrent.futures import ThreadPoolExecutor
|
|
5
5
|
|
|
6
6
|
from digitalhub.entities._base.executable.entity import ExecutableEntity
|
|
7
|
-
from digitalhub.entities.
|
|
7
|
+
from digitalhub.entities._commons.enums import EntityTypes, Relationship
|
|
8
8
|
from digitalhub.factory.api import get_run_kind, get_task_kind_from_action
|
|
9
9
|
from digitalhub.utils.exceptions import BackendError
|
|
10
10
|
|
|
@@ -81,6 +81,10 @@ class Function(ExecutableEntity):
|
|
|
81
81
|
# Run function from task
|
|
82
82
|
run = task.run(run_kind, local_execution, **kwargs)
|
|
83
83
|
|
|
84
|
+
# Set as run's parent
|
|
85
|
+
run.add_relationship(Relationship.RUN_OF.value, run.key + ":" + run.id, self.key)
|
|
86
|
+
run.save(update=True)
|
|
87
|
+
|
|
84
88
|
# If execution is done by DHCore backend, return the object
|
|
85
89
|
if not local_execution:
|
|
86
90
|
if self._context().local:
|
|
@@ -2,15 +2,8 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import typing
|
|
4
4
|
|
|
5
|
-
from digitalhub.entities.
|
|
6
|
-
|
|
7
|
-
get_context_entity_versions,
|
|
8
|
-
get_versioned_entity,
|
|
9
|
-
import_executable_entity,
|
|
10
|
-
list_context_entities,
|
|
11
|
-
new_context_entity,
|
|
12
|
-
)
|
|
13
|
-
from digitalhub.entities.utils.entity_types import EntityTypes
|
|
5
|
+
from digitalhub.entities._commons.enums import EntityTypes
|
|
6
|
+
from digitalhub.entities._operations.processor import processor
|
|
14
7
|
|
|
15
8
|
if typing.TYPE_CHECKING:
|
|
16
9
|
from digitalhub.entities.function._base.entity import Function
|
|
@@ -63,7 +56,7 @@ def new_function(
|
|
|
63
56
|
>>> code_src="function.py",
|
|
64
57
|
>>> handler="function-handler")
|
|
65
58
|
"""
|
|
66
|
-
return
|
|
59
|
+
return processor.create_context_entity(
|
|
67
60
|
project=project,
|
|
68
61
|
name=name,
|
|
69
62
|
kind=kind,
|
|
@@ -110,7 +103,7 @@ def get_function(
|
|
|
110
103
|
>>> project="my-project",
|
|
111
104
|
>>> entity_id="my-function-id")
|
|
112
105
|
"""
|
|
113
|
-
return
|
|
106
|
+
return processor.read_context_entity(
|
|
114
107
|
identifier,
|
|
115
108
|
entity_type=ENTITY_TYPE,
|
|
116
109
|
project=project,
|
|
@@ -150,7 +143,7 @@ def get_function_versions(
|
|
|
150
143
|
>>> obj = get_function_versions("my-function-name"
|
|
151
144
|
>>> project="my-project")
|
|
152
145
|
"""
|
|
153
|
-
return
|
|
146
|
+
return processor.read_context_entity_versions(
|
|
154
147
|
identifier,
|
|
155
148
|
entity_type=ENTITY_TYPE,
|
|
156
149
|
project=project,
|
|
@@ -178,7 +171,7 @@ def list_functions(project: str, **kwargs) -> list[Function]:
|
|
|
178
171
|
--------
|
|
179
172
|
>>> objs = list_functions(project="my-project")
|
|
180
173
|
"""
|
|
181
|
-
return list_context_entities(
|
|
174
|
+
return processor.list_context_entities(
|
|
182
175
|
project=project,
|
|
183
176
|
entity_type=ENTITY_TYPE,
|
|
184
177
|
**kwargs,
|
|
@@ -187,7 +180,7 @@ def list_functions(project: str, **kwargs) -> list[Function]:
|
|
|
187
180
|
|
|
188
181
|
def import_function(file: str) -> Function:
|
|
189
182
|
"""
|
|
190
|
-
|
|
183
|
+
Import object from a YAML file and create a new object into the backend.
|
|
191
184
|
|
|
192
185
|
Parameters
|
|
193
186
|
----------
|
|
@@ -203,7 +196,28 @@ def import_function(file: str) -> Function:
|
|
|
203
196
|
--------
|
|
204
197
|
>>> obj = import_function("my-function.yaml")
|
|
205
198
|
"""
|
|
206
|
-
return import_executable_entity(file)
|
|
199
|
+
return processor.import_executable_entity(file)
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def load_function(file: str) -> Function:
|
|
203
|
+
"""
|
|
204
|
+
Load object from a YAML file and update an existing object into the backend.
|
|
205
|
+
|
|
206
|
+
Parameters
|
|
207
|
+
----------
|
|
208
|
+
file : str
|
|
209
|
+
Path to YAML file.
|
|
210
|
+
|
|
211
|
+
Returns
|
|
212
|
+
-------
|
|
213
|
+
Function
|
|
214
|
+
Object instance.
|
|
215
|
+
|
|
216
|
+
Examples
|
|
217
|
+
--------
|
|
218
|
+
>>> obj = load_function("my-function.yaml")
|
|
219
|
+
"""
|
|
220
|
+
return processor.load_executable_entity(file)
|
|
207
221
|
|
|
208
222
|
|
|
209
223
|
def update_function(entity: Function) -> Function:
|
|
@@ -224,7 +238,12 @@ def update_function(entity: Function) -> Function:
|
|
|
224
238
|
--------
|
|
225
239
|
>>> obj = update_function(obj)
|
|
226
240
|
"""
|
|
227
|
-
return
|
|
241
|
+
return processor.update_context_entity(
|
|
242
|
+
project=entity.project,
|
|
243
|
+
entity_type=entity.ENTITY_TYPE,
|
|
244
|
+
entity_id=entity.id,
|
|
245
|
+
entity_dict=entity.to_dict(),
|
|
246
|
+
)
|
|
228
247
|
|
|
229
248
|
|
|
230
249
|
def delete_function(
|
|
@@ -268,7 +287,7 @@ def delete_function(
|
|
|
268
287
|
>>> project="my-project",
|
|
269
288
|
>>> delete_all_versions=True)
|
|
270
289
|
"""
|
|
271
|
-
return
|
|
290
|
+
return processor.delete_context_entity(
|
|
272
291
|
identifier=identifier,
|
|
273
292
|
entity_type=ENTITY_TYPE,
|
|
274
293
|
project=project,
|
|
@@ -3,7 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
import typing
|
|
4
4
|
|
|
5
5
|
from digitalhub.entities._base.versioned.builder import VersionedBuilder
|
|
6
|
-
from digitalhub.entities.
|
|
6
|
+
from digitalhub.entities._commons.enums import EntityTypes
|
|
7
7
|
from digitalhub.utils.exceptions import EntityError
|
|
8
8
|
|
|
9
9
|
if typing.TYPE_CHECKING:
|
|
@@ -3,7 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
import typing
|
|
4
4
|
|
|
5
5
|
from digitalhub.entities._base.material.entity import MaterialEntity
|
|
6
|
-
from digitalhub.entities.
|
|
6
|
+
from digitalhub.entities._commons.enums import EntityTypes
|
|
7
7
|
|
|
8
8
|
if typing.TYPE_CHECKING:
|
|
9
9
|
from digitalhub.entities._base.entity.metadata import Metadata
|
|
@@ -2,17 +2,9 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import typing
|
|
4
4
|
|
|
5
|
-
from digitalhub.entities.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
get_material_entity_versions,
|
|
9
|
-
import_context_entity,
|
|
10
|
-
list_material_entities,
|
|
11
|
-
new_context_entity,
|
|
12
|
-
)
|
|
13
|
-
from digitalhub.entities._base.entity._constructors.uuid import build_uuid
|
|
14
|
-
from digitalhub.entities.utils.entity_types import EntityTypes
|
|
15
|
-
from digitalhub.entities.utils.utils import build_log_path_from_source, eval_local_source
|
|
5
|
+
from digitalhub.entities._commons.enums import EntityTypes
|
|
6
|
+
from digitalhub.entities._operations.processor import processor
|
|
7
|
+
from digitalhub.entities.artifact.utils import eval_source, process_kwargs
|
|
16
8
|
|
|
17
9
|
if typing.TYPE_CHECKING:
|
|
18
10
|
from digitalhub.entities.model._base.entity import Model
|
|
@@ -68,7 +60,7 @@ def new_model(
|
|
|
68
60
|
>>> kind="model",
|
|
69
61
|
>>> path="s3://my-bucket/my-key")
|
|
70
62
|
"""
|
|
71
|
-
return
|
|
63
|
+
return processor.create_context_entity(
|
|
72
64
|
project=project,
|
|
73
65
|
name=name,
|
|
74
66
|
kind=kind,
|
|
@@ -119,16 +111,15 @@ def log_model(
|
|
|
119
111
|
>>> kind="model",
|
|
120
112
|
>>> source="./local-path")
|
|
121
113
|
"""
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
return obj
|
|
114
|
+
eval_source(source)
|
|
115
|
+
kwargs = process_kwargs(project, name, source=source, path=path, **kwargs)
|
|
116
|
+
return processor.log_material_entity(
|
|
117
|
+
source=source,
|
|
118
|
+
project=project,
|
|
119
|
+
name=name,
|
|
120
|
+
kind=kind,
|
|
121
|
+
**kwargs,
|
|
122
|
+
)
|
|
132
123
|
|
|
133
124
|
|
|
134
125
|
def get_model(
|
|
@@ -166,7 +157,7 @@ def get_model(
|
|
|
166
157
|
>>> project="my-project",
|
|
167
158
|
>>> entity_id="my-model-id")
|
|
168
159
|
"""
|
|
169
|
-
return
|
|
160
|
+
return processor.read_material_entity(
|
|
170
161
|
identifier=identifier,
|
|
171
162
|
entity_type=ENTITY_TYPE,
|
|
172
163
|
project=project,
|
|
@@ -206,7 +197,7 @@ def get_model_versions(
|
|
|
206
197
|
>>> objs = get_model_versions("my-model-name",
|
|
207
198
|
>>> project="my-project")
|
|
208
199
|
"""
|
|
209
|
-
return
|
|
200
|
+
return processor.read_material_entity_versions(
|
|
210
201
|
identifier=identifier,
|
|
211
202
|
entity_type=ENTITY_TYPE,
|
|
212
203
|
project=project,
|
|
@@ -234,7 +225,7 @@ def list_models(project: str, **kwargs) -> list[Model]:
|
|
|
234
225
|
--------
|
|
235
226
|
>>> objs = list_models(project="my-project")
|
|
236
227
|
"""
|
|
237
|
-
return list_material_entities(
|
|
228
|
+
return processor.list_material_entities(
|
|
238
229
|
project=project,
|
|
239
230
|
entity_type=ENTITY_TYPE,
|
|
240
231
|
**kwargs,
|
|
@@ -243,7 +234,7 @@ def list_models(project: str, **kwargs) -> list[Model]:
|
|
|
243
234
|
|
|
244
235
|
def import_model(file: str) -> Model:
|
|
245
236
|
"""
|
|
246
|
-
Import object from a YAML file.
|
|
237
|
+
Import object from a YAML file and create a new object into the backend.
|
|
247
238
|
|
|
248
239
|
Parameters
|
|
249
240
|
----------
|
|
@@ -259,7 +250,28 @@ def import_model(file: str) -> Model:
|
|
|
259
250
|
--------
|
|
260
251
|
>>> obj = import_model("my-model.yaml")
|
|
261
252
|
"""
|
|
262
|
-
return import_context_entity(file)
|
|
253
|
+
return processor.import_context_entity(file)
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
def load_model(file: str) -> Model:
|
|
257
|
+
"""
|
|
258
|
+
Load object from a YAML file and update an existing object into the backend.
|
|
259
|
+
|
|
260
|
+
Parameters
|
|
261
|
+
----------
|
|
262
|
+
file : str
|
|
263
|
+
Path to YAML file.
|
|
264
|
+
|
|
265
|
+
Returns
|
|
266
|
+
-------
|
|
267
|
+
Model
|
|
268
|
+
Object instance.
|
|
269
|
+
|
|
270
|
+
Examples
|
|
271
|
+
--------
|
|
272
|
+
>>> obj = load_model("my-model.yaml")
|
|
273
|
+
"""
|
|
274
|
+
return processor.load_context_entity(file)
|
|
263
275
|
|
|
264
276
|
|
|
265
277
|
def update_model(entity: Model) -> Model:
|
|
@@ -280,7 +292,12 @@ def update_model(entity: Model) -> Model:
|
|
|
280
292
|
--------
|
|
281
293
|
>>> obj = get_model("store://my-model-key")
|
|
282
294
|
"""
|
|
283
|
-
return
|
|
295
|
+
return processor.update_context_entity(
|
|
296
|
+
project=entity.project,
|
|
297
|
+
entity_type=entity.ENTITY_TYPE,
|
|
298
|
+
entity_id=entity.id,
|
|
299
|
+
entity_dict=entity.to_dict(),
|
|
300
|
+
)
|
|
284
301
|
|
|
285
302
|
|
|
286
303
|
def delete_model(
|
|
@@ -321,7 +338,7 @@ def delete_model(
|
|
|
321
338
|
>>> project="my-project",
|
|
322
339
|
>>> delete_all_versions=True)
|
|
323
340
|
"""
|
|
324
|
-
return
|
|
341
|
+
return processor.delete_context_entity(
|
|
325
342
|
identifier=identifier,
|
|
326
343
|
entity_type=ENTITY_TYPE,
|
|
327
344
|
project=project,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
from digitalhub.entities._commons.enums import EntityKinds
|
|
3
4
|
from digitalhub.entities.model._base.builder import ModelBuilder
|
|
4
5
|
from digitalhub.entities.model.huggingface.entity import ModelHuggingface
|
|
5
6
|
from digitalhub.entities.model.huggingface.spec import ModelSpecHuggingface, ModelValidatorHuggingface
|
|
@@ -15,4 +16,4 @@ class ModelHuggingfaceBuilder(ModelBuilder):
|
|
|
15
16
|
ENTITY_SPEC_CLASS = ModelSpecHuggingface
|
|
16
17
|
ENTITY_SPEC_VALIDATOR = ModelValidatorHuggingface
|
|
17
18
|
ENTITY_STATUS_CLASS = ModelStatusHuggingface
|
|
18
|
-
ENTITY_KIND =
|
|
19
|
+
ENTITY_KIND = EntityKinds.MODEL_HUGGINGFACE.value
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
from pydantic import Field
|
|
4
|
+
|
|
3
5
|
from digitalhub.entities.model._base.spec import ModelSpec, ModelValidator
|
|
4
6
|
|
|
5
7
|
|
|
@@ -29,8 +31,8 @@ class ModelValidatorHuggingface(ModelValidator):
|
|
|
29
31
|
ModelValidatorHuggingface validator.
|
|
30
32
|
"""
|
|
31
33
|
|
|
32
|
-
|
|
34
|
+
placeholder_model_id: str = Field(default=None, alias="model_id")
|
|
33
35
|
"""Huggingface model id. If not specified, the model is loaded from the model path."""
|
|
34
36
|
|
|
35
|
-
|
|
37
|
+
placeholder_model_revision: str = Field(default=None, alias="model_revision")
|
|
36
38
|
"""Huggingface model revision."""
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
from digitalhub.entities._commons.enums import EntityKinds
|
|
3
4
|
from digitalhub.entities.model._base.builder import ModelBuilder
|
|
4
5
|
from digitalhub.entities.model.mlflow.entity import ModelMlflow
|
|
5
6
|
from digitalhub.entities.model.mlflow.spec import ModelSpecMlflow, ModelValidatorMlflow
|
|
@@ -15,4 +16,4 @@ class ModelModelBuilder(ModelBuilder):
|
|
|
15
16
|
ENTITY_SPEC_CLASS = ModelSpecMlflow
|
|
16
17
|
ENTITY_SPEC_VALIDATOR = ModelValidatorMlflow
|
|
17
18
|
ENTITY_STATUS_CLASS = ModelStatusMlflow
|
|
18
|
-
ENTITY_KIND =
|
|
19
|
+
ENTITY_KIND = EntityKinds.MODEL_MLFLOW.value
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
3
5
|
from pydantic import BaseModel, Field
|
|
4
6
|
|
|
5
7
|
|
|
@@ -8,9 +10,12 @@ class Signature(BaseModel):
|
|
|
8
10
|
MLFlow model signature.
|
|
9
11
|
"""
|
|
10
12
|
|
|
11
|
-
inputs: str = None
|
|
12
|
-
outputs: str = None
|
|
13
|
-
params: str = None
|
|
13
|
+
inputs: Optional[str] = None
|
|
14
|
+
outputs: Optional[str] = None
|
|
15
|
+
params: Optional[str] = None
|
|
16
|
+
|
|
17
|
+
def to_dict(self):
|
|
18
|
+
return self.model_dump()
|
|
14
19
|
|
|
15
20
|
|
|
16
21
|
class Dataset(BaseModel):
|
|
@@ -18,9 +23,12 @@ class Dataset(BaseModel):
|
|
|
18
23
|
MLFlow model dataset.
|
|
19
24
|
"""
|
|
20
25
|
|
|
21
|
-
name: str = None
|
|
22
|
-
digest: str = None
|
|
23
|
-
profile: str = None
|
|
24
|
-
schema_: str = Field(default=None, alias="schema")
|
|
25
|
-
source: str = None
|
|
26
|
-
source_type: str = None
|
|
26
|
+
name: Optional[str] = None
|
|
27
|
+
digest: Optional[str] = None
|
|
28
|
+
profile: Optional[str] = None
|
|
29
|
+
schema_: Optional[str] = Field(default=None, alias="schema")
|
|
30
|
+
source: Optional[str] = None
|
|
31
|
+
source_type: Optional[str] = None
|
|
32
|
+
|
|
33
|
+
def to_dict(self):
|
|
34
|
+
return self.model_dump()
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
from pydantic import Field
|
|
4
|
+
|
|
3
5
|
from digitalhub.entities.model._base.spec import ModelSpec, ModelValidator
|
|
4
6
|
from digitalhub.entities.model.mlflow.models import Dataset, Signature
|
|
5
7
|
|
|
@@ -36,9 +38,12 @@ class ModelValidatorMlflow(ModelValidator):
|
|
|
36
38
|
|
|
37
39
|
flavor: str = None
|
|
38
40
|
"""Mlflow model flavor."""
|
|
39
|
-
|
|
41
|
+
|
|
42
|
+
placeholder_cfg_: dict = Field(default=None, alias="model_config")
|
|
40
43
|
"""Mlflow model config."""
|
|
44
|
+
|
|
41
45
|
input_datasets: list[Dataset] = None
|
|
42
46
|
"""Mlflow input datasets."""
|
|
47
|
+
|
|
43
48
|
signature: Signature = None
|
|
44
49
|
"""Mlflow model signature."""
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
1
3
|
from urllib.parse import urlparse
|
|
2
4
|
|
|
3
5
|
import mlflow
|
|
@@ -44,7 +46,7 @@ def from_mlflow_run(run_id: str) -> dict:
|
|
|
44
46
|
inputs=mlflow_signature.inputs.to_json() if mlflow_signature.inputs else None,
|
|
45
47
|
outputs=mlflow_signature.outputs.to_json() if mlflow_signature.outputs else None,
|
|
46
48
|
params=mlflow_signature.params.to_json() if mlflow_signature.params else None,
|
|
47
|
-
).
|
|
49
|
+
).to_dict()
|
|
48
50
|
|
|
49
51
|
# Extract datasets
|
|
50
52
|
datasets = []
|
|
@@ -57,7 +59,7 @@ def from_mlflow_run(run_id: str) -> dict:
|
|
|
57
59
|
schema=d.dataset.schema,
|
|
58
60
|
source=d.dataset.source,
|
|
59
61
|
source_type=d.dataset.source_type,
|
|
60
|
-
).
|
|
62
|
+
).to_dict()
|
|
61
63
|
for d in run.inputs.dataset_inputs
|
|
62
64
|
]
|
|
63
65
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
from digitalhub.entities._commons.enums import EntityKinds
|
|
3
4
|
from digitalhub.entities.model._base.builder import ModelBuilder
|
|
4
5
|
from digitalhub.entities.model.model.entity import ModelModel
|
|
5
6
|
from digitalhub.entities.model.model.spec import ModelSpecModel, ModelValidatorModel
|
|
@@ -15,4 +16,4 @@ class ModelMlflowBuilder(ModelBuilder):
|
|
|
15
16
|
ENTITY_SPEC_CLASS = ModelSpecModel
|
|
16
17
|
ENTITY_SPEC_VALIDATOR = ModelValidatorModel
|
|
17
18
|
ENTITY_STATUS_CLASS = ModelStatusModel
|
|
18
|
-
ENTITY_KIND =
|
|
19
|
+
ENTITY_KIND = EntityKinds.MODEL_MODEL.value
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
from digitalhub.entities._commons.enums import EntityKinds
|
|
3
4
|
from digitalhub.entities.model._base.builder import ModelBuilder
|
|
4
5
|
from digitalhub.entities.model.sklearn.entity import ModelSklearn
|
|
5
6
|
from digitalhub.entities.model.sklearn.spec import ModelSpecSklearn, ModelValidatorSklearn
|
|
@@ -15,4 +16,4 @@ class ModelSklearnBuilder(ModelBuilder):
|
|
|
15
16
|
ENTITY_SPEC_CLASS = ModelSpecSklearn
|
|
16
17
|
ENTITY_SPEC_VALIDATOR = ModelValidatorSklearn
|
|
17
18
|
ENTITY_STATUS_CLASS = ModelStatusSklearn
|
|
18
|
-
ENTITY_KIND =
|
|
19
|
+
ENTITY_KIND = EntityKinds.MODEL_SKLEARN.value
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from digitalhub.entities._base.entity._constructors.uuid import build_uuid
|
|
6
|
+
from digitalhub.entities._base.material.utils import build_log_path_from_source, eval_local_source
|
|
7
|
+
from digitalhub.entities._commons.enums import EntityTypes
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def eval_source(
|
|
11
|
+
source: str | list[str] | None = None,
|
|
12
|
+
) -> Any:
|
|
13
|
+
"""
|
|
14
|
+
Evaluate if source is local.
|
|
15
|
+
|
|
16
|
+
Parameters
|
|
17
|
+
----------
|
|
18
|
+
source : str | list[str]
|
|
19
|
+
Source(s).
|
|
20
|
+
|
|
21
|
+
Returns
|
|
22
|
+
-------
|
|
23
|
+
None
|
|
24
|
+
"""
|
|
25
|
+
return eval_local_source(source)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def process_kwargs(
|
|
29
|
+
project: str,
|
|
30
|
+
name: str,
|
|
31
|
+
source: str | list[str],
|
|
32
|
+
path: str | None = None,
|
|
33
|
+
**kwargs,
|
|
34
|
+
) -> dict:
|
|
35
|
+
"""
|
|
36
|
+
Process spec kwargs.
|
|
37
|
+
|
|
38
|
+
Parameters
|
|
39
|
+
----------
|
|
40
|
+
project : str
|
|
41
|
+
Project name.
|
|
42
|
+
name : str
|
|
43
|
+
Object name.
|
|
44
|
+
source : str
|
|
45
|
+
Source(s).
|
|
46
|
+
path : str
|
|
47
|
+
Destination path of the entity. If not provided, it's generated.
|
|
48
|
+
**kwargs : dict
|
|
49
|
+
Spec parameters.
|
|
50
|
+
|
|
51
|
+
Returns
|
|
52
|
+
-------
|
|
53
|
+
dict
|
|
54
|
+
Kwargs updated.
|
|
55
|
+
"""
|
|
56
|
+
if path is None:
|
|
57
|
+
uuid = build_uuid()
|
|
58
|
+
kwargs["uuid"] = uuid
|
|
59
|
+
kwargs["path"] = build_log_path_from_source(project, EntityTypes.MODEL.value, name, uuid, source)
|
|
60
|
+
else:
|
|
61
|
+
kwargs["path"] = path
|
|
62
|
+
return kwargs
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
from digitalhub.entities._base.entity.builder import EntityBuilder
|
|
4
|
+
from digitalhub.entities._commons.enums import EntityKinds, EntityTypes
|
|
4
5
|
from digitalhub.entities.project._base.entity import Project
|
|
5
6
|
from digitalhub.entities.project._base.spec import ProjectSpec, ProjectValidator
|
|
6
7
|
from digitalhub.entities.project._base.status import ProjectStatus
|
|
7
|
-
from digitalhub.entities.utils.entity_types import EntityTypes
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
class ProjectProjectBuilder(EntityBuilder):
|
|
@@ -17,7 +17,7 @@ class ProjectProjectBuilder(EntityBuilder):
|
|
|
17
17
|
ENTITY_SPEC_CLASS = ProjectSpec
|
|
18
18
|
ENTITY_SPEC_VALIDATOR = ProjectValidator
|
|
19
19
|
ENTITY_STATUS_CLASS = ProjectStatus
|
|
20
|
-
ENTITY_KIND =
|
|
20
|
+
ENTITY_KIND = EntityKinds.PROJECT_PROJECT.value
|
|
21
21
|
|
|
22
22
|
def build(
|
|
23
23
|
self,
|