Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating cmf repo push and pull commands. #224

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
9f58cad
Done git commit automatically, and Chage code to modify initialized n…
AyeshaSanadi Oct 15, 2024
e49161a
Resloved conflict issue
AyeshaSanadi Oct 16, 2024
ea66a3f
Added code for cmf repo push/pull
AyeshaSanadi Oct 18, 2024
904f1e7
Modified code for cmf repo push/pull command
AyeshaSanadi Oct 30, 2024
14db911
Merge branch 'HewlettPackard:master' into cmf_repo_command
AyeshaSanadi Oct 30, 2024
7f431f9
Merge branch 'HewlettPackard:master' into cmf_repo_command
AyeshaSanadi Nov 6, 2024
a74dc78
adding cmf exception and success code classes
Nov 21, 2024
b83956f
check applied to minios3to check files download failed or assed
Nov 22, 2024
e03d675
adding changes to metadata push
Dec 4, 2024
cbdb4ae
updated init, artifact, metadata, storage_backend with exception hand…
Dec 4, 2024
75b6af2
Merge branch 'HewlettPackard:master' into error_handling
AyeshaSanadi Dec 5, 2024
2a6e8a8
made changes to metadata push and renumbered all status codes
Dec 5, 2024
9d61555
removed print statements, added error handling to osdf init
Dec 9, 2024
6e44cc3
Fixed error occured during testing
AyeshaSanadi Dec 9, 2024
6db3409
Merge remote-tracking branch 'origin/master' into error_handling
Dec 12, 2024
5825d91
update
Dec 12, 2024
1bf5865
update
Dec 13, 2024
a02e5e2
made some changes in local_artifacts.py and other files
varkha-d-sharma Dec 13, 2024
7bc9b73
adding minio_artifact.py code
varkha-d-sharma Dec 13, 2024
f911270
changing way of writing amazons3_artifacts.py
Dec 16, 2024
11430ac
adding ssh remote changes
varkha-d-sharma Dec 16, 2024
fe2e3a1
changed the method for handling cmf exception for ssh remote
Dec 16, 2024
482c1e0
added comments
Dec 16, 2024
66aa912
Merge remote-tracking branch 'origin/master' into error_handling
Dec 18, 2024
a173286
added cmf exception and success handling also did testing
Dec 18, 2024
b1238f3
Merge branch 'HewlettPackard:master' into error_handling
abhinavchobey Dec 20, 2024
9c15ad6
update
Dec 20, 2024
355ef8d
made some review changes
varkha-d-sharma Dec 20, 2024
0dc64a6
update
Dec 20, 2024
fabf410
addressed review comments
varkha-d-sharma Dec 20, 2024
e2ec3fd
addressed review comments
varkha-d-sharma Dec 20, 2024
4e0377f
addressed revieew comments
varkha-d-sharma Dec 20, 2024
968d3dd
updated except block in amazons3
Dec 20, 2024
cbc1d22
Update pull.py
abhinavchobey Dec 24, 2024
3ff5d98
Pulled error_handling branch inside current branch
AyeshaSanadi Dec 26, 2024
282b14a
Added validation
AyeshaSanadi Dec 26, 2024
be0f58c
Added validation for artifact/metadata/repo push file
AyeshaSanadi Dec 26, 2024
fbf56f0
Added git push/pull command inside dvc_wrapper and apply validation f…
AyeshaSanadi Dec 30, 2024
1caa9c4
validaton added to artifact pull and metadata pull
Dec 30, 2024
9e5cffa
Added description for command
AyeshaSanadi Dec 31, 2024
2f70b13
Added description for cmf repo command inside document.
AyeshaSanadi Dec 31, 2024
4bf170e
Added comment repo pull/push file
AyeshaSanadi Jan 1, 2025
f921ed9
Merge remote-tracking branch 'origin/master' into cmf_repo_command
AyeshaSanadi Jan 8, 2025
22fb2d4
added missing argmuents and duplicate arguments to init
Jan 9, 2025
d185eb6
Added code for execution uuid, repo pull push command and apply valid…
AyeshaSanadi Jan 20, 2025
83a7588
Replaced execution id to execution uuid
AyeshaSanadi Jan 20, 2025
fab258a
Removed duplicate uuid from executions and display it inside gui
AyeshaSanadi Jan 24, 2025
5031e28
Renamed variable name
AyeshaSanadi Jan 24, 2025
d042b52
Added validation, Fixed -a issue and added proper comment
AyeshaSanadi Jan 24, 2025
5884aa8
Removed execution uuid from expanded row
AyeshaSanadi Jan 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmflib/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
"""Main parser for the cmf cli"""
import argparse

