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

path building and experiment fixes

parent 31b07726
...@@ -300,7 +300,7 @@ def add_exp( ...@@ -300,7 +300,7 @@ def add_exp(
tmp_simulation_files=tmp_sim_files, tmp_simulation_files=tmp_sim_files,
) )
inst_ = inst_base.Instantiation(inst_env) inst_ = inst_base.Instantiation(sim=simulation, env=inst_env)
output_ = output.SimulationOutput(simulation) output_ = output.SimulationOutput(simulation)
run = runs.base.Run( run = runs.base.Run(
simulation=simulation, simulation=simulation,
......
...@@ -123,6 +123,7 @@ class Instantiation(util_base.IdObj): ...@@ -123,6 +123,7 @@ class Instantiation(util_base.IdObj):
self._env: InstantiationEnvironment = env self._env: InstantiationEnvironment = env
self._executor: command_executor.Executor | None = None self._executor: command_executor.Executor | None = None
self._socket_per_interface: dict[sys_base.Interface, Socket] = {} self._socket_per_interface: dict[sys_base.Interface, Socket] = {}
self._simulation_topo: dict[]
@staticmethod @staticmethod
def is_absolute_exists(path: str) -> bool: def is_absolute_exists(path: str) -> bool:
...@@ -253,6 +254,19 @@ class Instantiation(util_base.IdObj): ...@@ -253,6 +254,19 @@ class Instantiation(util_base.IdObj):
self._updated_tracker_mapping(interface=interface, socket=new_socket) self._updated_tracker_mapping(interface=interface, socket=new_socket)
return new_socket return new_socket
def _build_simulation_topology(self) -> None:
# TODO: FIXME
def sim_graph(self) -> dict[sim_base.Simulator, set[sim_base.Simulator]]:
sims = self._simulation.all_simulators()
graph = {}
for sim in sims:
deps = sim.dependencies() + sim.extra_deps
print(f'deps of {sim}: {sim.dependencies()}')
graph[sim] = set()
for d in deps:
graph[sim].add(d)
return graph
async def cleanup_sockets( async def cleanup_sockets(
self, self,
sockets: list[Socket] = [], sockets: list[Socket] = [],
...@@ -318,9 +332,14 @@ class Instantiation(util_base.IdObj): ...@@ -318,9 +332,14 @@ class Instantiation(util_base.IdObj):
def _join_paths( def _join_paths(
self, base: str = "", relative_path: str = "", enforce_existence=False self, base: str = "", relative_path: str = "", enforce_existence=False
) -> str: ) -> str:
path = pathlib.Path(base) if relative_path.startswith("/"):
joined = path.joinpath(relative_path) raise Exception(
if not joined.exists() and enforce_existence: f"cannot join with base={base} because relative_path={relative_path} starts with '/'"
)
joined = pathlib.Path(base).joinpath(relative_path)
print(f"joined={joined}")
if enforce_existence and not joined.exists():
raise Exception(f"couldn't join {base} and {relative_path}") raise Exception(f"couldn't join {base} and {relative_path}")
return joined.absolute() return joined.absolute()
...@@ -341,7 +360,7 @@ class Instantiation(util_base.IdObj): ...@@ -341,7 +360,7 @@ class Instantiation(util_base.IdObj):
return hd_name_or_path return hd_name_or_path
path = self._join_paths( path = self._join_paths(
base=self._env._repodir, base=self._env._repodir,
relative_path=f"/images/output-{hd_name_or_path}/{hd_name_or_path}", relative_path=f"images/output-{hd_name_or_path}/{hd_name_or_path}",
enforce_existence=True, enforce_existence=True,
) )
return path return path
...@@ -356,21 +375,21 @@ class Instantiation(util_base.IdObj): ...@@ -356,21 +375,21 @@ class Instantiation(util_base.IdObj):
) )
def dynamic_img_path(self, img: disk_images.DiskImage, format: str) -> str: def dynamic_img_path(self, img: disk_images.DiskImage, format: str) -> str:
filename = img._id + "." + format filename = f"{img._id}.{format}"
return self._join_paths( return self._join_paths(
base=self._env._tmp_simulation_files, base=self._env._tmp_simulation_files,
relative_path=filename, relative_path=filename,
) )
def hdcopy_path(self, img: disk_images.DiskImage, format: str) -> str: def hdcopy_path(self, img: disk_images.DiskImage, format: str) -> str:
filename = img._id + "_hdcopy" "." + format filename = f"{img._id}_hdcopy.{format}"
return self._join_paths( return self._join_paths(
base=self._env._tmp_simulation_files, base=self._env._tmp_simulation_files,
relative_path=filename, relative_path=filename,
) )
def cpdir_subdir(self, sim: sim_base.Simulator) -> str: def cpdir_subdir(self, sim: sim_base.Simulator) -> str:
dir_path = f"/checkpoint.{sim.name}-{sim._id}" dir_path = f"checkpoint.{sim.name}-{sim._id}"
return self._join_paths( return self._join_paths(
base=self.cpdir(), relative_path=dir_path, enforce_existence=False base=self.cpdir(), relative_path=dir_path, enforce_existence=False
) )
...@@ -382,4 +401,5 @@ class Instantiation(util_base.IdObj): ...@@ -382,4 +401,5 @@ class Instantiation(util_base.IdObj):
) )
def find_sim_by_spec(self, spec: sys_host.FullSystemHost) -> sim_base.Simulator: def find_sim_by_spec(self, spec: sys_host.FullSystemHost) -> sim_base.Simulator:
util_base.has_expected_type(spec, sys_host.FullSystemHost)
return self._simulation.find_sim(spec) return self._simulation.find_sim(spec)
...@@ -331,8 +331,9 @@ class Simulation(utils_base.IdObj): ...@@ -331,8 +331,9 @@ class Simulation(utils_base.IdObj):
def find_sim(self, comp: sys_conf.Component) -> sim_base.Simulator: def find_sim(self, comp: sys_conf.Component) -> sim_base.Simulator:
"""Returns the used simulator object for the system component.""" """Returns the used simulator object for the system component."""
utils_base.has_expected_type(comp, sys_conf.Component)
if comp not in self._sys_sim_map: if comp not in self._sys_sim_map:
raise Exception("Simulator Not Found") raise Exception(f"Simulator not found for component: {comp}")
return self._sys_sim_map[comp] return self._sys_sim_map[comp]
async def prepare(self, inst: inst_base.Instantiation) -> None: async def prepare(self, inst: inst_base.Instantiation) -> None:
......
...@@ -48,7 +48,7 @@ class HostSim(sim_base.Simulator): ...@@ -48,7 +48,7 @@ class HostSim(sim_base.Simulator):
def config_str(self) -> str: def config_str(self) -> str:
return [] return []
def supported_image_formats() -> list[str]: def supported_image_formats(self) -> list[str]:
raise Exception("implement me") raise Exception("implement me")
...@@ -71,6 +71,9 @@ class Gem5Sim(HostSim): ...@@ -71,6 +71,9 @@ class Gem5Sim(HostSim):
def resreq_mem(self) -> int: def resreq_mem(self) -> int:
return 4096 return 4096
def supported_image_formats(self) -> list[str]:
return ["raw"]
async def prepare(self, inst: inst_base.Instantiation) -> None: async def prepare(self, inst: inst_base.Instantiation) -> None:
await super().prepare(inst=inst) await super().prepare(inst=inst)
...@@ -142,6 +145,8 @@ class QemuSim(HostSim): ...@@ -142,6 +145,8 @@ class QemuSim(HostSim):
def resreq_mem(self) -> int: def resreq_mem(self) -> int:
return 8192 return 8192
def supported_image_formats(self) -> list[str]:
return ["raw", "qcow2"]
async def prepare(self, inst: inst_base.Instantiation) -> None: async def prepare(self, inst: inst_base.Instantiation) -> None:
await super().prepare(inst=inst) await super().prepare(inst=inst)
......
...@@ -36,7 +36,8 @@ if tp.TYPE_CHECKING: ...@@ -36,7 +36,8 @@ if tp.TYPE_CHECKING:
class DiskImage(utils_base.IdObj): class DiskImage(utils_base.IdObj):
def __init__(self, h: sys_host.Host) -> None: def __init__(self, h: sys_host.Host) -> None:
self.host = None | str super().__init__()
self.host: sys_host.Host = h
@abc.abstractmethod @abc.abstractmethod
def available_formats(self) -> list[str]: def available_formats(self) -> list[str]:
......
...@@ -43,5 +43,5 @@ def check_type(obj, expected_type) -> bool: ...@@ -43,5 +43,5 @@ def check_type(obj, expected_type) -> bool:
def has_expected_type(obj, expected_type) -> None: def has_expected_type(obj, expected_type) -> None:
if not check_type(obj=obj, expected_type=expected_type): if not check_type(obj=obj, expected_type=expected_type):
raise Exception( raise Exception(
f"obj of type {type(obj)} has not the type or is not a subtype of {type(expected_type)}" f"obj of type {type(obj)} has not the type or is not a subtype of {expected_type}"
) )
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