Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ycai
simbricks
Commits
a20ed8c2
Unverified
Commit
a20ed8c2
authored
Sep 04, 2024
by
Jakob Görgen
Browse files
added IdObject as utils class for easy way to assign IDs to objects
parent
fddf6344
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
16 deletions
+50
-16
experiments/simbricks/orchestration/instantiation/base.py
experiments/simbricks/orchestration/instantiation/base.py
+11
-4
experiments/simbricks/orchestration/simulation/base.py
experiments/simbricks/orchestration/simulation/base.py
+3
-1
experiments/simbricks/orchestration/system/base.py
experiments/simbricks/orchestration/system/base.py
+5
-11
experiments/simbricks/orchestration/utils/base.py
experiments/simbricks/orchestration/utils/base.py
+31
-0
No files found.
experiments/simbricks/orchestration/instantiation/base.py
View file @
a20ed8c2
...
@@ -20,10 +20,11 @@
...
@@ -20,10 +20,11 @@
# 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
simbricks.orchestration
import
simulation
from
simbricks.orchestration
import
system
import
enum
import
enum
import
pathlib
import
pathlib
from
simbricks.orchestration.utils
import
base
from
simbricks.orchestration
import
simulation
from
simbricks.orchestration
import
system
class
SockType
(
enum
.
Enum
):
class
SockType
(
enum
.
Enum
):
...
@@ -38,7 +39,7 @@ class Socket:
...
@@ -38,7 +39,7 @@ class Socket:
self
.
_type
=
ty
self
.
_type
=
ty
class
InstantiationEnvironment
:
class
InstantiationEnvironment
(
base
.
IdObj
)
:
def
__init__
(
def
__init__
(
self
,
self
,
...
@@ -49,6 +50,7 @@ class InstantiationEnvironment:
...
@@ -49,6 +50,7 @@ class InstantiationEnvironment:
output_base
:
str
=
pathlib
.
Path
(),
output_base
:
str
=
pathlib
.
Path
(),
tmp_simulation_files
:
str
=
pathlib
.
Path
(),
tmp_simulation_files
:
str
=
pathlib
.
Path
(),
):
):
super
().
__init__
()
# TODO: add more parameters that wont change during instantiation
# TODO: add more parameters that wont change during instantiation
self
.
_repodir
:
str
=
pathlib
.
Path
(
repo_path
).
absolute
()
self
.
_repodir
:
str
=
pathlib
.
Path
(
repo_path
).
absolute
()
self
.
_workdir
:
str
=
pathlib
.
Path
(
workdir
).
absolute
()
self
.
_workdir
:
str
=
pathlib
.
Path
(
workdir
).
absolute
()
...
@@ -60,11 +62,12 @@ class InstantiationEnvironment:
...
@@ -60,11 +62,12 @@ class InstantiationEnvironment:
)
)
class
Instantiation
:
class
Instantiation
(
base
.
IdObj
)
:
def
__init__
(
def
__init__
(
self
,
simulation
,
env
:
InstantiationEnvironment
=
InstantiationEnvironment
()
self
,
simulation
,
env
:
InstantiationEnvironment
=
InstantiationEnvironment
()
):
):
super
().
__init__
()
self
.
_simulation
=
simulation
self
.
_simulation
=
simulation
self
.
_env
:
InstantiationEnvironment
=
env
self
.
_env
:
InstantiationEnvironment
=
env
self
.
_socket_per_interface
:
dict
[
system
.
base
.
Interface
,
Socket
]
=
{}
self
.
_socket_per_interface
:
dict
[
system
.
base
.
Interface
,
Socket
]
=
{}
...
@@ -160,6 +163,10 @@ class Instantiation:
...
@@ -160,6 +163,10 @@ class Instantiation:
# TODO: add more methods constructing paths as required by methods in simulators or image handling classes
# 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
(
def
_join_paths
(
self
,
base
:
str
=
""
,
relative_path
:
str
=
""
,
enforce_existence
=
True
self
,
base
:
str
=
""
,
relative_path
:
str
=
""
,
enforce_existence
=
True
)
->
str
:
)
->
str
:
...
...
experiments/simbricks/orchestration/simulation/base.py
View file @
a20ed8c2
...
@@ -26,6 +26,7 @@ import typing as tp
...
@@ -26,6 +26,7 @@ import typing as tp
import
simbricks.orchestration.system
as
sys_conf
import
simbricks.orchestration.system
as
sys_conf
from
simbricks.orchestration.experiment
import
experiment_environment_new
as
exp_env
from
simbricks.orchestration.experiment
import
experiment_environment_new
as
exp_env
from
simbricks.orchestration.instantiation
import
base
as
inst_base
from
simbricks.orchestration.instantiation
import
base
as
inst_base
from
simbricks.orchestration.utils
import
base
as
utils_base
if
tp
.
TYPE_CHECKING
:
if
tp
.
TYPE_CHECKING
:
from
simbricks.orchestration.simulation
import
(
from
simbricks.orchestration.simulation
import
(
...
@@ -37,12 +38,13 @@ if tp.TYPE_CHECKING:
...
@@ -37,12 +38,13 @@ if tp.TYPE_CHECKING:
)
)
class
Simulator
(
abc
.
ABC
):
class
Simulator
(
utils_base
.
IdObj
):
"""Base class for all simulators."""
"""Base class for all simulators."""
def
__init__
(
def
__init__
(
self
,
simulation
:
sim_base
.
Simulation
,
relative_executable_path
:
str
=
""
self
,
simulation
:
sim_base
.
Simulation
,
relative_executable_path
:
str
=
""
)
->
None
:
)
->
None
:
super
().
__init__
()
self
.
extra_deps
:
list
[
Simulator
]
=
[]
self
.
extra_deps
:
list
[
Simulator
]
=
[]
self
.
name
:
str
=
""
self
.
name
:
str
=
""
self
.
experiment
:
sim_base
.
Simulation
=
simulation
self
.
experiment
:
sim_base
.
Simulation
=
simulation
...
...
experiments/simbricks/orchestration/system/base.py
View file @
a20ed8c2
...
@@ -22,7 +22,8 @@
...
@@ -22,7 +22,8 @@
from
__future__
import
annotations
from
__future__
import
annotations
import
abc
import
abc
import
itertools
from
simbricks.orchestration.utils
import
base
class
System
:
class
System
:
"""Defines System configuration of the whole simulation"""
"""Defines System configuration of the whole simulation"""
...
@@ -35,14 +36,7 @@ class System:
...
@@ -35,14 +36,7 @@ class System:
self
.
all_component
.
append
(
c
)
self
.
all_component
.
append
(
c
)
class
IdObj
(
abc
.
ABC
):
class
Component
(
base
.
IdObj
):
__id_iter
=
itertools
.
count
()
def
__init__
(
self
):
self
.
_id
=
next
(
self
.
__id_iter
)
class
Component
(
IdObj
):
def
__init__
(
self
,
s
:
System
)
->
None
:
def
__init__
(
self
,
s
:
System
)
->
None
:
super
().
__init__
()
super
().
__init__
()
...
@@ -59,7 +53,7 @@ class Component(IdObj):
...
@@ -59,7 +53,7 @@ class Component(IdObj):
return
[
i
.
channel
for
i
in
self
.
interfaces
()
if
i
.
is_connected
()]
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
:
def
__init__
(
self
,
c
:
Component
)
->
None
:
super
().
__init__
()
super
().
__init__
()
self
.
component
=
c
self
.
component
=
c
...
@@ -76,7 +70,7 @@ class Interface(IdObj):
...
@@ -76,7 +70,7 @@ class Interface(IdObj):
self
.
channel
=
c
self
.
channel
=
c
class
Channel
(
IdObj
):
class
Channel
(
base
.
IdObj
):
def
__init__
(
self
,
a
:
Interface
,
b
:
Interface
)
->
None
:
def
__init__
(
self
,
a
:
Interface
,
b
:
Interface
)
->
None
:
super
().
__init__
()
super
().
__init__
()
self
.
latency
=
500
self
.
latency
=
500
...
...
experiments/simbricks/orchestration/utils/base.py
0 → 100644
View file @
a20ed8c2
# 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
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment