Unverified Commit a20ed8c2 authored by Jakob Görgen's avatar Jakob Görgen
Browse files

added IdObject as utils class for easy way to assign IDs to objects

parent fddf6344
......@@ -20,10 +20,11 @@
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
from simbricks.orchestration import simulation
from simbricks.orchestration import system
import enum
import pathlib
from simbricks.orchestration.utils import base
from simbricks.orchestration import simulation
from simbricks.orchestration import system
class SockType(enum.Enum):
......@@ -38,7 +39,7 @@ class Socket:
self._type = ty
class InstantiationEnvironment:
class InstantiationEnvironment(base.IdObj):
def __init__(
self,
......@@ -49,6 +50,7 @@ class InstantiationEnvironment:
output_base: str = pathlib.Path(),
tmp_simulation_files: str = pathlib.Path(),
):
super().__init__()
# TODO: add more parameters that wont change during instantiation
self._repodir: str = pathlib.Path(repo_path).absolute()
self._workdir: str = pathlib.Path(workdir).absolute()
......@@ -60,11 +62,12 @@ class InstantiationEnvironment:
)
class Instantiation:
class Instantiation(base.IdObj):
def __init__(
self, simulation, env: InstantiationEnvironment = InstantiationEnvironment()
):
super().__init__()
self._simulation = simulation
self._env: InstantiationEnvironment = env
self._socket_per_interface: dict[system.base.Interface, Socket] = {}
......@@ -160,6 +163,10 @@ class Instantiation:
# TODO: add more methods constructing paths as required by methods in simulators or image handling classes
def prepare_environment(self) -> None:
TODO
raise Exception("not implemented")
def _join_paths(
self, base: str = "", relative_path: str = "", enforce_existence=True
) -> str:
......
......@@ -26,6 +26,7 @@ import typing as tp
import simbricks.orchestration.system as sys_conf
from simbricks.orchestration.experiment import experiment_environment_new as exp_env
from simbricks.orchestration.instantiation import base as inst_base
from simbricks.orchestration.utils import base as utils_base
if tp.TYPE_CHECKING:
from simbricks.orchestration.simulation import (
......@@ -37,12 +38,13 @@ if tp.TYPE_CHECKING:
)
class Simulator(abc.ABC):
class Simulator(utils_base.IdObj):
"""Base class for all simulators."""
def __init__(
self, simulation: sim_base.Simulation, relative_executable_path: str = ""
) -> None:
super().__init__()
self.extra_deps: list[Simulator] = []
self.name: str = ""
self.experiment: sim_base.Simulation = simulation
......
......@@ -22,7 +22,8 @@
from __future__ import annotations
import abc
import itertools
from simbricks.orchestration.utils import base
class System:
"""Defines System configuration of the whole simulation"""
......@@ -35,14 +36,7 @@ class System:
self.all_component.append(c)
class IdObj(abc.ABC):
__id_iter = itertools.count()
def __init__(self):
self._id = next(self.__id_iter)
class Component(IdObj):
class Component(base.IdObj):
def __init__(self, s: System) -> None:
super().__init__()
......@@ -59,7 +53,7 @@ class Component(IdObj):
return [i.channel for i in self.interfaces() if i.is_connected()]
class Interface(IdObj):
class Interface(base.IdObj):
def __init__(self, c: Component) -> None:
super().__init__()
self.component = c
......@@ -76,7 +70,7 @@ class Interface(IdObj):
self.channel = c
class Channel(IdObj):
class Channel(base.IdObj):
def __init__(self, a: Interface, b: Interface) -> None:
super().__init__()
self.latency = 500
......
# Copyright 2024 Max Planck Institute for Software Systems, and
# National University of Singapore
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import abc
import itertools
class IdObj(abc.ABC):
__id_iter = itertools.count()
def __init__(self):
self._id = next(self.__id_iter)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment