1010from ymmsl .v0_2 .checkpoint import Checkpoints
1111from ymmsl .v0_2 .resources import ResourceRequirements
1212from ymmsl .v0_2 .identity import Reference
13+ from ymmsl .v0_2 .imports import ImportStatement
1314from ymmsl .v0_2 .settings import Settings
1415from ymmsl .v0_2 .document import Document
1516from ymmsl .v0_2 .implementation import Implementation
@@ -25,6 +26,7 @@ class Configuration(Document):
2526
2627 Attributes:
2728 description: A human-readable description of the configuration
29+ imports: A list of import statements
2830 models: A list of possibly connected models to run
2931 settings: Settings to run the models with
3032 programs: Programs to use to run the model. Dictionary mapping program names (as
@@ -36,6 +38,7 @@ class Configuration(Document):
3638 """
3739 def __init__ (
3840 self , description : str ,
41+ imports : Optional [Sequence [ImportStatement ]] = None ,
3942 models : Optional [Union [Model , Sequence [Model ]]] = None ,
4043 settings : Optional [Settings ] = None ,
4144 programs : Optional [Union [
@@ -54,15 +57,20 @@ def __init__(
5457
5558 Args:
5659 description: Human-readable description
60+ imports: A list of import statements
61+ models: A list of possibly connected models to run
5762 settings: Settings to run the model with.
63+ programs: Programs to use when running the model
5864 resources: Resources to allocate for the model components.
5965 checkpoints: When each component should create a snapshot
6066 resume: What snapshot each component should resume from
61-
6267 """
6368 self .description = description
6469
65- # TODO: imports
70+ if imports is None :
71+ self .imports : List [ImportStatement ] = list ()
72+ else :
73+ self .imports = list (imports )
6674
6775 if models is None :
6876 self .models : Sequence [Model ] = list ()
@@ -131,6 +139,8 @@ def check_consistent(self) -> None:
131139
132140 # TODO: check that resources and implementation both do or don't MPI
133141
142+ # TODO: no two implementations (programs or models) with the same name
143+
134144 if errors :
135145 raise RuntimeError (
136146 'The configuration is internally inconsistent. The following'
@@ -151,6 +161,12 @@ def update(self, overlay: 'Configuration') -> None:
151161 elif overlay .description :
152162 self .description += '\n \n ' + overlay .description
153163
164+ if not self .imports :
165+ self .imports = overlay .imports
166+ else :
167+ if overlay .imports :
168+ self .imports .extend (overlay .imports )
169+
154170 if self .models and overlay .models :
155171 raise RuntimeError (
156172 'Multiple ymmsl files containing models specified. Please'
@@ -267,6 +283,10 @@ def _yatiml_sweeten(cls, node: yatiml.Node) -> None:
267283 # output multi-line string in literal mode
268284 cast (yaml .ScalarNode , descr .yaml_node ).style = '|'
269285
286+ imports = node .get_attribute ('imports' )
287+ if imports .is_sequence () and imports .is_empty ():
288+ node .remove_attribute ('imports' )
289+
270290 models = node .get_attribute ('models' )
271291 if models .is_sequence () and models .is_empty ():
272292 node .remove_attribute ('models' )
0 commit comments