Skip to content
This repository was archived by the owner on Aug 27, 2024. It is now read-only.

Commit 7ed2267

Browse files
authored
Merge pull request #12 from omnibenchmark/remove_converter
Remove YAML Converter
2 parents 55f11dd + 16d5a64 commit 7ed2267

File tree

7 files changed

+121
-375
lines changed

7 files changed

+121
-375
lines changed

Diff for: main.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@
1515

1616

1717
def main(benchmark_file):
18-
converter = LinkMLConverter(benchmark_file)
19-
validator = Validator()
20-
converter = validator.validate(converter)
21-
benchmark = Benchmark(converter)
18+
benchmark = Benchmark(benchmark_file)
19+
converter = benchmark.get_converter()
2220
print(benchmark.get_definition())
2321

2422
stages = converter.get_benchmark_stages()

Diff for: src/converter/__init__.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
from .linkml_converter import *
2-
from .yaml_converter import *
1+
from .converter import *

Diff for: src/converter/converter.py

+97-26
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,139 @@
11
import os
22

3+
from src.utils.helpers import merge_dict_list, load_yaml
34

4-
class ConverterTrait:
5+
6+
class LinkMLConverter:
57

68
def __init__(self, benchmark_file):
79
self.stage_order_map = None
810
self.benchmark_file = os.path.abspath(benchmark_file)
11+
self.benchmark = load_yaml(benchmark_file)
912

10-
def get_stage_id(self, stage):
11-
raise NotImplementedError("Method not implemented yet")
12-
13-
def get_module_id(self, module):
14-
raise NotImplementedError("Method not implemented yet")
13+
def get_benchmark_name(self):
14+
return self.benchmark.name if self.benchmark.name else self.benchmark.id
1515

1616
def get_benchmark_definition(self):
17-
raise NotImplementedError("Method not implemented yet")
17+
return self.benchmark
1818

19-
def get_benchmark_definition_file(self):
20-
raise NotImplementedError("Method not implemented yet")
19+
def get_stage_id(self, stage):
20+
return stage.id
21+
22+
def get_module_id(self, module):
23+
return module.id
2124

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

2528
def get_benchmark_stage(self, stage_id):
26-
raise NotImplementedError("Method not implemented yet")
29+
stages = self.get_benchmark_stages().values()
30+
return next(stage for stage in stages if stage.id == stage_id)
2731

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

3135
def get_stage_implicit_inputs(self, stage):
32-
raise NotImplementedError("Method not implemented yet")
36+
if isinstance(stage, str):
37+
stage = self.get_benchmark_stages()[stage]
3338

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

37-
def get_stage_explicit_inputs(self, stage):
38-
raise NotImplementedError("Method not implemented yet")
41+
def get_inputs_stage(self, implicit_inputs):
42+
stages_map = {key: None for key in implicit_inputs}
43+
if implicit_inputs is not None:
44+
all_stages = self.get_benchmark_stages()
45+
all_stages_outputs = []
46+
for stage_id in all_stages:
47+
outputs = self.get_stage_outputs(stage=stage_id)
48+
outputs = {key: stage_id for key, value in outputs.items()}
49+
all_stages_outputs.append(outputs)
50+
51+
all_stages_outputs = merge_dict_list(all_stages_outputs)
52+
for in_deliverable in implicit_inputs:
53+
# beware stage needs to be substituted
54+
curr_output = all_stages_outputs[in_deliverable]
55+
56+
stages_map[in_deliverable] = curr_output
57+
58+
return stages_map
59+
60+
def get_stage_explicit_inputs(self, implicit_inputs):
61+
explicit = {key: None for key in implicit_inputs}
62+
if implicit_inputs is not None:
63+
all_stages = self.get_benchmark_stages()
64+
all_stages_outputs = []
65+
for stage_id in all_stages:
66+
outputs = self.get_stage_outputs(stage=stage_id)
67+
outputs = {
68+
key: value.format(
69+
input="{input}",
70+
stage=stage_id,
71+
module="{module}",
72+
params="{params}",
73+
dataset="{dataset}",
74+
)
75+
for key, value in outputs.items()
76+
}
77+
all_stages_outputs.append(outputs)
78+
79+
all_stages_outputs = merge_dict_list(all_stages_outputs)
80+
for in_deliverable in implicit_inputs:
81+
# beware stage needs to be substituted
82+
curr_output = all_stages_outputs[in_deliverable]
83+
84+
explicit[in_deliverable] = curr_output
85+
86+
return explicit
3987

4088
def get_stage_outputs(self, stage):
41-
raise NotImplementedError("Method not implemented yet")
89+
if isinstance(stage, str):
90+
stage = self.get_benchmark_stages()[stage]
91+
92+
return dict([(output.id, output.path) for output in stage.outputs])
4293

4394
def get_module_excludes(self, module):
44-
raise NotImplementedError("Method not implemented yet")
95+
if isinstance(module, str):
96+
module = self.get_benchmark_modules()[module]
97+
98+
return module.exclude
4599

46100
def get_module_parameters(self, module):
47-
raise NotImplementedError("Method not implemented yet")
101+
params = None
102+
if module.parameters is not None:
103+
params = [x.values for x in module.parameters]
104+
105+
return params
48106

49107
def get_module_repository(self, module):
50-
raise NotImplementedError("Method not implemented yet")
108+
return module.repository
51109

52110
def is_initial(self, stage):
53-
raise NotImplementedError("Method not implemented yet")
111+
if stage.inputs is None or len(stage.inputs) == 0:
112+
return True
113+
else:
114+
return False
54115

55116
def get_after(self, stage):
56-
raise NotImplementedError("Method not implemented yet")
117+
return stage.after
57118

58119
def get_stage_ids(self):
59-
raise NotImplementedError("Method not implemented yet")
120+
return [x.id for x in self.benchmark.stages]
60121

61122
def get_module_ids(self):
62-
raise NotImplementedError("Method not implemented yet")
123+
module_ids = []
124+
for stage in self.benchmark.stages:
125+
for module in stage.modules:
126+
module_ids.append(module.id)
127+
128+
return module_ids
63129

64130
def get_output_ids(self):
65-
raise NotImplementedError("Method not implemented yet")
131+
output_ids = []
132+
for stage in self.benchmark.stages:
133+
for output in stage.outputs:
134+
output_ids.append(output.id)
135+
136+
return output_ids
66137

67138
def get_initial_datasets(self):
68139
stages = self.get_benchmark_stages()

Diff for: src/converter/linkml_converter.py

-133
This file was deleted.

0 commit comments

Comments
 (0)