Skip to content

Commit 4e58caf

Browse files
authored
Merge pull request #24 from biosimulations/separate-state-schema
separate schema and state in pb datamodel
2 parents 781af0a + 8faf2da commit 4e58caf

24 files changed

+1376
-659
lines changed

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 0 additions & 123 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dsl/src/language/process-bigraph-language.langium

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ entry Model:
88
(stepDefs+=StepDef) |
99
(procDefs+=ProcDef) |
1010
('store' storeNodes+=StoreNode) |
11-
(parameters+=Parameter) |
12-
(step_calls+=StepCall) |
13-
(proc_calls+=ProcCall))*;
11+
(parameters+=Parameter))*;
1412

1513
Type:
1614
'type' name=ID (builtin='builtin')? ('extends' superType=[Type])? ('default' default=DefaultValue)? ('update' update=[Definition])? (subtypes+=NamedType)*;
@@ -43,7 +41,9 @@ StoreNode:
4341
name=ID (
4442
('=' optional_val=DefaultValue) |
4543
(':' optional_type=[Type] ('=' optional_val=DefaultValue)?) |
46-
('{' child_defs+=StoreNode (',' child_defs+=StoreNode)* '}'));
44+
(':' proc_call=ProcCall) |
45+
(':' step_call=StepCall) |
46+
(':' '{' child_defs+=StoreNode (',' child_defs+=StoreNode)* '}'));
4747

4848
StepDef:
4949
'step' name=ID python_path=PythonPath?
@@ -67,7 +67,7 @@ StepCall:
6767

6868
ProcCall:
6969
('update' '(' (output_node_list=StoreNodeList)? ')')
70-
(('using' | '<=') process_def_ref=[ProcDef])
70+
(('using' | '<=') proc_def_ref=[ProcDef])
7171
('[' (config_node_list=ParameterList)? ']')
7272
('(' (input_node_list=StoreNodeList)? ')');
7373

process_bigraph_lang/compiler/converter.py

Lines changed: 101 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,119 @@
11
from typing import Any
22

3-
from process_bigraph_lang.compiler.pb_model import PBModel
3+
from process_bigraph_lang.compiler.pb_model import PBModel, PBCollectionType
44

55

66
def assemble_pb(pb_model: PBModel) -> dict[str, Any]:
77
doc: dict[str, Any] = dict(composition={}, state={})
8-
for store in pb_model.stores:
9-
if store.value is not None:
10-
set_value_at_path(doc["state"], store.full_path, value=store.value)
11-
if store.data_type:
12-
set_value_at_path(doc["composition"], store.full_path, value=store.data_type)
13-
for step in pb_model.steps:
14-
address = step.address
8+
for store_schema in pb_model.store_schemas:
9+
# TODO: handle collection_type properly
10+
if store_schema.default_value is not None or store_schema.collection_type is not None:
11+
if store_schema.collection_type is None:
12+
set_value_at_path(
13+
doc["composition"], store_schema.full_path + ["_default"], value=store_schema.default_value
14+
)
15+
if store_schema.data_type:
16+
set_value_at_path(
17+
doc["composition"], store_schema.full_path + ["_type"], value=store_schema.data_type
18+
)
19+
elif store_schema.collection_type == PBCollectionType(coll_type="map"):
20+
if store_schema.data_type:
21+
set_value_at_path(doc["composition"], store_schema.path + ["_type"], value="map")
22+
set_value_at_path(doc["composition"], store_schema.path + ["_value"], value=store_schema.data_type)
23+
else:
24+
raise ValueError(
25+
f"Unsupported collection type '{store_schema.collection_type}' for store schema '{store_schema.full_path}'"
26+
)
27+
28+
elif store_schema.data_type:
29+
set_value_at_path(doc["composition"], store_schema.full_path, value=store_schema.data_type)
30+
31+
for store_state in pb_model.store_states:
32+
if store_state.value is not None:
33+
set_value_at_path(doc["state"], store_state.full_path, value=store_state.value)
34+
35+
for step_schema in pb_model.step_schemas:
36+
# TODO: handle collection_type properly
37+
address = step_schema.address
1538
if not address.startswith("local:"):
1639
address = "local:!" + address
1740
address_dict = dict(_type="quote", _default=address)
18-
step_schema_dict: dict[str, Any] = dict(_type=step._type, address=address_dict)
19-
if step.config_schema:
20-
step_schema_dict["_config"] = step.config_schema
21-
if step.input_schema:
22-
step_schema_dict["_inputs"] = step.input_schema
23-
if step.output_schema:
24-
step_schema_dict["_outputs"] = step.output_schema
25-
set_value_at_path(doc["composition"], step.full_path, value=step_schema_dict)
41+
step_schema_dict: dict[str, Any] = dict(_type=step_schema._type, address=address_dict)
42+
if step_schema.config_schema:
43+
step_schema_dict["_config"] = step_schema.config_schema
44+
if step_schema.input_schema:
45+
step_schema_dict["_inputs"] = step_schema.input_schema
46+
if step_schema.output_schema:
47+
step_schema_dict["_outputs"] = step_schema.output_schema
48+
if step_schema.default_config_state:
49+
step_schema_dict["config"] = step_schema.default_config_state
50+
if step_schema.default_input_state:
51+
step_schema_dict["inputs"] = step_schema.default_input_state
52+
if step_schema.default_output_state:
53+
step_schema_dict["outputs"] = step_schema.default_output_state
54+
if step_schema.collection_info is not None:
55+
if step_schema.collection_info.coll_type == "map":
56+
set_value_at_path(doc["composition"], step_schema.full_path + ["_type"], value="map")
57+
set_value_at_path(doc["composition"], step_schema.full_path + ["_value"], value=step_schema_dict)
58+
else:
59+
raise ValueError(
60+
f"Unsupported collection type '{step_schema.collection_info}' for step schema '{step_schema.full_path}'"
61+
)
62+
else:
63+
set_value_at_path(doc["composition"], step_schema.full_path, value=step_schema_dict)
2664

