Skip to content

Commit e50fcef

Browse files
committed
#591: modified PR to smoothly integrate with PR #592
1 parent 6df5ae7 commit e50fcef

File tree

2 files changed

+68
-75
lines changed

2 files changed

+68
-75
lines changed

src/lbaf/Utils/lbsJSONDataFilesMaker.py

Lines changed: 13 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,6 @@
6969
- Generate dataset from specification defined interactively in CLI
7070
`lbaf-vt-data-files-maker --interactive`
7171
72-
Python specification: a Python file can be loaded in the interactive mode and be printed as an example in either YAML or JSON format.
73-
Other examples can be found as unit tests configuration files in the the tests/unit/config/phases directory
74-
7572
"""
7673
from argparse import RawTextHelpFormatter
7774
from datetime import datetime
@@ -281,70 +278,6 @@ def build(self):
281278

282279
self.__args.data_stem = data_stem
283280

284-
def load_specification(self, use_explicit_keys: bool = False):
285-
"""Create a new Python specification as represented by diagram specified in issue #506
286-
This method implementation indicates also how to create a specification from Python code
287-
"""
288-
289-
spec = PhaseSpecification({
290-
"tasks": [
291-
TaskSpecification({
292-
"collection_id": 0,
293-
"time": 2.0
294-
}),
295-
TaskSpecification({
296-
"collection_id": 0,
297-
"time": 3.5
298-
}),
299-
TaskSpecification({
300-
"collection_id": 0,
301-
"time": 5.0
302-
})
303-
],
304-
"communications": [
305-
CommunicationSpecification({
306-
"size": 10000.0, # c1 (size)
307-
"from": 0, # from t1
308-
"to": 2 # to t3
309-
}),
310-
CommunicationSpecification({
311-
"size": 15000.0, # c2 (size)
312-
"from": 1, # from t2
313-
"to": 2 # to t3
314-
}),
315-
CommunicationSpecification({
316-
"size": 20000.0, # c3 (size)
317-
"from": 2, # from t3
318-
"to": 1 # to t2
319-
})
320-
],
321-
"shared_blocks": [
322-
# S1
323-
SharedBlockSpecification({
324-
"size": 10000.0,
325-
"home_rank": 0,
326-
"tasks": {0, 1}
327-
}),
328-
# S2
329-
SharedBlockSpecification({
330-
"size": 15000.0,
331-
"home_rank": 1,
332-
"tasks": {2}
333-
})
334-
],
335-
"ranks": {
336-
0: RankSpecification({"tasks": {0, 1}}),
337-
1: RankSpecification({"tasks": {2}})
338-
}
339-
})
340-
341-
if use_explicit_keys:
342-
spec["tasks"] = dict(enumerate(spec["tasks"]))
343-
spec["communications"] = dict(enumerate(spec["communications"]))
344-
spec["shared_blocks"] = dict(enumerate(spec["shared_blocks"]))
345-
346-
self.spec = spec
347-
348281
def load_spec_from_file(self, file_path) -> Optional[PhaseSpecificationNormalizer]:
349282
"""Load a specification from a file (Yaml or Json)
350283
@@ -356,7 +289,7 @@ def load_spec_from_file(self, file_path) -> Optional[PhaseSpecificationNormalize
356289
raise FileNotFoundError("File not found")
357290

358291
spec = PhaseSpecification()
359-
with open(file_path, "r", encoding="utf-8") as file_stream:
292+
with open(file_path, 'r', encoding="utf-8") as file_stream:
360293
if file_path.endswith(".json"):
361294
spec_dict = json.load(file_stream)
362295
# in json keys are strings (int not supported by the JSON format) so apply casts as needed
@@ -770,10 +703,7 @@ def remove_element(self):
770703
def run_extra_action(self, action: str):
771704
"""Run an extra action"""
772705

773-
if action == "Extra: load Python specification":
774-
self.load_specification(use_explicit_keys=True)
775-
action = "Build"
776-
elif action == "Extra: print":
706+
if action == "Extra: print":
777707
frmt = self.__prompt.prompt(
778708
"Format ?", choices=["yaml", "json", "python (debug)"], required=True, default="yaml")
779709
self.print(frmt)
@@ -794,10 +724,19 @@ def run_extra_action(self, action: str):
794724
with open(path, "wt", encoding="utf-8") as o_file:
795725
normalized_spec = PhaseSpecificationNormalizer().normalize(self.spec)
796726
if frmt == "json":
797-
o_file.write(json.dumps(normalized_spec, sort_keys=True, indent=2, separators=(',', ": ")))
727+
o_file.write(
728+
json.dumps(
729+
normalized_spec,
730+
sort_keys=True,
731+
indent=2,
732+
separators=(',', ": ")))
798733
elif frmt == "yaml":
799734
o_file.write(
800-
yaml.dump(normalized_spec, indent=2, Dumper=YamlSpecificationDumper, default_flow_style=None))
735+
yaml.dump(
736+
normalized_spec,
737+
indent=2,
738+
Dumper=YamlSpecificationDumper,
739+
default_flow_style=None))
801740

802741
def run_action(self, action: str):
803742
"""Run an action"""
@@ -868,7 +807,6 @@ def run(self):
868807
"Build",
869808
"Extra: load file",
870809
"Extra: run",
871-
"Extra: load Python specification",
872810
"Extra: print",
873811
"Extra: save",
874812
"Exit"

src/lbaf/Utils/spec.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
spec = PhaseSpecification({
2+
"tasks": [
3+
TaskSpecification({
4+
"collection_id": 0,
5+
"time": 2.0
6+
}),
7+
TaskSpecification({
8+
"collection_id": 0,
9+
"time": 3.5
10+
}),
11+
TaskSpecification({
12+
"collection_id": 0,
13+
"time": 5.0
14+
})
15+
],
16+
"communications": [
17+
CommunicationSpecification({
18+
"size": 10000.0, # c1 (size)
19+
"from": 0, # from t1
20+
"to": 2 # to t3
21+
}),
22+
CommunicationSpecification({
23+
"size": 15000.0, # c2 (size)
24+
"from": 1, # from t2
25+
"to": 2 # to t3
26+
}),
27+
CommunicationSpecification({
28+
"size": 20000.0, # c3 (size)
29+
"from": 2, # from t3
30+
"to": 1 # to t2
31+
})
32+
],
33+
"shared_blocks": [
34+
# S1
35+
SharedBlockSpecification({
36+
"size": 10000.0,
37+
"home_rank": 0,
38+
"tasks": {0, 1}
39+
}),
40+
# S2
41+
SharedBlockSpecification({
42+
"size": 15000.0,
43+
"home_rank": 1,
44+
"tasks": {2}
45+
})
46+
],
47+
"ranks": {
48+
0: RankSpecification({"tasks": {0, 1}}),
49+
1: RankSpecification({"tasks": {2}})
50+
}
51+
})
52+
53+
spec["tasks"] = dict(enumerate(spec["tasks"]))
54+
spec["communications"] = dict(enumerate(spec["communications"]))
55+
spec["shared_blocks"] = dict(enumerate(spec["shared_blocks"]))

0 commit comments

Comments
 (0)