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

fixes in simulation base module + channel impl extension

parent 24d55893
...@@ -186,13 +186,14 @@ class Simulator(utils_base.IdObj): ...@@ -186,13 +186,14 @@ class Simulator(utils_base.IdObj):
def _get_channel(self, chan: sys_conf.Channel) -> sim_chan.Channel | None: def _get_channel(self, chan: sys_conf.Channel) -> sim_chan.Channel | None:
if self._chan_needs_instance(chan): if self._chan_needs_instance(chan):
return self.experiment.retrieve_or_create_channel(chan=chan) return self._simulation.retrieve_or_create_channel(chan=chan)
return None return None
def _get_channels(self, inst: inst_base.Instantiation) -> list[sim_chan.Channel]: def get_channels(self) -> list[sim_chan.Channel]:
channels = [] channels = []
for comp_spec in self._components: for comp_spec in self._components:
for chan in self.experiment.retrieve_or_create_channel(chan=chan): comp_sys_channels = comp_spec.channels()
for chan in comp_sys_channels:
channel = self._get_channel(chan=chan) channel = self._get_channel(chan=chan)
if channel is None: if channel is None:
continue continue
...@@ -277,7 +278,7 @@ class Simulation(utils_base.IdObj): ...@@ -277,7 +278,7 @@ class Simulation(utils_base.IdObj):
self._sim_list: list[Simulator] = [] self._sim_list: list[Simulator] = []
"""Channel spec and its instanciation""" """Channel spec and its instanciation"""
def add_sim (self, sim: Simulator): def add_sim(self, sim: Simulator):
if sim in self._sim_list: if sim in self._sim_list:
raise Exception("Simulaotr is already added") raise Exception("Simulaotr is already added")
self._sim_list.append(sim) self._sim_list.append(sim)
...@@ -288,7 +289,7 @@ class Simulation(utils_base.IdObj): ...@@ -288,7 +289,7 @@ class Simulation(utils_base.IdObj):
raise Exception("system component is already mapped by simulator") raise Exception("system component is already mapped by simulator")
self._sys_sim_map[sys] = sim self._sys_sim_map[sys] = sim
def is_channel_instantiated(self, chan: Channel) -> bool: def is_channel_instantiated(self, chan: sys_conf.Channel) -> bool:
return chan in self._chan_map return chan in self._chan_map
def retrieve_or_create_channel(self, chan: sys_conf.Channel) -> Channel: def retrieve_or_create_channel(self, chan: sys_conf.Channel) -> Channel:
...@@ -302,6 +303,16 @@ class Simulation(utils_base.IdObj): ...@@ -302,6 +303,16 @@ class Simulation(utils_base.IdObj):
def all_simulators(self) -> list[Simulator]: def all_simulators(self) -> list[Simulator]:
return self._sim_list return self._sim_list
def get_all_channels(self, lazy: bool = False) -> list[Channel]:
if lazy:
return list(self._chan_map.values())
all_channels = []
for sim in self.all_simulators():
channels = sim.get_channels()
all_channels.extend(channels)
return all_channels
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."""
mem = 0 mem = 0
......
...@@ -20,7 +20,18 @@ ...@@ -20,7 +20,18 @@
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import enum
from simbricks.orchestration.system import base as system_base from simbricks.orchestration.system import base as system_base
from simbricks.orchestration.utils import base as utils_base
class Time(enum.IntEnum):
Picoseconds = 10 ** (-3)
Nanoseconds = 1
Microseconds = 10 ** (3)
Milliseconds = 10 ** (6)
Seconds = 10 ** (9)
class Channel: class Channel:
...@@ -32,3 +43,7 @@ class Channel: ...@@ -32,3 +43,7 @@ class Channel:
def full_name(self) -> str: def full_name(self) -> str:
return "channel." + self.name return "channel." + self.name
def set_sync_period(self, amount: int, ratio: Time = Time.Nanoseconds) -> None:
utils_base.has_expected_type(obj=ratio, expected_type=Time)
self.sync_period = amount * ratio
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