"...resnet50_tensorflow.git" did not exist on "037abae4f200220f604f4475ebf9fa781a7bc30c"
Commit 4669fc6c authored by Hejing Li's avatar Hejing Li
Browse files

add simulator list to simulation class. add simulator to this list at...

add simulator list to simulation class. add simulator to this list at initialization. & fix some syntex errors
parent ec39af87
...@@ -57,6 +57,7 @@ class Simulator(utils_base.IdObj): ...@@ -57,6 +57,7 @@ class Simulator(utils_base.IdObj):
self.extra_deps: list[Simulator] = [] self.extra_deps: list[Simulator] = []
self._simulation: sim_base.Simulation = simulation self._simulation: sim_base.Simulation = simulation
self._components: set[sys_conf.Component] = set() self._components: set[sys_conf.Component] = set()
simulation.add_sim(self)
@staticmethod @staticmethod
def filter_sockets( def filter_sockets(
...@@ -121,7 +122,7 @@ class Simulator(utils_base.IdObj): ...@@ -121,7 +122,7 @@ class Simulator(utils_base.IdObj):
"""Commands to prepare execution of this simulator.""" """Commands to prepare execution of this simulator."""
return [] return []
def add(self, comp: sys_base.Component) -> None: def add(self, comp: sys_conf.Component) -> None:
if comp in self._components: if comp in self._components:
raise Exception("cannot add the same specification twice to a simulator") raise Exception("cannot add the same specification twice to a simulator")
self._components.add(comp) self._components.add(comp)
...@@ -273,6 +274,14 @@ class Simulation(utils_base.IdObj): ...@@ -273,6 +274,14 @@ class Simulation(utils_base.IdObj):
self._chan_map: dict[sys_conf.Channel, sim_chan.Channel] = {} self._chan_map: dict[sys_conf.Channel, sim_chan.Channel] = {}
"""Channel spec and its instanciation""" """Channel spec and its instanciation"""
self._sim_list: list[Simulator] = []
"""Channel spec and its instanciation"""
def add_sim (self, sim: Simulator):
if sim in self._sim_list:
raise Exception("Simulaotr is already added")
self._sim_list.append(sim)
def add_spec_sim_map(self, sys: sys_conf.Component, sim: Simulator): def add_spec_sim_map(self, sys: sys_conf.Component, sim: Simulator):
"""Add a mapping from specification to simulation instance""" """Add a mapping from specification to simulation instance"""
if sys in self._sys_sim_map: if sys in self._sys_sim_map:
...@@ -290,10 +299,8 @@ class Simulation(utils_base.IdObj): ...@@ -290,10 +299,8 @@ class Simulation(utils_base.IdObj):
self._chan_map[chan] = channel self._chan_map[chan] = channel
return channel return channel
def all_simulators(self) -> set[Simulator]: def all_simulators(self) -> list[Simulator]:
"""Returns all simulators defined to run in this experiment.""" return self._sim_list
simulators = set(map(lambda kv: kv[1], self._sys_sim_map.items()))
return simulators
def resreq_mem(self) -> int: def resreq_mem(self) -> int:
"""Memory required to run all simulators in this experiment.""" """Memory required to run all simulators in this experiment."""
......
...@@ -56,9 +56,7 @@ class HostSim(sim_base.Simulator): ...@@ -56,9 +56,7 @@ class HostSim(sim_base.Simulator):
def add(self, host: 'Host'): def add(self, host: 'Host'):
self.hosts.append(host) self.hosts.append(host)
self.name = f'{self._id}' self.name = f'{self._id}'
# TODO: FIXME, call super method... self._simulation.add_spec_sim_map(host, self)
# self.experiment.add_host(self)
# self.experiment.sys_sim_map[host] = self
def config_str(self) -> str: def config_str(self) -> str:
return [] return []
......
...@@ -63,7 +63,7 @@ class WireNet(NetSim): ...@@ -63,7 +63,7 @@ class WireNet(NetSim):
self._relative_pcap_file_path: str | None = "relative_pcap_file_path" self._relative_pcap_file_path: str | None = "relative_pcap_file_path"
def add(self, wire: eth.EthWire): def add(self, wire: eth.EthWire):
base_utils.has_expected_type(wire, eth.EthWire()) base_utils.has_expected_type(wire, eth.EthWire)
if len(self._components) > 1: if len(self._components) > 1:
raise Exception( raise Exception(
"can only add a single wire component to the WireNet simulator" "can only add a single wire component to the WireNet simulator"
...@@ -104,7 +104,7 @@ class SwitchNet(NetSim): ...@@ -104,7 +104,7 @@ class SwitchNet(NetSim):
self._relative_pcap_file_path: str | None = relative_pcap_file_path self._relative_pcap_file_path: str | None = relative_pcap_file_path
def add(self, switch_spec: eth.EthSwitch): def add(self, switch_spec: eth.EthSwitch):
base_utils.has_expected_type(wire, eth.EthSwitch()) base_utils.has_expected_type(switch_spec, eth.EthSwitch)
if len(self._components) > 1: if len(self._components) > 1:
raise Exception("can only add a single switch component to the SwitchNet") raise Exception("can only add a single switch component to the SwitchNet")
super().add(switch_spec) super().add(switch_spec)
......
...@@ -64,10 +64,7 @@ class NICSim(PCIDevSim): ...@@ -64,10 +64,7 @@ class NICSim(PCIDevSim):
def add(self, nic: sys_conf.SimplePCIeNIC): def add(self, nic: sys_conf.SimplePCIeNIC):
self.nics.append(nic) self.nics.append(nic)
# nic.sim = self self.experiment.add_spec_sim_map(nic, self)
# TODO: FIXME, call super method...
#self.experiment.add_nic(self)
#self.experiment.sys_sim_map[nic] = self
self.name = f'{nic._id}' self.name = f'{nic._id}'
def basic_args(self, env: ExpEnv, extra: tp.Optional[str] = None) -> str: def basic_args(self, env: ExpEnv, extra: tp.Optional[str] = None) -> str:
......
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