27-
step_state_dict: dict[str, Any] = dict(_type=step._type)
28-
if step.config_state:
29-
step_state_dict["config"] = step.config_state
30-
if step.input_state:
31-
step_state_dict["inputs"] = step.input_state
32-
if step.output_state:
33-
step_state_dict["outputs"] = step.output_state
34-
set_value_at_path(doc["state"], step.full_path, value=step_state_dict)
65+
for step_state in pb_model.step_states:
66+
step_state_dict: dict[str, Any] = dict(_type=step_state._type)
67+
if step_state.config_state:
68+
step_state_dict["config"] = step_state.config_state
69+
if step_state.input_state:
70+
step_state_dict["inputs"] = step_state.input_state
71+
if step_state.output_state:
72+
step_state_dict["outputs"] = step_state.output_state
73+
set_value_at_path(doc["state"], step_state.full_path, value=step_state_dict)
3574

36-
for process in pb_model.processes:
37-
address = process.address
75+
for process_schema in pb_model.process_schemas:
76+
address = process_schema.address
3877
if not address.startswith("local:"):
3978
address = "local:!" + address
4079
address_dict = dict(_type="quote", _default=address)
41-
process_schema_dict: dict[str, Any] = dict(_type=process._type, address=address_dict)
42-
if process.config_schema:
43-
process_schema_dict["_config"] = process.config_schema
44-
if process.input_schema:
45-
process_schema_dict["_inputs"] = process.input_schema
46-
if process.output_schema:
47-
process_schema_dict["_outputs"] = process.output_schema
48-
set_value_at_path(doc["composition"], process.full_path, value=process_schema_dict)
80+
process_schema_dict: dict[str, Any] = dict(_type=process_schema._type, address=address_dict)
81+
if process_schema.config_schema:
82+
process_schema_dict["_config"] = process_schema.config_schema
83+
if process_schema.input_schema:
84+
process_schema_dict["_inputs"] = process_schema.input_schema
85+
if process_schema.output_schema:
86+
process_schema_dict["_outputs"] = process_schema.output_schema
87+
if process_schema.default_config_state:
88+
process_schema_dict["config"] = process_schema.default_config_state
89+
if process_schema.default_input_state:
90+
process_schema_dict["inputs"] = process_schema.default_input_state
91+
if process_schema.default_output_state:
92+
process_schema_dict["outputs"] = process_schema.default_output_state
93+
# if process_schema.default_interval is not None:
94+
# process_schema_dict["_interval"] = process_schema.default_interval
95+
if process_schema.collection_info is not None:
96+
if process_schema.collection_info.coll_type == "map":
97+
set_value_at_path(doc["composition"], process_schema.full_path + ["_type"], value="map")
98+
set_value_at_path(doc["composition"], process_schema.full_path + ["_value"], value=process_schema_dict)
99+
else:
100+
raise ValueError(
101+
f"Unsupported collection type '{process_schema.collection_info}' for process schema '{process_schema.full_path}'"
102+
)
103+
else:
104+
set_value_at_path(doc["composition"], process_schema.full_path, value=process_schema_dict)
49105

50-
address = process.address
51-
if not address.startswith("local:"):
52-
address = "local:!" + address
53-
process_state_dict: dict[str, Any] = dict(_type=process._type)
54-
if process.config_state:
55-
process_state_dict["config"] = process.config_state
56-
if process.input_state:
57-
process_state_dict["inputs"] = process.input_state
58-
if process.output_state:
59-
process_state_dict["outputs"] = process.output_state
60-
if process.interval is not None:
61-
process_state_dict["interval"] = process.interval
62-
set_value_at_path(doc["state"], process.full_path, value=process_state_dict)
106+
for process_state in pb_model.process_states:
107+
process_state_dict: dict[str, Any] = dict(_type=process_state._type)
108+
if process_state.config_state:
109+
process_state_dict["config"] = process_state.config_state
110+
if process_state.input_state:
111+
process_state_dict["inputs"] = process_state.input_state
112+
if process_state.output_state:
113+
process_state_dict["outputs"] = process_state.output_state
114+
if process_state.interval is not None:
115+
process_state_dict["interval"] = process_state.interval
116+
set_value_at_path(doc["state"], process_state.full_path, value=process_state_dict)
63117

64118
return doc
65119

0 commit comments

Comments
 (0)