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
35a75ec0
Unverified
Commit
35a75ec0
authored
Jan 16, 2025
by
Jakob Görgen
Browse files
symphony/orchestration: added rudimentary serialization and deserialization to instantiation
parent
8ec24962
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
85 additions
and
8 deletions
+85
-8
symphony/orchestration/simbricks/orchestration/instantiation/base.py
...chestration/simbricks/orchestration/instantiation/base.py
+48
-6
symphony/orchestration/simbricks/orchestration/instantiation/fragment.py
...tration/simbricks/orchestration/instantiation/fragment.py
+35
-2
symphony/utils/simbricks/utils/base.py
symphony/utils/simbricks/utils/base.py
+2
-0
No files found.
symphony/orchestration/simbricks/orchestration/instantiation/base.py
View file @
35a75ec0
...
@@ -62,15 +62,13 @@ class InstantiationEnvironment(util_base.IdObj):
...
@@ -62,15 +62,13 @@ class InstantiationEnvironment(util_base.IdObj):
self
.
_shm_base
:
str
=
pathlib
.
Path
(
f
"
{
self
.
_tmp_simulation_files
}
/shm"
).
resolve
()
self
.
_shm_base
:
str
=
pathlib
.
Path
(
f
"
{
self
.
_tmp_simulation_files
}
/shm"
).
resolve
()
class
Instantiation
:
class
Instantiation
(
util_base
.
IdObj
):
__id_iter
=
itertools
.
count
()
def
__init__
(
def
__init__
(
self
,
self
,
sim
:
sim_base
.
Simulation
,
sim
:
sim_base
.
Simulation
,
):
):
s
elf
.
_id
=
next
(
self
.
__id_iter
)
s
uper
().
__init__
(
)
self
.
simulation
:
sim_base
.
Simulation
=
sim
self
.
simulation
:
sim_base
.
Simulation
=
sim
self
.
simulation_fragments
:
set
[
inst_fragment
.
Fragment
]
=
set
()
self
.
simulation_fragments
:
set
[
inst_fragment
.
Fragment
]
=
set
()
self
.
fragment_runner_map
:
dict
[
inst_fragment
.
Fragment
,
str
]
=
dict
()
self
.
fragment_runner_map
:
dict
[
inst_fragment
.
Fragment
,
str
]
=
dict
()
...
@@ -89,7 +87,7 @@ class Instantiation:
...
@@ -89,7 +87,7 @@ class Instantiation:
# NOTE: temporary data structure
# NOTE: temporary data structure
self
.
_socket_per_interface
:
dict
[
sys_base
.
Interface
,
inst_socket
.
Socket
]
=
{}
self
.
_socket_per_interface
:
dict
[
sys_base
.
Interface
,
inst_socket
.
Socket
]
=
{}
# NOTE: temporary data structure
# NOTE: temporary data structure
self
.
_sim_dependency
:
dict
[
sim_base
.
Simulator
,
set
[
sim_base
.
Simulator
]]
|
None
=
None
self
.
_sim_dependency
:
inst_dep_topo
.
SimulationDependencyTopology
|
None
=
None
self
.
_cmd_executor
:
cmd_exec
.
CommandExecutorFactory
|
None
=
None
self
.
_cmd_executor
:
cmd_exec
.
CommandExecutorFactory
|
None
=
None
@
staticmethod
@
staticmethod
...
@@ -107,6 +105,50 @@ class Instantiation:
...
@@ -107,6 +105,50 @@ class Instantiation:
raise
RuntimeError
(
f
"
{
type
(
self
).
__name__
}
._cmd_executor should be set"
)
raise
RuntimeError
(
f
"
{
type
(
self
).
__name__
}
._cmd_executor should be set"
)
return
self
.
_cmd_executor
return
self
.
_cmd_executor
def
toJSON
(
self
)
->
dict
:
json_obj
=
super
().
toJSON
()
json_obj
[
"simulation"
]
=
self
.
simulation
.
id
()
fragments_json
=
[]
if
len
(
self
.
simulation_fragments
)
<
1
:
fragment
=
self
.
fragment
util_base
.
has_attribute
(
fragment
,
"toJSON"
)
fragments_json
.
append
(
fragment
.
toJSON
())
else
:
for
fragment
in
self
.
simulation_fragments
:
util_base
.
has_attribute
(
fragment
,
"toJSON"
)
fragments_json
.
append
(
fragment
.
toJSON
())
json_obj
[
"simulation_fragments"
]
=
fragments_json
json_obj
[
"artifact_name"
]
=
self
.
artifact_name
json_obj
[
"artifact_paths"
]
=
self
.
artifact_paths
# TODO: serialize other fields etc. of interest
return
json_obj
@
classmethod
def
fromJSON
(
cls
,
sim
:
sim_base
.
Simulation
,
json_obj
:
dict
)
->
Instantiation
:
instance
=
super
().
fromJSON
(
json_obj
)
simulation_id
=
int
(
util_base
.
get_json_attr_top
(
json_obj
,
"simulation"
))
assert
simulation_id
==
sim
.
id
()
instance
.
simulation
=
sim
instance
.
simulation_fragments
=
set
()
fragments_json
=
util_base
.
get_json_attr_top
(
json_obj
,
"simulation_fragments"
)
for
frag_json
in
fragments_json
:
frag_class
=
util_base
.
get_cls_by_json
(
frag_json
)
util_base
.
has_attribute
(
frag_class
,
"fromJSON"
)
frag
=
frag_class
.
fromJSON
(
frag_json
)
instance
.
simulation_fragments
.
add
(
frag
)
instance
.
artifact_name
=
util_base
.
get_json_attr_top
(
json_obj
,
"artifact_name"
)
instance
.
artifact_paths
=
util_base
.
get_json_attr_top
(
json_obj
,
"artifact_paths"
)
# TODO: deserialize other fields etc. of interest
return
instance
def
_get_opposing_interface
(
self
,
interface
:
sys_base
.
Interface
)
->
sys_base
.
Interface
:
def
_get_opposing_interface
(
self
,
interface
:
sys_base
.
Interface
)
->
sys_base
.
Interface
:
opposing_inf
=
interface
.
get_opposing_interface
()
opposing_inf
=
interface
.
get_opposing_interface
()
return
opposing_inf
return
opposing_inf
...
@@ -211,7 +253,7 @@ class Instantiation:
...
@@ -211,7 +253,7 @@ class Instantiation:
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
sim_dependencies
(
self
)
->
dict
[
sim_base
.
Simulator
,
set
[
sim_base
.
Simulator
]]
:
def
sim_dependencies
(
self
)
->
inst_dep_topo
.
SimulationDependencyTopology
:
if
self
.
_sim_dependency
is
not
None
:
if
self
.
_sim_dependency
is
not
None
:
return
self
.
_sim_dependency
return
self
.
_sim_dependency
self
.
_sim_dependency
=
inst_dep_topo
.
build_simulation_topology
(
self
)
self
.
_sim_dependency
=
inst_dep_topo
.
build_simulation_topology
(
self
)
...
...
symphony/orchestration/simbricks/orchestration/instantiation/fragment.py
View file @
35a75ec0
...
@@ -22,7 +22,8 @@
...
@@ -22,7 +22,8 @@
from
__future__
import
annotations
from
__future__
import
annotations
import
typing
import
typing
import
functools
from
simbricks.utils
import
base
as
util_base
from
simbricks.orchestration.instantiation
import
proxy
from
simbricks.orchestration.instantiation
import
proxy
from
simbricks.utils
import
base
as
util_base
from
simbricks.utils
import
base
as
util_base
...
@@ -39,8 +40,40 @@ class Fragment(util_base.IdObj):
...
@@ -39,8 +40,40 @@ class Fragment(util_base.IdObj):
self
.
_proxies
:
set
[
proxy
.
Proxy
]
=
set
()
self
.
_proxies
:
set
[
proxy
.
Proxy
]
=
set
()
self
.
_simulators
:
set
[
sim_base
.
Simulator
]
=
set
()
self
.
_simulators
:
set
[
sim_base
.
Simulator
]
=
set
()
def
toJSON
(
self
)
->
dict
:
json_obj
=
super
().
toJSON
()
proxy_json
=
[]
for
prox
in
self
.
_proxies
:
util_base
.
has_attribute
(
prox
,
"toJSON"
)
proxy_json
.
append
(
prox
.
toJSON
())
json_obj
[
"proxies"
]
=
proxy_json
json_obj
[
"simulators"
]
=
list
(
map
(
lambda
sim
:
sim
.
id
(),
self
.
_simulators
))
json_obj
[
"cores_required"
]
=
self
.
cores_required
json_obj
[
"memory_required"
]
=
self
.
memory_required
return
json_obj
@
property
def
cores_required
(
self
)
->
int
:
req_cores_per_sim
=
map
(
lambda
sim
:
sim
.
resreq_cores
(),
self
.
_simulators
)
req_cores
=
functools
.
reduce
(
lambda
x
,
y
:
x
+
y
,
req_cores_per_sim
)
return
req_cores
@
property
def
memory_required
(
self
)
->
int
:
req_mem_per_sim
=
map
(
lambda
sim
:
sim
.
resreq_mem
(),
self
.
_simulators
)
req_mem
=
functools
.
reduce
(
lambda
x
,
y
:
x
+
y
,
req_mem_per_sim
)
return
req_mem
@
classmethod
def
fromJSON
(
cls
,
json_obj
:
dict
)
->
Fragment
:
instance
=
super
().
fromJSON
(
json_obj
)
# TODO: FIXME implement proper reconstruction from json
return
instance
@
staticmethod
@
staticmethod
def
merged
(
*
fragments
:
"
Fragment
"
):
def
merged
(
*
fragments
:
Fragment
):
merged_fragment
=
Fragment
()
merged_fragment
=
Fragment
()
proxies
=
set
()
proxies
=
set
()
simulators
=
set
()
simulators
=
set
()
...
...
symphony/utils/simbricks/utils/base.py
View file @
35a75ec0
...
@@ -37,6 +37,8 @@ class IdObj(abc.ABC):
...
@@ -37,6 +37,8 @@ class IdObj(abc.ABC):
def
toJSON
(
self
):
def
toJSON
(
self
):
json_obj
=
{}
json_obj
=
{}
json_obj
[
"type"
]
=
self
.
__class__
.
__name__
json_obj
[
"module"
]
=
self
.
__class__
.
__module__
json_obj
[
"id"
]
=
self
.
_id
json_obj
[
"id"
]
=
self
.
_id
return
json_obj
return
json_obj
...
...
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