Example #1
0
    def __init__(self, path: str):
        path = os.path.abspath(path)
        metadata, err = MLObject.create_object_from_file(path)
        if err:
            raise RuntimeError(err)

        self.task_name: str = metadata['task_name']
        # Input/output bindings map parameter name to parameter value
        self.input_binding: dict = metadata['input_binding']
        self.output_binding: dict = metadata['output_binding']
Example #2
0
 def __init__(self, file_path: str):
     """
     Args:
         file_path (str): Path to a  'mlbox_docker.yaml' that is usually located in the MLBox root directory.
     """
     metadata, err = MLObject.create_object_from_file(file_path)
     if err:
         raise RuntimeError(err)
     self.type = RuntimeType.Docker
     self.image = metadata['image']             # Docker image name
     self.docker = metadata['docker_runtime']   # Docker executable ('docker' or 'nvidia-docker').
Example #3
0
 def __init__(self, path: str, **kwargs: Any):
     """
     Args:
         path (str): Path to a Singularity platform that is usually located in the MLBox `platforms` directory.
         **kwargs (Any): Reserved for future use to unify implementation of Platform Definition classes across
             various runners.
     """
     metadata, err = MLObject.create_object_from_file(path)
     if err:
         raise RuntimeError(err)
     self.type: str = 'singularity'
     self.image: str = metadata['image']
Example #4
0
    def __init__(self, path: str):
        """
        Args:
            path (str): Path to a MLBox task file.
        """
        path = os.path.abspath(path)
        metadata, err = MLObject.create_object_from_file(path)
        if err:
            raise RuntimeError(err)

        self.inputs = {input_['name']: input_['type'] for input_ in metadata.get('inputs', [])}
        self.outputs = {output['name']: output['type'] for output in metadata.get('outputs', [])}
Example #5
0
    def __init__(self, path: str):
        """
        Args:
            path (str): Path to a MLBox root directory.
        """
        path = os.path.abspath(path)
        metadata, err = MLObject.create_object_from_file(os.path.join(path, 'mlbox.yaml'))
        if err:
            raise RuntimeError(err)

        self.root = path
        self.name = metadata['name']
        self.version = metadata['version']
        self.runtime = DockerRuntime.load(path)
Example #6
0
    def __init__(self, path: str):
        """
        Args:
            path (str): Path to a MLBox root directory.
        """
        path = os.path.abspath(path)
        metadata, err = MLObject.create_object_from_file(os.path.join(path, 'mlbox.yaml'))
        if err:
            raise RuntimeError(err)

        self.root = path
        self.name = metadata['name']
        self.version = metadata['version']
        self.task: Optional[MLBoxTask] = None
        self.invoke: Optional[MLBoxInvoke] = None
        self.platform: Any = None
Example #7
0
def parse_mlcube_task(filename):
    (task, err) = MLObject.create_object_from_file(filename)
    if err:
      return None, err

    inputs = {}
    for input_dict in task.inputs:
      input_obj, err = mlobject_from_dict('mlcube_task_input', '1.0.0', input_dict)
      if err:
        return None, err
      inputs[input_obj.name] = input_obj

    outputs = {}
    for output_dict in task.outputs:
      output_obj, err = mlobject_from_dict('mlcube_task_output', '1.0.0', output_dict)
      if err:
        return None, err
      outputs[output_obj.name] = output_obj

    task.inputs = inputs
    task.outputs = outputs
    return task, None
Example #8
0
from mlspeclib import MLObject, MLSchema
from pathlib import Path
import pprint

MLSchema.populate_registry()
MLSchema.append_schema_to_registry(Path("schemas"))

(sample_instantiated_object,
 err) = MLObject.create_object_from_file('sample_instantiated_schema.yaml')

pp = pprint.PrettyPrinter(indent=4)
if err != {}:
    pp.pprint(err)
else:
    pp.pprint(sample_instantiated_object.tasks)

(sample_task_object,
 err) = MLObject.create_object_from_file('tasks/download_data.yaml')

if err != {}:
    pp.pprint(err)
else:
    pp.pprint(sample_task_object.inputs)
    pp.pprint(sample_task_object.outputs)

load_path = Path('tasks').glob("*.yaml")
load_list = list(load_path)

for this_file in load_list:
    file_text = this_file.read_text()
    (loaded_object, err) = MLObject.create_object_from_string(file_text)
Example #9
0
def parse_mlbox_docker(filename):
    (docker, err) = MLObject.create_object_from_file(filename)
    return docker, err
Example #10
0
def parse_mlbox_root(filename):
    (root, err) = MLObject.create_object_from_file(filename)
    return root, err
Example #11
0
def parse_mlbox_invoke(filename):
    if not os.path.exists(filename):
        return None, 'No such invocation file: {}'.format(filename)
    (root, err) = MLObject.create_object_from_file(filename)
    return root, err
Example #12
0
from mlspeclib import MLObject, MLSchema
from pathlib import Path
import pprint

MLSchema.populate_registry()
MLSchema.append_schema_to_registry(Path("schemas"))

(sample_instantiated_object,
 err) = MLObject.create_object_from_file('sample_docker_schema.yaml')

pp = pprint.PrettyPrinter(indent=4)
if err != {}:
    pp.pprint(err)
else:
    pp.pprint(sample_instantiated_object.tasks)