Skip to content
This repository was archived by the owner on Aug 27, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
3 changes: 1 addition & 2 deletions src/converter/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
from .linkml_converter import *
from .yaml_converter import *
from .converter import *
123 changes: 97 additions & 26 deletions src/converter/converter.py
Original file line number Diff line number Diff line change
@@ -1,68 +1,139 @@
import os

from src.utils.helpers import merge_dict_list, load_yaml

class ConverterTrait:

class LinkMLConverter:

def __init__(self, benchmark_file):
self.stage_order_map = None
self.benchmark_file = os.path.abspath(benchmark_file)
self.benchmark = load_yaml(benchmark_file)

def get_stage_id(self, stage):
raise NotImplementedError("Method not implemented yet")

def get_module_id(self, module):
raise NotImplementedError("Method not implemented yet")
def get_benchmark_name(self):
return self.benchmark.name if self.benchmark.name else self.benchmark.id

def get_benchmark_definition(self):
raise NotImplementedError("Method not implemented yet")
return self.benchmark

def get_benchmark_definition_file(self):
raise NotImplementedError("Method not implemented yet")
def get_stage_id(self, stage):
return stage.id

def get_module_id(self, module):
return module.id

def get_benchmark_stages(self):
raise NotImplementedError("Method not implemented yet")
return dict([(x.id, x) for x in self.benchmark.stages])

def get_benchmark_stage(self, stage_id):
raise NotImplementedError("Method not implemented yet")
stages = self.get_benchmark_stages().values()
return next(stage for stage in stages if stage.id == stage_id)

def get_modules_by_stage(self, stage):
raise NotImplementedError("Method not implemented yet")
return dict([(x.id, x) for x in stage.modules])

def get_stage_implicit_inputs(self, stage):
raise NotImplementedError("Method not implemented yet")
if isinstance(stage, str):
stage = self.get_benchmark_stages()[stage]

def get_inputs_stage(self, implicit_inputs):
raise NotImplementedError("Method not implemented yet")
return [input.entries for input in stage.inputs]

def get_stage_explicit_inputs(self, stage):
raise NotImplementedError("Method not implemented yet")
def get_inputs_stage(self, implicit_inputs):
stages_map = {key: None for key in implicit_inputs}
if implicit_inputs is not None:
all_stages = self.get_benchmark_stages()
all_stages_outputs = []
for stage_id in all_stages:
outputs = self.get_stage_outputs(stage=stage_id)
outputs = {key: stage_id for key, value in outputs.items()}
all_stages_outputs.append(outputs)

all_stages_outputs = merge_dict_list(all_stages_outputs)
for in_deliverable in implicit_inputs:
# beware stage needs to be substituted
curr_output = all_stages_outputs[in_deliverable]

stages_map[in_deliverable] = curr_output

return stages_map

def get_stage_explicit_inputs(self, implicit_inputs):
explicit = {key: None for key in implicit_inputs}
if implicit_inputs is not None:
all_stages = self.get_benchmark_stages()
all_stages_outputs = []
for stage_id in all_stages:
outputs = self.get_stage_outputs(stage=stage_id)
outputs = {
key: value.format(
input="{input}",
stage=stage_id,
module="{module}",
params="{params}",
dataset="{dataset}",
)
for key, value in outputs.items()
}
all_stages_outputs.append(outputs)

all_stages_outputs = merge_dict_list(all_stages_outputs)
for in_deliverable in implicit_inputs:
# beware stage needs to be substituted
curr_output = all_stages_outputs[in_deliverable]

explicit[in_deliverable] = curr_output

return explicit

def get_stage_outputs(self, stage):
raise NotImplementedError("Method not implemented yet")
if isinstance(stage, str):
stage = self.get_benchmark_stages()[stage]

return dict([(output.id, output.path) for output in stage.outputs])

def get_module_excludes(self, module):
raise NotImplementedError("Method not implemented yet")
if isinstance(module, str):
module = self.get_benchmark_modules()[module]

return module.exclude

def get_module_parameters(self, module):
raise NotImplementedError("Method not implemented yet")
params = None
if module.parameters is not None:
params = [x.values for x in module.parameters]

return params

def get_module_repository(self, module):
raise NotImplementedError("Method not implemented yet")
return module.repository

def is_initial(self, stage):
raise NotImplementedError("Method not implemented yet")
if stage.inputs is None or len(stage.inputs) == 0:
return True
else:
return False

def get_after(self, stage):
raise NotImplementedError("Method not implemented yet")
return stage.after

def get_stage_ids(self):
raise NotImplementedError("Method not implemented yet")
return [x.id for x in self.benchmark.stages]

def get_module_ids(self):
raise NotImplementedError("Method not implemented yet")
module_ids = []
for stage in self.benchmark.stages:
for module in stage.modules:
module_ids.append(module.id)

return module_ids

def get_output_ids(self):
raise NotImplementedError("Method not implemented yet")
output_ids = []
for stage in self.benchmark.stages:
for output in stage.outputs:
output_ids.append(output.id)

return output_ids

def get_initial_datasets(self):
stages = self.get_benchmark_stages()
Expand Down
133 changes: 0 additions & 133 deletions src/converter/linkml_converter.py

This file was deleted.

Loading