Commit c6d1fa2d authored by Jonas Kaufmann's avatar Jonas Kaufmann
Browse files

symphony: orchestration: fix multiple issues that pop up when invoking simbricks-run

- import errors
- simulators being inserted into dependency topology multiple times
- some uninitialized variables
- missing or wrong arguments in function calls
parent 03db98ba
...@@ -272,7 +272,7 @@ class Instantiation: ...@@ -272,7 +272,7 @@ class Instantiation:
# Experiment does not define any simulation fragments, so # Experiment does not define any simulation fragments, so
# implicitly, we create one fragment that spans the whole simulation # implicitly, we create one fragment that spans the whole simulation
self._simulation_fragment = inst_fragment.Fragment() self._simulation_fragment = inst_fragment.Fragment()
self._simulation_fragment.add_simulators(self.simulation.all_simulators()) self._simulation_fragment.add_simulators(*self.simulation.all_simulators())
else: else:
fragments = [ fragments = [
fragment fragment
......
...@@ -24,19 +24,21 @@ instantiated components like simulators that determines the order to start them ...@@ -24,19 +24,21 @@ instantiated components like simulators that determines the order to start them
in.""" in."""
from __future__ import annotations from __future__ import annotations
import typing
import enum import enum
import typing
from simbricks.orchestration.instantiation import proxy as inst_proxy
from simbricks.orchestration.instantiation import socket as inst_socket
from simbricks.orchestration.simulation import base as sim_base
if typing.TYPE_CHECKING: if typing.TYPE_CHECKING:
from simbricks.orchestration.simulation import base as sim_base
from simbricks.orchestration.instantiation import base as inst_base from simbricks.orchestration.instantiation import base as inst_base
from simbricks.orchestration.system import base as sys_base from simbricks.orchestration.system import base as sys_base
from simbricks.orchestration.instantiation import socket as inst_socket
from simbricks.orchestration.instantiation import proxy as inst_proxy
class TopologyComponentType(enum.Enum):
SIMULATOR = enum.auto() class TopologyComponentType(enum.Enum):
PROXY = enum.auto() SIMULATOR = enum.auto()
PROXY = enum.auto()
class TopologyComponent: class TopologyComponent:
...@@ -49,6 +51,25 @@ class TopologyComponent: ...@@ -49,6 +51,25 @@ class TopologyComponent:
self.type = type self.type = type
self.value = value self.value = value
def get_simulator(self) -> sim_base.Simulator:
if self.type != TopologyComponentType.SIMULATOR:
raise RuntimeError("Value stored is not a simulator")
return typing.cast(sim_base.Simulator, self.value)
def get_proxy(self) -> inst_proxy.Proxy:
if self.type != TopologyComponentType.PROXY:
raise RuntimeError("Value stored is not a proxy")
return typing.cast(inst_proxy.Proxy, self.value)
def __repr__(self) -> str:
match self.type:
case TopologyComponentType.SIMULATOR:
return str(("sim", self.get_simulator()))
case TopologyComponentType.PROXY:
return str(("proxy", self.get_proxy()))
case _:
raise RuntimeError("Unhandles type")
SimulationDependencyTopology = typing.NewType( SimulationDependencyTopology = typing.NewType(
"SimulationDependencyTopology", "SimulationDependencyTopology",
...@@ -66,7 +87,7 @@ def build_simulation_topology( ...@@ -66,7 +87,7 @@ def build_simulation_topology(
# start first before simulator can start # start first before simulator can start
sim_dependencies: SimulationDependencyTopology = {} sim_dependencies: SimulationDependencyTopology = {}
def insert_dependency(topo_comp_a: TopologyComponent, depends_on: TopologyComponent): def insert_dependency(topo_comp_a: TopologyComponent, depends_on: TopologyComponent) -> None:
if depends_on in sim_dependencies: if depends_on in sim_dependencies:
if topo_comp_a in sim_dependencies[depends_on]: if topo_comp_a in sim_dependencies[depends_on]:
# TODO: FIXME # TODO: FIXME
...@@ -86,7 +107,7 @@ def build_simulation_topology( ...@@ -86,7 +107,7 @@ def build_simulation_topology(
topo_comp_b: TopologyComponent, topo_comp_b: TopologyComponent,
) -> None: ) -> None:
a_sock = topo_comp_a.value.supported_socket_types(interface=inf_a) a_sock = topo_comp_a.value.supported_socket_types(interface=inf_a)
b_sock = topo_comp_a.value.supported_socket_types(interface=inf_b) b_sock = topo_comp_b.value.supported_socket_types(interface=inf_b)
if a_sock != b_sock: if a_sock != b_sock:
if len(a_sock) == 0 or len(b_sock) == 0: if len(a_sock) == 0 or len(b_sock) == 0:
...@@ -126,6 +147,8 @@ def build_simulation_topology( ...@@ -126,6 +147,8 @@ def build_simulation_topology(
) )
# build dependency graph # build dependency graph
topo_comp_sims: dict[sim_base.Simulator, TopologyComponent] = {}
topo_comp_proxies: dict[inst_proxy.Proxy, TopologyComponent] = {}
for sim in instantiation.fragment.all_simulators(): for sim in instantiation.fragment.all_simulators():
for comp in sim.components(): for comp in sim.components():
for sim_inf in comp.interfaces(): for sim_inf in comp.interfaces():
...@@ -134,22 +157,35 @@ def build_simulation_topology( ...@@ -134,22 +157,35 @@ def build_simulation_topology(
# simulator # simulator
continue continue
topo_comp_a = TopologyComponent( topo_comp_a = topo_comp_sims.get(
TopologyComponentType.SIMULATOR, sim sim, TopologyComponent(TopologyComponentType.SIMULATOR, sim)
) )
topo_comp_sims[sim] = topo_comp_a
opposing_inf = instantiation._get_opposing_interface(interface=sim_inf) opposing_inf = instantiation._get_opposing_interface(interface=sim_inf)
if not instantiation.fragment.interface_handled_by_proxy(opposing_inf): if not instantiation.fragment.interface_handled_by_proxy(opposing_inf):
topo_comp_b = TopologyComponent( sim_b = instantiation.find_sim_by_interface(opposing_inf)
TopologyComponentType.SIMULATOR, topo_comp_b = topo_comp_sims.get(
instantiation.find_sim_by_interface(opposing_inf), sim_b,
TopologyComponent(
TopologyComponentType.SIMULATOR,
sim_b,
),
) )
topo_comp_sims[sim_b] = topo_comp_b
else: else:
topo_comp_b = TopologyComponent( proxy_b = instantiation.fragment.get_proxy_by_interface(opposing_inf)
TopologyComponentType.PROXY, topo_comp_b = topo_comp_proxies.get(
instantiation.fragment.get_proxy_by_interface(opposing_inf), proxy_b,
TopologyComponent(
TopologyComponentType.PROXY,
proxy_b,
),
) )
topo_comp_proxies[proxy_b] = topo_comp_b
update_a_depends_on_b(sim_inf, topo_comp_a, opposing_inf, topo_comp_b) update_a_depends_on_b(sim_inf, topo_comp_a, opposing_inf, topo_comp_b)
# TODO (Jonas) Add iteration over proxies
return sim_dependencies return sim_dependencies
...@@ -19,12 +19,14 @@ ...@@ -19,12 +19,14 @@
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# 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.
from __future__ import annotations
import typing
from simbricks.utils import base as util_base
from simbricks.orchestration.instantiation import proxy from simbricks.orchestration.instantiation import proxy
import typing as tp from simbricks.utils import base as util_base
if tp.TYPE_CHECKING: if typing.TYPE_CHECKING:
from simbricks.orchestration.simulation import base as sim_base from simbricks.orchestration.simulation import base as sim_base
from simbricks.orchestration.system import base as sys_base from simbricks.orchestration.system import base as sys_base
...@@ -34,8 +36,8 @@ class Fragment(util_base.IdObj): ...@@ -34,8 +36,8 @@ class Fragment(util_base.IdObj):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self._proxies: set[proxy.Proxy] self._proxies: set[proxy.Proxy] = set()
self._simulators: set[sim_base.Simulator] self._simulators: set[sim_base.Simulator] = set()
@staticmethod @staticmethod
def merged(*fragments: "Fragment"): def merged(*fragments: "Fragment"):
......
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
# 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.
from __future__ import annotations
import typing import typing
import simbricks.utils.base as util_base import simbricks.utils.base as util_base
......
...@@ -21,10 +21,6 @@ ...@@ -21,10 +21,6 @@
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
from simbricks.runtime.runs.base import Run, Runtime from simbricks.runtime.runs.base import Run, Runtime
from simbricks.runtime.runs.distributed import (
DistributedSimpleRuntime, auto_dist
)
from simbricks.runtime.runs.local import ( from simbricks.runtime.runs.local import (
LocalParallelRuntime, LocalSimpleRuntime LocalParallelRuntime, LocalSimpleRuntime
) )
from simbricks.runtime.runs.slurm import SlurmRuntime
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