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
a05aec86
"ml/backend/git@developer.sourcefind.cn:OpenDAS/ollama.git" did not exist on "718eda1b3ec79b9b4a5f87ac8350d6ed7f63598b"
Commit
a05aec86
authored
Jan 15, 2025
by
Jonas Kaufmann
Browse files
orchestration/instantiation/base: run black formatter
parent
349e8ab7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
55 deletions
+31
-55
symphony/orchestration/simbricks/orchestration/instantiation/base.py
...chestration/simbricks/orchestration/instantiation/base.py
+31
-55
No files found.
symphony/orchestration/simbricks/orchestration/instantiation/base.py
View file @
a05aec86
...
@@ -49,8 +49,8 @@ class InstantiationEnvironment(util_base.IdObj):
...
@@ -49,8 +49,8 @@ class InstantiationEnvironment(util_base.IdObj):
def
__init__
(
def
__init__
(
self
,
self
,
workdir
:
pathlib
.
Path
=
pathlib
.
Path
.
cwd
()
/
pathlib
.
Path
(
'
simbricks-workdir
'
),
workdir
:
pathlib
.
Path
=
pathlib
.
Path
.
cwd
()
/
pathlib
.
Path
(
"
simbricks-workdir
"
),
simbricksdir
:
pathlib
.
Path
=
pathlib
.
Path
(
'
/simbricks
'
),
simbricksdir
:
pathlib
.
Path
=
pathlib
.
Path
(
"
/simbricks
"
),
):
):
super
().
__init__
()
super
().
__init__
()
self
.
_simbricksdir
:
str
=
simbricksdir
.
resolve
()
self
.
_simbricksdir
:
str
=
simbricksdir
.
resolve
()
...
@@ -58,15 +58,11 @@ class InstantiationEnvironment(util_base.IdObj):
...
@@ -58,15 +58,11 @@ class InstantiationEnvironment(util_base.IdObj):
self
.
_output_base
:
str
=
pathlib
.
Path
(
f
"
{
self
.
_workdir
}
/output"
).
resolve
()
self
.
_output_base
:
str
=
pathlib
.
Path
(
f
"
{
self
.
_workdir
}
/output"
).
resolve
()
self
.
_tmp_simulation_files
:
str
=
pathlib
.
Path
(
f
"
{
self
.
_workdir
}
/tmp"
).
resolve
()
self
.
_tmp_simulation_files
:
str
=
pathlib
.
Path
(
f
"
{
self
.
_workdir
}
/tmp"
).
resolve
()
self
.
_imgdir
:
str
=
pathlib
.
Path
(
f
"
{
self
.
_tmp_simulation_files
}
/imgs"
).
resolve
()
self
.
_imgdir
:
str
=
pathlib
.
Path
(
f
"
{
self
.
_tmp_simulation_files
}
/imgs"
).
resolve
()
self
.
_cpdir
:
str
=
pathlib
.
Path
(
self
.
_cpdir
:
str
=
pathlib
.
Path
(
f
"
{
self
.
_tmp_simulation_files
}
/checkpoints"
).
resolve
()
f
"
{
self
.
_tmp_simulation_files
}
/checkpoints"
self
.
_shm_base
:
str
=
pathlib
.
Path
(
f
"
{
self
.
_tmp_simulation_files
}
/shm"
).
resolve
()
).
resolve
()
self
.
_shm_base
:
str
=
pathlib
.
Path
(
f
"
{
self
.
_tmp_simulation_files
}
/shm"
).
resolve
()
class
Instantiation
()
:
class
Instantiation
:
__id_iter
=
itertools
.
count
()
__id_iter
=
itertools
.
count
()
...
@@ -94,9 +90,7 @@ class Instantiation():
...
@@ -94,9 +90,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
:
(
self
.
_sim_dependency
:
dict
[
sim_base
.
Simulator
,
set
[
sim_base
.
Simulator
]]
|
None
=
None
dict
[
sim_base
.
Simulator
,
set
[
sim_base
.
Simulator
]]
|
None
)
=
None
@
staticmethod
@
staticmethod
def
is_absolute_exists
(
path
:
str
)
->
bool
:
def
is_absolute_exists
(
path
:
str
)
->
bool
:
...
@@ -117,15 +111,11 @@ class Instantiation():
...
@@ -117,15 +111,11 @@ class Instantiation():
def
executor
(
self
,
executor
:
command_executor
.
Executor
):
def
executor
(
self
,
executor
:
command_executor
.
Executor
):
self
.
_executor
=
executor
self
.
_executor
=
executor
def
_get_opposing_interface
(
def
_get_opposing_interface
(
self
,
interface
:
sys_base
.
Interface
)
->
sys_base
.
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
def
_opposing_interface_within_same_sim
(
def
_opposing_interface_within_same_sim
(
self
,
interface
:
sys_base
.
Interface
)
->
bool
:
self
,
interface
:
sys_base
.
Interface
)
->
bool
:
opposing_interface
=
self
.
_get_opposing_interface
(
interface
=
interface
)
opposing_interface
=
self
.
_get_opposing_interface
(
interface
=
interface
)
component
=
interface
.
component
component
=
interface
.
component
opposing_component
=
opposing_interface
.
component
opposing_component
=
opposing_interface
.
component
...
@@ -177,9 +167,13 @@ class Instantiation():
...
@@ -177,9 +167,13 @@ class Instantiation():
enforce_existence
=
False
,
enforce_existence
=
False
,
)
)
def
_create_opposing_socket
(
self
,
socket
:
inst_socket
.
Socket
,
socket_type
:
inst_socket
.
SockType
)
->
inst_socket
.
Socket
:
def
_create_opposing_socket
(
self
,
socket
:
inst_socket
.
Socket
,
socket_type
:
inst_socket
.
SockType
)
->
inst_socket
.
Socket
:
new_ty
=
(
new_ty
=
(
inst_socket
.
SockType
.
LISTEN
if
socket
.
_type
==
inst_socket
.
SockType
.
CONNECT
else
inst_socket
.
SockType
.
CONNECT
inst_socket
.
SockType
.
LISTEN
if
socket
.
_type
==
inst_socket
.
SockType
.
CONNECT
else
inst_socket
.
SockType
.
CONNECT
)
)
if
new_ty
!=
socket_type
:
if
new_ty
!=
socket_type
:
raise
Exception
(
raise
Exception
(
...
@@ -212,9 +206,7 @@ class Instantiation():
...
@@ -212,9 +206,7 @@ class Instantiation():
# Check if other side already created a socket, and create an opposing one
# Check if other side already created a socket, and create an opposing one
socket
=
self
.
_get_opposing_socket_by_interface
(
interface
=
interface
)
socket
=
self
.
_get_opposing_socket_by_interface
(
interface
=
interface
)
if
socket
is
not
None
:
if
socket
is
not
None
:
new_socket
=
self
.
_create_opposing_socket
(
new_socket
=
self
.
_create_opposing_socket
(
socket
=
socket
,
socket_type
=
socket_type
)
socket
=
socket
,
socket_type
=
socket_type
)
self
.
_updated_tracker_mapping
(
interface
=
interface
,
socket
=
new_socket
)
self
.
_updated_tracker_mapping
(
interface
=
interface
,
socket
=
new_socket
)
print
(
f
"created socket:
{
new_socket
.
_path
}
"
)
print
(
f
"created socket:
{
new_socket
.
_path
}
"
)
return
new_socket
return
new_socket
...
@@ -283,9 +275,7 @@ class Instantiation():
...
@@ -283,9 +275,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_fragment
.
add_simulators
(
self
.
simulation
.
all_simulators
())
self
.
simulation
.
all_simulators
()
)
else
:
else
:
fragments
=
[
fragments
=
[
fragment
fragment
...
@@ -298,41 +288,33 @@ class Instantiation():
...
@@ -298,41 +288,33 @@ class Instantiation():
# TODO: this needs fixing...
# TODO: this needs fixing...
def
copy
(
self
)
->
Instantiation
:
def
copy
(
self
)
->
Instantiation
:
cop
=
Instantiation
(
sim
=
self
.
simulation
)
cop
=
Instantiation
(
sim
=
self
.
simulation
)
cop
.
simulation
=
copy
.
deepcopy
(
self
.
simulation
)
# maybe there is a smarter way of achieving this...
cop
.
simulation
=
copy
.
deepcopy
(
self
.
simulation
)
# maybe there is a smarter way of achieving this...
cop
.
artifact_name
=
self
.
artifact_name
cop
.
artifact_name
=
self
.
artifact_name
cop
.
artifact_paths
=
self
.
artifact_paths
cop
.
artifact_paths
=
self
.
artifact_paths
cop
.
_create_checkpoint
=
self
.
_create_checkpoint
cop
.
_create_checkpoint
=
self
.
_create_checkpoint
cop
.
_restore_checkpoint
=
self
.
_restore_checkpoint
cop
.
_restore_checkpoint
=
self
.
_restore_checkpoint
cop
.
_preserve_checkpoints
=
self
.
_preserve_checkpoints
cop
.
_preserve_checkpoints
=
self
.
_preserve_checkpoints
cop
.
preserve_tmp_folder
=
self
.
preserve_tmp_folder
cop
.
preserve_tmp_folder
=
self
.
preserve_tmp_folder
cop
.
_socket_per_interface
=
{}
cop
.
_socket_per_interface
=
{}
cop
.
_sim_dependency
=
None
cop
.
_sim_dependency
=
None
return
cop
return
cop
def
out_base_dir
(
self
)
->
str
:
def
out_base_dir
(
self
)
->
str
:
return
pathlib
.
Path
(
return
pathlib
.
Path
(
f
"
{
self
.
env
.
_output_base
}
/
{
self
.
simulation
.
name
}
/
{
self
.
_id
}
"
).
resolve
()
f
"
{
self
.
env
.
_output_base
}
/
{
self
.
simulation
.
name
}
/
{
self
.
_id
}
"
).
resolve
()
def
shm_base_dir
(
self
)
->
str
:
def
shm_base_dir
(
self
)
->
str
:
return
pathlib
.
Path
(
return
pathlib
.
Path
(
f
"
{
self
.
env
.
_shm_base
}
/
{
self
.
simulation
.
name
}
/
{
self
.
_id
}
"
).
resolve
()
f
"
{
self
.
env
.
_shm_base
}
/
{
self
.
simulation
.
name
}
/
{
self
.
_id
}
"
).
resolve
()
def
imgs_dir
(
self
)
->
str
:
def
imgs_dir
(
self
)
->
str
:
return
pathlib
.
Path
(
return
pathlib
.
Path
(
f
"
{
self
.
env
.
_imgdir
}
/
{
self
.
simulation
.
name
}
/
{
self
.
_id
}
"
).
resolve
()
f
"
{
self
.
env
.
_imgdir
}
/
{
self
.
simulation
.
name
}
/
{
self
.
_id
}
"
).
resolve
()
def
cpdir
(
self
)
->
str
:
def
cpdir
(
self
)
->
str
:
return
pathlib
.
Path
(
return
pathlib
.
Path
(
f
"
{
self
.
env
.
_cpdir
}
/
{
self
.
simulation
.
name
}
"
).
resolve
()
# /{self._id}"
f
"
{
self
.
env
.
_cpdir
}
/
{
self
.
simulation
.
name
}
"
# /{self._id}"
).
resolve
()
def
wrkdir
(
self
)
->
str
:
def
wrkdir
(
self
)
->
str
:
return
pathlib
.
Path
(
return
pathlib
.
Path
(
f
"
{
self
.
env
.
_workdir
}
/
{
self
.
simulation
.
name
}
"
).
resolve
()
# /{self._id}"
f
"
{
self
.
env
.
_workdir
}
/
{
self
.
simulation
.
name
}
"
# /{self._id}"
).
resolve
()
async
def
prepare
(
self
)
->
None
:
async
def
prepare
(
self
)
->
None
:
to_prepare
=
[
self
.
shm_base_dir
(),
self
.
imgs_dir
()]
to_prepare
=
[
self
.
shm_base_dir
(),
self
.
imgs_dir
()]
...
@@ -357,9 +339,7 @@ class Instantiation():
...
@@ -357,9 +339,7 @@ class Instantiation():
shutil
.
rmtree
(
td
,
ignore_errors
=
True
)
shutil
.
rmtree
(
td
,
ignore_errors
=
True
)
await
self
.
executor
.
rmtree
(
td
)
await
self
.
executor
.
rmtree
(
td
)
def
_join_paths
(
def
_join_paths
(
self
,
base
:
str
=
""
,
relative_path
:
str
=
""
,
enforce_existence
=
False
)
->
str
:
self
,
base
:
str
=
""
,
relative_path
:
str
=
""
,
enforce_existence
=
False
)
->
str
:
if
relative_path
.
startswith
(
"/"
):
if
relative_path
.
startswith
(
"/"
):
raise
Exception
(
raise
Exception
(
f
"cannot join with base=
{
base
}
because relative_path=
{
relative_path
}
starts with '/'"
f
"cannot join with base=
{
base
}
because relative_path=
{
relative_path
}
starts with '/'"
...
@@ -423,9 +403,7 @@ class Instantiation():
...
@@ -423,9 +403,7 @@ class Instantiation():
def
cpdir_subdir
(
self
,
sim
:
sim_base
.
Simulator
)
->
str
:
def
cpdir_subdir
(
self
,
sim
:
sim_base
.
Simulator
)
->
str
:
dir_path
=
f
"checkpoint.
{
sim
.
full_name
()
}
-
{
sim
.
_id
}
"
dir_path
=
f
"checkpoint.
{
sim
.
full_name
()
}
-
{
sim
.
_id
}
"
return
self
.
_join_paths
(
return
self
.
_join_paths
(
base
=
self
.
cpdir
(),
relative_path
=
dir_path
,
enforce_existence
=
False
)
base
=
self
.
cpdir
(),
relative_path
=
dir_path
,
enforce_existence
=
False
)
def
get_simmulator_output_dir
(
self
,
sim
:
sim_base
.
Simulator
)
->
str
:
def
get_simmulator_output_dir
(
self
,
sim
:
sim_base
.
Simulator
)
->
str
:
dir_path
=
f
"output.
{
sim
.
full_name
()
}
-
{
sim
.
_id
}
"
dir_path
=
f
"output.
{
sim
.
full_name
()
}
-
{
sim
.
_id
}
"
...
@@ -443,9 +421,7 @@ class Instantiation():
...
@@ -443,9 +421,7 @@ class Instantiation():
relative_path
=
f
"out.json"
,
relative_path
=
f
"out.json"
,
)
)
def
find_sim_by_interface
(
def
find_sim_by_interface
(
self
,
interface
:
sys_base
.
Interface
)
->
sim_base
.
Simulator
:
self
,
interface
:
sys_base
.
Interface
)
->
sim_base
.
Simulator
:
return
self
.
find_sim_by_spec
(
spec
=
interface
.
component
)
return
self
.
find_sim_by_spec
(
spec
=
interface
.
component
)
def
find_sim_by_spec
(
self
,
spec
:
sys_base
.
Component
)
->
sim_base
.
Simulator
:
def
find_sim_by_spec
(
self
,
spec
:
sys_base
.
Component
)
->
sim_base
.
Simulator
:
...
...
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