Skip to content

Commit

Permalink
added list of mona instances
Browse files Browse the repository at this point in the history
  • Loading branch information
mdorier committed Feb 5, 2024
1 parent c9abbb5 commit 58abd97
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
SCRIPT_DIR=$(dirname "$0")
cmake $SCRIPT_DIR -DENABLE_TESTS=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo -DENABLE_PYTHON=ON -DENABLE_MPI=ON -DENABLE_MONA=ON -DENABLE_SSG=ON -DENABLE_ABT_IO=ON
cmake $SCRIPT_DIR -DENABLE_TESTS=ON -DENABLE_EXAMPLES=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo -DENABLE_PYTHON=ON -DENABLE_MPI=ON -DENABLE_MONA=ON -DENABLE_SSG=ON -DENABLE_ABT_IO=ON
82 changes: 81 additions & 1 deletion python/mochi/bedrock/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,8 @@ class AbtIOSpec:
validator=[instance_of(str), _validate_object_name],
on_setattr=attr.setters.frozen)
pool: PoolSpec = attr.ib(validator=instance_of(PoolSpec))
config: dict = attr.ib(validator=instance_of(dict))
config: dict = attr.ib(validator=instance_of(dict),
factory=dict)

def to_dict(self) -> dict:
"""Convert the AbtIOSpec into a dictionary.
Expand Down Expand Up @@ -1091,6 +1092,72 @@ def from_json(json_string: str, abt_spec: ArgobotsSpec) -> 'AbtIOSpec':
return AbtIOSpec.from_dict(json.loads(json_string), abt_spec)


@attr.s(auto_attribs=True, on_setattr=_check_validators, kw_only=True)
class MonaSpec:
"""MoNA instance specification.
:param name: Name of the MoNA instance
:type name: str
:param pool: Pool associated with the instance
:type pool: PoolSpec
:param config: Configuration
:type config: dict
"""

name: str = attr.ib(
validator=[instance_of(str), _validate_object_name],
on_setattr=attr.setters.frozen)
pool: PoolSpec = attr.ib(validator=instance_of(PoolSpec))
config: dict = attr.ib(validator=instance_of(dict),
factory=dict)

def to_dict(self) -> dict:
"""Convert the MonaSpec into a dictionary.
"""
return {'name': self.name,
'pool': self.pool.name,
'config': self.config}

@staticmethod
def from_dict(data: dict, abt_spec: ArgobotsSpec) -> 'MonaSpec':
"""Construct a MonaSpec from a dictionary. Since the dictionary
references the pool by name or index, an ArgobotsSpec is necessary
to resolve the reference.
:param data: Dictionary
:type data: dict
:param abt_spec: ArgobotsSpec in which to look for the PoolSpec
:type abt_spec: ArgobotsSpec
"""
name = data['name']
config = data['config']
pool = abt_spec.pools[data['pool']]
mona = MonaSpec(name=name, pool=pool, config=config)
return mona

def to_json(self, *args, **kwargs) -> str:
"""Convert the MonaSpec into a JSON string.
"""
return json.dumps(self.to_dict(), *args, **kwargs)

@staticmethod
def from_json(json_string: str, abt_spec: ArgobotsSpec) -> 'MonaSpec':
"""Construct an MonaSpec from a JSON string. Since the JSON string
references the pool by name or index, an ArgobotsSpec is necessary
to resolve the reference.
:param json_string: JSON string
:type json_string: str
:param abt_spec: ArgobotsSpec in which to look for the PoolSpec
:type abt_spec: ArgobotsSpec
"""
return MonaSpec.from_dict(json.loads(json_string), abt_spec)


@attr.s(auto_attribs=True, on_setattr=_check_validators, kw_only=True)
class SwimSpec:
"""Swim specification for SSG.
Expand Down Expand Up @@ -1503,6 +1570,9 @@ class ProcSpec:
:param abt_io: List of AbtIOSpec
:type abt_io: list
:param mona: List of MonaSpec
:type mona: list
:param ssg: List of SSGSpec
:type ssg: list
Expand All @@ -1522,6 +1592,9 @@ class ProcSpec:
_abt_io: List[AbtIOSpec] = attr.ib(
factory=list,
validator=instance_of(list))
_mona: List[MonaSpec] = attr.ib(
factory=list,
validator=instance_of(list))
_ssg: List[SSGSpec] = attr.ib(
factory=list,
validator=instance_of(list))
Expand All @@ -1546,6 +1619,13 @@ def abt_io(self) -> SpecListDecorator:
"""
return SpecListDecorator(list=self._abt_io, type=AbtIOSpec)

@property
def mona_io(self) -> SpecListDecorator:
"""Return a decorator to access the internal list of MonaSpec
and validate changes to this list.
"""
return SpecListDecorator(list=self._mona, type=MonaSpec)

@property
def ssg(self) -> SpecListDecorator:
"""Return a decorator to access the internal list of SSGSpec
Expand Down

0 comments on commit 58abd97

Please sign in to comment.