from cmflib.commands import artifact, metadata, init, execution, pipeline
from cmflib.commands import artifact, metadata, init, execution, pipeline, repo

from cmflib.cli import CmfParserError

COMMANDS = [artifact, metadata, init, execution, pipeline]
COMMANDS = [artifact, metadata, init, execution, pipeline, repo]


def _find_parser(parser, cmd_cls):
Expand Down
73 changes: 58 additions & 15 deletions cmflib/cmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
_artifact_list,
_pipeline_list,
_execution_list,
_repo_push,
_repo_pull,
)

class Cmf:
Expand Down Expand Up @@ -1996,42 +1998,42 @@ def commit_existing(self, uri: str, props: t.Optional[t.Dict] = None, custom_pro
# print(last)
# os.symlink(str(index), slicedir + "/ " + last)

def metadata_push(pipeline_name: str, filepath = "./mlmd", tensorboard_path: str = "", execution_id: str = ""):
def metadata_push(pipeline_name: str, filepath = "./mlmd", tensorboard_path: str = "", execution_uuid: str = ""):
""" Pushes MLMD file to CMF-server.
Example:
```python
result = metadata_push("example_pipeline", "mlmd_file", "3")
result = metadata_push("example_pipeline", "mlmd_file", "eg_execution_uuid")
```
Args:
pipeline_name: Name of the pipeline.
filepath: Path to the MLMD file.
execution_id: Optional execution ID.
execution_uuid: Optional execution UUID.
tensorboard_path: Path to tensorboard logs.

Returns:
Response output from the _metadata_push function.
"""
# Required arguments: pipeline_name
# Optional arguments: Execution_ID, filepath (mlmd file path, tensorboard_path
output = _metadata_push(pipeline_name, filepath, execution_id, tensorboard_path)
# Optional arguments: Execution_UUID, filepath (mlmd file path), tensorboard_path
output = _metadata_push(pipeline_name, filepath, execution_uuid, tensorboard_path)
return output

def metadata_pull(pipeline_name: str, filepath = "./mlmd", execution_id: str = ""):
def metadata_pull(pipeline_name: str, filepath = "./mlmd", execution_uuid: str = ""):
""" Pulls MLMD file from CMF-server.
Example:
```python
result = metadata_pull("example_pipeline", "./mlmd_directory", "execution_123")
result = metadata_pull("example_pipeline", "./mlmd_directory", "eg_execution_uuid")
```
Args:
pipeline_name: Name of the pipeline.
filepath: File path to store the MLMD file.
execution_id: Optional execution ID.
execution_uuid: Optional execution UUID.
Returns:
Message from the _metadata_pull function.
"""
# Required arguments: pipeline_name
#Optional arguments: Execution_ID, filepath(file path to store mlmd file)
output = _metadata_pull(pipeline_name, filepath, execution_id)
#Optional arguments: Execution_UUID, filepath(file path to store mlmd file)
output = _metadata_pull(pipeline_name, filepath, execution_uuid)
return output

def metadata_export(pipeline_name: str, jsonfilepath: str = "", filepath = "./mlmd"):
Expand Down Expand Up @@ -2331,23 +2333,23 @@ def pipeline_list(filepath = "./mlmd"):
return output


def execution_list(pipeline_name: str, filepath = "./mlmd", execution_id: str = ""):
def execution_list(pipeline_name: str, filepath = "./mlmd", execution_uuid: str = ""):
"""Displays executions from the MLMD file with a few properties in a 7-column table, limited to 20 records per page.
Example:
```python
result = _execution_list("example_pipeline", "./mlmd_directory", "example_execution_id")
result = _execution_list("example_pipeline", "./mlmd_directory", "example_execution_uuid")
```
Args:
pipeline_name: Name of the pipeline.
filepath: Path to store the mlmd file.
execution_id: Executions for particular execution id.
execution_uuid: Executions for particular execution uuid.
Returns:
Output from the _execution_list function.
"""

# Required arguments: pipeline_name
# Optional arguments: filepath( path to store mlmd file), execution_id
output = _execution_list(pipeline_name, filepath, execution_id)
# Optional arguments: filepath( path to store mlmd file), execution_uuid
output = _execution_list(pipeline_name, filepath, execution_uuid)
return output


Expand All @@ -2369,3 +2371,44 @@ def artifact_list(pipeline_name: str, filepath = "./mlmd", artifact_name: str =
# Optional arguments: filepath( path to store mlmd file), artifact_name
output = _artifact_list(pipeline_name, filepath, artifact_name)
return output


def repo_push(pipeline_name: str, filepath = "./mlmd", tensorboard_path: str = "", execution_uuid: str = ""):
""" Push artifacts, metadata files, and source code to the user's artifact repository, cmf-server, and git respectively.
Example:
```python
result = _repo_push("example_pipeline", "./mlmd_directory", "example_execution_uuid", "./tensorboard_path")
```
Args:
pipeline_name: Name of the pipeline.
filepath: Path to store the mlmd file.
execution_uuid: Executions for particular execution uuid.
tensorboard_path: Path to tensorboard logs.
Returns:
Output from the _repo_push function.
"""

# Required arguments: pipeline_name
# Optional arguments: filepath, execution_uuid, tensorboard_path
output = _repo_push(pipeline_name, filepath, execution_uuid, tensorboard_path)
return output


def repo_pull(pipeline_name: str, filepath = "./mlmd", execution_uuid: str = ""):
""" Pull artifacts, metadata files, and source code from the user's artifact repository, cmf-server, and git respectively.
Example:
```python
result = _repo_pull("example_pipeline", "./mlmd_directory", "example_execution_uuid")
```
Args:
pipeline_name: Name of the pipeline.
filepath: Path to store the mlmd file.
execution_uuid: Executions for particular execution uuid.
Returns:
Output from the _repo_pull function.
"""

# Required arguments: pipeline_name
# Optional arguments: filepath, execution_uuid
output = _repo_pull(pipeline_name, filepath, execution_uuid)
return output
50 changes: 44 additions & 6 deletions cmflib/cmf_commands_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from cmflib import cli


def _metadata_push(pipeline_name, file_name, execution_id, tensorboard):
def _metadata_push(pipeline_name, file_name, execution_uuid, tensorboard):
cli_args = cli.parse_args(
[
"metadata",
Expand All @@ -27,7 +27,7 @@ def _metadata_push(pipeline_name, file_name, execution_id, tensorboard):
"-f",
file_name,
"-e",
execution_id,
execution_uuid,
"-t",
tensorboard
]
Expand All @@ -37,7 +37,7 @@ def _metadata_push(pipeline_name, file_name, execution_id, tensorboard):
print(msg)
return msg

def _metadata_pull(pipeline_name, file_name, execution_id):
def _metadata_pull(pipeline_name, file_name, execution_uuid):
cli_args = cli.parse_args(
[
"metadata",
Expand All @@ -47,7 +47,7 @@ def _metadata_pull(pipeline_name, file_name, execution_id):
"-f",
file_name,
"-e",
execution_id,
execution_uuid,
]
)
cmd = cli_args.func(cli_args)
Expand Down Expand Up @@ -316,7 +316,7 @@ def _pipeline_list(file_name):
print(msg)
return msg

def _execution_list(pipeline_name, file_name, execution_id):
def _execution_list(pipeline_name, file_name, execution_uuid):
cli_args = cli.parse_args(
[
"execution",
Expand All @@ -326,7 +326,45 @@ def _execution_list(pipeline_name, file_name, execution_id):
"-f",
file_name,
"-e",
execution_id
execution_uuid
]
)
cmd = cli_args.func(cli_args)
msg = cmd.do_run()
print(msg)
return msg

def _repo_push(pipeline_name, file_name, tensorboard_path, execution_uuid):
cli_args = cli.parse_args(
[
"repo",
"push",
"-p",
pipeline_name,
"-f",
file_name,
"-e",
execution_uuid,
"-t",
tensorboard_path
]
)
cmd = cli_args.func(cli_args)
msg = cmd.do_run()
print(msg)
return msg

def _repo_pull(pipeline_name, file_name, execution_uuid):
cli_args = cli.parse_args(
[
"repo",
"pull",
"-p",
pipeline_name,
"-f",
file_name,
"-e",
execution_uuid
]
)
cmd = cli_args.func(cli_args)
Expand Down
8 changes: 4 additions & 4 deletions cmflib/cmf_exception_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,13 @@ def handle(self):
return f"ERROR: Executions not found."


class ExecutionIDNotFound(CmfFailure):
def __init__(self, exec_id, return_code=105):
self.exec_id = exec_id
class ExecutionUUIDNotFound(CmfFailure):
def __init__(self, exec_uuid, return_code=105):
self.exec_uuid = exec_uuid
super().__init__(return_code)

def handle(self):
return f"ERROR: Execution id {self.exec_id} is not present in mlmd."
return f"ERROR: Execution uuid {self.exec_uuid} is not present in mlmd."


class ArtifactNotFound(CmfFailure):
Expand Down
11 changes: 5 additions & 6 deletions cmflib/cmf_merger.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from ml_metadata.proto import metadata_store_pb2 as mlpb
from typing import Union

def parse_json_to_mlmd(mlmd_json, path_to_store: str, cmd: str, exec_id: Union[str, int]) -> Union[str, None]:
def parse_json_to_mlmd(mlmd_json, path_to_store: str, cmd: str, exec_uuid: Union[str, str]) -> Union[str, None]:
try:
mlmd_data = json.loads(mlmd_json)
pipelines = mlmd_data["Pipeline"]
Expand Down Expand Up @@ -52,17 +52,16 @@ def parse_json_to_mlmd(mlmd_json, path_to_store: str, cmd: str, exec_id: Union[s
graph=graph, is_server=True)

for stage in data["Pipeline"][0]["stages"]: # Iterates over all the stages
if exec_id is None: #if exec_id is None we pass all the executions.
if exec_uuid is None: #if exec_uuid is None we pass all the executions.
list_executions = [execution for execution in stage["executions"]]
elif exec_id is not None: # elif exec_id is not None, we pass executions for that specific id.
elif exec_uuid is not None: # elif exec_uuid is not None, we pass executions for that specific uuid.
list_executions = [
execution
for execution in stage["executions"]
if execution["id"] == int(exec_id)
if exec_uuid in execution['properties']["Execution_uuid"].split(",")
]
else:
return "Invalid execution id given."

return "Invalid execution uuid given."
for execution in list_executions: # Iterates over all the executions
try:
_ = cmf_class.merge_created_context(
Expand Down
29 changes: 22 additions & 7 deletions cmflib/cmfquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def _get_executions(self, stage_id: int, execution_id: t.Optional[int] = None) -

Args:
stage_id: Stage identifier.
execution_id: If not None, return only execution with this ID.
execution_id: If not None, return execution with this ID.
Returns:
List of executions matching input parameters.
"""
Expand Down Expand Up @@ -889,17 +889,14 @@ def get_one_hop_parent_artifacts_with_id(self, artifact_id: int) -> pd.DataFrame
)
return df

def dumptojson(self, pipeline_name: str, exec_id: t.Optional[int] = None) -> t.Optional[str]:
def dumptojson(self, pipeline_name: str, exec_uuid: t.Optional[str] = None) -> t.Optional[str]:
"""Return JSON-parsable string containing details about the given pipeline.
Args:
pipeline_name: Name of an AI pipelines.
exec_id: Optional stage execution ID - filter stages by this execution ID.
exec_uuid: Optional stage execution_uuid - filter stages by this execution_uuid.
Returns:
Pipeline in JSON format.
"""
if exec_id is not None:
exec_id = int(exec_id)

def _get_node_attributes(_node: t.Union[mlpb.Context, mlpb.Execution, mlpb.Event], _attrs: t.Dict) -> t.Dict:
for attr in CONTEXT_LIST:
#Artifacts getattr call on Type was giving empty string, which was overwriting
Expand All @@ -921,7 +918,7 @@ def _get_node_attributes(_node: t.Union[mlpb.Context, mlpb.Execution, mlpb.Event
pipeline_attrs = _get_node_attributes(pipeline, {"stages": []})
for stage in self._get_stages(pipeline.id):
stage_attrs = _get_node_attributes(stage, {"executions": []})
for execution in self._get_executions(stage.id, execution_id=exec_id):
for execution in self.get_all_executions_by_uuid(stage.id, execution_uuid=exec_uuid):
# name will be an empty string for executions that are created with
# create new execution as true(default)
# In other words name property will there only for execution
Expand Down Expand Up @@ -982,6 +979,24 @@ def get_all_executions_for_artifact_id(self, artifact_id: int) -> pd.DataFrame:
except:
return df
return df

def get_all_executions_by_uuid(self, stage_id: int, execution_uuid: t.Optional[str] = None) -> t.List[mlpb.Execution]:
"""Return executions of the given stage.
Args:
stage_id: Stage identifier.
execution_uuid: If not None, return execution with this uuid.
Returns:
List of executions matching input parameters.
"""
executions: t.List[mlpb.Execution] = self.store.get_executions_by_context(stage_id)
if execution_uuid is None:
return executions
executions_with_uuid = []
for execution in executions:
exec_uuid_list = execution.properties['Execution_uuid'].string_value.split(",")
if execution_uuid in exec_uuid_list:
executions_with_uuid.append(execution)
return executions_with_uuid

"""def materialize(self, artifact_name:str):
artifacts = self.store.get_artifacts()
Expand Down
Loading